|
|
@@ -4,7 +4,7 @@
|
|
|
<ut-navbar title="追溯码查询" :fixed="false"></ut-navbar>
|
|
|
</template>
|
|
|
<view class="pd-20">
|
|
|
- <up-button class="bg-fff" type="primary" plain>
|
|
|
+ <up-button class="bg-fff" type="primary" plain @click="handleScan">
|
|
|
<image class="w-36 h-36 mr-10" src="https://yujin-szyy.oss-cn-chengdu.aliyuncs.com/szyy/images-plt/common/primary_scan.png" mode="widthFix" />
|
|
|
<span>请扫描追溯码查询</span>
|
|
|
</up-button>
|
|
|
@@ -28,6 +28,54 @@ const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
const { pt_code_downflag } = toRefs<any>(proxy?.useDict('pt_code_downflag'));
|
|
|
const paging = ref();
|
|
|
const info = ref<any>(null);
|
|
|
+// 获取追溯码信息
|
|
|
+const getInfo = async (code: string) => {
|
|
|
+ //
|
|
|
+}
|
|
|
+
|
|
|
+const getQueryParam = (url: string, key: string) => {
|
|
|
+ const queryIndex = url.indexOf('?');
|
|
|
+ if (queryIndex < 0) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ const query = url.slice(queryIndex + 1);
|
|
|
+ const pairs = query.split('&').filter(Boolean);
|
|
|
+ for (const pair of pairs) {
|
|
|
+ const [rawKey, ...rest] = pair.split('=');
|
|
|
+ if (decodeURIComponent(rawKey || '') !== key) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return decodeURIComponent((rest.join('=') || '').replace(/\+/g, ' '));
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+};
|
|
|
+
|
|
|
+const resolveTraceCode = (result: string) => {
|
|
|
+ const value = (result || '').trim();
|
|
|
+ if (!value) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ // 扫描到地址码时优先取参数 c,普通码则直接返回原值。
|
|
|
+ return getQueryParam(value, 'c') || value;
|
|
|
+};
|
|
|
+
|
|
|
+const handleScan = () => {
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ uni.scanCode({
|
|
|
+ onlyFromCamera: true,
|
|
|
+ success: (res) => {
|
|
|
+ const result = (res.result || '').trim();
|
|
|
+ const code = resolveTraceCode(result);
|
|
|
+ if (!code) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log('扫码结果:', result);
|
|
|
+ console.log('追溯码:', code);
|
|
|
+ },
|
|
|
+ fail: () => {},
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+};
|
|
|
|
|
|
onMounted(() => {
|
|
|
|