refactor(projects): 代码优化

This commit is contained in:
Soybean
2022-04-13 23:45:15 +08:00
parent 46e1ae7825
commit e8b534b84e
15 changed files with 533 additions and 479 deletions

View File

@ -1,6 +1,7 @@
import type { App } from 'vue';
import { createPinia } from 'pinia';
/** setup vue store plugin: pinia. - [安装vue状态管理插件pinia] */
export function setupStore(app: App) {
const store = createPinia();
app.use(store);

View File

@ -11,14 +11,14 @@ interface AuthState {
/** 用户token */
token: string;
/** 登录的加载状态 */
loginLoding: boolean;
loginLoading: boolean;
}
export const useAuthStore = defineStore('auth-store', {
state: (): AuthState => ({
userInfo: getUserInfo(),
token: getToken(),
loginLoding: false
loginLoading: false
}),
getters: {
/** 是否登录 */
@ -81,12 +81,12 @@ export const useAuthStore = defineStore('auth-store', {
* @param type - 登录方式: pwd - 密码登录; sms - 验证码登录
*/
async login(phone: string, pwdOrCode: string, type: 'pwd' | 'sms') {
this.loginLoding = true;
this.loginLoading = true;
const { data } = await fetchLogin(phone, pwdOrCode, type);
if (data) {
await this.loginByToken(data);
}
this.loginLoding = false;
this.loginLoading = false;
}
}
});