|
|
@ -95,7 +95,7 @@ import { ref, reactive, onMounted, onBeforeUnmount, nextTick } from 'vue'; |
|
|
import { useRouter, useRoute } from 'vue-router'; |
|
|
import { useRouter, useRoute } from 'vue-router'; |
|
|
import { showFailToast, showSuccessToast, showToast, showConfirmDialog } from 'vant'; |
|
|
import { showFailToast, showSuccessToast, showToast, showConfirmDialog } from 'vant'; |
|
|
import { baseUrl, appEnv } from '@/config/env.js'; |
|
|
import { baseUrl, appEnv } from '@/config/env.js'; |
|
|
import { getEntInfoByQRCode, queryEnterpriseListAndQrInfo, szyptGetToken } from '@/api/enforcement/index'; |
|
|
import { getEntInfoByQRCode, queryEnterpriseListAndQrInfo } from '@/api/enforcement/index'; |
|
|
import wx from 'weixin-js-sdk'; |
|
|
import wx from 'weixin-js-sdk'; |
|
|
|
|
|
|
|
|
const router = useRouter(); |
|
|
const router = useRouter(); |
|
|
@ -209,60 +209,53 @@ const onFileSelected = async (event) => { |
|
|
// ---------- prod 环境:wx.scanQRCode ---------- |
|
|
// ---------- prod 环境:wx.scanQRCode ---------- |
|
|
|
|
|
|
|
|
const openWxScan = () => { |
|
|
const openWxScan = () => { |
|
|
let fullUrl = window.location.href; |
|
|
// TODO: 对接实际微信 JSSDK token 接口后启用 |
|
|
let code = fullUrl.substring(fullUrl.indexOf('code=') + 5, fullUrl.indexOf('&state=')); |
|
|
// 当前仅预留调用骨架,需配合服务端 szyptGetToken 接口获取签名 |
|
|
let paramUrl = window.location.href.split("#")[0]; |
|
|
const fullUrl = window.location.href; |
|
|
let param = {code: code, url: paramUrl}; |
|
|
const paramUrl = fullUrl.split('#')[0]; |
|
|
szyptGetToken(param, success => { |
|
|
showToast('正在调起微信扫码...'); |
|
|
let resMsg = success.data; |
|
|
// 以下为 wx.config + wx.scanQRCode 的标准流程 |
|
|
console.log(resMsg); |
|
|
// 实际使用时需先调用服务端接口获取 config 参数 |
|
|
wx.config({ |
|
|
szyptGetToken({ url: paramUrl }, (res) => { |
|
|
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 |
|
|
const data = res.data; |
|
|
debug: false, |
|
|
wx.config({ |
|
|
// 必填,公众号的唯一标识 |
|
|
debug: false, |
|
|
appId: resMsg.corpid, |
|
|
appId: data.corpid, |
|
|
// 必填,生成签名的时间戳 |
|
|
timestamp: data.timestamp, |
|
|
timestamp: resMsg.timestamp, |
|
|
nonceStr: data.nonceStr, |
|
|
// 必填,生成签名的随机串 |
|
|
signature: data.signature, |
|
|
nonceStr: resMsg.nonceStr, |
|
|
jsApiList: ['scanQRCode'], |
|
|
// 必填,签名,见附录1 |
|
|
}); |
|
|
signature: resMsg.signature, |
|
|
wx.ready(() => { |
|
|
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2 |
|
|
wxClickScan(); |
|
|
jsApiList: ["scanQRCode"], |
|
|
}); |
|
|
}); |
|
|
wx.error((err) => { |
|
|
wx.ready(() => { |
|
|
console.error('wx.config 失败', err); |
|
|
//微信扫一扫请求操作 |
|
|
showFailToast('微信配置失败,请重试'); |
|
|
ClickScan() |
|
|
|
|
|
}); |
|
|
|
|
|
wx.error((res) => { |
|
|
|
|
|
console.log("获取失败", res); |
|
|
|
|
|
}); |
|
|
|
|
|
}, error => { |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 开发阶段直接尝试调用(在微信浏览器内有效) |
|
|
|
|
|
wxClickScan(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const ClickScan = () => { |
|
|
const wxClickScan = () => { |
|
|
wx.scanQRCode({ |
|
|
wx.scanQRCode({ |
|
|
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, |
|
|
needResult: 1, |
|
|
scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有 |
|
|
scanType: ['qrCode', 'barCode'], |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
// 页面跳转 |
|
|
console.log('wx 扫码返回:', res); |
|
|
console.log("=========== 扫码返回 ===========") |
|
|
handleScanResult(res.resultStr); |
|
|
console.log(res) |
|
|
|
|
|
if(isHttpLink(res.resultStr)){ |
|
|
|
|
|
handleScanResult(res.resultStr); |
|
|
|
|
|
}else{ |
|
|
|
|
|
showFailToast("该二维码不正确"); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
}, |
|
|
error: function(res) { |
|
|
error: (res) => { |
|
|
console.log("错误回调",res) |
|
|
console.error('wx 扫码错误:', res); |
|
|
if (res.errMsg.indexOf('function_not_exist') > 0) { |
|
|
if (res.errMsg && res.errMsg.indexOf('function_not_exist') > 0) { |
|
|
showFailToast('版本过低请升级') |
|
|
showFailToast('版本过低请升级'); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
cancel: (res) => { |
|
|
cancel: () => { |
|
|
console.log('err', res); |
|
|
console.log('用户取消扫码'); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
@ -286,7 +279,7 @@ const handleScanResult = (resultStr) => { |
|
|
// 将企业信息存入 sessionStorage,预览页直接使用,无需再调接口 |
|
|
// 将企业信息存入 sessionStorage,预览页直接使用,无需再调接口 |
|
|
sessionStorage.setItem('enterpriseScanData', JSON.stringify(data)); |
|
|
sessionStorage.setItem('enterpriseScanData', JSON.stringify(data)); |
|
|
// 跳转企业详情预览页,携带执法类型参数和企业编号 |
|
|
// 跳转企业详情预览页,携带执法类型参数和企业编号 |
|
|
router.push({ |
|
|
router.push({ |
|
|
path: '/enforcement/enterpriseScanPreview', |
|
|
path: '/enforcement/enterpriseScanPreview', |
|
|
query: { type: enforceType, enterpriseNumber: data.enterpriseNumber } |
|
|
query: { type: enforceType, enterpriseNumber: data.enterpriseNumber } |
|
|
}); |
|
|
}); |
|
|
@ -401,7 +394,7 @@ const selectEnterprise = (item) => { |
|
|
showSearchModal.value = false; |
|
|
showSearchModal.value = false; |
|
|
router.push({ |
|
|
router.push({ |
|
|
path: '/enforcement/enterpriseScanPreview', |
|
|
path: '/enforcement/enterpriseScanPreview', |
|
|
query: { |
|
|
query: { |
|
|
enterpriseNumber: item.enterpriseNumber, |
|
|
enterpriseNumber: item.enterpriseNumber, |
|
|
type: enforceType |
|
|
type: enforceType |
|
|
} |
|
|
} |
|
|
|