Skip to content

Commit

Permalink
Fix: 细节
Browse files Browse the repository at this point in the history
  • Loading branch information
毛瑞 committed Jun 26, 2020
1 parent bd851ba commit 3ad7a53
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 57 deletions.
44 changes: 22 additions & 22 deletions src/components/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ 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')
container.innerHTML =
'<svg aria-hidden=true style=position:absolute;width:0;height:0;overflow:hidden>' +
res.default +
'</svg>'
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) {
Expand Down Expand Up @@ -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 (
<img
width={size}
Expand All @@ -85,22 +84,23 @@ export default {
}

let icon = this.icon
if (isSymbol(icon)) {
switch (loadingStatus.state) {
case 1:
return (
<svg class={STYLE.svg + ' ' + STYLE.i} style={this.style}>
{h('use', { attrs: { 'xlink:href': '#' + icon } })}
</svg>
)
case 2:
switch (loadingState.value) {
case 1:
if (isSymbol(icon)) {
return (<svg class={STYLE.svg + ' ' + STYLE.i} style={this.style}>
{h('use', { attrs: { 'xlink:href': '#' + icon } })}
</svg>)
}
break
case 2:
if (isSymbol(icon)) {
return
default:
icon = 'el-icon-loading'
}
}
break
default:
icon = 'el-icon-loading'
}

return <i class={icon + ' ' + STYLE.i} style={'font-size:' + this.size} />
return <i class={icon + ' ' + STYLE.i} style={'font-size:' + size} />
},
}
</script>
Expand Down
26 changes: 9 additions & 17 deletions src/functions/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -134,36 +135,26 @@ 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

const originReplace = router.replace
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])
Expand All @@ -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 }
Expand Down
28 changes: 13 additions & 15 deletions src/functions/router/routerGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ┐(: ´ ゞ`)┌
}
}
Expand All @@ -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])) {
Expand Down
5 changes: 3 additions & 2 deletions src/libs/components/junior.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/scss/export/fontSize.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** 字号 */
:export {
smaller: $smaller;
small: $small;
medium: $medium;
larger: $larger;
large: $large;
xLarge: $xLarge;
xxLarge: $xxLarge;
xxxLarge: $xxxLarge;
xxxxLarge: $xLarge * 2;
}
2 changes: 1 addition & 1 deletion src/utils/ajax/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/formatNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default function(
decimal = decimal.replace('0.', '.')
}
}
} else if (!isNaN(digit as number)) {
decimal = (0).toFixed(2).substring(1)
}

// 每三位加逗号
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/utils/formatNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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万')
Expand Down

0 comments on commit 3ad7a53

Please sign in to comment.