增加 zustand 框架,删除切换供应商相关页面

feature/price_manager
Jimmy Liow 1 year ago
parent 696f2bb816
commit 7f3ed0b42c

@ -21,7 +21,8 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-i18next": "^14.1.2", "react-i18next": "^14.1.2",
"react-router-dom": "^6.10.0", "react-router-dom": "^6.10.0",
"react-to-pdf": "^1.0.1" "react-to-pdf": "^1.0.1",
"zustand": "^4.5.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.0.28", "@types/react": "^18.0.28",

@ -26,7 +26,6 @@
"ChangePassword": "Change password", "ChangePassword": "Change password",
"Profile": "Profile", "Profile": "Profile",
"Logout": "Logout", "Logout": "Logout",
"ChangeVendor": "Change Vendor",
"LoginTimeout": "Login timeout", "LoginTimeout": "Login timeout",
"LoginTimeoutTip": "Please input your password", "LoginTimeoutTip": "Please input your password",

@ -26,7 +26,6 @@
"ChangePassword": "修改密码", "ChangePassword": "修改密码",
"Profile": "账户中心", "Profile": "账户中心",
"Logout": "退出", "Logout": "退出",
"ChangeVendor": "切换账户",
"LoginTimeout": "登录超时", "LoginTimeout": "登录超时",
"LoginTimeoutTip": "请输入密码", "LoginTimeoutTip": "请输入密码",

@ -27,7 +27,6 @@ import InvoiceIndex from "@/views/invoice/Index";
import InvoiceDetail from "@/views/invoice/Detail"; import InvoiceDetail from "@/views/invoice/Detail";
import InvoicePaid from "@/views/invoice/Paid"; import InvoicePaid from "@/views/invoice/Paid";
import InvoicePaidDetail from "@/views/invoice/PaidDetail"; import InvoicePaidDetail from "@/views/invoice/PaidDetail";
import ChangeVendor from "@/views/account/ChangeVendor";
import './i18n'; import './i18n';
@ -61,7 +60,6 @@ const router = createBrowserRouter([
{ path: "invoice/detail/:GMDSN/:GSN",element:<InvoiceDetail />}, { path: "invoice/detail/:GMDSN/:GSN",element:<InvoiceDetail />},
{ path: "invoice/paid",element:<InvoicePaid />}, { path: "invoice/paid",element:<InvoicePaid />},
{ path: "invoice/paid/detail/:flid",element:<InvoicePaidDetail />}, { path: "invoice/paid/detail/:flid",element:<InvoicePaidDetail />},
{ path: "account/change-vendor",element:<ChangeVendor />},
] ]
}, },
{ {

@ -3,11 +3,47 @@ import { fetchJSON, postForm } from '@/utils/request';
import { HT_HOST } from "@/config"; import { HT_HOST } from "@/config";
import { isNotEmpty, prepareUrl } from '@/utils/commons'; import { isNotEmpty, prepareUrl } from '@/utils/commons';
import { loadPageSpy } from '@/pageSpy'; import { loadPageSpy } from '@/pageSpy';
import { create } from 'zustand'
const KEY_LOGIN_TOKEN = 'KEY_LOGIN_TOKEN'; const KEY_LOGIN_TOKEN = 'KEY_LOGIN_TOKEN';
const KEY_TRAVEL_AGENCY_ID = 'KEY_TRAVEL_AGENCY_ID'; const KEY_TRAVEL_AGENCY_ID = 'KEY_TRAVEL_AGENCY_ID';
const KEY_USER_ID = 'KEY_USER_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 { class Auth {
constructor(root) { 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 = { login = {
token: '', token: '',
userId: 0, // LMI_SN userId: 0, // LMI_SN

@ -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 (
<Row justify="center" align="middle" style={{ minHeight: 500 }}>
<Form
name="basic"
form={form}
layout="vertical"
size="large"
style={{
maxWidth: 600,
}}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
autoComplete="off"
>
<Form.Item>
<Title level={2}>Change your password</Title>
</Form.Item>
<Form.Item
name="VEISN"
label="供应商"
rules={[
{
required: true,
message: "请选择需要切换的供应商!",
},
]}
>
<Select
placeholder="请选择"
onChange={onVeiSnChange}
options={bindVendor()}
></Select>
</Form.Item>
<Form.Item>
<Space size="middle">
<Button type="primary" htmlType="submit">
</Button>
</Space>
</Form.Item>
</Form>
</Row>
);
}
export default observer(ChangeVendor);
Loading…
Cancel
Save