Переглянути джерело

修正登录登出流程

main
郑州 3 роки тому
джерело
коміт
a412e5f310
5 змінених файлів з 16 додано та 17 видалено
  1. +1
    -1
      electron/preload.js
  2. +2
    -2
      src/app.ts
  3. +6
    -1
      src/components/AppHeader/components/userCenter/UserCenter.tsx
  4. +3
    -8
      src/pages/login/index.tsx
  5. +4
    -5
      src/services/user.ts

+ 1
- 1
electron/preload.js Переглянути файл

@@ -1,5 +1,5 @@
const electron = require('electron');
const { contextBridge } = electron;
const { contextBridge, ipcRenderer } = electron;

// console.log(electron.ipcRenderer.on);



+ 2
- 2
src/app.ts Переглянути файл

@@ -98,8 +98,8 @@ export const request: RequestConfig = {

export async function getInitialState(): Promise<{
isLogin: boolean;
fetchUserInfo: () => Promise<DATA.User>;
currentUser?: DATA.User;
fetchUserInfo: () => Promise<DATA.User | null>;
currentUser?: DATA.User | null;
}> {
async function fetchUserInfo() {
const res = await queryCurrent();


+ 6
- 1
src/components/AppHeader/components/userCenter/UserCenter.tsx Переглянути файл

@@ -46,13 +46,18 @@ export default function UserCenter(props: UserCenterProps) {
}

function PopContent(props) {
const { initialState: { currentUser } = {} } = useModel('@@initialState');
const {
refresh,
initialState: { currentUser } = {},
setInitialState,
} = useModel('@@initialState');
console.log(currentUser);

const tryLogout = useCallback(() => {
confirm({
onOk() {
logout();
refresh();
},
content: '确实退出登录?',
});


+ 3
- 8
src/pages/login/index.tsx Переглянути файл

@@ -14,7 +14,7 @@ export default function Login() {
const [account, setAccount] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const { refresh } = useModel('@@initialState');
// const { loading, signin } = useModel('useAuthModel');

const onLogin = useCallback(async () => {
@@ -37,14 +37,9 @@ export default function Login() {
// history.push('/');
// window.location.href = '/';
history.replace('/');
window.location.reload();
refresh();
// window.location.reload();
});
// if(!isReqSuccess(res)) {
// setErrText(res.msg);
// return;
// }
// Taro.switchTab({ url: '/pages/project/index' });
// Taro.navigateTo({ url: '/pages/project/index' });
}, [account, password]);

useEffect(() => {


+ 4
- 5
src/services/user.ts Переглянути файл

@@ -9,10 +9,9 @@ export async function queryCurrent() {
if (!accountId) {
return errorReponse('');
}
const res = await fetchApi<API.ResponseData<DATA.User>>(
'user/queryUserByUserId',
{ id: accountId },
);
const res = await fetchApi<DATA.User>('user/queryUserByUserId', {
id: accountId,
});
return res;
}

@@ -64,5 +63,5 @@ export function logout() {
storage.clear();
// window.location.href = '/login';
history.replace('/login');
window.location.reload();
// window.location.reload();
}

Завантаження…
Відмінити
Зберегти