refactor: 删除扫码页相册选择功能,仅保留拍照扫码+手动输入
This commit is contained in:
@ -1,17 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="page">
|
<view class="page">
|
||||||
<!-- 🚀 全屏扫码大按钮 -->
|
<!-- 🚀 全屏扫码大按钮 -->
|
||||||
<view class="scan-area">
|
<view class="scan-btn camera-btn" @tap="handleScanCamera">
|
||||||
<view class="scan-btn camera-btn" @tap="handleScanCamera">
|
<text class="scan-icon">📷</text>
|
||||||
<text class="scan-icon">📷</text>
|
<text class="scan-text">拍照扫码</text>
|
||||||
<text class="scan-text">拍照扫码</text>
|
<text class="scan-hint">全屏扫描二维码 / 条码</text>
|
||||||
<text class="scan-hint">全屏扫描二维码 / 条码</text>
|
|
||||||
</view>
|
|
||||||
<view class="scan-btn album-btn" @tap="handleScanAlbum">
|
|
||||||
<text class="scan-icon">🖼️</text>
|
|
||||||
<text class="scan-text">从相册选择</text>
|
|
||||||
<text class="scan-hint">识别图片中的二维码</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 手动输入 -->
|
<!-- 手动输入 -->
|
||||||
@ -95,57 +88,6 @@ export default {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 🖼️ 从相册识别二维码
|
|
||||||
handleScanAlbum() {
|
|
||||||
uni.chooseImage({
|
|
||||||
count: 1,
|
|
||||||
sizeType: ["original", "compressed"],
|
|
||||||
sourceType: ["album"],
|
|
||||||
success: (chooseRes) => {
|
|
||||||
const path = chooseRes.tempFilePaths[0];
|
|
||||||
if (!path) return;
|
|
||||||
// 使用 uni.getImageInfo 获取图片后,再调用 scanCode 的 base64 模式
|
|
||||||
// 或者直接用 #ifdef 编译条件
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
this.decodeQRFromImage(path);
|
|
||||||
// #endif
|
|
||||||
// #ifndef APP-PLUS
|
|
||||||
uni.scanCode({
|
|
||||||
onlyFromCamera: false,
|
|
||||||
scanType: ["qrCode"],
|
|
||||||
success: (scanRes) => {
|
|
||||||
const sn = (scanRes.result || "").replace(/[^a-zA-Z0-9]/g, "").slice(0, 16);
|
|
||||||
this.doQuery(sn);
|
|
||||||
},
|
|
||||||
fail: () => {
|
|
||||||
uni.showToast({ title: "未识别到二维码", icon: "none" });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// #endif
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
if (!err.errMsg || !err.errMsg.includes("cancel")) {
|
|
||||||
uni.showToast({ title: "选择失败", icon: "none" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// APP-PLUS: 从图片解码二维码
|
|
||||||
decodeQRFromImage(path) {
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
plus.barcode.scan(path, (type, result) => {
|
|
||||||
const sn = (result || "").replace(/[^a-zA-Z0-9]/g, "").slice(0, 16);
|
|
||||||
this.doQuery(sn);
|
|
||||||
}, (err) => {
|
|
||||||
uni.showToast({ title: "未识别到二维码", icon: "none" });
|
|
||||||
}, {
|
|
||||||
filters: ["QRCODE"],
|
|
||||||
scanBoth: true,
|
|
||||||
});
|
|
||||||
// #endif
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -154,13 +96,11 @@ export default {
|
|||||||
.page { min-height: 100vh; padding: 24px 16px 16px; background: #f3f4f6; }
|
.page { min-height: 100vh; padding: 24px 16px 16px; background: #f3f4f6; }
|
||||||
|
|
||||||
/* 扫码区域 */
|
/* 扫码区域 */
|
||||||
.scan-area { display: flex; gap: 12px; }
|
.scan-btn { display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||||
.scan-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
height: 180px; border-radius: 20px; color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,0.12);
|
||||||
height: 160px; border-radius: 20px; color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,0.12);
|
transition: transform 0.15s; margin-bottom: 24px; }
|
||||||
transition: transform 0.15s; }
|
|
||||||
.scan-btn:active { transform: scale(0.96); }
|
.scan-btn:active { transform: scale(0.96); }
|
||||||
.camera-btn { background: linear-gradient(135deg, #2563EB, #4F46E5); }
|
.camera-btn { background: linear-gradient(135deg, #2563EB, #4F46E5); }
|
||||||
.album-btn { background: linear-gradient(135deg, #7C3AED, #A855F7); }
|
|
||||||
.scan-icon { font-size: 44px; margin-bottom: 6px; }
|
.scan-icon { font-size: 44px; margin-bottom: 6px; }
|
||||||
.scan-text { font-size: 17px; font-weight: 700; }
|
.scan-text { font-size: 17px; font-weight: 700; }
|
||||||
.scan-hint { font-size: 11px; opacity: 0.75; margin-top: 4px; }
|
.scan-hint { font-size: 11px; opacity: 0.75; margin-top: 4px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user