初步完成使用 Zustand 管理登陆

feature/price_manager
Jimmy Liow 1 year ago
parent 4fff1229fd
commit 8d3a7354c7

@ -60,7 +60,7 @@ const useAuthStore = create((set, get) => ({
} }
} }
const token = await fetchLoginToken() const token = await fetchLoginToken()
console.info('token: ' + token) appendRequestParams('token', token)
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo') const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo')
.append('token', token) .append('token', token)

@ -16,6 +16,7 @@ import enLocale from 'antd/locale/en_US';
import 'dayjs/locale/zh-cn'; import 'dayjs/locale/zh-cn';
import { BUILD_VERSION, } from '@/config'; import { BUILD_VERSION, } from '@/config';
import useNoticeStore from '@/stores/Notice'; import useNoticeStore from '@/stores/Notice';
import useAuthStore from '@/stores/Auth'
const { Header, Content, Footer } = Layout; const { Header, Content, Footer } = Layout;
const { Title } = Typography; const { Title } = Typography;
@ -26,10 +27,13 @@ function App() {
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const { authStore } = useStore(); const { authStore } = useStore();
const { notification } = AntApp.useApp(); const { notification } = AntApp.useApp();
const login = toJS(authStore.login);
const loginUser = useAuthStore((state) => state.loginUser)
// const login = toJS(authStore.login);
const noticeUnRead = useNoticeStore((state) => state.noticeUnRead); const noticeUnRead = useNoticeStore((state) => state.noticeUnRead);
const href = useHref(); const href = useHref();
const loginToken = login.token; const loginToken = loginUser.token;
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
@ -44,7 +48,7 @@ function App() {
}, [location]); }, [location]);
const onSubmit = () => { const onSubmit = () => {
authStore.valdateUserPassword(login.username, password) authStore.valdateUserPassword(loginUser.username, password)
.then(() => { .then(() => {
authStore.fetchUserDetail() authStore.fetchUserDetail()
.catch(ex => { .catch(ex => {
@ -96,7 +100,7 @@ function App() {
closable={false} closable={false}
maskClosable={false} maskClosable={false}
footer={null} footer={null}
open={login.timeout} open={loginUser.timeout}
> >
<Title level={3}>{t('LoginTimeout')}</Title> <Title level={3}>{t('LoginTimeout')}</Title>
<div>{t('LoginTimeoutTip')}</div> <div>{t('LoginTimeoutTip')}</div>
@ -104,7 +108,7 @@ function App() {
<Input.Password value={password} <Input.Password value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
onPressEnter={() => onSubmit()} onPressEnter={() => onSubmit()}
addonBefore={login.username} /> addonBefore={loginUser.username} />
<Button <Button
onClick={() => onSubmit()} onClick={() => onSubmit()}
>{t('Submit')}</Button></Space> >{t('Submit')}</Button></Space>
@ -143,7 +147,7 @@ function App() {
</Col> </Col>
<Col span={4}> <Col span={4}>
<Title level={3} style={{ color: "white", marginBottom: "0", display: "flex", justifyContent: "end" }}> <Title level={3} style={{ color: "white", marginBottom: "0", display: "flex", justifyContent: "end" }}>
{authStore.login.travelAgencyName} {loginUser.travelAgencyName}
</Title> </Title>
</Col> </Col>
<Col span={2}> <Col span={2}>
@ -163,7 +167,7 @@ function App() {
> >
<a onClick={e => e.preventDefault()}> <a onClick={e => e.preventDefault()}>
<Space> <Space>
{authStore.login.username} {loginUser.username}
<DownOutlined /> <DownOutlined />
</Space> </Space>
</a> </a>

@ -31,7 +31,7 @@ function Login() {
useEffect (() => { useEffect (() => {
if (loginStatus === 302) { if (loginStatus === 302) {
// navigate("/reservation/newest") navigate("/reservation/newest")
} }
}, [loginStatus]); }, [loginStatus]);

Loading…
Cancel
Save