Files
ys-app/src/pages/loading/loading.vue

287 lines
8.3 KiB
Vue
Raw Normal View History

2025-07-22 11:21:01 +08:00
<template>
2025-08-01 18:12:36 +08:00
<view class="container" :style="{ height: `100vh` }">
<view class="bg"></view>
<view class="version">Version {{ appVersion }}</view>
<!-- <view class="bottom-bg"></view> -->
<!-- 检查版本弹窗 -->
<view class="version-con" v-if="versionVisible">
<view class="v-bg">
<view class="v-title">发现新版本</view>
<uni-icons custom-prefix="iconfont" color="#28B6FF" type="icon-phonefilled" size="40"></uni-icons>
2025-08-12 14:46:20 +08:00
<view class="v-version">最新版本 Version {{ newVersion }}</view>
2025-08-01 18:12:36 +08:00
<view class="v-update">立刻更新吗</view>
<view class="version-btn" @click="handleDown"> </view>
<view class="version-sub" @click="handleClose" v-if="btnVisible">暂不处理</view>
</view>
2025-07-22 11:21:01 +08:00
</view>
</view>
2025-08-01 18:12:36 +08:00
2025-07-22 11:21:01 +08:00
</template>
<script setup>
2025-07-31 17:36:27 +08:00
import { ref } from 'vue';
2025-07-22 11:21:01 +08:00
import { onLoad } from '@dcloudio/uni-app';
2025-08-01 18:12:36 +08:00
import { versionCheck,getBindStatus } from '@/api/auth.js';
2025-08-12 13:43:21 +08:00
import { formatIOS } from '@/utils/status.js'
2025-08-14 20:26:26 +08:00
import { requestAndroidPermissionAsync,requestAndroidPermission } from '@/utils/common.js'
import {showAlert} from '@/utils/message.js'
2025-07-22 11:21:01 +08:00
import { useUserStore } from '@/stores/user';
2025-07-31 17:36:27 +08:00
const userStore = useUserStore();
2025-07-22 11:21:01 +08:00
2025-08-14 14:01:54 +08:00
// #ifdef APP-PLUS
// 获取 存储手机的module
2025-08-14 20:26:26 +08:00
const safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
2025-08-14 14:01:54 +08:00
// #endif
2025-08-14 20:26:26 +08:00
let systemInfo={};
2025-08-01 18:12:36 +08:00
let appVersion = ref("1.0.0");//当前版本号
let newVersion = ref('1.0.0');//最新版本号
let versionVisible=ref(false);//版本弹窗
let btnVisible = ref(true);// 暂不处理 按钮是否显示
let downloadURL = ref(''); //下载地址
let versionData = ref({}); //版本参数
// 初始load页面
onLoad(async(opt) => {
2025-07-22 11:21:01 +08:00
console.log("onLoad");
2025-08-19 13:28:14 +08:00
// uni.preloadPage({url: "/pages/login/login"});
// uni.preloadPage({url: "/pages/deviceAuth/deviceAuth"});
// uni.preloadPage({url: "/pages/home/home"});
2025-08-01 18:12:36 +08:00
// #ifdef APP-PLUS
// 查询版本接口
await getOSVesion();
// 不更新版本 执行设备ID查询和绑定操作
if(!versionVisible.value){
2025-08-14 20:26:26 +08:00
try {
// 授权设备存储
2025-08-15 10:13:39 +08:00
let granted = requestAndroidPermission(systemInfo);
if(granted){
// showAlert("22授权成功")
setTimeout(()=>{
selectDeviceId();
},500)
}
2025-08-14 20:26:26 +08:00
} catch (error) {
console.error('权限请求出错:', error);
2025-08-15 10:13:39 +08:00
// showAlert(JSON.stringify(error))
2025-08-14 20:26:26 +08:00
}
2025-08-01 18:12:36 +08:00
}
2025-08-12 13:43:21 +08:00
// #endif
// #ifdef H5
2025-08-15 10:13:39 +08:00
// setTimeout(()=>{
2025-08-12 13:43:21 +08:00
if(userStore.isLogin){
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/login/login',
});
}
2025-08-15 10:13:39 +08:00
// },1000)
2025-08-12 13:43:21 +08:00
// #endif
2025-07-22 11:21:01 +08:00
});
2025-08-14 20:26:26 +08:00
// 检查版本是否是最新的s
const getOSVesion = async()=>{
systemInfo = uni.getSystemInfoSync();
2025-08-01 18:12:36 +08:00
let param = {
// #ifdef APP-PLUS
2025-08-12 13:43:21 +08:00
verNumber:systemInfo.appWgtVersion,//当前版本号
2025-08-01 18:12:36 +08:00
// #endif
// #ifdef H5
2025-08-12 13:43:21 +08:00
verNumber : systemInfo.appVersion,
2025-08-01 18:12:36 +08:00
// #endif
2025-08-12 13:43:21 +08:00
// deviceType:systemInfo.model,//型号
os: formatIOS(systemInfo.osName),//操作系统 Android IOS
// osVersion:systemInfo.osVersion,//操作系统版本
// resolution:systemInfo.windowWidth+"*"+systemInfo.windowHeight,//分辨率
// trademark:systemInfo.deviceBrand,//设备品牌
// uniqueCode:systemInfo.deviceId//设备ID
2025-08-01 18:12:36 +08:00
}
// 当前手机版本
2025-08-12 13:43:21 +08:00
appVersion.value = param.verNumber;
2025-08-01 18:12:36 +08:00
// console.log("appVersion=>",appVersion)
versionData.value = param;
let data = await versionCheck(param);
2025-08-12 13:43:21 +08:00
newVersion.value = data.verNumber;
2025-08-13 09:22:58 +08:00
downloadURL.value = data.downloadUrl || '';
2025-08-12 13:43:21 +08:00
// isForceUpdate 是否强制更新 1-是 2-否
let isForceUpdate = data.isForceUpdate;
if(isForceUpdate==1){
btnVisible.value = false;
}else{
btnVisible.value = true;
}
// 是否为当前最新版本(是=1否=2)
let isCurrent = data.isCurrent;
if(isCurrent == 1){
versionVisible.value=false;
}else{
versionVisible.value=true;
}
2025-08-01 18:12:36 +08:00
}
2025-08-12 13:43:21 +08:00
// 查询设备ID
const selectDeviceId = async()=>{
// 查询本地缓存的设备状态是否绑定过
2025-08-14 20:26:26 +08:00
// let deviceId = uni.getStorageSync('app_device_id');// 本地设备ID
try {
safeSave.getSafeFile({ "key": "app_device_id" }, res2 => {
if (res2.code == 1) {
let deviceId = res2.data;
console.log("读取成功=>",deviceId)
2025-08-15 10:13:39 +08:00
// showAlert("读取成功=>"+deviceId);
2025-08-14 20:26:26 +08:00
getBindStatus({uniqCode:deviceId}).then(res=>{
let bindStatus = res.bindStatus
2025-08-15 10:13:39 +08:00
// setTimeout(()=>{
2025-08-14 20:26:26 +08:00
// 绑定状态1=已提交、2=等待审核、3=审核通过、4=绑定成功、5=审核拒绝)
if(bindStatus == 4){
// 检查是否已登录 并 获取用户信息
if (userStore.isLogin) {
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/login/login',
});
}
}else{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
}
2025-08-15 10:13:39 +08:00
// },1000)
2025-08-14 20:26:26 +08:00
});
} else {
2025-08-15 10:13:39 +08:00
// showAlert('读取失败:'+res2.msg)
// setTimeout(()=>{
2025-08-12 13:43:21 +08:00
uni.reLaunch({
2025-08-14 20:26:26 +08:00
url: '/pages/deviceAuth/deviceAuth',
2025-08-12 13:43:21 +08:00
});
2025-08-15 10:13:39 +08:00
// },1000)
2025-08-12 16:19:19 +08:00
}
2025-08-14 20:26:26 +08:00
})
} catch (error) {
2025-08-15 10:13:39 +08:00
console.log("getSafeFile=>",error)
// showAlert("catch=>"+error)
2025-08-12 13:43:21 +08:00
}
}
2025-08-01 18:12:36 +08:00
// 下载最新版本
const handleDown = ()=>{
// 跳转到应用商店或下载最新版本的页面
plus.runtime.openURL(downloadURL.value);
2025-08-12 13:43:21 +08:00
if (versionData.value.os == 'ios'){
plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
} else if (versionData.value.os == 'android'){
2025-08-01 18:12:36 +08:00
plus.runtime.quit();
2025-08-12 13:43:21 +08:00
}
2025-08-01 18:12:36 +08:00
}
//版本更新关闭
const handleClose=()=>{
versionVisible.value = false;
// 不更新版本 执行设备ID查询和绑定操作
if(!versionVisible.value){
selectDeviceId()
}
}
2025-07-22 11:21:01 +08:00
</script>
<style>
.container {
background:#307AF5 !important;
2025-08-01 18:12:36 +08:00
height: calc(100vh - 100px) !important;
2025-07-22 11:21:01 +08:00
position: relative;
2025-08-01 18:12:36 +08:00
padding-top:100px;
2025-07-22 11:21:01 +08:00
}
.container .bg{
background:url('@/static/images/loading-logo.png') no-repeat;
background-size:700rpx 800rpx;
width: 700rpx;
height: 800rpx;
margin:0 auto;
}
.container .version{
color:#A8D4FF;
font-size:32rpx;
text-align: center;
margin-top:35rpx;
}
.container .bottom-bg{
background:url('@/static/images/loading-txt.png') no-repeat;
background-size:656rpx 123rpx;
width: 656rpx;
height: 123rpx;
position: absolute;
bottom:48rpx;
left:50%;
margin-left:-328rpx;
}
2025-08-01 18:12:36 +08:00
.container .version-con{
width:100%;
position: fixed;
top:0;
left:0;
height: 100vh;
background: rgba(0, 0, 0, 0.4);
}
.version-con .v-bg{
position: absolute;
top:50%;
left: 50%;
/* width:620rpx; */
width:540rpx;
background-color: #fff;
border-radius: 20rpx;
padding:40rpx;
margin-left:-310rpx;
margin-top:-45%;
text-align: center;
}
.version-con .v-bg .v-title{
font-size: 36rpx;
font-weight: bold;
text-align: center;
margin-bottom:30rpx;
}
.version-con .v-bg .v-icon{
font-size:70rpx;
color:#28B6FF;
}
.version-con .v-bg .v-version{
color:#0395E0;
font-size:42rpx;
font-weight: bold;
margin:20rpx 0 30rpx;
}
.version-con .v-bg .v-update{
font-size:32rpx;
margin-bottom:70rpx;
}
.version-con .v-bg .version-btn{
background-color: #05A3F4;
text-align: center;
width:360rpx;
height:80rpx;
line-height: 80rpx;
border-radius: 40rpx;
margin:0 auto;
color:#fff;
}
.version-con .v-bg .version-sub{
color:#05A3F4;
font-size:32rpx;
margin:40rpx 0 30rpx;
}
2025-07-22 11:21:01 +08:00
</style>