@netang/quasar 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/data/index.vue +20 -20
- package/components/dragger/index.vue +203 -203
- package/components/empty/index.vue +2 -0
- package/components/field-date/methods.js +100 -100
- package/components/field-text/index.vue +165 -165
- package/components/list-menu/index.vue +149 -149
- package/components/list-menu-item/index.vue +79 -79
- package/components/power-page/index.vue +3 -1
- package/components/price/index.vue +188 -188
- package/components/private/components/index.js +11 -11
- package/components/table-pagination/index.vue +192 -192
- package/components/thumbnail/index.vue +72 -72
- package/components/value-format/index.vue +274 -274
- package/configs/area3.js +1 -1
- package/docs/css/index.css +3 -3
- package/package.json +1 -1
- package/sass/line.scss +39 -39
- package/sass/quasar/btn.scss +46 -46
- package/sass/quasar/common.scss +3 -3
- package/sass/quasar/drawer.scss +6 -6
- package/sass/quasar/loading.scss +6 -6
- package/sass/quasar/toolbar.scss +22 -22
- package/store/index.js +29 -29
- package/utils/$auth.js +127 -127
- package/utils/$rule.js +13 -13
- package/utils/$ruleValid.js +10 -10
- package/utils/alert.js +12 -12
- package/utils/area.js +400 -400
- package/utils/arr.js +51 -51
- package/utils/bus.js +6 -6
- package/utils/confirm.js +11 -11
- package/utils/copy.js +30 -30
- package/utils/dictOptions.js +28 -28
- package/utils/loading.js +15 -15
- package/utils/notify.js +13 -13
- package/utils/price.js +18 -18
- package/utils/symbols.js +18 -18
- package/utils/toast.js +13 -13
- package/utils/useAuth.js +30 -30
- package/utils/useRouter.js +47 -47
package/utils/arr.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import $n_isFunction from 'lodash/isFunction'
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* 操作数组
|
|
5
|
-
*/
|
|
6
|
-
const arr = {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 数组添加值
|
|
10
|
-
*/
|
|
11
|
-
add(children, index, newItem) {
|
|
12
|
-
if (Array.isArray(children)) {
|
|
13
|
-
children.splice(index + 1, 0, $n_isFunction(newItem) ? newItem() : newItem)
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 数组删除值
|
|
19
|
-
*/
|
|
20
|
-
delete(children, index) {
|
|
21
|
-
if (Array.isArray(children)) {
|
|
22
|
-
children.splice(index, 1)
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 数组值上移
|
|
28
|
-
*/
|
|
29
|
-
up(children, index) {
|
|
30
|
-
if (Array.isArray(children)) {
|
|
31
|
-
// 在上一项插入该项
|
|
32
|
-
children.splice(index - 1, 0, children[index])
|
|
33
|
-
// 删除后一项
|
|
34
|
-
children.splice(index + 1, 1)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 数组值下移
|
|
40
|
-
*/
|
|
41
|
-
down(children, index) {
|
|
42
|
-
if (Array.isArray(children)) {
|
|
43
|
-
// 在下一项插入该项
|
|
44
|
-
children.splice(index + 2, 0, children[index])
|
|
45
|
-
// 删除前一项
|
|
46
|
-
children.splice(index, 1)
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default arr
|
|
1
|
+
import $n_isFunction from 'lodash/isFunction'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* 操作数组
|
|
5
|
+
*/
|
|
6
|
+
const arr = {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 数组添加值
|
|
10
|
+
*/
|
|
11
|
+
add(children, index, newItem) {
|
|
12
|
+
if (Array.isArray(children)) {
|
|
13
|
+
children.splice(index + 1, 0, $n_isFunction(newItem) ? newItem() : newItem)
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 数组删除值
|
|
19
|
+
*/
|
|
20
|
+
delete(children, index) {
|
|
21
|
+
if (Array.isArray(children)) {
|
|
22
|
+
children.splice(index, 1)
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 数组值上移
|
|
28
|
+
*/
|
|
29
|
+
up(children, index) {
|
|
30
|
+
if (Array.isArray(children)) {
|
|
31
|
+
// 在上一项插入该项
|
|
32
|
+
children.splice(index - 1, 0, children[index])
|
|
33
|
+
// 删除后一项
|
|
34
|
+
children.splice(index + 1, 1)
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 数组值下移
|
|
40
|
+
*/
|
|
41
|
+
down(children, index) {
|
|
42
|
+
if (Array.isArray(children)) {
|
|
43
|
+
// 在下一项插入该项
|
|
44
|
+
children.splice(index + 2, 0, children[index])
|
|
45
|
+
// 删除前一项
|
|
46
|
+
children.splice(index, 1)
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default arr
|
package/utils/bus.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EventBus } from 'quasar'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 事件总线
|
|
5
|
-
*/
|
|
6
|
-
export default new EventBus()
|
|
1
|
+
import { EventBus } from 'quasar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 事件总线
|
|
5
|
+
*/
|
|
6
|
+
export default new EventBus()
|
package/utils/confirm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Dialog } from 'quasar'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 确认框
|
|
5
|
-
*/
|
|
6
|
-
export default function confirm(options) {
|
|
7
|
-
return Dialog.create(Object.assign({
|
|
8
|
-
title: '提示',
|
|
9
|
-
cancel: true,
|
|
10
|
-
}, options))
|
|
11
|
-
}
|
|
1
|
+
import { Dialog } from 'quasar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 确认框
|
|
5
|
+
*/
|
|
6
|
+
export default function confirm(options) {
|
|
7
|
+
return Dialog.create(Object.assign({
|
|
8
|
+
title: '提示',
|
|
9
|
+
cancel: true,
|
|
10
|
+
}, options))
|
|
11
|
+
}
|
package/utils/copy.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { copyToClipboard } from 'quasar'
|
|
2
|
-
|
|
3
|
-
import $n_toast from './toast'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 复制
|
|
7
|
-
*/
|
|
8
|
-
export default function copy(text, message = null) {
|
|
9
|
-
|
|
10
|
-
// 提示
|
|
11
|
-
if (message !== false) {
|
|
12
|
-
|
|
13
|
-
// 如果为 true, 则 message 设为 text
|
|
14
|
-
if (message === true) {
|
|
15
|
-
message = `复制【${text}】成功`
|
|
16
|
-
} else if (! message) {
|
|
17
|
-
message = '复制成功'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 轻提示
|
|
21
|
-
$n_toast({
|
|
22
|
-
type: 'positive',
|
|
23
|
-
message,
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 复制
|
|
28
|
-
copyToClipboard(text)
|
|
29
|
-
.finally()
|
|
30
|
-
}
|
|
1
|
+
import { copyToClipboard } from 'quasar'
|
|
2
|
+
|
|
3
|
+
import $n_toast from './toast'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 复制
|
|
7
|
+
*/
|
|
8
|
+
export default function copy(text, message = null) {
|
|
9
|
+
|
|
10
|
+
// 提示
|
|
11
|
+
if (message !== false) {
|
|
12
|
+
|
|
13
|
+
// 如果为 true, 则 message 设为 text
|
|
14
|
+
if (message === true) {
|
|
15
|
+
message = `复制【${text}】成功`
|
|
16
|
+
} else if (! message) {
|
|
17
|
+
message = '复制成功'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 轻提示
|
|
21
|
+
$n_toast({
|
|
22
|
+
type: 'positive',
|
|
23
|
+
message,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 复制
|
|
28
|
+
copyToClipboard(text)
|
|
29
|
+
.finally()
|
|
30
|
+
}
|
package/utils/dictOptions.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import $n_get from 'lodash/get'
|
|
2
|
-
|
|
3
|
-
import { configs } from './config'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 数据字典选项数组
|
|
7
|
-
* @param {String} key 字典键值
|
|
8
|
-
* @param {String} labelKey 标签键值
|
|
9
|
-
* @param {String} valueKey 值键值
|
|
10
|
-
* @returns {Array}
|
|
11
|
-
*/
|
|
12
|
-
export default function dictOptions(key, labelKey = 'label', valueKey = 'value') {
|
|
13
|
-
|
|
14
|
-
const lists = []
|
|
15
|
-
|
|
16
|
-
const dictItem = $n_get(configs.userDict, key, [])
|
|
17
|
-
|
|
18
|
-
for (const item of dictItem) {
|
|
19
|
-
|
|
20
|
-
const val = {}
|
|
21
|
-
val[labelKey] = item[0]
|
|
22
|
-
val[valueKey] = item[1]
|
|
23
|
-
|
|
24
|
-
lists.push(val)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return lists
|
|
28
|
-
}
|
|
1
|
+
import $n_get from 'lodash/get'
|
|
2
|
+
|
|
3
|
+
import { configs } from './config'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 数据字典选项数组
|
|
7
|
+
* @param {String} key 字典键值
|
|
8
|
+
* @param {String} labelKey 标签键值
|
|
9
|
+
* @param {String} valueKey 值键值
|
|
10
|
+
* @returns {Array}
|
|
11
|
+
*/
|
|
12
|
+
export default function dictOptions(key, labelKey = 'label', valueKey = 'value') {
|
|
13
|
+
|
|
14
|
+
const lists = []
|
|
15
|
+
|
|
16
|
+
const dictItem = $n_get(configs.userDict, key, [])
|
|
17
|
+
|
|
18
|
+
for (const item of dictItem) {
|
|
19
|
+
|
|
20
|
+
const val = {}
|
|
21
|
+
val[labelKey] = item[0]
|
|
22
|
+
val[valueKey] = item[1]
|
|
23
|
+
|
|
24
|
+
lists.push(val)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return lists
|
|
28
|
+
}
|
package/utils/loading.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Loading } from 'quasar'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 全局加载
|
|
5
|
-
*/
|
|
6
|
-
const loading = {
|
|
7
|
-
show() {
|
|
8
|
-
Loading.show()
|
|
9
|
-
},
|
|
10
|
-
hide() {
|
|
11
|
-
Loading.hide()
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default loading
|
|
1
|
+
import { Loading } from 'quasar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 全局加载
|
|
5
|
+
*/
|
|
6
|
+
const loading = {
|
|
7
|
+
show() {
|
|
8
|
+
Loading.show()
|
|
9
|
+
},
|
|
10
|
+
hide() {
|
|
11
|
+
Loading.hide()
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default loading
|
package/utils/notify.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Notify } from 'quasar'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 通知
|
|
5
|
-
*/
|
|
6
|
-
export default function notify(params) {
|
|
7
|
-
Notify.create(Object.assign({
|
|
8
|
-
// 出现位置
|
|
9
|
-
position: 'bottom-right',
|
|
10
|
-
// 显示时间
|
|
11
|
-
timeout: 1500,
|
|
12
|
-
}, params))
|
|
13
|
-
}
|
|
1
|
+
import { Notify } from 'quasar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 通知
|
|
5
|
+
*/
|
|
6
|
+
export default function notify(params) {
|
|
7
|
+
Notify.create(Object.assign({
|
|
8
|
+
// 出现位置
|
|
9
|
+
position: 'bottom-right',
|
|
10
|
+
// 显示时间
|
|
11
|
+
timeout: 1500,
|
|
12
|
+
}, params))
|
|
13
|
+
}
|
package/utils/price.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import $n_decimal from '@netang/utils/decimal'
|
|
2
|
-
|
|
3
|
-
import $n_config from './config'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 换算金额
|
|
7
|
-
*/
|
|
8
|
-
export default function price(value, options) {
|
|
9
|
-
|
|
10
|
-
return $n_decimal(value, Object.assign({
|
|
11
|
-
// 最小值
|
|
12
|
-
min: 0,
|
|
13
|
-
// 小数点位数
|
|
14
|
-
decimalLength: 2,
|
|
15
|
-
// 是否开启人民币分转元(如值 189 -> 1.89)
|
|
16
|
-
centToYuan: $n_config('priceCentToYuan') === true,
|
|
17
|
-
}, options))
|
|
18
|
-
}
|
|
1
|
+
import $n_decimal from '@netang/utils/decimal'
|
|
2
|
+
|
|
3
|
+
import $n_config from './config'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 换算金额
|
|
7
|
+
*/
|
|
8
|
+
export default function price(value, options) {
|
|
9
|
+
|
|
10
|
+
return $n_decimal(value, Object.assign({
|
|
11
|
+
// 最小值
|
|
12
|
+
min: 0,
|
|
13
|
+
// 小数点位数
|
|
14
|
+
decimalLength: 2,
|
|
15
|
+
// 是否开启人民币分转元(如值 189 -> 1.89)
|
|
16
|
+
centToYuan: $n_config('priceCentToYuan') === true,
|
|
17
|
+
}, options))
|
|
18
|
+
}
|
package/utils/symbols.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
// 渲染组件注入符号
|
|
3
|
-
export const NRenderKey = '_n_render_'
|
|
4
|
-
|
|
5
|
-
// 权限注入符号
|
|
6
|
-
export const NPowerKey = '_n_power_'
|
|
7
|
-
|
|
8
|
-
// 表格注入符号
|
|
9
|
-
export const NTableKey = '_n_table_'
|
|
10
|
-
|
|
11
|
-
// 表单注入符号
|
|
12
|
-
export const NFormKey = '_n_form_'
|
|
13
|
-
|
|
14
|
-
// 对话框注入符号
|
|
15
|
-
export const NDialogKey = '_n_dialog_'
|
|
16
|
-
|
|
17
|
-
// 上传器注入符号
|
|
18
|
-
export const NUploaderKey = '_n_uploader_'
|
|
1
|
+
|
|
2
|
+
// 渲染组件注入符号
|
|
3
|
+
export const NRenderKey = '_n_render_'
|
|
4
|
+
|
|
5
|
+
// 权限注入符号
|
|
6
|
+
export const NPowerKey = '_n_power_'
|
|
7
|
+
|
|
8
|
+
// 表格注入符号
|
|
9
|
+
export const NTableKey = '_n_table_'
|
|
10
|
+
|
|
11
|
+
// 表单注入符号
|
|
12
|
+
export const NFormKey = '_n_form_'
|
|
13
|
+
|
|
14
|
+
// 对话框注入符号
|
|
15
|
+
export const NDialogKey = '_n_dialog_'
|
|
16
|
+
|
|
17
|
+
// 上传器注入符号
|
|
18
|
+
export const NUploaderKey = '_n_uploader_'
|
package/utils/toast.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Notify, Platform } from 'quasar'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 轻提示
|
|
5
|
-
*/
|
|
6
|
-
export default function toast(params) {
|
|
7
|
-
return Notify.create(Object.assign({
|
|
8
|
-
// 出现位置
|
|
9
|
-
position: Platform.is.desktop ? 'top' : 'bottom',
|
|
10
|
-
// 显示时间
|
|
11
|
-
timeout: 1000,
|
|
12
|
-
}, params))
|
|
13
|
-
}
|
|
1
|
+
import { Notify, Platform } from 'quasar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 轻提示
|
|
5
|
+
*/
|
|
6
|
+
export default function toast(params) {
|
|
7
|
+
return Notify.create(Object.assign({
|
|
8
|
+
// 出现位置
|
|
9
|
+
position: Platform.is.desktop ? 'top' : 'bottom',
|
|
10
|
+
// 显示时间
|
|
11
|
+
timeout: 1000,
|
|
12
|
+
}, params))
|
|
13
|
+
}
|
package/utils/useAuth.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import $n_validator from '@netang/utils/validator'
|
|
2
|
-
import $n_cookie from '@netang/utils/cookie'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 初始化鉴权状态
|
|
6
|
-
*/
|
|
7
|
-
export function initAuthStore() {
|
|
8
|
-
// 获取管理员信息缓存
|
|
9
|
-
const cache = $n_cookie.get('_tk')
|
|
10
|
-
return checkUserInfo(cache) ? cache : {
|
|
11
|
-
id: 0,
|
|
12
|
-
token: '',
|
|
13
|
-
info: {},
|
|
14
|
-
isLogin: false,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 验证用户信息
|
|
20
|
-
*/
|
|
21
|
-
export function checkUserInfo(data) {
|
|
22
|
-
return ! $n_validator(data, {
|
|
23
|
-
// 管理员 id
|
|
24
|
-
id: 'required|natural_no_zero',
|
|
25
|
-
// 鉴权认证
|
|
26
|
-
token: 'required|string',
|
|
27
|
-
// 用户信息
|
|
28
|
-
info: 'required',
|
|
29
|
-
})
|
|
30
|
-
}
|
|
1
|
+
import $n_validator from '@netang/utils/validator'
|
|
2
|
+
import $n_cookie from '@netang/utils/cookie'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 初始化鉴权状态
|
|
6
|
+
*/
|
|
7
|
+
export function initAuthStore() {
|
|
8
|
+
// 获取管理员信息缓存
|
|
9
|
+
const cache = $n_cookie.get('_tk')
|
|
10
|
+
return checkUserInfo(cache) ? cache : {
|
|
11
|
+
id: 0,
|
|
12
|
+
token: '',
|
|
13
|
+
info: {},
|
|
14
|
+
isLogin: false,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 验证用户信息
|
|
20
|
+
*/
|
|
21
|
+
export function checkUserInfo(data) {
|
|
22
|
+
return ! $n_validator(data, {
|
|
23
|
+
// 管理员 id
|
|
24
|
+
id: 'required|natural_no_zero',
|
|
25
|
+
// 鉴权认证
|
|
26
|
+
token: 'required|string',
|
|
27
|
+
// 用户信息
|
|
28
|
+
info: 'required',
|
|
29
|
+
})
|
|
30
|
+
}
|
package/utils/useRouter.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import $n_isNil from 'lodash/isNil'
|
|
2
|
-
import $n_has from 'lodash/has'
|
|
3
|
-
import $n_get from 'lodash/get'
|
|
4
|
-
|
|
5
|
-
import $n_forIn from '@netang/utils/forIn'
|
|
6
|
-
import $n_slash from '@netang/utils/slash'
|
|
7
|
-
|
|
8
|
-
import { configs } from './config'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 获取路由
|
|
12
|
-
*/
|
|
13
|
-
export function getRouters(mainRouter, errorRouter, routers = null) {
|
|
14
|
-
|
|
15
|
-
const routes = [
|
|
16
|
-
mainRouter,
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
if ($n_isNil(routers)) {
|
|
20
|
-
routers = $n_get(configs, 'routers')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
$n_forIn(routers, function(item, key) {
|
|
24
|
-
|
|
25
|
-
// 如果没有 meta
|
|
26
|
-
if (! $n_has(item, 'meta')) {
|
|
27
|
-
item.meta = {}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// path
|
|
31
|
-
item.path = $n_slash(key, 'start', true)
|
|
32
|
-
|
|
33
|
-
// 如果是单独路由
|
|
34
|
-
if ($n_get(item.meta, 'parent') === false) {
|
|
35
|
-
routes.push(item)
|
|
36
|
-
|
|
37
|
-
// 否则为框架页面
|
|
38
|
-
} else {
|
|
39
|
-
mainRouter.children.push(item)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// 添加错误路由
|
|
44
|
-
routes.push(errorRouter)
|
|
45
|
-
|
|
46
|
-
return routes
|
|
47
|
-
}
|
|
1
|
+
import $n_isNil from 'lodash/isNil'
|
|
2
|
+
import $n_has from 'lodash/has'
|
|
3
|
+
import $n_get from 'lodash/get'
|
|
4
|
+
|
|
5
|
+
import $n_forIn from '@netang/utils/forIn'
|
|
6
|
+
import $n_slash from '@netang/utils/slash'
|
|
7
|
+
|
|
8
|
+
import { configs } from './config'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取路由
|
|
12
|
+
*/
|
|
13
|
+
export function getRouters(mainRouter, errorRouter, routers = null) {
|
|
14
|
+
|
|
15
|
+
const routes = [
|
|
16
|
+
mainRouter,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
if ($n_isNil(routers)) {
|
|
20
|
+
routers = $n_get(configs, 'routers')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
$n_forIn(routers, function(item, key) {
|
|
24
|
+
|
|
25
|
+
// 如果没有 meta
|
|
26
|
+
if (! $n_has(item, 'meta')) {
|
|
27
|
+
item.meta = {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// path
|
|
31
|
+
item.path = $n_slash(key, 'start', true)
|
|
32
|
+
|
|
33
|
+
// 如果是单独路由
|
|
34
|
+
if ($n_get(item.meta, 'parent') === false) {
|
|
35
|
+
routes.push(item)
|
|
36
|
+
|
|
37
|
+
// 否则为框架页面
|
|
38
|
+
} else {
|
|
39
|
+
mainRouter.children.push(item)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// 添加错误路由
|
|
44
|
+
routes.push(errorRouter)
|
|
45
|
+
|
|
46
|
+
return routes
|
|
47
|
+
}
|