<uni-popup ref="perm" type="dialog">
<uni-popup-dialog mode="base" title="提示" :content="未给与相机权限"
confirmText="前往设置" @close="permCancel" :cancelText="取消" @confirm="permConfirm">
</uni-popup-dialog>
</uni-popup>
- 发布:2024-05-24 17:22
- 更新:2024-05-29 09:30
- 阅读:103
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 4.15
第三方开发者工具版本号: 1.06.2402040
基础库版本号: 3.4.2
项目创建方式: HBuilderX
示例代码:
操作步骤:
代码里面引用该组件
代码里面引用该组件
预期结果:
控制台不会出现错误提示
控制台不会出现错误提示
实际结果:
微信小程序控制台报错
微信小程序控制台报错
喜欢技术的前端 - QQ---445849201
改一下 属性 content cancelText
<template>
<view>
<uni-popup ref="perm" type="dialog">
<uni-popup-dialog mode="base" title="提示" content="未给与相机权限" confirmText="前往设置" @close="permCancel"
cancelText="取消" @confirm="permConfirm">
</uni-popup-dialog>
</uni-popup>
<button @click="btn">button</button>
</view>
</template>
<script>
export default {
methods: {
btn() {
this.$refs.perm.open()
},
permCancel(){
},
permConfirm(){
}
}
}
</script>
<style lang="scss">
</style>
-
宇林 (作者)
我用的国际化,我把国际化代码删了,用的中文方便看,你的uni-popup-dialog组件是最新版本吗?微信开发工具、基础库版本和hbuilderx版本都和我一样吗?我只要使用就报错
2024-05-25 09:05
宇林 (作者)
<template>
<view>
<uni-popup ref="perm" type="dialog">
<uni-popup-dialog mode="base" :title="$t('lang.public.text_07')" :content="permissionText"
:confirmText="confirmText" @close="permCancel" :cancelText="cancelText" @confirm="permConfirm">
</uni-popup-dialog>
</uni-popup>
</view>
</template>
<script>
const app = getApp();
export default {
emits: ['permOk'],
data() {
return {
permissionText: '',
confirmText: this.$t('lang.perm.text_03'),
cancelText: this.$t('lang.public.text_05')
}
},
methods: {
// 确认
permConfirm() {
uni.openAppAuthorizeSetting({
success() {
app.globalData.openSetting = true;
},
fail(res) {
console.log('打开系统设置失败', res)
}
})
},
// 取消
permCancel() {
this.$refs.perm.close()
},
// 判断相机和相册权限
checkCameraAndAlbumPerm() {
let isIos = uni.getSystemInfoSync().platform == 'ios';
if (isIos) {
var album = plus.ios.import("PHPhotoLibrary"),
camera = plus.ios.import("AVCaptureDevice"),
authA = album.authorizationStatus(),
authC = camera.authorizationStatusForMediaType('vide');
console.log('ios权限获取情况:', '相册:', authA, '相机:', authC)
plus.ios.deleteObject(album);
plus.ios.deleteObject(camera);
if (authC != 0 && authC != 3) {
this.permissionText = this.$t('lang.perm.text_01');
this.cancelText = this.$t('lang.public.text_05');
this.$refs.perm.open()
} else if (authA != 0 && authA != 3) {
this.permissionText = this.$t('lang.perm.text_02');
this.cancelText = this.$t('lang.perm.text_04');
this.$refs.perm.open()
} else {
this.$emit('permOk')
}
} else {
const perms = ['android.permission.CAMERA', 'android.permission.READ_EXTERNAL_STORAGE'];
this.requestAndroidPermission(perms).then(resp => {
var camera, album;
for (var i = 0; i < perms.length; i++) {
if (perms[0] === resp[i].name) {
camera = resp[i].value;
}
if (perms[1] === resp[i].name) {
album = resp[i].value;
}
}
console.log('安卓权限获取情况:', '相册:', album, '相机:', camera)
if (camera != 3) {
this.permissionText = this.$t('lang.perm.text_01');
this.cancelText = this.$t('lang.public.text_05');
this.$refs.perm.open()
} else if (album != 3) {
this.permissionText = this.$t('lang.perm.text_02');
this.cancelText = this.$t('lang.perm.text_04');
this.$refs.perm.open()
} else {
this.$emit('permOk')
}
})
}
},
// Android权限查询
requestAndroidPermission(permissionIDs) {
return new Promise((resolve, reject) => {
plus.android.requestPermissions(
permissionIDs,
function(obj) {
var result = [];
for (var i = 0; i < obj.granted.length; i++) {
result.push({
name: obj.granted[i],
value: 3
})
}
for (var i = 0; i < obj.deniedPresent.length; i++) {
result.push({
name: obj.deniedPresent[i],
value: -1
})
}
for (var i = 0; i < obj.deniedAlways.length; i++) {
result.push({
name: obj.deniedAlways[i],
value: -2
})
}
resolve(result)
},
function(error) {
console.log('申请权限错误:' + error.code + " = " + error.message);
resolve({
code: error.code,
message: error.message
})
}
)
})
},
// 提示或等待
showLoadOrToast(title, type = 0, time = 1500) {
switch (type) {
case 0:
uni.showToast({
title: title,
icon: 'none',
duration: time
})
break;
case 1:
uni.showLoading({
title: title,
mask: true
})
break;
}
}
}
}
</script>
<style>
</style>
宇林 (作者)
我先测试你的方案发现仍然报错,然后我尝试把组件换个地方,就不报错了,是什么原因?截图贴在下面
2024-05-29 09:28