124 lines
3.2 KiB
Vue
124 lines
3.2 KiB
Vue
<script setup>
|
||
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'
|
||
// #ifdef APP
|
||
// 引入各种权限配置
|
||
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>",
|
||
}
|
||
// #endif
|
||
|
||
onLaunch(() => {
|
||
// 获取用户信息
|
||
getUserinfo()
|
||
// 获取系统配置
|
||
getConfig()
|
||
// #ifdef APP
|
||
// 处理用户在app端提交的权限
|
||
init()
|
||
// #endif
|
||
})
|
||
|
||
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
|
||
}
|
||
}
|
||
setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
|
||
if (hasDeniedPermission)
|
||
uni.showModal({
|
||
content: "权限已经被拒绝,请前往设置中开启"
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
// 获取用户信息
|
||
function getUserinfo() {
|
||
// 登录令牌
|
||
const token = uni.getStorageSync('token')
|
||
// 用户信息
|
||
const userinfo = uni.getStorageSync('userinfo')
|
||
|
||
// 如果登录保活
|
||
if (token) {
|
||
// 用户信息
|
||
if (userinfo) store.commit('setState', {
|
||
key: 'userinfo',
|
||
value: userinfo
|
||
})
|
||
|
||
//
|
||
util.getUserinfo().then(rs => {
|
||
if (userinfo.isRealName) {
|
||
// 腾讯im登录
|
||
util.loginTencent(userinfo)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
// 获取系统配置
|
||
function getConfig() {
|
||
api.getConfig().then(rs => {
|
||
if (rs.code == 200) {
|
||
store.commit('setState', {
|
||
key: 'config',
|
||
value: rs.data
|
||
})
|
||
return
|
||
}
|
||
})
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/*每个页面公共css */
|
||
@import "./common/css/style.scss";
|
||
</style> |