快捷扫码支付修改
This commit is contained in:
1 parent
80bda75548
commit
37aff79bfd
1 file changed
+44
-23
+44
-23
@@ -61,7 +61,6 @@ import { getAppInfo } from "@@/utils/getAppInfo"
|
||||
import { hooks, router, constant } from "@@/index"
|
||||
import { userApi } from "@@/api"
|
||||
import isDevEnv from "@/sheep/utils/isDevEnv"
|
||||
import { usePayStore } from "@/sheep/stores/pay"
|
||||
// import dd from "gdt-jsapi"
|
||||
|
||||
const state = reactive<{
|
||||
@@ -270,18 +269,20 @@ const login = {
|
||||
const scanCode = {
|
||||
// 扫一扫
|
||||
scan: async () => {
|
||||
try {
|
||||
const decodedString = await scanCode.getScanResult()
|
||||
if (decodedString) {
|
||||
scanCode.processScanResult(decodedString)
|
||||
}
|
||||
// else {
|
||||
// uni.showToast({ title: "无效的二维码", icon: "none" })
|
||||
// }
|
||||
} catch (error: any) {
|
||||
// if (error) {
|
||||
// uni.showToast({ title: error, icon: "none" })
|
||||
// }
|
||||
// 获取扫码结果
|
||||
const scanResult = await scanCode.getScanResult()
|
||||
|
||||
if (!scanResult) return uni.showToast({ title: "扫码错误", icon: "none" })
|
||||
|
||||
// 判断扫码结果
|
||||
if (scanResult.startsWith("http")) {
|
||||
// 扫码结果是url链接
|
||||
scanCode.processUrlScanResult(scanResult.replace("/#", ""))
|
||||
} else {
|
||||
// 扫码结果是base64字符串
|
||||
const decodedString = scanCode.decodeBase64(scanResult)
|
||||
if (!decodedString) return
|
||||
scanCode.processBase64ScanResult(decodedString)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -289,30 +290,33 @@ const scanCode = {
|
||||
getScanResult: async (): Promise<string | undefined> => {
|
||||
if (isDevEnv()) {
|
||||
// 开发环境模拟扫码
|
||||
// const testQrCode = "eyJpZCI6IjE4OTYxNTcyMDc2NDQwNTM1MDYiLCJuYW1lIjoi5rWL6K+V5ZWG5oi3In0=" // 线上-测试超市-收款码
|
||||
const testQrCode = "eyJpZCI6IjE5MDU4MTY3NTEwNDM0NTI5MzAiLCJuYW1lIjoi5paw5Y6/5bqc6LaF5biCIn0=" // 测试环境-邓本地-新县府超市-收款码
|
||||
// const testQrCode = "eyJoYXJkRG9vcklkIjoiMTkxMzE1NzA4MDQxODI5NTgwOSIsImNhYmluZXRObyI6IjEifQ==" // 测试智能柜货柜二维码
|
||||
// const testQrCode = "eyJpZCI6IjE4OTYxNTcyMDc2NDQwNTM1MDYiLCJuYW1lIjoi5rWL6K+V5ZWG5oi3In0=" // 线上-测试超市-收款二维码
|
||||
// const testQrCode = "eyJpZCI6IjE5MDU4MTY3NTEwNDM0NTI5MzAiLCJuYW1lIjoi5paw5Y6/5bqc6LaF5biCIn0=" // 邓本地-测试环境-新县府超市收款二维码
|
||||
// const testQrCode = "eyJoYXJkRG9vcklkIjoiMTkxNDI0MjgzMDkyOTk4OTYzNCIsImNhYmluZXRObyI6IjEifQ==" // 测试智能柜柜门二维码
|
||||
// const testQrCode = "http://192.168.101.45:8889/h5/#/pages/pay/scanPay?id=1905816751043452930&name=测试新县府超市" // 邓本地-测试环境-新县府超市收款二维码
|
||||
const testQrCode = "http://192.168.101.45:8889/h5/#/pages/pay/scanPay?hardDoorId=1914242830929989634&cabinetNo=1" // 测试智能柜柜门二维码
|
||||
uni.showModal({ content: "开发环境不是浙政钉和诗画环境,扫码仅供测试,收款商家为测试商户超市" })
|
||||
return scanCode.decodeBase64(testQrCode)
|
||||
|
||||
return testQrCode
|
||||
} else if (state.appInfo == "zzd") {
|
||||
// 浙政钉扫码
|
||||
const res: any = await (window as any).dd.scan({ type: "all" })
|
||||
return scanCode.decodeBase64(res.text)
|
||||
return res.text
|
||||
} else if (state.appInfo == "sh") {
|
||||
// 诗画扫码
|
||||
const res = await (window as any).CP2.showScanQr({ needResult: 1 })
|
||||
if (res.code == 1) return scanCode.decodeBase64(res.data.qrCode)
|
||||
if (res.code == 1) return res.data.qrCode
|
||||
} else {
|
||||
uni.showToast({ title: "当前环境未知", icon: "none" })
|
||||
}
|
||||
},
|
||||
|
||||
// 处理扫码结果
|
||||
processScanResult: (decodedString: string) => {
|
||||
// 处理base64扫码结果
|
||||
processBase64ScanResult: (decodedString: string) => {
|
||||
try {
|
||||
const decodedJson = JSON.parse(decodedString)
|
||||
if (decodedJson?.id && decodedJson?.name) {
|
||||
router.jump("/pages/pay/scanPay", { id: decodedJson.id, name: decodedJson.name })
|
||||
if (decodedJson.id) {
|
||||
router.jump("/pages/pay/scanPay", { id: decodedJson.id })
|
||||
} else if (decodedJson?.hardDoorId && decodedJson?.cabinetNo) {
|
||||
router.jump("/pages/cabinet/buy", { hardDoorId: decodedJson.hardDoorId, cabinetNo: decodedJson.cabinetNo })
|
||||
} else {
|
||||
@@ -323,6 +327,23 @@ const scanCode = {
|
||||
}
|
||||
},
|
||||
|
||||
// 处理url扫码结果
|
||||
processUrlScanResult: (url: string) => {
|
||||
const searchParams = new URL(url).searchParams
|
||||
const id = searchParams.get("id")
|
||||
const name = searchParams.get("name")
|
||||
const hardDoorId = searchParams.get("hardDoorId")
|
||||
const cabinetNo = searchParams.get("cabinetNo")
|
||||
|
||||
if (id) {
|
||||
router.jump("/pages/pay/scanPay", { id, name })
|
||||
} else if (hardDoorId && cabinetNo) {
|
||||
router.jump("/pages/cabinet/buy", { hardDoorId, cabinetNo })
|
||||
} else {
|
||||
uni.showToast({ title: "无效的二维码", icon: "none" })
|
||||
}
|
||||
},
|
||||
|
||||
// 解码base64
|
||||
decodeBase64: (base64String: string): string | undefined => {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user