From 7f3ed0b42c3a657433f71b197fe4b9604439174e Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Mon, 3 Jun 2024 15:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20zustand=20=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=EF=BC=8C=E5=88=A0=E9=99=A4=E5=88=87=E6=8D=A2=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86=E7=9B=B8=E5=85=B3=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- public/locales/en/common.json | 1 - public/locales/zh/common.json | 1 - src/main.jsx | 2 - src/stores/Auth.js | 64 +++++++++------- src/views/account/ChangeVendor.jsx | 113 ----------------------------- 6 files changed, 38 insertions(+), 146 deletions(-) delete mode 100644 src/views/account/ChangeVendor.jsx diff --git a/package.json b/package.json index 8809e6d..34b2c55 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "react-dom": "^18.2.0", "react-i18next": "^14.1.2", "react-router-dom": "^6.10.0", - "react-to-pdf": "^1.0.1" + "react-to-pdf": "^1.0.1", + "zustand": "^4.5.0" }, "devDependencies": { "@types/react": "^18.0.28", diff --git a/public/locales/en/common.json b/public/locales/en/common.json index f691c79..a8b3a66 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -26,7 +26,6 @@ "ChangePassword": "Change password", "Profile": "Profile", "Logout": "Logout", - "ChangeVendor": "Change Vendor", "LoginTimeout": "Login timeout", "LoginTimeoutTip": "Please input your password", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index ffccf32..58c5f6b 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -26,7 +26,6 @@ "ChangePassword": "修改密码", "Profile": "账户中心", "Logout": "退出", - "ChangeVendor": "切换账户", "LoginTimeout": "登录超时", "LoginTimeoutTip": "请输入密码", diff --git a/src/main.jsx b/src/main.jsx index 97d59e1..1e4e687 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -27,7 +27,6 @@ import InvoiceIndex from "@/views/invoice/Index"; import InvoiceDetail from "@/views/invoice/Detail"; import InvoicePaid from "@/views/invoice/Paid"; import InvoicePaidDetail from "@/views/invoice/PaidDetail"; -import ChangeVendor from "@/views/account/ChangeVendor"; import './i18n'; @@ -61,7 +60,6 @@ const router = createBrowserRouter([ { path: "invoice/detail/:GMDSN/:GSN",element:}, { path: "invoice/paid",element:}, { path: "invoice/paid/detail/:flid",element:}, - { path: "account/change-vendor",element:}, ] }, { diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 0110238..2338254 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -3,11 +3,47 @@ import { fetchJSON, postForm } from '@/utils/request'; import { HT_HOST } from "@/config"; import { isNotEmpty, prepareUrl } from '@/utils/commons'; import { loadPageSpy } from '@/pageSpy'; +import { create } from 'zustand' const KEY_LOGIN_TOKEN = 'KEY_LOGIN_TOKEN'; const KEY_TRAVEL_AGENCY_ID = 'KEY_TRAVEL_AGENCY_ID'; const KEY_USER_ID = 'KEY_USER_ID'; +const useAuthStore = create((set, get) => ({ + + loginUser: { + userId: -1, + username: '', + avatarUrl: '', + mobile: '', + email: '', + permissionList: [], + }, + + isPermitted: (perm) => { + return true + // 以上是 Hardcode 判断 + // 以下是权限列表从数据库读取后使用的方法 + // return this.permissionList.some((value, key, arry) => { + // if (value.indexOf(WILDCARD_TOKEN) > -1) { + // return true; + // } + // if (value === perm) { + // return true; + // } + // return false; + // }); + + }, + + login: async (authCode) => { + }, + + logout: () => { + }, + +})) + class Auth { constructor(root) { @@ -143,34 +179,6 @@ class Auth { }); } - //切换供应商 - changeVendor(VEISN){ - // const formData = new FormData(); - // formData.append('VEI_SN',VEISN); - // formData.append('LMI_SN',this.login.userId); - // formData.append('token', this.login.token); - const fetchUrl = prepareUrl(HT_HOST+'/service-cusservice/PTChangeVendor') - .append('LMI_SN',this.login.userId) - .append('VEI_SN',VEISN) - .append('token', this.login.token) - .build(); - //console.log(fetchUrl); - // return false; - - return fetchJSON(fetchUrl) - .then(()=>{ - let json = {"errcode": 0, "errmsg": "ok", "Result":[]}; - if (json.errcode==0){ - //console.log(json); - return json; - }else{ - throw new Error(json.errmsg+":"+json.errcode); - } - }); - } - - VendorList = [];//海外供应商列表 - login = { token: '', userId: 0, // LMI_SN diff --git a/src/views/account/ChangeVendor.jsx b/src/views/account/ChangeVendor.jsx deleted file mode 100644 index 190eb71..0000000 --- a/src/views/account/ChangeVendor.jsx +++ /dev/null @@ -1,113 +0,0 @@ -import { useNavigate } from "react-router-dom"; -import { useEffect, useState, useRef } from "react"; -import { observer } from "mobx-react"; -import { Button, Space, Form, Input, Row, Typography, App,Select } from "antd"; -import { useStore } from "@/stores/StoreContext.js"; - -const { Title } = Typography; - -function ChangeVendor() { - const navigate = useNavigate(); - const { authStore,VendorList } = useStore(); - const { notification } = App.useApp(); - const [form] = Form.useForm(); - const { formVeiSn, onVeiSnChange } = useState(); - - - useEffect(() => { - authStore.fetchVendorList(); - },[]); - - //币种 - function bindVendor() { - - let arr=[]; - arr = authStore.VendorList.map((data,index) =>{ - return { - value: data.VEI_SN, - label: data.VEI2_CompanyBN, - } - }) - return arr; - - } - - const onFinish = (values) => { - if (values.VEISN == authStore.login.travelAgencyId){ - notification.error({ - message: `Notification`, - description: "切换的供应商是当前供应商.", - placement: "top", - duration: 4, - }); - return ; - } - // console.log(values); - // console.log(authStore.login.travelAgencyId); - - authStore.changeVendor(values.VEISN) - .then(()=>{ - authStore.logout(); - }) - .catch(()=>{ - //console.log(json); - notification.error({ - message: `Notification`, - description: "切换的供应商错误,请重试!", - placement: "top", - duration: 4, - }); - }) - }; - - const onFinishFailed = (errorInfo) => { - console.log("Failed:", errorInfo); - // form.resetFields(); - }; - - return ( - -
- - Change your password - - - - - - - - - -
-
- ); -} - -export default observer(ChangeVendor);