增加 存储设备插件
This commit is contained in:
@@ -4,14 +4,6 @@
|
||||
<view class="version">Version {{ appVersion }}</view>
|
||||
<!-- <view class="bottom-bg"></view> -->
|
||||
|
||||
<!-- 测试用 -->
|
||||
<!-- #ifdef APP-PLUS -->
|
||||
<button @click="saveValue">保存数据</button>
|
||||
<button @click="getValue">加载数据</button>
|
||||
<view>{{content}}--{{ app_device_id }}</view>
|
||||
<!-- #endif -->
|
||||
|
||||
|
||||
<!-- 检查版本弹窗 -->
|
||||
<view class="version-con" v-if="versionVisible">
|
||||
<view class="v-bg">
|
||||
@@ -32,16 +24,17 @@ import { ref } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { versionCheck,getBindStatus } from '@/api/auth.js';
|
||||
import { formatIOS } from '@/utils/status.js'
|
||||
import { requestAndroidPermissionAsync,requestAndroidPermission } from '@/utils/common.js'
|
||||
import {showAlert} from '@/utils/message.js'
|
||||
import { useUserStore } from '@/stores/user';
|
||||
const userStore = useUserStore();
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// 获取 存储手机的module
|
||||
let safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
|
||||
let app_device_id = ref("7f47cfb4-59e2-4cb9-ac46-9da5e23c4de2");
|
||||
let content = ref('')
|
||||
const safeSave = uni.requireNativePlugin("Tm-TmSafeSaveFileModule");
|
||||
// #endif
|
||||
|
||||
let systemInfo={};
|
||||
let appVersion = ref("1.0.0");//当前版本号
|
||||
let newVersion = ref('1.0.0');//最新版本号
|
||||
let versionVisible=ref(false);//版本弹窗
|
||||
@@ -62,7 +55,39 @@ onLoad(async(opt) => {
|
||||
|
||||
// 不更新版本 执行设备ID查询和绑定操作
|
||||
if(!versionVisible.value){
|
||||
selectDeviceId()
|
||||
try {
|
||||
// 授权设备存储
|
||||
// let result = {granted:false}
|
||||
// if(systemInfo.osVersion<13){
|
||||
// let permissions = ['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.WRITE_EXTERNAL_STORAGE'];
|
||||
// result = await requestAndroidPermissionAsync(systemInfo,permissions);
|
||||
// }else if(systemInfo.osVersion==13){
|
||||
// let permissions = ['android.permission.READ_MEDIA_IMAGES', 'android.permission.READ_MEDIA_VIDEO', 'android.permission.READ_MEDIA_AUDIO'];
|
||||
// result = await requestAndroidPermissionAsync(systemInfo,permissions);
|
||||
// }else{
|
||||
// let permissions = ['android.permission.READ_MEDIA_VISUAL_USER_SELECTED'];
|
||||
// result = await requestAndroidPermissionAsync(systemInfo,permissions);
|
||||
// }
|
||||
|
||||
// if (result.granted) {
|
||||
// showAlert("11授权成功!")
|
||||
// setTimeout(()=>{
|
||||
// selectDeviceId();
|
||||
// },500)
|
||||
// } else {
|
||||
let granted = requestAndroidPermission(systemInfo);
|
||||
if(granted){
|
||||
showAlert("22授权成功!")
|
||||
setTimeout(()=>{
|
||||
selectDeviceId();
|
||||
},500)
|
||||
}
|
||||
// showAlert("您还没对设备授权,请授权!")
|
||||
// }
|
||||
} catch (error) {
|
||||
console.error('权限请求出错:', error);
|
||||
showAlert(JSON.stringify(error))
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
@@ -82,60 +107,9 @@ onLoad(async(opt) => {
|
||||
|
||||
});
|
||||
|
||||
// 保存设备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,
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
// 检查版本是否是最新的
|
||||
let getOSVesion = async()=>{
|
||||
let systemInfo = uni.getSystemInfoSync();
|
||||
// 检查版本是否是最新的s
|
||||
const getOSVesion = async()=>{
|
||||
systemInfo = uni.getSystemInfoSync();
|
||||
let param = {
|
||||
// #ifdef APP-PLUS
|
||||
verNumber:systemInfo.appWgtVersion,//当前版本号
|
||||
@@ -177,36 +151,49 @@ let getOSVesion = async()=>{
|
||||
// 查询设备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(()=>{
|
||||
// 绑定状态(1=已提交、2=等待审核、3=审核通过、4=绑定成功、5=审核拒绝)
|
||||
if(res.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',
|
||||
// let deviceId = uni.getStorageSync('app_device_id');// 本地设备ID
|
||||
try {
|
||||
// showAlert("safeSave=>"+safeSave)
|
||||
safeSave.getSafeFile({ "key": "app_device_id" }, res2 => {
|
||||
// showAlert("读取成功=>"+JSON.stringify(res2));
|
||||
if (res2.code == 1) {
|
||||
let deviceId = res2.data;
|
||||
console.log("读取成功=>",deviceId)
|
||||
showAlert("读取成功=>"+deviceId);
|
||||
getBindStatus({uniqCode:deviceId}).then(res=>{
|
||||
let bindStatus = res.bindStatus
|
||||
setTimeout(()=>{
|
||||
// 绑定状态(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',
|
||||
});
|
||||
}
|
||||
},2000)
|
||||
});
|
||||
} else {
|
||||
showAlert('读取失败:'+res2.msg)
|
||||
setTimeout(()=>{
|
||||
uni.reLaunch({
|
||||
url: '/pages/deviceAuth/deviceAuth',
|
||||
});
|
||||
},2000)
|
||||
}
|
||||
},2000)
|
||||
})
|
||||
} catch (error) {
|
||||
showAlert("catch=>"+error)
|
||||
}
|
||||
}
|
||||
// 下载最新版本
|
||||
|
||||
Reference in New Issue
Block a user