From fb09018f1e785c4282bc45dde90a48ac7f5198ba Mon Sep 17 00:00:00 2001 From: dengtongyu Date: Fri, 21 Apr 2023 01:08:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/index.ts | 4 ++-- package.json | 2 ++ src/App.vue | 4 +++- src/api/index.ts | 8 ++++---- src/main.ts | 4 ++-- src/pages/Home.vue | 7 ++++--- src/store/pay.ts | 17 +++++++++++++---- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/config/index.ts b/config/index.ts index de6ef18..12355eb 100644 --- a/config/index.ts +++ b/config/index.ts @@ -9,10 +9,10 @@ switch (VITE_APP_ENV) { proxyTarget = "http://apibeta.haloapp.vip"; break; case "prod": - proxyTarget = "http://apibeta.haloapp.vip"; + proxyTarget = "https://api.xingyuwenhua.com.cn"; break; default: - proxyTarget = "http://apibeta.haloapp.vip"; + proxyTarget = "http://api.xingyuwenhua.com.cn"; break; } diff --git a/package.json b/package.json index 3d9011f..d9d9517 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,14 @@ "dependencies": { "axios": "^0.27.2", "pinia": "^2.0.19", + "qs": "^6.11.1", "vant": "^4.2.0", "vue": "^3.2.37", "vue-router": "^4.1.3" }, "devDependencies": { "@types/node": "^18.11.18", + "@types/qs": "^6.9.7", "@typescript-eslint/eslint-plugin": "^5.40.1", "@typescript-eslint/parser": "^5.40.1", "@vitejs/plugin-legacy": "^2.0.1", diff --git a/src/App.vue b/src/App.vue index 27c46ae..170f4ee 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,8 @@ diff --git a/src/api/index.ts b/src/api/index.ts index 79cac8b..3451031 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,17 +1,17 @@ import ajax from "../lib/ajax"; -// import { passid } from "../../config"; +import { stringify } from "qs"; const chargeprodList = function (param?: any) { const params = Object.assign({channelType: 2}, param || {}); return ajax.get("/chargeprod/list", { params }); }; -const chargeUser = function (param: any) { - return ajax.get("/user/getChargeUser", { params: param }); +const chargeUser = function (param: any, config?:any) { + return ajax.get("/user/getChargeUser", { params: param, ...config }); }; const submitPay = function (param: any) { - return ajax.post("/wx/submitPay", param); + return ajax.post("/wx/submitPay", stringify(param)); }; export { diff --git a/src/main.ts b/src/main.ts index bb3ca69..c510f31 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import { createApp } from "vue"; -import routes from "./routes"; +// import routes from "./routes"; import App from "./App.vue"; import pinia from "./store/pinia"; import { install } from "./installComponents"; @@ -7,7 +7,7 @@ import "./styles/index.less"; const app = createApp(App); app.use(pinia); -app.use(routes); +// app.use(routes); install(app); app.mount("#app"); diff --git a/src/pages/Home.vue b/src/pages/Home.vue index 3ca16a2..a75f18c 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -7,6 +7,7 @@ import { getQueryString } from "@/lib/util"; const payStore = pay(pinia); const locateObj = getQueryString(); +// console.log("locateObj", locateObj); const { openId, data, channel } = locateObj; const searchKeyword = ref(""); @@ -36,11 +37,12 @@ const selectHandler = (index: number) => { }; -const regUser = /^\d{7}$/; +const regUser = /^[0-9]*$/; const regPhone = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; const searchHandler = () => { const keyword = searchKeyword.value; + if(!keyword) return; // console.log(keyword, regUser.test(keyword), regPhone.test(keyword)); if (regUser.test(keyword) || regPhone.test(keyword)) { payStore.getChargeUser(keyword); @@ -95,9 +97,8 @@ const payHandler = () => { const confirmHandler = () => { const data:any = {}; const isPhone = regPhone.test(searchKeyword.value); - const isUserId = regUser.test(searchKeyword.value); if(isPhone) data.phone = searchKeyword.value; - if(isUserId) data.erban_no = searchKeyword.value; + else data.erban_no = userInfoErbanNo.value; payStore.payRequest(data); }; diff --git a/src/store/pay.ts b/src/store/pay.ts index 9031ffb..f9ed5f8 100644 --- a/src/store/pay.ts +++ b/src/store/pay.ts @@ -3,6 +3,9 @@ import { defineStore } from "pinia"; import { showNotify, showToast } from "vant"; import { chargeprodList, chargeUser, submitPay } from "@/api/index"; import { onBridgeReady } from "@/wx/index"; +import axios from "axios"; +const CancelToken = axios.CancelToken; +let source = CancelToken.source(); const pay = defineStore("pay", () => { @@ -12,7 +15,7 @@ const pay = defineStore("pay", () => { const initParams = (data:any) => { openId.value = data.openId || ""; - dataId.value = data.dataId || ""; + dataId.value = data.data || ""; channel.value = data.channel || ""; }; @@ -54,14 +57,16 @@ const pay = defineStore("pay", () => { const getChargeUser = (erbanNo: string | number) => { + source.cancel("getChargeUser canceled"); + source = CancelToken.source(); return new Promise((resolve, reject) => { - chargeUser({ erbanNo: erbanNo }) + chargeUser({ erbanNo: erbanNo }, { cancelToken: source.token }) .then((res: any) => { const { code, data, message } = res; if (code === 200) { receiveUser.value = data; } else if (code === 1404) { - showNotify({ type: "warning", message: "您输入的账号不存在" }); + // showNotify({ type: "warning", message: "您输入的账号不存在" }); } else { showNotify({ type: "warning", message: message }); @@ -69,7 +74,11 @@ const pay = defineStore("pay", () => { resolve(res); }) .catch((err: any) => { - reject(err); + if (axios.isCancel(err)) { + console.info("Request canceled", err.message); + }else{ + reject(err); + } }); }); };