mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 代码优化
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router';
|
||||
import { zhCN, dateZhCN } from 'naive-ui';
|
||||
import { useThemeStore, subscribeStore } from '@/store';
|
||||
|
||||
|
@ -2,6 +2,7 @@ import type { App } from 'vue';
|
||||
import setupNetworkDirective from './network';
|
||||
import setupLoginDirective from './login';
|
||||
|
||||
/** setup custom vue directives. - [安装自定义的vue指令] */
|
||||
export function setupDirectives(app: App) {
|
||||
setupNetworkDirective(app);
|
||||
setupLoginDirective(app);
|
||||
|
@ -14,6 +14,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router';
|
||||
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
|
||||
|
||||
interface Props {
|
||||
|
15
src/main.ts
15
src/main.ts
@ -1,26 +1,21 @@
|
||||
import { createApp } from 'vue';
|
||||
import { setupAssets } from '@/plugins';
|
||||
import { setupRouter } from '@/router';
|
||||
import { setupStore } from '@/store';
|
||||
import { setupDirectives } from '@/directives';
|
||||
import { setupImportAssets } from './plugins';
|
||||
import { setupStore } from './store';
|
||||
import { setupDirectives } from './directives';
|
||||
import { setupRouter } from './router';
|
||||
import App from './App.vue';
|
||||
|
||||
async function setupApp() {
|
||||
// 引入静态资源
|
||||
setupAssets();
|
||||
setupImportAssets();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
// 挂载pinia状态
|
||||
setupStore(app);
|
||||
|
||||
// 挂载自定义vue指令
|
||||
setupDirectives(app);
|
||||
|
||||
// 挂载路由
|
||||
await setupRouter(app);
|
||||
|
||||
// 路由准备就绪后挂载 App
|
||||
app.mount('#app');
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import 'swiper/css/navigation';
|
||||
import 'swiper/css/pagination';
|
||||
import '../styles/css/global.css';
|
||||
|
||||
/** 引入静态资源(全局引入css、字体等) */
|
||||
export default function setupAssets() {
|
||||
/** import static assets: css, js , font and so on. - [引入静态资源,css、js和字体文件等] */
|
||||
export default function setupImportAssets() {
|
||||
//
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
import setupAssets from './assets';
|
||||
import setupImportAssets from './assets';
|
||||
|
||||
export { setupAssets };
|
||||
export { setupImportAssets };
|
||||
|
@ -6,14 +6,14 @@ import { scrollBehavior } from './helpers';
|
||||
import { createRouterGuard } from './guard';
|
||||
|
||||
const { VITE_HASH_ROUTE = 'false', VITE_BASE_URL } = import.meta.env;
|
||||
const history = VITE_HASH_ROUTE === 'true' ? createWebHashHistory(VITE_BASE_URL) : createWebHistory(VITE_BASE_URL);
|
||||
|
||||
export const router = createRouter({
|
||||
history,
|
||||
history: VITE_HASH_ROUTE === 'true' ? createWebHashHistory(VITE_BASE_URL) : createWebHistory(VITE_BASE_URL),
|
||||
routes: transformAuthRoutesToVueRoutes(constantRoutes),
|
||||
scrollBehavior
|
||||
});
|
||||
|
||||
/** setup vue router. - [安装vue路由] */
|
||||
export async function setupRouter(app: App) {
|
||||
app.use(router);
|
||||
createRouterGuard(router);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -24,7 +24,7 @@
|
||||
size="large"
|
||||
:block="true"
|
||||
:round="true"
|
||||
:loading="auth.loginLoding"
|
||||
:loading="auth.loginLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
确定
|
||||
|
@ -16,7 +16,7 @@
|
||||
size="large"
|
||||
:block="true"
|
||||
:round="true"
|
||||
:loading="auth.loginLoding"
|
||||
:loading="auth.loginLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
确定
|
||||
|
Reference in New Issue
Block a user