初步完成使用 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()
console.info('token: ' + token)
appendRequestParams('token', token)
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo')
.append('token', token)

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

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

Loading…
Cancel
Save