refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,454 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view>
|
||||
<page-head title="navigate"></page-head>
|
||||
<page-intro content="本页演示页面路由:展示 onLoad/onShow/onReady 等生命周期时间戳;通过按钮跳转新页、返回、redirect 等,可传递参数。"></page-intro>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<view style="flex-direction: row;">
|
||||
<switch @change="onChange"></switch>
|
||||
<view class="uni-title">是否启用共享元素动画</view>
|
||||
</view>
|
||||
<share-element :share-key="data.shareElementKey">
|
||||
<image style="width: 250px; height: 176px;" src="/static/shuijiao.jpg" mode="scaleToFill"></image>
|
||||
</share-element>
|
||||
<text style="font-size: 13px;" >注意:开启共享元素动画后仅支持slide-in-right和fade-in动画效果</text>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP && !VUE3-VAPOR -->
|
||||
<image style="width: 250px; height: 176px;" src="/static/shuijiao.jpg" mode="scaleToFill"></image>
|
||||
<!-- #endif -->
|
||||
<view class="uni-padding-wrap uni-common-mt uni-common-mb">
|
||||
<view class="direction-row">
|
||||
<text class="label">onLoad触发时间戳:</text>
|
||||
<text>{{ data.onLoadTime }}</text>
|
||||
</view>
|
||||
<view class="direction-row">
|
||||
<text class="label">onShow触发时间戳:</text>
|
||||
<text>{{ data.onShowTime }}</text>
|
||||
</view>
|
||||
<view class="direction-row">
|
||||
<text class="label">onReady触发时间戳:</text>
|
||||
<text>{{ data.onReadyTime }}</text>
|
||||
</view>
|
||||
<view class="direction-row">
|
||||
<text class="label">onHide触发时间戳:</text>
|
||||
<text>{{ data.onHideTime }}</text>
|
||||
</view>
|
||||
<view class="direction-row">
|
||||
<text class="label">onBackPress触发时间戳:</text>
|
||||
<text>见控制台</text>
|
||||
</view>
|
||||
<view class="direction-row">
|
||||
<text class="label">onUnload触发时间戳:</text>
|
||||
<text>见控制台</text>
|
||||
</view>
|
||||
<view class="uni-btn-v">
|
||||
<button @tap="navigateTo" class="uni-btn">
|
||||
跳转新页面,并传递数据
|
||||
</button>
|
||||
<button @tap="navigateBack" class="uni-btn">返回上一页</button>
|
||||
<button @tap="redirectTo" class="uni-btn">在当前页面打开</button>
|
||||
<button @tap="switchTab" class="uni-btn">切换到模板选项卡</button>
|
||||
<button @tap="reLaunch" class="uni-btn">
|
||||
关闭所有页面,打开首页
|
||||
</button>
|
||||
<button @tap="navigateToErrorPage" class="uni-btn">
|
||||
打开不存在的页面
|
||||
</button>
|
||||
<button v-for="(item, _) in data.animationTypeList" @tap="navigateToAnimationType(item)"
|
||||
class="uni-btn">navigateTo动画({{item}})</button>
|
||||
<button class="uni-btn" @click="goOnLoadCallAPI">测试 onLoad 调用 API</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { state, setLifeCycleNum } from '@/store/index.uts'
|
||||
type AnimationType = "slide-in-right" | "slide-in-left" | "slide-in-top" | "slide-in-bottom" | "pop-in" | "fade-in" | "zoom-out" | "zoom-fade-out" | "none" | "auto"
|
||||
|
||||
type DataType = {
|
||||
onLoadTime: number;
|
||||
onShowTime: number;
|
||||
onReadyTime: number;
|
||||
onHideTime: number;
|
||||
shareElementKey: string;
|
||||
animationTypeList: string[];
|
||||
}
|
||||
|
||||
const data = reactive<DataType>({
|
||||
onLoadTime: 0,
|
||||
onShowTime: 0,
|
||||
onReadyTime: 0,
|
||||
onHideTime: 0,
|
||||
shareElementKey: "",
|
||||
animationTypeList: [
|
||||
'slide-in-right',
|
||||
'slide-in-left',
|
||||
'slide-in-top',
|
||||
'slide-in-bottom',
|
||||
'pop-in',
|
||||
'fade-in',
|
||||
'zoom-out',
|
||||
'zoom-fade-out',
|
||||
'none'
|
||||
]
|
||||
})
|
||||
onLoad(() => {
|
||||
data.onLoadTime = Date.now()
|
||||
console.log('onLoad', data.onLoadTime)
|
||||
})
|
||||
|
||||
onPageShow(() => {
|
||||
data.onShowTime = Date.now()
|
||||
console.log('onShow', data.onShowTime)
|
||||
})
|
||||
|
||||
onReady(() => {
|
||||
data.onReadyTime = Date.now()
|
||||
console.log('onReady', data.onReadyTime)
|
||||
})
|
||||
|
||||
onPageHide(() => {
|
||||
data.onHideTime = Date.now()
|
||||
console.log('onHide', data.onHideTime)
|
||||
})
|
||||
|
||||
onBackPress((options : OnBackPressOptions) : boolean | null => {
|
||||
console.log('onBackPress', Date.now())
|
||||
console.log('onBackPress from', options.from)
|
||||
return null
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
console.log('onUnload', Date.now())
|
||||
})
|
||||
const 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)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateTo = () => {
|
||||
uni.navigateTo({
|
||||
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)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateToAnimationType = (animationType : AnimationType) => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-1?data=Hello',
|
||||
animationType: animationType,
|
||||
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)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateToErrorPage = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/error-page/error-page',
|
||||
success(result) {
|
||||
console.log('navigateTo success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('navigateTo fail', error.errMsg)
|
||||
uni.showToast({
|
||||
title: error.errMsg,
|
||||
icon: 'none',
|
||||
})
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('navigateTo complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const 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)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 自动化测试
|
||||
const navigateToRelativePath1 = () => {
|
||||
uni.navigateTo({
|
||||
url: 'new-page/new-page-1?data=new-page/new-page-1',
|
||||
success() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail() {
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 自动化测试
|
||||
const navigateToRelativePath2 = () => {
|
||||
uni.navigateTo({
|
||||
url: './new-page/new-page-1?data=./new-page/new-page-1',
|
||||
success() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail() {
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 自动化测试
|
||||
const navigateToRelativePath3 = () => {
|
||||
uni.navigateTo({
|
||||
url: '../navigator/new-page/new-page-1?data=../navigator/new-page/new-page-1',
|
||||
success() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail() {
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete() {
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateBack = () => {
|
||||
uni.navigateBack({
|
||||
success(result) {
|
||||
console.log('navigateBack success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('navigateBack fail', error.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('navigateBack complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateBackWithDelta1 = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-1',
|
||||
success() {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
success(result) {
|
||||
console.log('navigateBack success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('navigateBack fail', error.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('navigateBack complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateBackWithDelta100 = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-1',
|
||||
success() {
|
||||
uni.navigateBack({
|
||||
delta: 100,
|
||||
success(result) {
|
||||
console.log('navigateBack success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('navigateBack fail', error.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('navigateBack complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const redirectTo = () => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-1?data=Hello',
|
||||
success(result) {
|
||||
console.log('redirectTo success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('redirectTo fail', error.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('redirectTo complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const switchTab = () => {
|
||||
uni.switchTab({
|
||||
url: '/pages/tabBar/template',
|
||||
success(result) {
|
||||
console.log('switchTab success', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('switchTab fail', error.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum - 1)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('switchTab complete', result.errMsg)
|
||||
// 自动化测试
|
||||
setLifeCycleNum(state.lifeCycleNum + 1)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 自动化测试
|
||||
const getLifeCycleNum = () : number => {
|
||||
return state.lifeCycleNum
|
||||
}
|
||||
|
||||
// 自动化测试
|
||||
const setLifeCycleNumWrapper = (num : number) => {
|
||||
setLifeCycleNum(num)
|
||||
}
|
||||
|
||||
const onChange = (event: UniSwitchChangeEvent) => {
|
||||
if (event.detail.value) {
|
||||
data.shareElementKey = "test-share-element-key"
|
||||
} else {
|
||||
data.shareElementKey = ""
|
||||
}
|
||||
}
|
||||
|
||||
const goOnLoadCallAPI = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/API/navigator/new-page/onLoad-call-api'
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.direction-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.label {
|
||||
width: 190px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<page-head title="new-page-1" />
|
||||
<!-- #ifndef (APP-ANDROID || APP-IOS) && !VUE3-VAPOR -->
|
||||
<image style="width: 250px; height: 176px;" src="/static/shuijiao.jpg" mode="scaleToFill"></image>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef (APP-ANDROID || APP-IOS) && !VUE3-VAPOR -->
|
||||
<share-element share-key="test-share-element-key">
|
||||
<image style="width: 250px; height: 176px;" src="/static/shuijiao.jpg" mode="scaleToFill"></image>
|
||||
</share-element>
|
||||
<!-- #endif -->
|
||||
<view class="uni-padding-wrap">
|
||||
<text>onLoad 接收到参数</text>
|
||||
<text>data: {{ data.data }}</text>
|
||||
<button @tap="navigateBackWithDelta2" class="uni-btn">
|
||||
回退到上上层页面
|
||||
</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
import { state } from '@/store/index.uts'
|
||||
|
||||
type DataType = {
|
||||
data: string,
|
||||
}
|
||||
|
||||
const checked = ref(false)
|
||||
const data = reactive({
|
||||
data: '',
|
||||
} as DataType)
|
||||
|
||||
function getLifeCycleNum() : number {
|
||||
return state.lifeCycleNum
|
||||
}
|
||||
|
||||
function navigateBackWithDelta2() {
|
||||
uni.navigateBack({
|
||||
delta: 2,
|
||||
success() {
|
||||
console.log('回退上上层页面成功')
|
||||
},
|
||||
fail(error) {
|
||||
console.warn(`回退上上层页面失败: ${error.errMsg}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function navigateToOnLoadWithType(type : string) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/API/navigator/new-page/onLoad?type=${type}`,
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options : OnLoadOptions) => {
|
||||
if (options['data'] != null) {
|
||||
data.data = options['data']!
|
||||
}
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
navigateToOnLoadWithType
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<view class="uni-padding-wrap" style="flex: 1;">
|
||||
<page-head title="new-page-3" />
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
<template>
|
||||
<view class="uni-padding-wrap">
|
||||
<button @click="goOnLoad('adjustData')">onLoad adjust data</button>
|
||||
<button @click="goOnLoad('navigateTo')">onLoad navigateTo</button>
|
||||
<button @click="goOnLoad('navigateBack')">onLoad navigateBack</button>
|
||||
<button @click="goOnLoad('redirectTo')">onLoad redirectTo</button>
|
||||
<button @click="goOnLoad('reLaunch')">onLoad reLaunch</button>
|
||||
<button @click="goOnLoad('switchTab')">onLoad switchTab</button>
|
||||
<button @click="goOnLoad('showToast')">onLoad showToast</button>
|
||||
<button @click="goOnLoad('showLoading')">onLoad showLoading</button>
|
||||
<button @click="goOnLoad('showModal')">onLoad showModal</button>
|
||||
<button @click="goOnLoad('showActionSheet')">onLoad showActionSheet</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
function goOnLoad(type: string){
|
||||
uni.navigateTo({
|
||||
url: `/pages/API/navigator/new-page/onLoad?type=${type}`
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,204 @@
|
||||
const PAGE_PATH = "/pages/API/navigator/new-page/onLoad";
|
||||
const INTERMEDIATE_PAGE_PATH = "/pages/API/navigator/new-page/new-page-1";
|
||||
const TARGET_PAGE_PATH = "/pages/API/navigator/new-page/new-page-3";
|
||||
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isIos = platformInfo.startsWith('ios')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
|
||||
let page;
|
||||
|
||||
describe("onLoad", () => {
|
||||
if (isMP) {
|
||||
it('not support', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (
|
||||
isIos &&
|
||||
(platformInfo.indexOf('15.5') != -1 ||
|
||||
platformInfo.indexOf('14.5') != -1 ||
|
||||
platformInfo.indexOf('13.7') != -1 ||
|
||||
platformInfo.indexOf('12.4') != -1)
|
||||
) {
|
||||
// TODO: 排查 ios 不兼容版本 测试异常原因
|
||||
it('ios 15.5 14.5 13.7 12.4 测试异常', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let deviceShotOptions = {}
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
const windowInfo = await program.callUniMethod('getWindowInfo');
|
||||
let topSafeArea = windowInfo.safeAreaInsets.top;
|
||||
if (isAppWebView) {
|
||||
if (isIos) {
|
||||
topSafeArea = 59
|
||||
if (platformInfo.includes('26')) {
|
||||
topSafeArea = 62
|
||||
}
|
||||
} else if (isAndroid) {
|
||||
topSafeArea = 24
|
||||
windowInfo.safeArea.bottom = 867
|
||||
if (platformInfo.startsWith('android 5')) {
|
||||
topSafeArea = 25
|
||||
}if (platformInfo.startsWith('android 6')) {
|
||||
windowInfo.safeArea.bottom = 592
|
||||
}if (platformInfo.startsWith('android 8')) {
|
||||
windowInfo.safeArea.bottom = 534
|
||||
} else if (platformInfo.startsWith('android 11')) {
|
||||
topSafeArea = 52
|
||||
} else if (platformInfo.startsWith('android 12')) {
|
||||
topSafeArea = 24
|
||||
windowInfo.safeArea.bottom = 716
|
||||
} else if (platformInfo.startsWith('android 13') || platformInfo.startsWith('android 15')) {
|
||||
topSafeArea = 49
|
||||
windowInfo.safeArea.bottom = 891
|
||||
} else if (platformInfo.startsWith('android 14')) {
|
||||
windowInfo.safeArea.bottom = 891
|
||||
}
|
||||
} else if (isHarmony) {
|
||||
topSafeArea = 39
|
||||
if (platformInfo.includes('nova_12')) {
|
||||
topSafeArea = 35
|
||||
}
|
||||
}
|
||||
}
|
||||
const top = topSafeArea + 44
|
||||
const bottom = Math.min(top + windowInfo.windowHeight, windowInfo.safeArea.bottom)
|
||||
const left = windowInfo.safeArea.left
|
||||
const right = windowInfo.safeArea.right
|
||||
deviceShotOptions = {
|
||||
deviceShot: true,
|
||||
area: {
|
||||
x: left,
|
||||
y: top,
|
||||
width: right - left,
|
||||
height: bottom - top
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
it("adjustData", async () => {
|
||||
await page.callMethod("navigateToOnLoadWithType", "adjustData");
|
||||
await page.waitFor(1000);
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot();
|
||||
});
|
||||
it("navigateTo", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
await page.callMethod("navigateToOnLoadWithType", "navigateTo");
|
||||
await page.waitFor(1000);
|
||||
page = await program.currentPage();
|
||||
expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
|
||||
});
|
||||
if (!isAppWebView) {
|
||||
it("navigateBack", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
await page.callMethod("navigateToOnLoadWithType", "navigateBack");
|
||||
await page.waitFor(1000);
|
||||
page = await program.currentPage();
|
||||
expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1));
|
||||
});
|
||||
}
|
||||
it("redirectTo", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
await page.callMethod("navigateToOnLoadWithType", "redirectTo");
|
||||
await page.waitFor(100);
|
||||
page = await program.currentPage();
|
||||
expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
|
||||
});
|
||||
it("reLaunch", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
await page.callMethod("navigateToOnLoadWithType", "reLaunch");
|
||||
await page.waitFor(100);
|
||||
page = await program.currentPage();
|
||||
expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
|
||||
});
|
||||
if (!isDom2) {
|
||||
// dom2 目前 tabbar 是页面+组件实现,无法支持 switchTab 测试
|
||||
it("switchTab", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
await page.callMethod("navigateToOnLoadWithType", "switchTab");
|
||||
await page.waitFor(100);
|
||||
page = await program.currentPage();
|
||||
expect(page.path).toBe("pages/tabBar/component");
|
||||
});
|
||||
}
|
||||
it("showToast", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor("view");
|
||||
await page.callMethod("navigateToOnLoadWithType", "showToast");
|
||||
await page.waitFor(1000);
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot({
|
||||
failureThreshold: 0.05,
|
||||
failureThresholdType: "percent",
|
||||
});
|
||||
await page.waitFor(2000);
|
||||
});
|
||||
it("showLoading", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor("view");
|
||||
await page.callMethod("navigateToOnLoadWithType", "showLoading");
|
||||
await page.waitFor(1000);
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot({
|
||||
failureThreshold: 0.05,
|
||||
failureThresholdType: "percent",
|
||||
});
|
||||
await page.waitFor(2000);
|
||||
});
|
||||
it("showModal", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor("view");
|
||||
await page.callMethod("navigateToOnLoadWithType", "showModal");
|
||||
await page.waitFor(1000);
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot({
|
||||
failureThreshold: 0.05,
|
||||
failureThresholdType: "percent",
|
||||
});
|
||||
});
|
||||
it("showActionSheet", async () => {
|
||||
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
|
||||
await page.waitFor("view");
|
||||
await page.callMethod("navigateToOnLoadWithType", "showActionSheet");
|
||||
await page.waitFor(1000);
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
expect(image).toSaveImageSnapshot({
|
||||
failureThreshold: 0.05,
|
||||
failureThresholdType: "percent",
|
||||
});
|
||||
page = await program.currentPage();
|
||||
await page.callMethod("hideActionSheet");
|
||||
await page.waitFor(1000);
|
||||
});
|
||||
it('onLoad 参数 decode', async () => {
|
||||
page = await program.reLaunch(PAGE_PATH);
|
||||
await page.waitFor("view");
|
||||
const TEXT = '中文测试'
|
||||
uni.navigateTo({
|
||||
url: INTERMEDIATE_PAGE_PATH + '?data=' + encodeURIComponent(TEXT),
|
||||
success() {
|
||||
|
||||
}
|
||||
})
|
||||
await page.waitFor(1000);
|
||||
page = await program.currentPage();
|
||||
const pageData = await page.data('data');
|
||||
expect(pageData.data).toBe(TEXT);
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view class="uni-padding-wrap">
|
||||
<page-head title="onLoad 生命周期调用 uni api 测试" />
|
||||
<text v-if="isTrueValue">v-if with true</text>
|
||||
<text v-if="isFalseValue">v-if with false</text>
|
||||
<text v-show="isTrueValue">v-show with true</text>
|
||||
<text v-show="isFalseValue">v-show with false</text>
|
||||
<text>msg: {{ msg }}</text>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
const isTrueValue = ref(false)
|
||||
const isFalseValue = ref(true)
|
||||
const msg = ref('default msg')
|
||||
|
||||
function adjustData() {
|
||||
isTrueValue.value = true
|
||||
isFalseValue.value = false
|
||||
msg.value = 'new msg'
|
||||
}
|
||||
|
||||
function navigateTo() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-3'
|
||||
})
|
||||
}
|
||||
|
||||
function navigateBack() {
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
function redirectTo() {
|
||||
uni.redirectTo({
|
||||
url: '/pages/API/navigator/new-page/new-page-3'
|
||||
})
|
||||
}
|
||||
|
||||
function reLaunch() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/API/navigator/new-page/new-page-3'
|
||||
})
|
||||
}
|
||||
|
||||
function switchTab() {
|
||||
uni.switchTab({
|
||||
url: '/pages/tabBar/component'
|
||||
})
|
||||
}
|
||||
|
||||
function showToast() {
|
||||
uni.showToast({
|
||||
title: 'test title',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
|
||||
function showLoading() {
|
||||
uni.showLoading({
|
||||
title: 'test title',
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
function showModal() {
|
||||
uni.showModal({
|
||||
title: 'test title',
|
||||
content: 'test content'
|
||||
})
|
||||
}
|
||||
|
||||
function showActionSheet() {
|
||||
uni.showActionSheet({
|
||||
title: 'test title',
|
||||
itemList: ['1', '2', '3']
|
||||
})
|
||||
}
|
||||
|
||||
function hideActionSheet() {
|
||||
uni.hideActionSheet()
|
||||
}
|
||||
|
||||
onLoad((options : OnLoadOptions) => {
|
||||
const type = options['type']
|
||||
switch (type) {
|
||||
case 'adjustData':
|
||||
adjustData()
|
||||
break;
|
||||
case 'navigateTo':
|
||||
navigateTo()
|
||||
break;
|
||||
case 'navigateBack':
|
||||
navigateBack()
|
||||
break;
|
||||
case 'redirectTo':
|
||||
redirectTo()
|
||||
break;
|
||||
case 'reLaunch':
|
||||
reLaunch()
|
||||
break;
|
||||
case 'switchTab':
|
||||
switchTab()
|
||||
break;
|
||||
case 'showToast':
|
||||
showToast()
|
||||
break;
|
||||
case 'showLoading':
|
||||
showLoading()
|
||||
break;
|
||||
case 'showModal':
|
||||
showModal()
|
||||
break;
|
||||
case 'showActionSheet':
|
||||
showActionSheet()
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
// #ifdef WEB
|
||||
onUnload(() => {
|
||||
// web 端页面销毁前,关闭 modal 和 actionsheet
|
||||
// @ts-ignore
|
||||
const modalBtn = document.querySelector('.uni-modal__btn')
|
||||
if (modalBtn) {
|
||||
modalBtn.click()
|
||||
}
|
||||
// @ts-ignore
|
||||
const actionSheetBtn = document.querySelector('.uni-actionsheet__action .uni-actionsheet__cell')
|
||||
if (actionSheetBtn) {
|
||||
actionSheetBtn.click()
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
defineExpose({hideActionSheet})
|
||||
</script>
|
||||
在新工单中引用
屏蔽一个用户