Files
urbanLifeline/urbanLifelineWeb/packages/workcase_wechat/App.uvue

100 lines
2.3 KiB
Plaintext
Raw Normal View History

2025-12-08 19:01:09 +08:00
<script lang="uts">
// #ifdef APP-ANDROID || APP-HARMONY
let firstBackTime = 0
// #endif
export default {
onLaunch: function () {
console.log('App Launch')
2025-12-22 19:16:53 +08:00
// 检查是否已选择模式
this.checkModeSelection()
2025-12-08 19:01:09 +08:00
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},
// #ifdef APP-ANDROID || APP-HARMONY
onLastPageBackPress: function () {
console.log('App LastPageBackPress')
if (firstBackTime == 0) {
uni.showToast({
title: '再按一次退出应用',
position: 'bottom',
})
firstBackTime = Date.now()
setTimeout(() => {
firstBackTime = 0
}, 2000)
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now()
uni.exit()
}
},
// #endif
onExit: function () {
console.log('App Exit')
},
2025-12-22 19:16:53 +08:00
methods: {
// 检查并选择模式
checkModeSelection() {
const mode = uni.getStorageSync('userMode')
if (!mode) {
this.showModeSelector()
}
},
// 显示模式选择器
showModeSelector() {
uni.showActionSheet({
2025-12-27 19:23:33 +08:00
itemList: ['员工模式 (17857100375)', '访客模式 (17857100377)'],
2025-12-22 19:16:53 +08:00
success: (res) => {
let wechatId = ''
let userMode = ''
let phone = ''
if (res.tapIndex === 0) {
wechatId = '17857100375'
phone = '17857100375'
userMode = 'staff'
} else {
2025-12-27 19:23:33 +08:00
wechatId = '17857100377'
phone = '17857100377'
2025-12-22 19:16:53 +08:00
userMode = 'guest'
}
// 存储选择
uni.setStorageSync('userMode', userMode)
uni.setStorageSync('wechatId', wechatId)
uni.setStorageSync('phone', phone)
console.log('已选择模式:', userMode, 'wechatId:', wechatId)
uni.showToast({
title: userMode === 'staff' ? '员工模式' : '访客模式',
icon: 'success'
})
},
fail: () => {
// 用户取消,默认使用访客模式
uni.setStorageSync('userMode', 'guest')
2025-12-27 19:23:33 +08:00
uni.setStorageSync('wechatId', '17857100377')
2025-12-22 19:16:53 +08:00
console.log('默认使用访客模式')
}
})
}
}
2025-12-08 19:01:09 +08:00
}
</script>
<style>
/*每个页面公共css */
2025-12-23 13:27:36 +08:00
view {
border: none;
background-color: transparent;
box-sizing: border-box;
}
2025-12-08 19:01:09 +08:00
.uni-row {
flex-direction: row;
}
.uni-column {
flex-direction: column;
}
</style>