2025-01-05 20:06:22 +08:00
|
|
|
|
<script setup>
|
2025-03-06 22:00:21 +08:00
|
|
|
|
import {
|
|
|
|
|
onLaunch,
|
|
|
|
|
onExit
|
|
|
|
|
} from '@dcloudio/uni-app'
|
|
|
|
|
// 工具库
|
|
|
|
|
import util from '@/common/js/util';
|
|
|
|
|
//
|
|
|
|
|
import api from '@/api/index.js'
|
|
|
|
|
// vuex
|
|
|
|
|
import store from '@/store/index.js'
|
2025-02-25 18:39:55 +08:00
|
|
|
|
// #ifdef APP
|
2025-03-06 22:00:21 +08:00
|
|
|
|
// 引入各种权限配置
|
|
|
|
|
import {
|
|
|
|
|
registerRequestPermissionTipsListener,
|
|
|
|
|
unregisterRequestPermissionTipsListener,
|
|
|
|
|
setRequestPermissionTips
|
|
|
|
|
} from "@/uni_modules/uni-registerRequestPermissionTips"
|
|
|
|
|
var PermissionTips = {
|
|
|
|
|
"android.permission.CAMERA": "<h4 style=\"font-size:40px;\">相机使用权限说明</h4><font color=#cccccc>用于在添加、上传、发布、图片和视频等场景中读取和写入相册和文件内容</font>",
|
|
|
|
|
"android.permission.WRITE_EXTERNAL_STORAGE": "<h4 style=\"font-size:40px;\">存储空间/照片权限说明</h4><font color=#cccccc>用于在添加、上传、发布、图片和视频等场景中读取和写入相册和文件内容</font>",
|
|
|
|
|
"android.permission.RECORD_AUDIO": "<h4 style=\"font-size:40px;\">录音权限说明</h4><font color=#cccccc>用于发送语音消息、语音通话功能</font>",
|
|
|
|
|
}
|
2025-02-25 18:39:55 +08:00
|
|
|
|
// #endif
|
2025-02-19 16:36:12 +08:00
|
|
|
|
|
2025-03-06 22:00:21 +08:00
|
|
|
|
onLaunch(() => {
|
|
|
|
|
// 获取用户信息
|
|
|
|
|
getUserinfo()
|
|
|
|
|
// 获取系统配置
|
|
|
|
|
getConfig()
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
// 处理用户在app端提交的权限
|
|
|
|
|
init()
|
|
|
|
|
// 获取APP版本
|
|
|
|
|
util.getAppVersion()
|
|
|
|
|
// #endif
|
|
|
|
|
})
|
2025-02-25 18:39:55 +08:00
|
|
|
|
|
2025-03-06 22:00:21 +08:00
|
|
|
|
onExit(() => {
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
unregisterRequestPermissionTipsListener(null)
|
|
|
|
|
// #endif
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理用户在app端申请的权限
|
|
|
|
|
* 文档地址:https://ext.dcloud.net.cn/plugin?name=uni-registerRequestPermissionTips
|
|
|
|
|
*/
|
|
|
|
|
function init() {
|
|
|
|
|
var brand = uni.getSystemInfoSync().deviceBrand
|
|
|
|
|
setRequestPermissionTips(PermissionTips)
|
|
|
|
|
registerRequestPermissionTipsListener({
|
|
|
|
|
// 申请系统权限回调
|
|
|
|
|
onRequest: (e) => {
|
|
|
|
|
console.log(e)
|
|
|
|
|
},
|
|
|
|
|
// 弹出系统权限授权框回调
|
|
|
|
|
onConfirm: (e) => {
|
|
|
|
|
console.log(e)
|
|
|
|
|
},
|
|
|
|
|
// onComplete
|
|
|
|
|
onComplete: (e) => {
|
|
|
|
|
// 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
|
|
|
|
|
if (brand.toLowerCase() == "huawei") {
|
|
|
|
|
var tips = {}
|
|
|
|
|
var hasDeniedPermission = false
|
|
|
|
|
for (var k in PermissionTips) {
|
|
|
|
|
if (e[k] != "denied") {
|
|
|
|
|
tips[k] = PermissionTips[k]
|
|
|
|
|
} else {
|
|
|
|
|
hasDeniedPermission = true
|
|
|
|
|
}
|
2025-02-25 18:39:55 +08:00
|
|
|
|
}
|
2025-03-06 22:00:21 +08:00
|
|
|
|
setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
|
|
|
|
|
if (hasDeniedPermission)
|
|
|
|
|
uni.showModal({
|
|
|
|
|
content: "权限已经被拒绝,请前往设置中开启"
|
|
|
|
|
})
|
2025-02-25 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-06 22:00:21 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
2025-02-25 18:39:55 +08:00
|
|
|
|
|
2025-03-06 22:00:21 +08:00
|
|
|
|
// 获取用户信息
|
|
|
|
|
function getUserinfo() {
|
|
|
|
|
// 登录令牌
|
|
|
|
|
const token = uni.getStorageSync('token')
|
2025-02-26 16:36:32 +08:00
|
|
|
|
// 用户信息
|
2025-03-06 22:00:21 +08:00
|
|
|
|
const userinfo = uni.getStorageSync('userinfo')
|
2025-02-25 18:39:55 +08:00
|
|
|
|
|
2025-03-06 22:00:21 +08:00
|
|
|
|
// 如果登录保活
|
|
|
|
|
if (token) {
|
|
|
|
|
// 用户信息
|
|
|
|
|
if (userinfo) store.commit('setState', {
|
|
|
|
|
key: 'userinfo',
|
|
|
|
|
value: userinfo
|
|
|
|
|
})
|
2025-02-26 16:36:32 +08:00
|
|
|
|
|
2025-03-06 22:00:21 +08:00
|
|
|
|
//
|
|
|
|
|
util.getUserinfo().then(rs => {
|
|
|
|
|
if (userinfo.isRealName) {
|
|
|
|
|
// 腾讯im登录
|
|
|
|
|
util.loginTencent(userinfo)
|
|
|
|
|
}
|
2025-02-26 16:36:32 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
2025-03-06 22:00:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取系统配置
|
|
|
|
|
function getConfig() {
|
|
|
|
|
api.getConfig().then(rs => {
|
|
|
|
|
if (rs.code == 200) {
|
|
|
|
|
store.commit('setState', {
|
|
|
|
|
key: 'config',
|
|
|
|
|
value: rs.data
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-12-18 15:46:27 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2025-03-06 22:00:21 +08:00
|
|
|
|
/*每个页面公共css */
|
|
|
|
|
@import "./common/css/style.scss";
|
2024-12-18 15:46:27 +08:00
|
|
|
|
</style>
|