From cf83611d02afe7c39af609ccc8e26633db671f19 Mon Sep 17 00:00:00 2001 From: AstarF <18842336486Q@163.com> Date: Wed, 5 Jun 2024 10:35:27 +0800 Subject: [PATCH] new --- .env.production | 4 +++- README.md | 30 ++++-------------------------- src/pages/home.tsx | 24 ++++++++++++++++++++++-- src/store/AuthStore.ts | 18 +++++++++++++++++- src/utils/Requests.ts | 25 ++++++++++++++++++++++++- 5 files changed, 70 insertions(+), 31 deletions(-) diff --git a/.env.production b/.env.production index 9418d87..2f8c46f 100644 --- a/.env.production +++ b/.env.production @@ -3,7 +3,9 @@ VITE_NODE_ENV = 'production' #生产环境接口地址 VITE_SERVE = 'https://zxjt.86698.cn' + +VITE_SERVE_TEST = 'https://zxjt.test.86698.cn' #'https://lottery.api.86698.cn' # 'http://39.98.117.3' -https://lsxdwx.access.86698.cn/ \ No newline at end of file +# https://lsxdwx.access.86698.cn/ \ No newline at end of file diff --git a/README.md b/README.md index 0d6babe..13748dd 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,8 @@ -# React + TypeScript + Vite +# 中信银行-授权H5页 -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. +## 说明 -Currently, two official plugins are available: +## 部署方式 -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh - -## Expanding the ESLint configuration - -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: - -- Configure the top-level `parserOptions` property like this: - -```js -export default { - // other rules... - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.node.json'], - tsconfigRootDir: __dirname, - }, -} ``` - -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list +``` \ No newline at end of file diff --git a/src/pages/home.tsx b/src/pages/home.tsx index 04c4acc..5ef6d46 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -54,12 +54,16 @@ function Home() { const activityCode = authStore.activityCode const userId = authStore.userId const corpId = authStore.corpId + const tradeNo = authStore.tradeNo + // const code = authStore.code authStore.clear() let url = "" if (activityCode != "") { url = res.data.url + `?activityCode=${activityCode}&userId=${userId}&corpId=${corpId}` - } else { + } else if(tradeNo != ""){ + url = res.data.url + `?code=${urlParams.get('code')}` + }else { url = res.data.url } @@ -119,16 +123,21 @@ function Home() { const openid = urlParams.get('openid') || urlParams.get('openId') const phone = urlParams.get('phone') const sign = urlParams.get('sign') + //学知识专用参数 + const redirect_url = urlParams.get('redirect_url') || "" //裂变专用参数 const activityCode = urlParams.get('activityCode') || "" const userId = urlParams.get('userId') || "" const corpId = urlParams.get('corpId') || "" const timestamp = urlParams.get('timestamp') || "" + const tradeNo = urlParams.get('tradeNo') || "" authStore.setActivityCode(activityCode) authStore.setUserId(userId) authStore.setCorpId(corpId) authStore.setTimeStamp(timestamp) + authStore.setRedirectUrl(redirect_url) + if (tid && openid && sign) { //初次登陆或者重新登陆 @@ -142,11 +151,22 @@ function Home() { authStore.setPhone(phone) authStore.setSign(sign) navigateAccessPage() + } else if(tid && tradeNo){ + authStore.setTid(tid) + authStore.setTradeNo(tradeNo) + navigateAccessPage() } else { //微信跳回 const code = urlParams.get('code') if (code) { - bindIds(code) + const tradeNo = authStore.tradeNo + if(tradeNo){ + const tid = authStore.tid + authStore.setCode(code) + navigateActivityPage(tid) + }else{ + bindIds(code) + } } else { recordState() setTips("授权参数不完整") diff --git a/src/store/AuthStore.ts b/src/store/AuthStore.ts index 6ff2f70..a499904 100644 --- a/src/store/AuthStore.ts +++ b/src/store/AuthStore.ts @@ -11,6 +11,8 @@ interface AuthState { userId:string, corpId:string, timeStamp:string, + redirect_url:string, + tradeNo:string, setClientOpenId: (clientOpenid: string) => void, setCode: (code: string) => void, setPhone: (phone: string) => void, @@ -20,6 +22,8 @@ interface AuthState { setUserId: (userId: string) => void, setCorpId: (corpId: string) => void, setTimeStamp: (timeStamp: string) => void, + setRedirectUrl: (redirect_url: string) => void, + setTradeNo: (tradeNo: string) => void, clear: () => void } export const useAuthStore = create()( @@ -34,6 +38,8 @@ export const useAuthStore = create()( userId: '', corpId: '', timeStamp: '', + redirect_url: '', + tradeNo: '', setClientOpenId: (clientOpenid) => { set({ clientOpenid }) }, @@ -61,8 +67,16 @@ export const useAuthStore = create()( setTimeStamp: (timeStamp) => { set({ timeStamp }) }, + setRedirectUrl: (redirect_url) => { + set({ redirect_url }) + }, + setTradeNo: (tradeNo) => { + set({ tradeNo }) + }, clear: () => { - set({ clientOpenid: '', code:'', tid:0, phone:'', sign: '' }) + set({ clientOpenid: '', code:'', + tid:0, phone:'', sign: '',redirect_url:'', + activityCode:'', userId:'', corpId:'', timeStamp:''}) } }), { @@ -78,6 +92,8 @@ export const useAuthStore = create()( userId: state.userId, corpId: state.corpId, timeStamp: state.timeStamp, + redirect_url: state.redirect_url, + tradeNo: state.tradeNo }) } ) diff --git a/src/utils/Requests.ts b/src/utils/Requests.ts index 6185c38..e0179a5 100644 --- a/src/utils/Requests.ts +++ b/src/utils/Requests.ts @@ -8,11 +8,34 @@ export interface ReqParam { options?: any; } +const test_customer_id = [ + 2,3,674,675,676,677,690,691,695,696,697,698 +] + export const mRequest = async (req: ReqParam) => { console.log("api: ", req.url, " method: ", req.method, " body: ", req.body) const current_env = import.meta.env.VITE_NODE_ENV; + let url = current_env == "production" ? import.meta.env.VITE_SERVE + req.url:req.url; + + + if(req.method == "GET"){ + console.log(req.url) + const param = req.url.split("?") + if(param.length > 1){ + const customer_id = Number(param[1].split("=")[1]) + if(test_customer_id.includes(Number(customer_id))){ + url = import.meta.env.VITE_SERVE_TEST + req.url + } + } + }else{ + const customer_id = req.body.customer_id + if(test_customer_id.includes(Number(customer_id))){ + url = import.meta.env.VITE_SERVE_TEST + req.url + } + } + + console.log(url) - const url = current_env == "production" ? import.meta.env.VITE_SERVE + req.url:req.url;//req.url.replace(/^\/api/, '') : req.url; const content_type = req.body && req.body instanceof FormData ? {} : { 'Content-Type': 'application/json', }