Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jekip/naive-ui-admin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: whitemay/naive-ui-admin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 9 commits
  • 19 files changed
  • 1 contributor

Commits on Aug 17, 2021

  1. 尝试改造结构。

    aston committed Aug 17, 2021
    Copy the full SHA
    809ddc6 View commit details
  2. loading状态保存

    aston committed Aug 17, 2021
    Copy the full SHA
    19223a8 View commit details
  3. fix

    aston committed Aug 17, 2021
    Copy the full SHA
    714d3cf View commit details
  4. minor fix.

    aston committed Aug 17, 2021
    Copy the full SHA
    688d864 View commit details
  5. 加入注释

    aston committed Aug 17, 2021
    Copy the full SHA
    ddd0b23 View commit details
  6. no lint

    aston committed Aug 17, 2021
    Copy the full SHA
    3066969 View commit details

Commits on Aug 18, 2021

  1. eventbus改为rxjs方案

    aston committed Aug 18, 2021
    Copy the full SHA
    8feb681 View commit details
  2. clean

    aston committed Aug 18, 2021
    Copy the full SHA
    3bbcf96 View commit details

Commits on Aug 19, 2021

  1. 简化AppProvider

    aston committed Aug 19, 2021
    Copy the full SHA
    6c05ffb View commit details
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<style>.first-loading-wrp{display:flex;justify-content:center;align-items:center;flex-direction:column;min-height:420px;height:100%}.first-loading-wrp>h1{font-size:128px}.first-loading-wrp .loading-wrp{padding:98px;display:flex;justify-content:center;align-items:center}.dot{animation:antRotate 1.2s infinite linear;transform:rotate(45deg);position:relative;display:inline-block;font-size:32px;width:32px;height:32px;box-sizing:border-box}.dot i{width:14px;height:14px;position:absolute;display:block;background-color:#1890ff;border-radius:100%;transform:scale(.75);transform-origin:50% 50%;opacity:.3;animation:antSpinMove 1s infinite linear alternate}.dot i:nth-child(1){top:0;left:0}.dot i:nth-child(2){top:0;right:0;-webkit-animation-delay:.4s;animation-delay:.4s}.dot i:nth-child(3){right:0;bottom:0;-webkit-animation-delay:.8s;animation-delay:.8s}.dot i:nth-child(4){bottom:0;left:0;-webkit-animation-delay:1.2s;animation-delay:1.2s}@keyframes antRotate{to{-webkit-transform:rotate(405deg);transform:rotate(405deg)}}@-webkit-keyframes antRotate{to{-webkit-transform:rotate(405deg);transform:rotate(405deg)}}@keyframes antSpinMove{to{opacity:1}}@-webkit-keyframes antSpinMove{to{opacity:1}}</style>
</head>
<body>
<div id="appProvider" style="display: none"></div>
<div id="app">
<div class="first-loading-wrp">
<div class="loading-wrp">
2 changes: 1 addition & 1 deletion mock/table/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Random } from 'mockjs';
import { resultSuccess, doCustomTimes } from '../_util';
import { resultSuccess, doCustomTimes, resultError } from '../_util';

const tableList = (pageSize) => {
const result: any[] = [];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
"naive-ui": "^2.16.2",
"pinia": "^2.0.0-rc.4",
"qs": "^6.10.1",
"rxjs": "^7.3.0",
"vfonts": "^0.1.0",
"vue": "^3.2.2",
"vue-router": "^4.0.11",
40 changes: 25 additions & 15 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<template>
<NConfigProvider
v-if="!isLock"
:locale="zhCN"
:theme="getDarkTheme"
:theme-overrides="getThemeOverrides"
:date-locale="dateZhCN"
>
<AppProvider>
<RouterView />
</AppProvider>
</NConfigProvider>
<NLoadingBarProvider>
<NMessageProvider>
<NDialogProvider>
<NConfigProvider
v-if="!isLock"
:locale="zhCN"
:theme="getDarkTheme"
:theme-overrides="getThemeOverrides"
:date-locale="dateZhCN"
>
<AppProvider>
<RouterView />
</AppProvider>
</NConfigProvider>

<transition v-if="isLock && $route.name !== 'login'" name="slide-up">
<LockScreen />
</transition>
<transition v-if="isLock && $route.name !== 'login'" name="slide-up">
<LockScreen />
</transition>
</NDialogProvider>
</NMessageProvider>
</NLoadingBarProvider>
</template>

<script lang="ts" setup>
import { computed, onMounted, onUnmounted } from 'vue';
import { zhCN, dateZhCN, createTheme, inputDark, datePickerDark, darkTheme } from 'naive-ui';
import { zhCN, dateZhCN, createTheme, inputDark, datePickerDark, darkTheme,
NLoadingBarProvider,
NMessageProvider,
NDialogProvider
} from 'naive-ui';
import { LockScreen } from '@/components/Lockscreen';
import { AppProvider } from '@/components/Application';
import { useLockscreenStore } from '@/store/modules/lockscreen';
40 changes: 0 additions & 40 deletions src/components/Application/Application.vue

This file was deleted.

64 changes: 62 additions & 2 deletions src/components/Application/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
import AppProvider from './Application.vue';
import { defineComponent } from 'vue';
import { useMessage, useDialog, useLoadingBar } from 'naive-ui';
import { loadingSubject, messageSubject, modalSubject } from '@/utils/subjects';

export { AppProvider };
export const AppProvider = defineComponent({
name: 'Application',
setup() {
const loadingBar = useLoadingBar();
const message = useMessage();
const dialog = useDialog();

loadingSubject.subscribe({
next: (status) => {
if (status == 'start') {
loadingBar.start();
} else if (status == 'error') {
loadingBar.error();
} else {
loadingBar.finish();
}
},
});

messageSubject.subscribe((event: any) => {
switch (event.type) {
case 'error': {
message.error(event.info);
break;
}
case 'warning': {
message.warning(event.info);
break;
}
case 'info': {
message.info(event.info);
break;
}
case 'success': {
message.success(event.info);
}
}
});

modalSubject.subscribe((event: any) => {
switch (event.type) {
case 'info': {
dialog.info(event.params);
break;
}
case 'warning': {
dialog.warning(event.params);
break;
}
}
});

return {};
},
render() {
function noop() {} // 单纯为了避免TS报错
return [(this.$slots.default || noop)()];
},
});
3 changes: 0 additions & 3 deletions src/components/DialogContent/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/DialogContent/index.vue

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/LoadingContent/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/LoadingContent/index.vue

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/MessageContent/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/MessageContent/index.vue

This file was deleted.

4 changes: 2 additions & 2 deletions src/layout/index.vue
Original file line number Diff line number Diff line change
@@ -148,8 +148,8 @@
onMounted(() => {
window.addEventListener('resize', watchWidth);
//挂载在 window 方便与在js中使用
window['$loading'] = useLoadingBar();
window['$loading'].finish();
//window['$loading'] = useLoadingBar();
//window['$loading'].finish();
});
</script>
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -6,10 +6,11 @@ import { setupStore } from '@/store';
import MakeitCaptcha from 'makeit-captcha';
import 'makeit-captcha/dist/captcha.min.css';
import { setupNaive, setupDirectives } from '@/plugins';
import { AppProvider } from '@/components/Application';
import {} from '@/utils/subjects'; // 只是为了确保模块提前被加载
//import { AppProvider } from '@/components/Application';

async function bootstrap() {
const appProvider = createApp(AppProvider);
//const appProvider = createApp(AppProvider);

const app = createApp(App);

@@ -31,7 +32,7 @@ async function bootstrap() {
setupStore(app);

//优先挂载一下 Provider 解决路由守卫,Axios中可使用,Dialog,Message 等之类组件
appProvider.mount('#appProvider', true);
//appProvider.mount('#appProvider', true);

// 挂载路由
await setupRouter(app);
11 changes: 6 additions & 5 deletions src/router/router-guards.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import { ACCESS_TOKEN } from '@/store/mutation-types';
import { storage } from '@/utils/Storage';
import { PageEnum } from '@/enums/pageEnum';
import { ErrorPageRoute } from '@/router/base';
import { loadingSubject } from '@/utils/subjects';

const LOGIN_PATH = PageEnum.BASE_LOGIN;

@@ -15,8 +16,8 @@ export function createRouterGuards(router: Router) {
const userStore = useUserStoreWidthOut();
const asyncRouteStore = useAsyncRouteStoreWidthOut();
router.beforeEach(async (to, from, next) => {
const Loading = window['$loading'] || null;
Loading && Loading.start();
//const Loading = window['$loading'] || null;
loadingSubject.next('start');
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
next(PageEnum.BASE_HOME);
return;
@@ -76,7 +77,7 @@ export function createRouterGuards(router: Router) {
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
asyncRouteStore.setDynamicAddedRoute(true);
next(nextData);
Loading && Loading.finish();
loadingSubject.next('finish');
});

router.afterEach((to, _, failure) => {
@@ -99,8 +100,8 @@ export function createRouterGuards(router: Router) {
}
}
asyncRouteStore.setKeepAliveComponents(keepAliveComponents);
const Loading = window['$loading'] || null;
Loading && Loading.finish();
//const Loading = window['$loading'] || null;
loadingSubject.next('finish');
});

router.onError((error) => {
30 changes: 16 additions & 14 deletions src/utils/http/axios/checkStatus.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
export function checkStatus(status: number, msg: string, message: any): void {
import { messageSubject } from '@/utils/subjects';

export function checkStatus(status: number, msg: string): void {
switch (status) {
case 400:
message.error(`${msg}`);
messageSubject.next({ type: 'error', info: `${msg}` });
break;
// 401: 未登录
// 未登录则跳转登录页面,并携带当前页面的路径
// 在登录成功后返回当前页面,这一步需要在登录页操作。
case 401:
message.error('用户没有权限(令牌、用户名、密码错误)!');
messageSubject.next({ type: 'error', info: '用户没有权限(令牌、用户名、密码错误)!' });
break;
case 403:
message.error('用户得到授权,但是访问是被禁止的。!');
messageSubject.next({ type: 'error', info: '用户得到授权,但是访问是被禁止的。!' });
break;
// 404请求不存在
case 404:
message.error('网络请求错误,未找到该资源!');
messageSubject.next({ type: 'error', info: '网络请求错误,未找到该资源!' });
break;
case 405:
message.error('网络请求错误,请求方法未允许!');
messageSubject.next({ type: 'error', info: '网络请求错误,请求方法未允许!' });
break;
case 408:
message.error('网络请求超时!');
messageSubject.next({ type: 'error', info: '网络请求超时!' });
break;
case 500:
message.error('服务器错误,请联系管理员!');
messageSubject.next({ type: 'error', info: '服务器错误,请联系管理员!' });
break;
case 501:
message.error('网络未实现!');
messageSubject.next({ type: 'error', info: '网络未实现!' });
break;
case 502:
message.error('网络错误!');
messageSubject.next({ type: 'error', info: '网络错误!' });
break;
case 503:
message.error('服务不可用,服务器暂时过载或维护!');
messageSubject.next({ type: 'error', info: '服务不可用,服务器暂时过载或维护!'});
break;
case 504:
message.error('网络超时!');
messageSubject.next({ type: 'error', info: '网络超时!'});
break;
case 505:
message.error('http版本不支持该请求!');
messageSubject.next({ type: 'error', info: 'http版本不支持该请求!' });
break;
default:
message.error(msg);
messageSubject.next({ type: 'error', info: msg });
}
}
Loading