Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
51d75c2b
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6006
Star
91
Fork
164
代码
文件
提交
分支
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看板
提交
51d75c2b
编写于
8月 02, 2024
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加scheme和通用链接启动应用解析直达页面功能
(cherry picked from commit
8efaa21c
)
上级
d4021a0d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
146 addition
and
105 deletion
+146
-105
App.uvue
App.uvue
+146
-105
未找到文件。
App.uvue
浏览文件 @
51d75c2b
<script lang="uts">
<script lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
// #ifdef APP-ANDROID
let firstBackTime = 0
// #endif
export default {
globalData: {
str: 'default globalData str',
num: 0,
bool: false,
obj: {
str: 'default globalData obj str',
num: 0,
bool: false,
},
null: null as string | null,
arr: [] as number[],
mySet: new Set<string>(),
myMap: new Map<string, any>(),
func: () : string => {
return 'globalData func'
},
launchOptions: {
path: '',
} as OnLaunchOptions,
onShowOption: {
path: ''
} as OnShowOptions
},
onLaunch: function (res : OnLaunchOptions) {
this.globalData.launchOptions = res
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
console.log('App Launch')
// 页面性能分析
// const performance = uni.getPerformance()
// const observer1: PerformanceObserver = performance.createObserver(
// (entryList: PerformanceObserverEntryList) => {
// console.log('observer1:entryList.getEntries()' +JSON.stringify(entryList.getEntries()))
// }
// )
// observer1.observe({
// entryTypes: ['render', 'navigation'],
// } as PerformanceObserverOptions)
},
onShow: function (res : OnShowOptions) {
this.globalData.onShowOption = res
// #ifdef APP-ANDROID
// 处理scheme或通用链接直达
let firstBackTime = 0
let url = this.getRedirectUrl(res.appScheme, res.appLink);
// #endif
if (null != url) {
export default {
uni.navigateTo({
globalData: {
url: url
str: 'default globalData str',
})
num: 0,
}
bool: false,
obj: {
// 自动化测试
str: 'default globalData obj str',
setLifeCycleNum(state.lifeCycleNum + 100)
num: 0,
console.log('App Show')
bool: false,
},
},
onHide: function () {
null: null as string | null,
// 自动化测试
arr: [] as number[],
setLifeCycleNum(state.lifeCycleNum - 100)
mySet: new Set<string>(),
console.log('App Hide')
myMap: new Map<string, any>(),
},
func: () : string => {
// #ifdef APP-ANDROID
return 'globalData func'
onLastPageBackPress: function () {
},
// 自动化测试
launchOptions: {
setLifeCycleNum(state.lifeCycleNum - 1000)
path: '',
console.log('App LastPageBackPress')
} as OnLaunchOptions,
if (firstBackTime == 0) {
onShowOption: {
uni.showToast({
path: ''
title: '再按一次退出应用',
} as OnShowOptions
position: 'bottom',
},
})
onLaunch: function (res : OnLaunchOptions) {
firstBackTime = Date.now()
this.globalData.launchOptions = res
setTimeout(() => {
firstBackTime = 0
// 自动化测试
}, 2000)
setLifeCycleNum(state.lifeCycleNum + 1000)
} else if (Date.now() - firstBackTime < 2000) {
console.log('App Launch')
firstBackTime = Date.now()
uni.exit()
// 页面性能分析
}
// const performance = uni.getPerformance()
},
// const observer1: PerformanceObserver = performance.createObserver(
onExit() {
// (entryList: PerformanceObserverEntryList) => {
console.log('App Exit')
// console.log('observer1:entryList.getEntries()' +JSON.stringify(entryList.getEntries()))
},
// }
// #endif
// )
methods: {
// observer1.observe({
increasetLifeCycleNum() {
// entryTypes: ['render', 'navigation'],
setLifeCycleNum(state.lifeCycleNum + 100)
// } as PerformanceObserverOptions)
console.log('App increasetLifeCycleNum')
},
},
onShow: function (res : OnShowOptions) {
getRedirectUrl(scheme : string | null, ulink : string | null) : string | null {
this.globalData.onShowOption = res
//解析scheme或universal link启动直达页面:
//scheme格式:uniappx://redirect/pages/component/view/view?key=value //其中redirect后为页面路径
// 自动化测试
//universal link格式:https://uniappx.dcloud.net.cn/ulink/redirect.html?url=%2Fpages%2Fcomponent%2Fview%2Fview%3Fkey%3Dvalue //通用链接路径需固定,?后面的url参数为直达页面路径,注意url字段值需做url编码(可使用encodeURIComponent方法)
setLifeCycleNum(state.lifeCycleNum + 100)
let url : string | null = null;
console.log('App Show')
if (null != scheme && scheme.length > 0) {
},
const PATHPRE = 'redirect';
onHide: function () {
let parts : string | null = null;
// 自动化测试
let pos = scheme.search('//');
setLifeCycleNum(state.lifeCycleNum - 100)
if (pos > 0) {
console.log('App Hide')
parts = scheme.substring(pos + 2);
},
}
// #ifdef APP-ANDROID
if (null != parts && parts.startsWith(PATHPRE)) {
onLastPageBackPress: function () {
url = parts.substring(PATHPRE.length);
// 自动化测试
}
setLifeCycleNum(state.lifeCycleNum - 1000)
} else if (null != ulink && ulink.length > 0) {
console.log('App LastPageBackPress')
const PATH = 'ulink/redirect.html';
if (firstBackTime == 0) {
let parts = ulink.split('?');
uni.showToast({
if (parts.length > 1 && parts[0].endsWith(PATH) && parts[1].length > 0) {
title: '再按一次退出应用',
parts[1].split('&').forEach((e) => {
position: 'bottom',
let params = e.split('=');
})
if (params.length > 1 && params[0].length > 0 && params[1].length > 0) {
firstBackTime = Date.now()
if ('url' == params[0]) {
setTimeout(() => {
if (null == url) {
firstBackTime = 0
url = decodeURIComponent(params[1]);
}, 2000)
}
} else if (Date.now() - firstBackTime < 2000) {
}
firstBackTime = Date.now()
}
uni.exit()
});
}
}
},
}
onExit() {
return url;
console.log('App Exit')
}
},
}
// #endif
}
methods: {
</script>
increasetLifeCycleNum() {
setLifeCycleNum(state.lifeCycleNum + 100)
<style>
console.log('App increasetLifeCycleNum')
/*每个页面公共css */
}
@import "./common/uni.css";
}
}
/* #ifdef WEB */
</script>
.uni-top-window uni-tabbar .uni-tabbar {
background-color: #fff !important;
<style>
}
/*每个页面公共css */
@import "./common/uni.css";
.uni-app--showleftwindow .uni-page-head-btn {
display: none !important;
/* #ifdef WEB */
}
.uni-top-window uni-tabbar .uni-tabbar {
background-color: #fff !important;
/* #endif */
}
.uni-app--showleftwindow .uni-page-head-btn {
display: none !important;
}
/* #endif */
</style>
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录