提交 dc1621bf authored 作者: JaxBBLL's avatar JaxBBLL

fix

上级 30298de4
...@@ -67,66 +67,89 @@ export default { ...@@ -67,66 +67,89 @@ export default {
methods: { methods: {
// 检查并请求权限 // 检查并请求权限
async checkAndRequestPermission() { // async checkAndRequestPermission() {
// 定义所需权限 // // 定义所需权限
const permissions = []; // const permissions = [];
if (this.sourceType.includes("camera")) { // if (this.sourceType.includes("camera")) {
permissions.push("android.permission.CAMERA"); // 相机权限 // permissions.push("android.permission.CAMERA"); // 相机权限
} // }
if (this.sourceType.includes("album")) { // if (this.sourceType.includes("album")) {
permissions.push("android.permission.READ_EXTERNAL_STORAGE"); // 相册权限 // permissions.push("android.permission.READ_EXTERNAL_STORAGE"); // 相册权限
} // }
// 检查权限状态 // // 检查权限状态
const hasPermission = await new Promise((resolve) => { // const hasPermission = await new Promise((resolve) => {
plus.android.requestPermissions( // plus.android.requestPermissions(
permissions, // permissions,
(result) => { // (result) => {
let granted = true; // let granted = true;
for (let i = 0; i < result.granted.length; i++) { // for (let i = 0; i < result.granted.length; i++) {
if (!result.granted[i]) { // if (!result.granted[i]) {
granted = false; // granted = false;
break; // break;
} // }
} // }
resolve(granted); // resolve(granted);
}, // },
(error) => { // (error) => {
console.error("权限请求失败:", error.message); // console.error("权限请求失败:", error.message);
resolve(false); // resolve(false);
} // }
); // );
}); // });
if (!hasPermission) { // if (!hasPermission) {
// 用户拒绝授权,弹出提示 // // 用户拒绝授权,弹出提示
uni.showModal({ // uni.showModal({
title: "权限提示", // title: "权限提示",
content: // content:
"您拒绝了必要的权限,可能导致功能无法正常使用。是否前往设置页面开启权限?", // "您拒绝了必要的权限,可能导致功能无法正常使用。是否前往设置页面开启权限?",
success: (modalRes) => { // success: (modalRes) => {
if (modalRes.confirm) { // if (modalRes.confirm) {
// 打开应用设置页面 // // 打开应用设置页面
plus.runtime.openURL( // plus.runtime.openURL(
"app-settings://", // 跳转到系统设置页面 // "app-settings://", // 跳转到系统设置页面
(err) => { // (err) => {
console.error("跳转设置页面失败:", err.message); // console.error("跳转设置页面失败:", err.message);
} // }
); // );
} // }
}, // },
}); // });
return false; // return false;
} // }
return true; // return true;
}, // },
// 选择图片 // // 选择图片
async chooseImage() { // async chooseImage() {
// 检查权限 // // 检查权限
const isAuthorized = await this.checkAndRequestPermission(); // const isAuthorized = await this.checkAndRequestPermission();
if (!isAuthorized) return; // if (!isAuthorized) return;
// const count = this.maxCount - this.images.length; // 剩余可选图片数量
// uni.chooseImage({
// count: count,
// sizeType: this.sizeType,
// sourceType: this.sourceType, // 使用传递的 sourceType
// success: async (res) => {
// const tempFilePaths = res.tempFilePaths;
// for (const filePath of tempFilePaths) {
// const base64 = await this.convertFileToBase64(filePath);
// this.images.push(base64);
// }
// },
// fail: (err) => {
// console.error("选择图片失败:", err);
// uni.showToast({
// title: "选择图片失败,请重试",
// icon: "none",
// });
// },
// });
// },
// 选择图片
chooseImage() {
const count = this.maxCount - this.images.length; // 剩余可选图片数量 const count = this.maxCount - this.images.length; // 剩余可选图片数量
uni.chooseImage({ uni.chooseImage({
count: count, count: count,
...@@ -139,13 +162,6 @@ export default { ...@@ -139,13 +162,6 @@ export default {
this.images.push(base64); this.images.push(base64);
} }
}, },
fail: (err) => {
console.error("选择图片失败:", err);
uni.showToast({
title: "选择图片失败,请重试",
icon: "none",
});
},
}); });
}, },
// 预览图片 // 预览图片
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论