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

fix

上级 25dc648d
...@@ -46,6 +46,10 @@ export default { ...@@ -46,6 +46,10 @@ export default {
type: Array, type: Array,
default: () => ["camera"], // 默认从相机拍摄 default: () => ["camera"], // 默认从相机拍摄
}, },
sizeType: {
type: Array,
default: () => ["compressed"], // 默认压缩图 ["original", "compressed"]
},
}, },
data() { data() {
return { return {
...@@ -60,12 +64,73 @@ export default { ...@@ -60,12 +64,73 @@ export default {
this.$emit("input", newVal); // 同步更新父组件绑定的数据 this.$emit("input", newVal); // 同步更新父组件绑定的数据
}, },
}, },
methods: { 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; // 剩余可选图片数量 const count = this.maxCount - this.images.length; // 剩余可选图片数量
uni.chooseImage({ uni.chooseImage({
count: count, count: count,
sizeType: this.sizeType,
sourceType: this.sourceType, // 使用传递的 sourceType sourceType: this.sourceType, // 使用传递的 sourceType
success: async (res) => { success: async (res) => {
const tempFilePaths = res.tempFilePaths; const tempFilePaths = res.tempFilePaths;
...@@ -74,6 +139,13 @@ export default { ...@@ -74,6 +139,13 @@ export default {
this.images.push(base64); this.images.push(base64);
} }
}, },
fail: (err) => {
console.error("选择图片失败:", err);
uni.showToast({
title: "选择图片失败,请重试",
icon: "none",
});
},
}); });
}, },
// 预览图片 // 预览图片
......
...@@ -47,6 +47,9 @@ ...@@ -47,6 +47,9 @@
></image> ></image>
<button class="record-button" @click="toSign">重签</button> <button class="record-button" @click="toSign">重签</button>
</div> </div>
<button class="record-button ml-10" @click="onSyncData">
数据同步
</button>
</view> </view>
</view> </view>
</view> </view>
...@@ -285,6 +288,7 @@ export default { ...@@ -285,6 +288,7 @@ export default {
getRoomList() { getRoomList() {
return assRoomApi.selectRoomList(1).then((res) => { return assRoomApi.selectRoomList(1).then((res) => {
console.log("机房列表", res); console.log("机房列表", res);
console.log("机房列表", JSON.stringify(res));
return res; return res;
}); });
}, },
...@@ -593,6 +597,9 @@ export default { ...@@ -593,6 +597,9 @@ export default {
urls: images, urls: images,
}); });
}, },
onSyncData() {
console.log(this.uid);
},
}, },
}; };
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论