Commit 8f9eff78aa3979929c3efff4967b1608abcab7e8
1 parent
dddda5b2
style: update back-top style
Showing
6 changed files
with
39 additions
and
19 deletions
CHANGELOG.zh_CN.md
src/components/ClickOutSide/index.ts
1 | -import ClickOutSide from './src/index.vue'; | |
2 | 1 | import { withInstall } from '../util'; |
2 | +import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent'; | |
3 | 3 | |
4 | -withInstall(ClickOutSide); | |
4 | +export const ClickOutSide = createAsyncComponent(() => import('./src/index.vue')); | |
5 | 5 | |
6 | -export { ClickOutSide }; | |
6 | +withInstall(ClickOutSide); | ... | ... |
src/design/ant/index.less
src/router/index.ts
... | ... | @@ -6,7 +6,7 @@ import { createRouter, createWebHashHistory } from 'vue-router'; |
6 | 6 | import { createGuard } from './guard/'; |
7 | 7 | |
8 | 8 | import { basicRoutes } from './routes/'; |
9 | -import { scrollBehavior } from './scrollBehaviour'; | |
9 | +import { scrollBehavior } from './scrollBehavior'; | |
10 | 10 | |
11 | 11 | export const hashRouter = createWebHashHistory(); |
12 | 12 | ... | ... |
src/router/scrollBehaviour.ts renamed to src/router/scrollBehavior.ts
src/utils/factory/createAsyncComponent.tsx
1 | 1 | import { defineAsyncComponent } from 'vue'; |
2 | 2 | import { Spin } from 'ant-design-vue'; |
3 | +import { noop } from '/@/utils/index'; | |
4 | +interface Options { | |
5 | + size?: 'default' | 'small' | 'large'; | |
6 | + delay?: number; | |
7 | + timeout?: number; | |
8 | + loading?: boolean; | |
9 | + retry?: boolean; | |
10 | +} | |
3 | 11 | |
4 | -export function createAsyncComponent(loader: any) { | |
12 | +export function createAsyncComponent(loader: Fn, options: Options = {}) { | |
13 | + const { size = 'small', delay = 100, timeout = 3000, loading = true, retry = true } = options; | |
5 | 14 | return defineAsyncComponent({ |
6 | - loader: loader, | |
7 | - loadingComponent: <Spin spinning={true} />, | |
15 | + loader, | |
16 | + loadingComponent: loading ? <Spin spinning={true} size={size} /> : undefined, | |
8 | 17 | // The error component will be displayed if a timeout is |
9 | 18 | // provided and exceeded. Default: Infinity. |
10 | - timeout: 3000, | |
19 | + timeout, | |
11 | 20 | // Defining if component is suspensible. Default: true. |
12 | 21 | // suspensible: false, |
13 | - delay: 100, | |
22 | + delay, | |
14 | 23 | /** |
15 | 24 | * |
16 | 25 | * @param {*} error Error message object |
... | ... | @@ -18,15 +27,17 @@ export function createAsyncComponent(loader: any) { |
18 | 27 | * @param {*} fail End of failure |
19 | 28 | * @param {*} attempts Maximum allowed retries number |
20 | 29 | */ |
21 | - onError(error, retry, fail, attempts) { | |
22 | - if (error.message.match(/fetch/) && attempts <= 3) { | |
23 | - // retry on fetch errors, 3 max attempts | |
24 | - retry(); | |
25 | - } else { | |
26 | - // Note that retry/fail are like resolve/reject of a promise: | |
27 | - // one of them must be called for the error handling to continue. | |
28 | - fail(); | |
29 | - } | |
30 | - }, | |
30 | + onError: !retry | |
31 | + ? noop | |
32 | + : (error, retry, fail, attempts) => { | |
33 | + if (error.message.match(/fetch/) && attempts <= 3) { | |
34 | + // retry on fetch errors, 3 max attempts | |
35 | + retry(); | |
36 | + } else { | |
37 | + // Note that retry/fail are like resolve/reject of a promise: | |
38 | + // one of them must be called for the error handling to continue. | |
39 | + fail(); | |
40 | + } | |
41 | + }, | |
31 | 42 | }); |
32 | 43 | } | ... | ... |