InspectionCleaning/App.vue

159 lines
5.4 KiB
Vue
Raw Normal View History

2025-04-07 09:30:11 +08:00
<script>
2025-04-10 09:12:18 +08:00
// #ifdef APP-PLUS
2025-04-29 16:02:02 +08:00
import appUpdate from '@/components/appUpdate/appUpdate.js'
2025-04-10 09:12:18 +08:00
// #endif
2025-04-29 16:02:02 +08:00
import { jwtDecode } from 'jwt-decode'
2025-04-10 09:12:18 +08:00
export default {
onLaunch: function () {
2025-04-29 16:02:02 +08:00
console.log('%c%s', 'color:red', 'onLaunch---')
uni.showLoading({ title: '加载中' })
2025-04-10 09:12:18 +08:00
// uni.setStorageSync("token", "");
2025-04-29 16:02:02 +08:00
window.initFn = this.initFn
2025-04-10 09:12:18 +08:00
// this.initFn();
//console.log('App Launch')
// #ifdef APP-PLUS
2025-04-29 16:02:02 +08:00
let systemInfo = uni.getSystemInfoSync()
2025-04-10 09:12:18 +08:00
const data = {
appid: systemInfo.appId,
2025-04-29 16:02:02 +08:00
version: systemInfo.appVersion
}
console.log(data)
2025-04-10 09:12:18 +08:00
//把appid和版本发送请求服务器看服务器上是否有更新
2025-04-29 16:02:02 +08:00
this.$api.checkVersion(data).then(res => {
console.log(res)
2025-04-10 09:12:18 +08:00
if (res.code == 0) {
//如果返回0则表示有更新
2025-04-29 16:02:02 +08:00
appUpdate(res)
2025-04-10 09:12:18 +08:00
}
2025-04-29 16:02:02 +08:00
})
2025-04-10 09:12:18 +08:00
// #endif
},
onShow: function () {
// console.log('%c%s', 'color:red', 'onShow---');
// #ifdef MP-WEIXIN
// 当向小程序后台请求完新版本信息会进行回调。res: {hasUpdate: true, version: 1.0.0}
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
// 有更新
2025-04-29 16:02:02 +08:00
uni.showLoading({ title: '更新中...' }) // 开始下载前显示Loading
2025-04-10 09:12:18 +08:00
}
2025-04-29 16:02:02 +08:00
})
2025-04-10 09:12:18 +08:00
// 当新版本下载完成,会进行回调
updateManager.onUpdateReady(function () {
2025-04-29 16:02:02 +08:00
uni.hideLoading() // 关闭 Loading
2025-04-10 09:12:18 +08:00
uni.showModal({
// 弹确认框(强制更新)
2025-04-29 16:02:02 +08:00
title: '更新提示',
content: '更新完毕,是否重启?',
2025-04-10 09:12:18 +08:00
success: function (res) {
if (res.confirm) {
2025-04-29 16:02:02 +08:00
updateManager.applyUpdate() // 强制小程序重启并使用新版本。
2025-04-10 09:12:18 +08:00
}
2025-04-29 16:02:02 +08:00
}
})
})
2025-04-10 09:12:18 +08:00
// 当新版本下载失败,会进行回调
updateManager.onUpdateFailed(function () {
2025-04-29 16:02:02 +08:00
uni.hideLoading() // 关闭 Loading
uni.showToast({ title: '更新失败,稍后再试...', icon: 'error' })
})
2025-04-10 09:12:18 +08:00
// #endif
},
2025-04-29 16:02:02 +08:00
onHide: function () {},
2025-04-10 09:12:18 +08:00
methods: {
initFn(data) {
2025-04-29 16:02:02 +08:00
uni.hideLoading() // 关闭 Loading
2025-04-10 16:49:39 +08:00
if (!data) {
2025-04-29 16:02:02 +08:00
return uni.showToast({ title: '未传入参数 initFn', icon: 'none' })
2025-04-10 16:49:39 +08:00
}
2025-04-10 09:12:18 +08:00
// uni.showModal({
2025-04-10 16:49:39 +08:00
// title: "查看initFn",
// content: JSON.stringify(data) || "未传入参数 initFn",
2025-04-10 09:12:18 +08:00
// showCancel: true,
// success: function (res) {},
// });
2025-04-10 16:49:39 +08:00
// "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiIwOGRkNzFiZC01N2MxLTQ1YmMtODBiYS0xMjkzYjU4MTViMmEiLCJ1bmlxdWVfbmFtZSI6IuS_nea0gSIsInJvbGUiOiJVc2VyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbW9iaWxlcGhvbmUiOiIxODE3NDAxMDU2MiIsImdyb3Vwc2lkIjoiNGIyZDk2NjItYTc2OC0wOGYyLWEwYzgtNzYyYjhjNzZkYTJhIiwibmJmIjoxNzQ0MjYzMTAyLCJleHAiOjE3NDQyNjY3MDIsImlhdCI6MTc0NDI2MzEwMn0.ZJTwC7rWCcywoM7ncysw-JRIiwXz4y_6hlmqctN-gMM"
2025-04-29 16:02:02 +08:00
let token = data.token
uni.setStorageSync('token', 'Bearer ' + token)
console.log(jwtDecode(token), '解析的token信息')
let resData = jwtDecode(token)
this.$u.vuex('vuex_userData', resData)
console.log(this.vuex_userData, 'vuex_userData')
2025-04-18 11:55:50 +08:00
// User | Admin
2025-04-29 16:02:02 +08:00
let role = resData.role
console.log(role, 'role----')
2025-04-18 11:55:50 +08:00
// return;
2025-04-29 16:02:02 +08:00
if (role === 'User') {
2025-04-18 11:55:50 +08:00
const normalTabBar = [
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/index/planList',
iconPath: '/static/tab/planList.png',
selectedIconPath: '/static/tab/planList-active.png',
text: '计划'
2025-04-18 11:55:50 +08:00
},
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/index/index',
iconPath: '/static/tab/admin-home.png',
selectedIconPath: '/static/tab/admin-home-acitve.png',
text: '首页'
2025-04-18 11:55:50 +08:00
},
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/user/index',
iconPath: '/static/tab/admin-my.png',
selectedIconPath: '/static/tab/admin-my-active.png',
text: '设置'
}
]
this.$u.vuex('vuex_tabbar', normalTabBar)
2025-04-18 11:55:50 +08:00
uni.switchTab({
2025-04-29 16:02:02 +08:00
url: '/pages/index/index',
2025-04-18 11:55:50 +08:00
success() {
2025-04-29 16:02:02 +08:00
console.log('跳转成功')
window.initFn = null // 清除全局函数
2025-04-18 11:55:50 +08:00
},
fail(err) {
2025-04-29 16:02:02 +08:00
console.error('跳转失败', err)
}
})
2025-04-29 11:45:17 +08:00
} else {
2025-04-18 11:55:50 +08:00
const adminTabBar = [
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/adminHome/index',
iconPath: '/static/tab/admin-home.png',
selectedIconPath: '/static/tab/admin-home-acitve.png',
text: '首页'
2025-04-18 11:55:50 +08:00
},
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/adminNfc/index',
iconPath: '/static/tab/nfc.png',
selectedIconPath: '/static/tab/nfc-active.png',
text: 'nfc写入'
2025-04-18 11:55:50 +08:00
},
{
2025-04-29 16:02:02 +08:00
pagePath: '/pages/adminMy/index',
iconPath: '/static/tab/admin-my.png',
selectedIconPath: '/static/tab/admin-my-active.png',
text: '我的'
}
]
this.$u.vuex('vuex_tabbar', adminTabBar)
2025-04-18 11:55:50 +08:00
uni.switchTab({
2025-04-29 16:02:02 +08:00
url: '/pages/adminHome/index',
2025-04-18 11:55:50 +08:00
success() {
2025-04-29 16:02:02 +08:00
console.log('跳转成功')
window.initFn = null // 清除全局函数
2025-04-18 11:55:50 +08:00
},
fail(err) {
2025-04-29 16:02:02 +08:00
console.error('跳转失败', err)
}
})
2025-04-18 11:55:50 +08:00
}
2025-04-29 16:02:02 +08:00
}
}
}
2025-04-07 09:30:11 +08:00
</script>
<style lang="scss">
2025-04-29 16:02:02 +08:00
@import '@/uni_modules/uview-ui/index.scss';
2025-04-07 09:30:11 +08:00
</style>