Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
239477b9
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
239477b9
编写于
7月 17, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: navigator & lifecycle
上级
4f347962
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
301 addition
and
85 deletion
+301
-85
pages.json
pages.json
+34
-27
pages/API/navigator/navigator.uvue
pages/API/navigator/navigator.uvue
+105
-17
pages/API/navigator/new-page/new-page-1.uvue
pages/API/navigator/new-page/new-page-1.uvue
+28
-0
pages/API/navigator/new-page/new-page-2.test.js
pages/API/navigator/new-page/new-page-2.test.js
+43
-25
pages/API/navigator/new-page/new-page-2.uvue
pages/API/navigator/new-page/new-page-2.uvue
+87
-0
store/index.uts
store/index.uts
+4
-16
未找到文件。
pages.json
浏览文件 @
239477b9
...
@@ -121,13 +121,13 @@
...
@@ -121,13 +121,13 @@
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"大图测试"
"navigationBarTitleText"
:
"大图测试"
}
}
},
},
{
{
"path"
:
"pages/component/video/video"
,
"path"
:
"pages/component/video/video"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"video"
"navigationBarTitleText"
:
"video"
}
}
},
},
{
{
"path"
:
"pages/component/web-view/web-view"
,
"path"
:
"pages/component/web-view/web-view"
,
"style"
:
{
"style"
:
{
...
@@ -154,9 +154,16 @@
...
@@ -154,9 +154,16 @@
}
}
},
},
{
{
"path"
:
"pages/API/navigator/new-page/new-page"
,
"path"
:
"pages/API/navigator/new-page/new-page
-1
"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"新页面"
"navigationBarTitleText"
:
"新页面-1"
}
},
{
"path"
:
"pages/API/navigator/new-page/new-page-2"
,
"style"
:
{
"navigationBarTitleText"
:
"新页面-2"
,
"enablePullDownRefresh"
:
true
}
}
},
},
{
{
...
@@ -592,24 +599,24 @@
...
@@ -592,24 +599,24 @@
"navigationBarTitleText"
:
"详情示例"
"navigationBarTitleText"
:
"详情示例"
}
}
},
},
{
{
"path"
:
"pages/template/swiper-vertical-video/swiper-vertical-video"
,
"path"
:
"pages/template/swiper-vertical-video/swiper-vertical-video"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
""
"navigationBarTitleText"
:
""
}
}
},
},
{
{
"path"
:
"pages/template/custom-pull-page/custom-pull-page"
,
"path"
:
"pages/template/custom-pull-page/custom-pull-page"
,
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"自定义下拉上拉效果"
"navigationBarTitleText"
:
"自定义下拉上拉效果"
}
}
},
},
{
{
"path"
:
"pages/template/scroll-fold-nav/scroll-fold-nav"
,
"path"
:
"pages/template/scroll-fold-nav/scroll-fold-nav"
,
"style"
:
{
"style"
:
{
"navigationStyle"
:
"custom"
"navigationStyle"
:
"custom"
}
}
},
},
{
{
"path"
:
"pages/API/get-battery-info/get-battery-info"
,
"path"
:
"pages/API/get-battery-info/get-battery-info"
,
"style"
:
{
"style"
:
{
...
...
pages/API/navigator/navigator.uvue
浏览文件 @
239477b9
...
@@ -77,17 +77,101 @@ export default {
...
@@ -77,17 +77,101 @@ export default {
console.log('onUnload', Date.now())
console.log('onUnload', Date.now())
},
},
methods: {
methods: {
reLaunch() {
uni.reLaunch({
url: '/pages/tabBar/component',
success(result) {
console.log('reLaunch success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('reLaunch fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('reLaunch complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
navigateTo() {
navigateTo() {
uni.navigateTo({
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page?data=Hello',
url: '/pages/API/navigator/new-page/new-page-1?data=Hello',
success(result) {
console.log('navigateTo success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateTo fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateTo complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
navigateToErrorPage() {
uni.navigateTo({
url: '/pages/error-page/error-page',
success(result) {
success(result) {
console.log('navigateTo success', result.errMsg)
console.log('navigateTo success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
},
fail(error) {
fail(error) {
console.log('navigateTo fail', error.errMsg)
console.log('navigateTo fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
complete(result) {
complete(result) {
console.log('navigateTo complete', result.errMsg)
console.log('navigateTo complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
navigateToDebounce() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1?data=debounce',
success(result) {
console.log('navigateTo success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateTo fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateTo complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1?data=debounce',
success(result) {
console.log('navigateTo success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
fail(error) {
console.log('navigateTo fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
complete(result) {
console.log('navigateTo complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
})
})
},
},
...
@@ -95,26 +179,38 @@ export default {
...
@@ -95,26 +179,38 @@ export default {
uni.navigateBack({
uni.navigateBack({
success(result) {
success(result) {
console.log('navigateBack success', result.errMsg)
console.log('navigateBack success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
fail(error) {
fail(error) {
console.log('navigateBack fail', error.errMsg)
console.log('navigateBack fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
},
complete(result) {
complete(result) {
console.log('navigateBack complete', result.errMsg)
console.log('navigateBack complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
})
})
},
},
redirectTo() {
redirectTo() {
uni.redirectTo({
uni.redirectTo({
url: '/pages/API/navigator/new-page/new-page?data=Hello',
url: '/pages/API/navigator/new-page/new-page
-1
?data=Hello',
success(result) {
success(result) {
console.log('redirectTo success', result.errMsg)
console.log('redirectTo success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
fail(error) {
fail(error) {
console.log('redirectTo fail', error.errMsg)
console.log('redirectTo fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
},
complete(result) {
complete(result) {
console.log('redirectTo complete', result.errMsg)
console.log('redirectTo complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
})
})
},
},
...
@@ -123,32 +219,24 @@ export default {
...
@@ -123,32 +219,24 @@ export default {
url: '/pages/tabBar/template',
url: '/pages/tabBar/template',
success(result) {
success(result) {
console.log('switchTab success', result.errMsg)
console.log('switchTab success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
},
fail(error) {
fail(error) {
console.log('switchTab fail', error.errMsg)
console.log('switchTab fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
},
complete(result) {
complete(result) {
console.log('switchTab complete', result.errMsg)
console.log('switchTab complete', result.errMsg)
},
// 自动化测试
})
setLifeCycleNum(state.lifeCycleNum + 1)
},
reLaunch() {
uni.reLaunch({
url: '/pages/tabBar/component',
success(result) {
console.log('reLaunch success', result.errMsg)
},
fail(error) {
console.log('reLaunch fail', error.errMsg)
},
complete(result) {
console.log('reLaunch complete', result.errMsg)
},
},
})
})
},
},
customAnimation() {
customAnimation() {
uni.navigateTo({
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page?data=自定义动画打开页面',
url: '/pages/API/navigator/new-page/new-page
-1
?data=自定义动画打开页面',
animationType: 'slide-in-bottom',
animationType: 'slide-in-bottom',
animationDuration: 200,
animationDuration: 200,
})
})
...
...
pages/API/navigator/new-page/new-page-1.uvue
0 → 100644
浏览文件 @
239477b9
<template>
<view class="uni-padding-wrap">
<text>onLoad 接收到参数</text>
<text>data: {{ data }}</text>
</view>
</template>
<script lang="ts">
import { state } from '@/store/index.uts'
export default {
data() {
return {
data: '',
}
},
onLoad(options: OnLoadOptions) {
console.log('new-page2 onLoad', options)
if (options.has('data')) {
this.data = options.get('data')!
}
},
methods: {
// 自动化测试
getLifeCycleNum(): number {
return state.lifeCycleNum
},
},
}
</script>
pages/API/navigator/new-page/new-page.test.js
→
pages/API/navigator/new-page/new-page
-2
.test.js
浏览文件 @
239477b9
const
PAGE_PATH
=
'
/pages/API/navigator/new-page/new-page
'
const
PAGE_PATH
=
'
/pages/API/navigator/new-page/new-page
-2
'
const
INTERMEDIATE_PAGE_PATH
=
'
/pages/API/navigator/navigator
'
const
INTERMEDIATE_PAGE_PATH
=
'
/pages/API/navigator/navigator
'
let
page
let
lifeCycleNum
describe
(
'
page-lifecycle
'
,
()
=>
{
describe
(
'
app-lifecycle
'
,
()
=>
{
let
page
it
(
'
onLaunch onShow
'
,
async
()
=>
{
let
lifeCycleNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
INTERMEDIATE_PAGE_PATH
)
page
=
await
program
.
reLaunch
(
INTERMEDIATE_PAGE_PATH
)
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
expect
(
lifeCycleNum
).
toBe
(
1100
)
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
100
)
const
initLifecycleNum
=
0
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
initLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
initLifecycleNum
)
expect
(
lifeCycleNum
).
toBe
(
0
)
})
})
describe
(
'
page-lifecycle
'
,
()
=>
{
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
await
page
.
waitFor
(
1000
)
})
it
(
'
onLoad onShow onReady
'
,
async
()
=>
{
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
120
)
expect
(
lifeCycleNum
).
toBe
(
120
)
})
})
it
(
'
onPullDownRefresh
'
,
async
()
=>
{
await
page
.
callMethod
(
'
pullDownRefresh
'
)
await
page
.
waitFor
(
1500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
130
)
})
// TODO: pageScrollTo 无法触发 onReachBottom, 待修复后调整 lifeCycleNum
it
(
'
onPageScroll onReachBottom
'
,
async
()
=>
{
await
program
.
pageScrollTo
(
2000
)
const
data
=
await
page
.
data
()
expect
(
data
.
isScrolled
).
toBe
(
true
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
130
)
})
it
(
'
onHide
'
,
async
()
=>
{
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
INTERMEDIATE_PAGE_PATH
)
page
=
await
program
.
navigateTo
(
INTERMEDIATE_PAGE_PATH
)
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1
1
0
)
expect
(
lifeCycleNum
).
toBe
(
1
2
0
)
page
=
await
program
.
navigateBack
()
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1
2
0
)
expect
(
lifeCycleNum
).
toBe
(
1
3
0
)
})
})
it
(
'
onUnload
'
,
async
()
=>
{
it
(
'
onUnload
'
,
async
()
=>
{
page
=
await
program
.
redirectTo
(
INTERMEDIATE_PAGE_PATH
)
page
=
await
program
.
redirectTo
(
INTERMEDIATE_PAGE_PATH
)
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
0
)
expect
(
lifeCycleNum
).
toBe
(
3
0
)
})
})
it
(
'
onBackPress
'
,
async
()
=>
{
it
(
'
onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
140
)
expect
(
lifeCycleNum
).
toBe
(
150
)
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
30
)
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
1000
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
-
970
)
expect
(
lifeCycleNum
).
toBe
(
40
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
})
})
})
pages/API/navigator/new-page/new-page.uvue
→
pages/API/navigator/new-page/new-page
-2
.uvue
浏览文件 @
239477b9
<template>
<template>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap container">
<text>onLoad 接收到参数</text>
<button @click="pageScrollTo">scrollToBottom</button>
<text>data: {{ data }}</text>
</view>
</view>
</template>
</template>
<script lang="ts">
<script lang="ts">
...
@@ -9,14 +8,10 @@ import { state, setLifeCycleNum } from '@/store/index.uts'
...
@@ -9,14 +8,10 @@ import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
export default {
data() {
data() {
return {
return {
data: ''
,
isScrolled: false
,
}
}
},
},
onLoad(options: OnLoadOptions) {
onLoad(_: OnLoadOptions) {
console.log('new-page onLoad', options)
if(options.has('data')) {
this.data = options.get('data')!
}
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
setLifeCycleNum(state.lifeCycleNum + 100)
},
},
...
@@ -28,15 +23,29 @@ export default {
...
@@ -28,15 +23,29 @@ export default {
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 10)
setLifeCycleNum(state.lifeCycleNum + 10)
},
},
onHide() {
onPullDownRefresh() {
console.log('onPullDownRefresh')
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 10)
setLifeCycleNum(state.lifeCycleNum + 10)
},
onPageScroll(_) {
// 自动化测试
this.isScrolled = true
},
onReachBottom() {
console.log('onReachBottom')
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 10)
},
},
onBackPress(_: OnBackPressOptions): boolean | null {
onBackPress(_: OnBackPressOptions): boolean | null {
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 10)
setLifeCycleNum(state.lifeCycleNum - 10)
return null
return null
},
},
onHide() {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 10)
},
onUnload() {
onUnload() {
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100)
setLifeCycleNum(state.lifeCycleNum - 100)
...
@@ -50,6 +59,29 @@ export default {
...
@@ -50,6 +59,29 @@ export default {
setLifeCycleNum(num: number) {
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
setLifeCycleNum(num)
},
},
pullDownRefresh() {
uni.startPullDownRefresh({
success() {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1000)
},
})
},
pageScrollTo(){
uni.pageScrollTo({
scrollTop: 1200,
complete(res){
console.warn('pageScrollTo', res)
}
})
}
},
},
}
}
</script>
</script>
<style>
.container {
height: 1200px;
}
</style>
store/index.uts
浏览文件 @
239477b9
export type State = {
class State {
colorIndex: number,
constructor(public lifeCycleNum: number) {
currentColor: string,
}
lifeCycleNum: number
}
}
const colorList: string[] = ['#FF0000', '#00FF00', '#0000FF']
export const state = reactive(new State(0))
export const state = reactive({
colorIndex: 0,
currentColor: colorList[0],
lifeCycleNum: 0
} as State)
export const setColorIndex = (index: number) => {
state.colorIndex = index
state.currentColor = colorList[index]
}
export const setLifeCycleNum = (num: number) => {
export const setLifeCycleNum = (num: number) => {
state.lifeCycleNum = num
state.lifeCycleNum = num
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录