提交 30298de4 authored 作者: JaxBBLL's avatar JaxBBLL

fix

上级 25dc648d
......@@ -46,6 +46,10 @@ export default {
type: Array,
default: () => ["camera"], // 默认从相机拍摄
},
sizeType: {
type: Array,
default: () => ["compressed"], // 默认压缩图 ["original", "compressed"]
},
},
data() {
return {
......@@ -60,12 +64,73 @@ export default {
this.$emit("input", newVal); // 同步更新父组件绑定的数据
},
},
methods: {
// 检查并请求权限
async checkAndRequestPermission() {
// 定义所需权限
const permissions = [];
if (this.sourceType.includes("camera")) {
permissions.push("android.permission.CAMERA"); // 相机权限
}
if (this.sourceType.includes("album")) {
permissions.push("android.permission.READ_EXTERNAL_STORAGE"); // 相册权限
}
// 检查权限状态
const hasPermission = await new Promise((resolve) => {
plus.android.requestPermissions(
permissions,
(result) => {
let granted = true;
for (let i = 0; i < result.granted.length; i++) {
if (!result.granted[i]) {
granted = false;
break;
}
}
resolve(granted);
},
(error) => {
console.error("权限请求失败:", error.message);
resolve(false);
}
);
});
if (!hasPermission) {
// 用户拒绝授权,弹出提示
uni.showModal({
title: "权限提示",
content:
"您拒绝了必要的权限,可能导致功能无法正常使用。是否前往设置页面开启权限?",
success: (modalRes) => {
if (modalRes.confirm) {
// 打开应用设置页面
plus.runtime.openURL(
"app-settings://", // 跳转到系统设置页面
(err) => {
console.error("跳转设置页面失败:", err.message);
}
);
}
},
});
return false;
}
return true;
},
// 选择图片
chooseImage() {
async chooseImage() {
// 检查权限
const isAuthorized = await this.checkAndRequestPermission();
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;
......@@ -74,6 +139,13 @@ export default {
this.images.push(base64);
}
},
fail: (err) => {
console.error("选择图片失败:", err);
uni.showToast({
title: "选择图片失败,请重试",
icon: "none",
});
},
});
},
// 预览图片
......
......@@ -47,6 +47,9 @@
></image>
<button class="record-button" @click="toSign">重签</button>
</div>
<button class="record-button ml-10" @click="onSyncData">
数据同步
</button>
</view>
</view>
</view>
......@@ -285,6 +288,7 @@ export default {
getRoomList() {
return assRoomApi.selectRoomList(1).then((res) => {
console.log("机房列表", res);
console.log("机房列表", JSON.stringify(res));
return res;
});
},
......@@ -593,6 +597,9 @@ export default {
urls: images,
});
},
onSyncData() {
console.log(this.uid);
},
},
};
</script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论