From 253c5e57bcc5767fc1219f03dff4de49287cef96 Mon Sep 17 00:00:00 2001 From: huozhongyi Date: Mon, 15 Nov 2021 15:48:46 +0800 Subject: [PATCH 1/3] feat(harmony): add navigator component --- .../components-harmony/navigator/index.css | 7 ++ .../components-harmony/navigator/index.hml | 7 ++ .../components-harmony/navigator/index.js | 87 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 packages/taro-harmony/src/components/components-harmony/navigator/index.css create mode 100644 packages/taro-harmony/src/components/components-harmony/navigator/index.hml create mode 100644 packages/taro-harmony/src/components/components-harmony/navigator/index.js diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.css b/packages/taro-harmony/src/components/components-harmony/navigator/index.css new file mode 100644 index 000000000000..c35b50acc107 --- /dev/null +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.css @@ -0,0 +1,7 @@ +.navigate { + overflow: hidden; +} + +.navigate:hover { + background-color: #CCCCCC; +} diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.hml b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml new file mode 100644 index 000000000000..77da29a6528c --- /dev/null +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml @@ -0,0 +1,7 @@ + diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.js b/packages/taro-harmony/src/components/components-harmony/navigator/index.js new file mode 100644 index 000000000000..8f831a01a39e --- /dev/null +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.js @@ -0,0 +1,87 @@ +import router from '@system.router' +import { createOption } from '../utils' + +export default createOption({ + data () { + return { + targetObj: { + navigate: 'push', + redirect: 'replace', + switchTab: 'push', + reLaunch: 'replace', + navigateBack: 'back' + } + } + }, + props: [ + 'id', + 'target', + 'url', + 'openType', + 'delta', + 'appId', + 'path', + 'extraData', + 'version', + 'hoverClass', + 'hoverStopPropagation', + 'hoverStartTime', + 'hoverStayTime' + ], + + onClick () { + const { openType = 'navigate', url = '' } = this + this.getRouterFunc(`${openType}`, url) + }, + + getRouterFunc (method, url) { + // switchTab目前实现不了 + const methodName = this.targetObj[method] + const [uri, queryString = ''] = url.split('?') + const params = this.queryToJson(queryString) + + const uriObj = url ? { uri: uri.replace(/^\//, '') } : {} + + const paramsObj = queryString ? { params } : {} + + if (method === 'reLaunch') { + router.clear() + } + + router[methodName]({ + ...uriObj, + ...paramsObj + }) + }, + + queryToJson (str) { + const dec = decodeURIComponent + const qp = str.split('&') + const ret = {} + let name + let val + for (let i = 0, l = qp.length, item; i < l; ++i) { + item = qp[i] + if (item.length) { + const s = item.indexOf('=') + if (s < 0) { + name = dec(item) + val = '' + } else { + name = dec(item.slice(0, s)) + val = dec(item.slice(s + 1)) + } + if (typeof ret[name] === 'string') { + ret[name] = [ret[name]] + } + + if (Array.isArray(ret[name])) { + ret[name].push(val) + } else { + ret[name] = val + } + } + } + return ret + } +}) From 163870362a2c0a84740c8c6d7bb2b2625dbcb436 Mon Sep 17 00:00:00 2001 From: huozhongyi Date: Mon, 15 Nov 2021 16:52:24 +0800 Subject: [PATCH 2/3] feat(harmony): add hover navigator component --- .../components-harmony/navigator/index.css | 5 +- .../components-harmony/navigator/index.hml | 6 +- .../components-harmony/navigator/index.js | 71 ++++++++++++++----- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.css b/packages/taro-harmony/src/components/components-harmony/navigator/index.css index c35b50acc107..361795c5fddd 100644 --- a/packages/taro-harmony/src/components/components-harmony/navigator/index.css +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.css @@ -1,7 +1,8 @@ .navigate { overflow: hidden; + transition: all linear 0.2s; } -.navigate:hover { - background-color: #CCCCCC; +.navigator-hover { + background-color: #dedede; } diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.hml b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml index 77da29a6528c..b771fcb3bbea 100644 --- a/packages/taro-harmony/src/components/components-harmony/navigator/index.hml +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml @@ -1,7 +1,9 @@ diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.js b/packages/taro-harmony/src/components/components-harmony/navigator/index.js index 8f831a01a39e..7912636935cd 100644 --- a/packages/taro-harmony/src/components/components-harmony/navigator/index.js +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.js @@ -2,6 +2,30 @@ import router from '@system.router' import { createOption } from '../utils' export default createOption({ + props: { + id: { + default: '' + }, + cls: { + default: '' + }, + openType: { + default: 'navigate' + }, + url: { + default: '' + }, + hoverStartTime: { + default: 50 + }, + hoverStayTime: { + default: 600 + }, + hoverClass: { + default: 'navigator-hover' + } + }, + data () { return { targetObj: { @@ -10,24 +34,17 @@ export default createOption({ switchTab: 'push', reLaunch: 'replace', navigateBack: 'back' - } + }, + hover: false, + touch: false + } + }, + + computed: { + clsHover () { + return this.hover ? this.hoverClass : '' } }, - props: [ - 'id', - 'target', - 'url', - 'openType', - 'delta', - 'appId', - 'path', - 'extraData', - 'version', - 'hoverClass', - 'hoverStopPropagation', - 'hoverStartTime', - 'hoverStayTime' - ], onClick () { const { openType = 'navigate', url = '' } = this @@ -83,5 +100,27 @@ export default createOption({ } } return ret + }, + + onTouchStart () { + this.touch = true + if (this.hoverClass) { + setTimeout(() => { + if (this.touch) { + this.hover = true + } + }, this.hoverStartTime) + } + }, + + onTouchEnd () { + this.touch = false + if (this.hoverClass) { + setTimeout(() => { + if (!this.touch) { + this.hover = false + } + }, this.hoverStayTime) + } } }) From 5e7d3f4489ba54d599029cdc0e4932aaf5ac1442 Mon Sep 17 00:00:00 2001 From: huozhongyi Date: Sat, 27 Nov 2021 14:27:08 +0800 Subject: [PATCH 3/3] feat: change harmony com some quest --- .../components-harmony/navigator/index.hml | 2 +- .../components-harmony/navigator/index.js | 38 +------------------ .../components-harmony/utils/index.js | 31 +++++++++++++++ 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/packages/taro-harmony/src/components/components-harmony/navigator/index.hml b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml index b771fcb3bbea..f66919327b0f 100644 --- a/packages/taro-harmony/src/components/components-harmony/navigator/index.hml +++ b/packages/taro-harmony/src/components/components-harmony/navigator/index.hml @@ -1,6 +1,6 @@