提交 558dff52 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

fix: remove useless page & add annotation

上级 cb82131b
...@@ -2,37 +2,48 @@ ...@@ -2,37 +2,48 @@
import { state, setLifeCycleNum } from './store/index.uts' import { state, setLifeCycleNum } from './store/index.uts'
export default { export default {
onLaunch: function () { onLaunch: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000) setLifeCycleNum(state.lifeCycleNum + 1000)
console.log("App Launch"); console.log('App Launch')
// const performance: Performance = uni.getPerformance() const performance: Performance = uni.getPerformance()
// const observer1: PerformanceObserver = performance.createObserver((entryList: PerformanceObserverEntryList) => { const observer1: PerformanceObserver = performance.createObserver(
// console.log("observer1:entryList.getEntries()" + JSON.stringify(entryList.getEntries())) (entryList: PerformanceObserverEntryList) => {
// }) console.log(
// observer1.observe({ entryTypes: ['render', 'navigation'] } as PerformanceObserverOptions) 'observer1:entryList.getEntries()' +
JSON.stringify(entryList.getEntries())
)
}
)
observer1.observe({
entryTypes: ['render', 'navigation'],
} as PerformanceObserverOptions)
}, },
onShow: function () { onShow: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100) setLifeCycleNum(state.lifeCycleNum + 100)
console.log("App Show"); console.log('App Show')
}, },
onHide: function () { onHide: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100) setLifeCycleNum(state.lifeCycleNum - 100)
console.log("App Hide"); console.log('App Hide')
}, },
onLastPageBackPress: function (): boolean | null { onLastPageBackPress: function (): boolean | null {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1000) setLifeCycleNum(state.lifeCycleNum - 1000)
uni.showToast({ uni.showToast({
title: "再按一次退出应用", title: '再按一次退出应用',
position: "bottom", position: 'bottom',
}); })
return null; return null
}, },
}; }
</script> </script>
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
@import "./common/uni.css"; @import './common/uni.css';
/* #ifdef H5 */ /* #ifdef H5 */
@media screen and (min-width: 768px) { @media screen and (min-width: 768px) {
......
<template> <template>
<view> <view>
<page-head title="navigate"></page-head> <page-head title="navigate"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view style="flex-direction: row"> <view style="flex-direction: row">
<text style="width: 170px">onLoad触发时间戳:</text> <text style="width: 170px">onLoad触发时间戳:</text>
<text style="text-align: right">{{ onLoadTime }}</text> <text style="text-align: right">{{ onLoadTime }}</text>
</view> </view>
<view style="flex-direction: row"> <view style="flex-direction: row">
<text style="width: 170px">onReady触发时间戳:</text> <text style="width: 170px">onReady触发时间戳:</text>
<text style="text-align: right">{{ onReadyTime }}</text> <text style="text-align: right">{{ onReadyTime }}</text>
</view> </view>
<view style="flex-direction: row"> <view style="flex-direction: row">
<text style="width: 170px">onUnload触发时间戳:</text> <text style="width: 170px">onUnload触发时间戳:</text>
<text style="text-align: right">见控制台</text> <text style="text-align: right">见控制台</text>
</view> </view>
<view style="flex-direction: row"> <view style="flex-direction: row">
<text style="width: 170px">onShow触发时间戳:</text> <text style="width: 170px">onShow触发时间戳:</text>
<text style="text-align: right">{{ onShowTime }}</text> <text style="text-align: right">{{ onShowTime }}</text>
</view> </view>
<view style="flex-direction: row"> <view style="flex-direction: row">
<text style="width: 170px">onHide触发时间戳:</text> <text style="width: 170px">onHide触发时间戳:</text>
<text style="text-align: right">{{ onHideTime }}</text> <text style="text-align: right">{{ onHideTime }}</text>
</view> </view>
<text>onBackPress触发时间戳:见控制台</text> <text>onBackPress触发时间戳:见控制台</text>
<!-- <view style="flex-direction: row"> <!-- <view style="flex-direction: row">
<text style="width: 170px">onBackPress触发时间戳:</text> <text style="width: 170px">onBackPress触发时间戳:</text>
<text style="text-align: right">见控制台</text> <text style="text-align: right">见控制台</text>
</view> --> </view> -->
<view class="uni-btn-v"> <view class="uni-btn-v">
<button @tap="navigateTo" class="uni-btn"> <button @tap="navigateTo" class="uni-btn">
跳转新页面,并传递数据 跳转新页面,并传递数据
</button> </button>
<button @tap="navigateBack" class="uni-btn">返回上一页</button> <button @tap="navigateBack" class="uni-btn">返回上一页</button>
<button @tap="redirectTo" class="uni-btn">在当前页面打开</button> <button @tap="redirectTo" class="uni-btn">在当前页面打开</button>
<button @tap="switchTab" class="uni-btn">切换到模板选项卡</button> <button @tap="switchTab" class="uni-btn">切换到模板选项卡</button>
<button @tap="reLaunch" class="uni-btn">关闭所有页面,打开首页</button> <button @tap="reLaunch" class="uni-btn">关闭所有页面,打开首页</button>
<button @tap="customAnimation" class="uni-btn"> <button @tap="customAnimation" class="uni-btn">
使用自定义动画打开页面 使用自定义动画打开页面
</button> </button>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script lang="ts"> <script lang="ts">
import { setLifeCycleNum, state } from '@/store/index.uts' import { setLifeCycleNum, state } from '@/store/index.uts'
export default { export default {
data() { data() {
return { return {
onLoadTime: 0, onLoadTime: 0,
onShowTime: 0, onShowTime: 0,
onReadyTime: 0, onReadyTime: 0,
onHideTime: 0, onHideTime: 0,
} }
}, },
onLoad() { onLoad() {
this.onLoadTime = Date.now() this.onLoadTime = Date.now()
console.log('onLoad', this.onLoadTime) console.log('onLoad', this.onLoadTime)
}, },
onShow() { onShow() {
this.onShowTime = Date.now() this.onShowTime = Date.now()
console.log('onShow', this.onShowTime) console.log('onShow', this.onShowTime)
}, },
onReady() { onReady() {
this.onReadyTime = Date.now() this.onReadyTime = Date.now()
console.log('onReady', this.onReadyTime) console.log('onReady', this.onReadyTime)
}, },
onHide() { onHide() {
this.onHideTime = Date.now() this.onHideTime = Date.now()
console.log('onHide', Date.now()) console.log('onHide', Date.now())
}, },
onUnload() { onUnload() {
console.log('onUnLoad', Date.now()) console.log('onUnLoad', Date.now())
}, },
/* onBackPress() { /* onBackPress() {
console.log('onBackPress', Date.now()) // 为何不生效??? console.log('onBackPress', Date.now()) // 为何不生效???
// 要把event也打出来 // 要把event也打出来
}, */ }, */
methods: { methods: {
navigateTo() { navigateTo() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello', url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
}) })
}, },
navigateBack() { navigateBack() {
uni.navigateBack({ uni.navigateBack({
delta: 1, delta: 1,
}) })
}, },
redirectTo() { redirectTo() {
uni.redirectTo({ uni.redirectTo({
url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello', url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
}) })
}, },
switchTab() { switchTab() {
uni.switchTab({ uni.switchTab({
url: '/pages/tabBar/template', url: '/pages/tabBar/template',
}) })
}, },
reLaunch() { reLaunch() {
uni.reLaunch({ uni.reLaunch({
url: '/pages/tabBar/component', url: '/pages/tabBar/component',
}) })
}, },
customAnimation() { customAnimation() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/API/navigator/new-page/new-uvue-page-1?data=使用自定义动画打开页面', url: '/pages/API/navigator/new-page/new-uvue-page-1?data=使用自定义动画打开页面',
animationType: 'slide-in-bottom', animationType: 'slide-in-bottom',
animationDuration: 200, animationDuration: 200,
}) })
}, },
setLifeCycleNum(num : number) { // 自动化测试
setLifeCycleNum(num) setLifeCycleNum(num: number) {
}, setLifeCycleNum(num)
getLifeCycleNum() : number { },
return state.lifeCycleNum // 自动化测试
}, getLifeCycleNum(): number {
}, return state.lifeCycleNum
} },
</script> },
\ No newline at end of file }
</script>
const PAGE_PATH = '/pages/API/page-lifecycle/page-lifecycle'
const INTERMEDIATE_PAGE_PATH = '/pages/API/navigator/navigator'
describe('page-lifecycle', () => {
let page
let lifeCycleNum
beforeAll(async () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(1100)
const initLifecycleNum = 0
await page.callMethod('setLifeCycleNum', initLifecycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(initLifecycleNum)
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(1000)
})
it('onLoad onShow onReady', async () => {
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(120)
})
it('onHide', async () => {
page = await program.navigateTo(INTERMEDIATE_PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(110)
page = await program.navigateBack()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(120)
})
it('onUnload', async () => {
page = await program.redirectTo(INTERMEDIATE_PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(20)
})
it('onBackPress', async () => {
page = await program.navigateTo(PAGE_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(140)
page = await program.navigateBack()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(30)
})
it('onLastPageBackPress', async () => {
page = await program.navigateBack()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(-970)
const resetLifecycleNum = 1100
await page.callMethod('setLifeCycleNum', resetLifecycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(resetLifecycleNum)
})
})
<template>
<view class="page">
<text>page lifecycle</text>
</view>
</template>
<script lang="ts">
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
onLoad() {
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('Page onLoad')
},
onShow() {
setLifeCycleNum(state.lifeCycleNum + 10)
console.log('Page onShow')
},
onReady() {
setLifeCycleNum(state.lifeCycleNum + 10)
console.log('Page onReady')
},
onHide() {
setLifeCycleNum(state.lifeCycleNum - 10)
console.log('Page onHide')
},
onUnload() {
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('Page onUnload')
},
onBackPress(options: Map<string, string>) : boolean | null {
setLifeCycleNum(state.lifeCycleNum - 10)
console.log('Page onBackPress',options)
return null
},
methods: {
getLifeCycleNum() : number {
return state.lifeCycleNum
}
},
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册