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

321 lines
8.5 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> -->
2025-08-14 14:01:54 +08:00
<!-- 测试用 -->
<!-- #ifdef APP-PLUS -->
<button @click="saveValue">保存数据</button>
<button @click="getValue">加载数据</button>
<view>{{content}}--{{ app_device_id }}</view>
<!-- #endif -->
2025-08-01 18:12:36 +08:00
<!-- 检查版本弹窗 -->
<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-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
let safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
let app_device_id = ref("7f47cfb4-59e2-4cb9-ac46-9da5e23c4de2");
let content = ref('')
// #endif
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-01 18:12:36 +08:00
uni.preloadPage({url: "/pages/login/login"});
uni.preloadPage({url: "/pages/deviceAuth/deviceAuth"});
uni.preloadPage({url: "/pages/home/home"});
// #ifdef APP-PLUS
// 查询版本接口
await getOSVesion();
// 不更新版本 执行设备ID查询和绑定操作
if(!versionVisible.value){
selectDeviceId()
}
2025-08-12 13:43:21 +08:00
// #endif
// #ifdef H5
setTimeout(()=>{
if(userStore.isLogin){
uni.reLaunch({
url: '/pages/home/home',
});
}else{
uni.reLaunch({
url: '/pages/login/login',
});
}
},2000)
// #endif
2025-07-22 11:21:01 +08:00
});
2025-08-14 14:01:54 +08:00
// 保存设备ID
const saveValue = ()=>{
console.log("saveValue",safeSave)
safeSave.saveSafeFile({
"key": "app_device_id",
"value": app_device_id.value
}, (res) => {
console.log(res);
if (res.code == 1) {
uni.showModal({
title: "保存成功",
content:res.msg,
success: function (res) {
if (res.confirm) {
content.value("成功=>")
}
}
})
} else {
uni.showModal({
title: "保存失败",
content:res.msg,
})
}
})
}
// 读取设备ID
const getValue =()=>{
console.log(safeSave)
safeSave.getSafeFile({
"key": "app_device_id"
}, (res) => {
console.log(res);
if (res.code == 1) {
app_device_id.value = res.data;
content.value = "aaaa==>"
uni.showModal({
title: "读取成功",
content:res.data,
})
} else {
uni.showModal({
title: "读取失败",
content: res.msg,
})
}
})
};
2025-08-01 18:12:36 +08:00
// 检查版本是否是最新的
let getOSVesion = async()=>{
2025-08-12 16:19:19 +08:00
let 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()=>{
// 查询本地缓存的设备状态是否绑定过
let deviceId = uni.getStorageSync('app_device_id');// 本地设备ID
console.log("uniqCode=>",deviceId)
if(!deviceId){
setTimeout(()=>{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
},2000)
}else{
let res = await getBindStatus({uniqCode:deviceId});
setTimeout(()=>{
2025-08-12 16:19:19 +08:00
// 绑定状态1=已提交、2=等待审核、3=审核通过、4=绑定成功、5=审核拒绝)
if(res.bindStatus == 4){
// 检查是否已登录 并 获取用户信息
if (userStore.isLogin) {
2025-08-12 13:43:21 +08:00
uni.reLaunch({
url: '/pages/home/home',
});
2025-08-12 16:19:19 +08:00
2025-08-12 13:43:21 +08:00
}else{
uni.reLaunch({
2025-08-12 16:19:19 +08:00
url: '/pages/login/login',
2025-08-12 13:43:21 +08:00
});
}
2025-08-12 16:19:19 +08:00
}else{
uni.reLaunch({
url: '/pages/deviceAuth/deviceAuth',
});
}
2025-08-12 13:43:21 +08:00
},2000)
}
}
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>