2025-08-14 20:26:26 +08:00
|
|
|
import {showAlert} from '@/utils/message.js'
|
|
|
|
|
|
2025-08-13 18:15:04 +08:00
|
|
|
// 递归算法
|
2025-08-14 20:26:26 +08:00
|
|
|
export const initTree = (arr, parentId = '0', id) => {
|
2025-08-13 18:15:04 +08:00
|
|
|
const tree = [];
|
|
|
|
|
arr.filter(item => item.parentId === parentId).forEach(item => {
|
2025-08-14 20:26:26 +08:00
|
|
|
const children = initTree(arr, item[id]);
|
|
|
|
|
if (children.length > 0) {
|
|
|
|
|
item.children = children;
|
|
|
|
|
}
|
|
|
|
|
tree.push(item);
|
2025-08-13 18:15:04 +08:00
|
|
|
});
|
|
|
|
|
return tree;
|
2025-08-14 20:26:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 安卓异步调用
|
|
|
|
|
export const requestAndroidPermissionAsync = (systemInfo,permissions) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// if (uni.getSystemInfoSync().platform !== 'android') {
|
|
|
|
|
// resolve({ granted: true, nonSystem: true })
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
plus.android.requestPermissions(permissions,(result) => {
|
|
|
|
|
showAlert("result=>"+JSON.stringify(result))
|
|
|
|
|
// const granted = Object.values(result.granted).every(Boolean);
|
|
|
|
|
|
|
|
|
|
let granted = false;
|
|
|
|
|
if(systemInfo.osVersion<13){
|
|
|
|
|
granted = result.granted.length==2
|
|
|
|
|
} else if(systemInfo.osVersion==13){
|
|
|
|
|
granted =result.granted.length==3
|
|
|
|
|
} else{
|
|
|
|
|
granted = result.granted.length==1
|
|
|
|
|
}
|
|
|
|
|
resolve({ ...result, granted })
|
|
|
|
|
|
|
|
|
|
},(error) => {
|
|
|
|
|
reject(error)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-15 10:13:39 +08:00
|
|
|
|
2025-08-14 20:26:26 +08:00
|
|
|
// 安卓同步调用
|
|
|
|
|
export const requestAndroidPermission = (systemInfo) => {
|
|
|
|
|
let granted = false;
|
|
|
|
|
const Manifest = plus.android.importClass("android.Manifest");
|
|
|
|
|
const MainActivity = plus.android.runtimeMainActivity();
|
|
|
|
|
if(systemInfo.osVersion <13){ // 安卓系统版本
|
|
|
|
|
let permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
|
|
let perStatus = 0;
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
if(perStatus ==2){
|
|
|
|
|
granted=true
|
|
|
|
|
}else{
|
|
|
|
|
granted=false //"当前文件保存权限被关闭,请到设置中开启才能继续后续操作"
|
2025-08-15 10:13:39 +08:00
|
|
|
goPermission();//调用授权方法去授权
|
2025-08-14 20:26:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(systemInfo.osVersion ==13){
|
|
|
|
|
let permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.READ_MEDIA_IMAGES);
|
|
|
|
|
let perStatus = 0;
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.READ_MEDIA_VIDEO);
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.READ_MEDIA_AUDIO);
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
if(perStatus ==3){
|
|
|
|
|
granted=true
|
|
|
|
|
}else{
|
|
|
|
|
granted=false //"当前文件保存权限被关闭,请到设置中开启才能继续后续操作"
|
2025-08-15 10:13:39 +08:00
|
|
|
goPermission();//调用授权方法去授权
|
2025-08-14 20:26:26 +08:00
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
let permissionStatus = MainActivity.checkSelfPermission(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED);
|
|
|
|
|
let perStatus = 0;
|
|
|
|
|
if (permissionStatus === 0) {
|
|
|
|
|
perStatus++;
|
|
|
|
|
}
|
|
|
|
|
if(perStatus ==1){
|
|
|
|
|
granted=true
|
|
|
|
|
}else{
|
|
|
|
|
granted=false //"当前文件保存权限被关闭,请到设置中开启才能继续后续操作"
|
2025-08-15 10:13:39 +08:00
|
|
|
goPermission();//调用授权方法去授权
|
2025-08-14 20:26:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return granted
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 10:13:39 +08:00
|
|
|
// 弹窗跳授权页面
|
|
|
|
|
const goPermission=()=>{
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: "请进行设备授权",
|
|
|
|
|
cancelText:'去授权',
|
|
|
|
|
confirmText:'已授权',
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
url: '/pages/loading/loading',
|
|
|
|
|
});
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
jumpAuthPermission();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-14 20:26:26 +08:00
|
|
|
// 跳转授权按钮
|
|
|
|
|
const jumpAuthPermission=()=>{
|
|
|
|
|
var main = plus.android.runtimeMainActivity();
|
|
|
|
|
var Intent = plus.android.importClass('android.content.Intent');
|
|
|
|
|
var Uri = plus.android.importClass('android.net.Uri');
|
|
|
|
|
var pkg = main.getPackageName();
|
|
|
|
|
var intent = new Intent('android.settings.APPLICATION_DETAILS_SETTINGS');
|
|
|
|
|
intent.setData(Uri.parse('package:' + pkg));
|
|
|
|
|
main.startActivity(intent);
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
url: '/pages/loading/loading',
|
|
|
|
|
});
|
2025-08-15 10:13:39 +08:00
|
|
|
},1000)
|
2025-08-14 20:26:26 +08:00
|
|
|
}
|