-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(harmony): add navigator component (#10664)
* feat(harmony): add navigator component * feat(harmony): add hover navigator component * feat: change harmony com some quest Co-authored-by: huozhongyi <[email protected]>
- Loading branch information
1 parent
13bfccd
commit ffed3ef
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/taro-harmony/src/components/components-harmony/navigator/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.navigate { | ||
overflow: hidden; | ||
transition: all linear 0.2s; | ||
} | ||
|
||
.navigator-hover { | ||
background-color: #dedede; | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/taro-harmony/src/components/components-harmony/navigator/index.hml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="{{id}}" | ||
class="{{clsHover}}" | ||
@click="onClick" | ||
@touchstart="onTouchStart" | ||
@touchend="onTouchEnd" | ||
> | ||
<slot></slot> | ||
</div> |
92 changes: 92 additions & 0 deletions
92
packages/taro-harmony/src/components/components-harmony/navigator/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import router from '@system.router' | ||
import { createOption, queryToJson } from '../utils' | ||
|
||
export default createOption({ | ||
props: { | ||
id: { | ||
default: '' | ||
}, | ||
openType: { | ||
default: 'navigate' | ||
}, | ||
url: { | ||
default: '' | ||
}, | ||
hoverStartTime: { | ||
default: 50 | ||
}, | ||
hoverStayTime: { | ||
default: 600 | ||
}, | ||
hoverClass: { | ||
default: 'navigator-hover' | ||
} | ||
}, | ||
|
||
data () { | ||
return { | ||
targetObj: { | ||
navigate: 'push', | ||
redirect: 'replace', | ||
switchTab: 'push', | ||
reLaunch: 'replace', | ||
navigateBack: 'back' | ||
}, | ||
hover: false, | ||
touch: false | ||
} | ||
}, | ||
|
||
computed: { | ||
clsHover () { | ||
return this.hover ? this.hoverClass : '' | ||
} | ||
}, | ||
|
||
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 = queryToJson(queryString) | ||
|
||
const uriObj = url ? { uri: uri.replace(/^\//, '') } : {} | ||
|
||
const paramsObj = queryString ? { params } : {} | ||
|
||
if (method === 'reLaunch') { | ||
router.clear() | ||
} | ||
|
||
router[methodName]({ | ||
...uriObj, | ||
...paramsObj | ||
}) | ||
}, | ||
|
||
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) | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters