diff --git a/src/components/Icon.vue b/src/components/Icon.vue index 01c778f..b718aff 100644 --- a/src/components/Icon.vue +++ b/src/components/Icon.vue @@ -6,7 +6,7 @@ import Vue, { CreateElement } from 'vue' /// 常量(UPPER_CASE), 单例/变量(camelCase), 函数(无副作用,camelCase) const REG_NUM = /\s*([\d.]+)(\w+)/ -const loadingStatus = Vue.observable({ state: 0 }) +const loadingState = Vue.observable({ value: 0 }) import(/* webpackChunkName: "icon" */ '@/scss/font/fonts') .then(res => { const container = document.createElement('i') @@ -14,15 +14,13 @@ import(/* webpackChunkName: "icon" */ '@/scss/font/fonts') '' - res.default = null - document.querySelector('html').appendChild(container.firstChild) - setTimeout(() => { - loadingStatus.state = 1 - }) + res.default = '' + document.querySelector('html').insertBefore(container.firstChild, document.body) + loadingState.value = 1 }) .catch(err => { console.error(err) - loadingStatus.state = 2 + loadingState.value = 2 }) function isSymbol(id: string) { @@ -70,10 +68,11 @@ export default { // see: https://github.com/vuejs/jsx // eslint-disable-next-line @typescript-eslint/no-unused-vars render(h: CreateElement) { + const size = this.size const STYLE = this.$style + const imgIcon = this.imgIcon if (imgIcon) { - const size = this.size return ( - {h('use', { attrs: { 'xlink:href': '#' + icon } })} - - ) - case 2: + switch (loadingState.value) { + case 1: + if (isSymbol(icon)) { + return ( + {h('use', { attrs: { 'xlink:href': '#' + icon } })} + ) + } + break + case 2: + if (isSymbol(icon)) { return - default: - icon = 'el-icon-loading' - } + } + break + default: + icon = 'el-icon-loading' } - - return + return }, } diff --git a/src/functions/router/index.ts b/src/functions/router/index.ts index 6a94f59..58179a1 100644 --- a/src/functions/router/index.ts +++ b/src/functions/router/index.ts @@ -4,6 +4,7 @@ import Router, { Route, RouterOptions, RouteConfig, Location } from 'vue-router' import CONFIG, { SPA } from '@/config' import { isString } from '@/utils' +import { getById } from '../auth' import authenticate from './authenticate' import routerGuards from './routerGuards' @@ -134,28 +135,17 @@ export default (config: RouterOptions, authority?: boolean) => { const router = new Router(config) - config = (router as any).options.routes - function getPathById(id?: string) { - if (id) { - let route - for (route of config as any) { - if (id === route.meta.id) { - return route.path - } - } - } - return '' - } - // 相对路径支持 '' './' '../' const originPush = router.push router.push = (function(this: any) { const location = arguments[0] arguments[0] = resolveUrl( - getPathById((location || 0).id) || router.currentRoute.path, + ((location || 0).id && (getById((location || 0).id) || {}).path) || + router.currentRoute.path, location ) - ;(location || 0).SPA && CONFIG.g((location || 0).SPA, (arguments[0] || 0).path) + ;(location || 0).SPA && + CONFIG.g((location || 0).SPA, (arguments[0] || 0).path) return originPush.apply(this, arguments as any) } as any) as typeof originPush @@ -163,7 +153,8 @@ export default (config: RouterOptions, authority?: boolean) => { router.replace = (function(this: any) { const location = arguments[0] arguments[0] = resolveUrl( - getPathById((location || 0).id) || router.currentRoute.path, + ((location || 0).id && (getById((location || 0).id) || {}).path) || + router.currentRoute.path, location ) ;(location || 0).SPA && CONFIG.g((location || 0).SPA, arguments[0]) @@ -174,7 +165,8 @@ export default (config: RouterOptions, authority?: boolean) => { router.resolve = (function(this: any) { const location = arguments[0] arguments[0] = resolveUrl( - getPathById((location as ILocation || 0).id) || router.currentRoute.path, + ((location || 0).id && (getById((location || 0).id) || {}).path) || + router.currentRoute.path, arguments[2] ? isString(location) ? { path: location, append: true } diff --git a/src/functions/router/routerGuards.ts b/src/functions/router/routerGuards.ts index c796bfd..e42a534 100644 --- a/src/functions/router/routerGuards.ts +++ b/src/functions/router/routerGuards.ts @@ -58,7 +58,7 @@ export default (router: Router) => { } } - // 没实例(已经渲染了,劫持render也没用) 刷她爸爸/整个网页 + // 没实例(已经渲染了, 劫持render也没用) 刷她爸爸/整个网页 instance || ((temp = (route as any).parent) // eslint-disable-line no-cond-assign ? refreshRoute(temp, noTop) @@ -87,7 +87,7 @@ export default (router: Router) => { } if ((to = router.resolve(temp).route).matched.length) { - refreshRoute(to, 1) + to.meta.reload = 1 return next(to as Location) // 还是会再进一次beforeEach ┐(: ´ ゞ`)┌ } } @@ -112,29 +112,27 @@ export default (router: Router) => { if ((temp = to.meta).alive <= 0) { refreshRoute(to, 1) } else { - if (temp.reload) { - refreshRoute(to, 1) - temp.reload = 0 - } - + temp.reload && refreshRoute(to, 1) if (temp.t) { clearTimeout(temp.t) temp.t = 0 } - if (!((temp = from.meta.alive) <= 0)) { + if (!(from.meta.alive <= 0)) { from.meta.t = setTimeout(() => { from.meta.reload = 1 - }, temp || CONFIG.pageAlive) + }, from.meta.alive || CONFIG.pageAlive) } } // 关闭所有提示 - temp = router.app - try { - temp.$message.closeAll() - temp.$notify.closeAll() - temp.$msgbox.close() - } catch (error) {} + if ((!temp.reload || (temp.reload = 0)) && from.matched.length) { + temp = router.app + try { + temp.$message.closeAll() + temp.$notify.closeAll() + temp.$msgbox.close() + } catch (error) {} + } // 为每个路由对应的组件添加 props:route (路由配置props只允许对象 不然报错给你看) if ((temp = to.matched) && (temp = temp[temp.length - 1])) { diff --git a/src/libs/components/junior.scss b/src/libs/components/junior.scss index 2647af3..54775e9 100644 --- a/src/libs/components/junior.scss +++ b/src/libs/components/junior.scss @@ -23,18 +23,19 @@ // 通知 .el-notification { position: fixed; - z-index: $zFixed !important; + z-index: $zInfo !important; margin-top: $heightHeader; } // loading & 遮罩 .v-modal, .el-loading-mask { z-index: $zFixed !important; - background-color: rgba($colorBackGround, 0.9); + background-color: rgba($colorBackGround, 0.6); } // 弹窗 .el-dialog__wrapper { z-index: $zInfo !important; + background-color: rgba($colorBackGround, 0.6); } // 对话框 .el-message-box__wrapper { diff --git a/src/scss/export/fontSize.scss b/src/scss/export/fontSize.scss new file mode 100644 index 0000000..41ab593 --- /dev/null +++ b/src/scss/export/fontSize.scss @@ -0,0 +1,12 @@ +/** 字号 */ +:export { + smaller: $smaller; + small: $small; + medium: $medium; + larger: $larger; + large: $large; + xLarge: $xLarge; + xxLarge: $xxLarge; + xxxLarge: $xxxLarge; + xxxxLarge: $xLarge * 2; +} diff --git a/src/utils/ajax/index.ts b/src/utils/ajax/index.ts index 952167a..ab66363 100644 --- a/src/utils/ajax/index.ts +++ b/src/utils/ajax/index.ts @@ -99,7 +99,7 @@ function setHEAD( */ function getUri(url: string, query?: IObject) { return combineURLs( - AXIOS.defaults.baseURL, + AXIOS.defaults.baseURL || '', AXIOS.getUri({ url, params: SEARCH ? Object.assign(query || {}, SEARCH) : query, diff --git a/src/utils/formatNumber.ts b/src/utils/formatNumber.ts index e980fcb..1286db3 100644 --- a/src/utils/formatNumber.ts +++ b/src/utils/formatNumber.ts @@ -67,6 +67,8 @@ export default function( decimal = decimal.replace('0.', '.') } } + } else if (!isNaN(digit as number)) { + decimal = (0).toFixed(2).substring(1) } // 每三位加逗号 diff --git a/tests/unit/utils/formatNumber.spec.ts b/tests/unit/utils/formatNumber.spec.ts index 0ddf018..8bfcf48 100644 --- a/tests/unit/utils/formatNumber.spec.ts +++ b/tests/unit/utils/formatNumber.spec.ts @@ -12,6 +12,8 @@ describe('@/utils/formatNumber: 格式化数字', () => { }) it('formatNumber 指定小数位数格式化', () => { expect(formatNumber(1234567890.9876, 2)).toBe('1,234,567,890.99') + expect(formatNumber(0, 1)).toBe('0.0') + expect(formatNumber(1234567890, 2)).toBe('1,234,567,890.00') }) it('formatNumber 指定单位格式化', () => { expect(formatNumber(1234567890.9876, '万')).toBe('1,234,567,890.9876万')