100 lines
2.3 KiB
Vue
100 lines
2.3 KiB
Vue
<script setup>
|
||
import {
|
||
useCartsStore
|
||
} from '@/stores/carts.js';
|
||
import {
|
||
useNavbarStore
|
||
} from '@/stores/navbarStore';
|
||
import {
|
||
APIgeocodelocation
|
||
} from "@/common/api/api.js"
|
||
import {
|
||
onLaunch,
|
||
onShow
|
||
} from '@dcloudio/uni-app';
|
||
import {
|
||
getCurrentInstance,
|
||
nextTick
|
||
} from 'vue';
|
||
import {
|
||
Storelogin
|
||
} from '@/stores/user.js';
|
||
|
||
import {
|
||
useCartStore
|
||
} from '@/stores/order.js';
|
||
// websocket
|
||
|
||
const {
|
||
proxy
|
||
} = getCurrentInstance()
|
||
// 小程序启动时执行
|
||
onLaunch(async () => {
|
||
// 标记应用启动完成
|
||
// clear
|
||
await nextTick()
|
||
const store = useNavbarStore();
|
||
await store.initNavbarHeight();
|
||
getApp().globalData.websocket=null;
|
||
const cartsStore=useCartsStore()
|
||
cartsStore.isloading=false;
|
||
});
|
||
onShow(async () => {
|
||
try {
|
||
// #ifdef MP-WEIXIN
|
||
// 当向小程序后台请求完新版本信息,会进行回调。res: {hasUpdate: true, version: 1.0.0}
|
||
const updateManager = uni.getUpdateManager();
|
||
updateManager.onCheckForUpdate((res) => {
|
||
if (res.hasUpdate) { // 有更新
|
||
uni.showLoading({
|
||
title: '更新中...'
|
||
}); // 开始下载前,显示Loading
|
||
}
|
||
});
|
||
// 当新版本下载完成,会进行回调
|
||
updateManager.onUpdateReady(() => {
|
||
uni.hideLoading(); // 关闭 Loading
|
||
uni.showModal({ // 弹确认框(强制更新)
|
||
title: '更新提示',
|
||
content: '更新完毕,是否重启?',
|
||
success: function(res) {
|
||
if (res.confirm) {
|
||
updateManager.applyUpdate(); // 强制小程序重启并使用新版本。
|
||
}
|
||
}
|
||
})
|
||
});
|
||
// 当新版本下载失败,会进行回调
|
||
updateManager.onUpdateFailed(() => {
|
||
uni.hideLoading(); // 关闭 Loading
|
||
uni.showToast({
|
||
title: '更新失败,稍后再试...',
|
||
icon: "error"
|
||
});
|
||
});
|
||
// #endif
|
||
} catch (error) {
|
||
//TODO handle the exception
|
||
}
|
||
// #ifndef H5
|
||
// try {
|
||
const storelogin = Storelogin();
|
||
await storelogin.actionslogin()
|
||
proxy.$isResolve()
|
||
// } catch (error) {
|
||
// proxy.$isResolve()
|
||
// console.log(error)
|
||
// }
|
||
// #endif
|
||
|
||
})
|
||
// onHide: function() {}
|
||
// }
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/*每个页面公共css */
|
||
@import "@/uni_modules/uview-plus/index.scss";
|
||
@import '@/common/css/flex.css';
|
||
@import "@/common/css/common.scss";
|
||
</style> |