@netang/quasar 0.0.21 → 0.0.23

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/utils/$tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isRef, watch } from 'vue'
2
- import { useRoute } from 'vue-router'
2
+ import { NPowerKey } from './symbols'
3
3
 
4
4
  /**
5
5
  * 获取节点
@@ -43,17 +43,19 @@ function getChildren(data, callback) {
43
43
  }
44
44
 
45
45
  /**
46
- * 树业务
46
+ * 创建树实例
47
47
  */
48
- utils.$tree = function(params) {
48
+ function create(params) {
49
49
 
50
50
  const {
51
+ // 路由路径
52
+ path,
53
+ // 路由参数
54
+ query,
51
55
  // 树节点列表
52
56
  nodes,
53
57
  // 树展开节点
54
58
  expanded,
55
- // 权限按钮列表
56
- roleBtnLists,
57
59
  // 原始表单数据
58
60
  rawFormData,
59
61
  // 表单数据
@@ -63,16 +65,30 @@ utils.$tree = function(params) {
63
65
  // 是否开启展开节点缓存
64
66
  cache,
65
67
  } = Object.assign({
68
+ // 路由路径
69
+ path: '',
70
+ // 路由参数
71
+ query: {},
66
72
  // 是否开启展开节点缓存
67
73
  cache: false,
68
74
  }, params)
69
75
 
70
- // 如果没有地址, 则使用当前路由地址
71
- let url = ''
72
- if (! _.get(params, 'url')) {
73
- // 当前路由
74
- url = useRoute().fullPath
75
- }
76
+ // 获取权限注入
77
+ const $power = _.has(params, '$power') ? params.$power : inject(NPowerKey)
78
+ const hasPowr = !! $power
79
+
80
+ // 获取权限路由
81
+ const $route = utils.isValidString(path) ?
82
+ // 如果为自定义路由
83
+ utils.router.resolve({
84
+ path,
85
+ query,
86
+ })
87
+ // 否则获取当前路由
88
+ : (hasPowr ? $power.getRoute() : utils.router.getRoute())
89
+
90
+ // 权限按钮
91
+ const powerBtns = hasPowr ? $power.powerBtns : ref([])
76
92
 
77
93
  // 是否有展开节点
78
94
  const hasExpanded = ! _.isNil(expanded) && isRef(expanded)
@@ -194,21 +210,21 @@ utils.$tree = function(params) {
194
210
  maps[o.deleteName] = 'delete'
195
211
  maps[o.statusName] = 'status'
196
212
 
197
- const allRoleBtn = {}
198
- for (const item of roleBtnLists.value) {
213
+ const allPowerBtn = {}
214
+ for (const item of powerBtns.value) {
199
215
  if (_.has(maps, _.get(item, 'name'))) {
200
- allRoleBtn[maps[item.name]] = item
216
+ allPowerBtn[maps[item.name]] = item
201
217
  }
202
218
  }
203
219
 
204
220
  return {
205
- all: utils.isValidObject(allRoleBtn),
206
- update: _.has(allRoleBtn, 'update'),
207
- move: _.has(allRoleBtn, 'move'),
208
- copy: _.has(allRoleBtn, 'copy'),
209
- delete: _.has(allRoleBtn, 'delete'),
210
- status: _.has(allRoleBtn, 'status'),
211
- allRoleBtn,
221
+ all: utils.isValidObject(allPowerBtn),
222
+ update: _.has(allPowerBtn, 'update'),
223
+ move: _.has(allPowerBtn, 'move'),
224
+ copy: _.has(allPowerBtn, 'copy'),
225
+ delete: _.has(allPowerBtn, 'delete'),
226
+ status: _.has(allPowerBtn, 'status'),
227
+ allPowerBtn,
212
228
  }
213
229
  }
214
230
 
@@ -255,7 +271,7 @@ utils.$tree = function(params) {
255
271
  // 移至节点下
256
272
  case 'moveDown':
257
273
 
258
- if (! _.get(o.menuStatus, 'value.allRoleBtn.move.url')) {
274
+ if (! _.get(o.menuStatus, 'value.allPowerBtn.move.url')) {
259
275
  console.error('没有找到复制地址')
260
276
  return
261
277
  }
@@ -268,7 +284,7 @@ utils.$tree = function(params) {
268
284
  minWidth: 500,
269
285
  // 组件标识
270
286
  name: 'moveToTree',
271
- // 传参
287
+ // 组件参数
272
288
  props: {
273
289
  // 树节点列表
274
290
  nodes,
@@ -388,7 +404,7 @@ utils.$tree = function(params) {
388
404
 
389
405
  // 请求 - 移动
390
406
  const { status } = await utils.http({
391
- url: o.menuStatus.value.allRoleBtn.move.url,
407
+ url: o.menuStatus.value.allPowerBtn.move.url,
392
408
  data: {
393
409
  data: moveLists,
394
410
  },
@@ -407,7 +423,7 @@ utils.$tree = function(params) {
407
423
  // 确认菜单
408
424
  confirmMenu(async function() {
409
425
 
410
- if (! _.get(o.menuStatus, 'value.allRoleBtn.copy.url')) {
426
+ if (! _.get(o.menuStatus, 'value.allPowerBtn.copy.url')) {
411
427
  console.error('没有找到复制地址')
412
428
  return
413
429
  }
@@ -432,7 +448,7 @@ utils.$tree = function(params) {
432
448
 
433
449
  // 请求 - 复制
434
450
  const { status, data: res } = await utils.http({
435
- url: o.menuStatus.value.allRoleBtn.copy.url,
451
+ url: o.menuStatus.value.allPowerBtn.copy.url,
436
452
  data: {
437
453
  data: copyLists,
438
454
  },
@@ -489,7 +505,7 @@ utils.$tree = function(params) {
489
505
  return
490
506
  }
491
507
 
492
- if (! _.get(o.menuStatus, 'value.allRoleBtn.delete.url')) {
508
+ if (! _.get(o.menuStatus, 'value.allPowerBtn.delete.url')) {
493
509
  console.error('没有找到删除地址')
494
510
  return
495
511
  }
@@ -499,7 +515,7 @@ utils.$tree = function(params) {
499
515
 
500
516
  // 请求 - 删除
501
517
  const { status } = await utils.http({
502
- url: o.menuStatus.value.allRoleBtn.delete.url,
518
+ url: o.menuStatus.value.allPowerBtn.delete.url,
503
519
  data: {
504
520
  id: o.node.id,
505
521
  },
@@ -524,7 +540,7 @@ utils.$tree = function(params) {
524
540
  // 全部正常
525
541
  case 'statusNormal':
526
542
 
527
- if (! _.get(o.menuStatus, 'value.allRoleBtn.status.url')) {
543
+ if (! _.get(o.menuStatus, 'value.allPowerBtn.status.url')) {
528
544
  console.error('没有找到状态地址')
529
545
  return
530
546
  }
@@ -550,7 +566,7 @@ utils.$tree = function(params) {
550
566
 
551
567
  // 请求 - 全部禁用/正常
552
568
  const { status } = await utils.http({
553
- url: o.menuStatus.value.allRoleBtn.status.url,
569
+ url: o.menuStatus.value.allPowerBtn.status.url,
554
570
  data: {
555
571
  // ids
556
572
  ids: statusIds,
@@ -587,7 +603,7 @@ utils.$tree = function(params) {
587
603
  */
588
604
  function getExpandedCache(defaultValue = []) {
589
605
  // 获取展开节点缓存
590
- const res = utils.storage.get('tree_expanded_' + url)
606
+ const res = utils.storage.get('tree_expanded_' + $route.fullPath)
591
607
  return utils.isValidArray(res) ? res : defaultValue
592
608
  }
593
609
 
@@ -596,12 +612,12 @@ utils.$tree = function(params) {
596
612
  */
597
613
  function setExpandedCache(expanded) {
598
614
  // 设置展开节点缓存(永久缓存)
599
- utils.storage.set('tree_expanded_' + url, expanded, 0)
615
+ utils.storage.set('tree_expanded_' + $route.fullPath, expanded, 0)
600
616
  }
601
617
 
602
618
  return {
603
619
  // 当前地址
604
- url,
620
+ fullPath: $route.fullPath,
605
621
  // 获取节点
606
622
  getNode,
607
623
  // 更新节点
@@ -618,3 +634,11 @@ utils.$tree = function(params) {
618
634
  setExpandedCache,
619
635
  }
620
636
  }
637
+
638
+ /**
639
+ * 树业务
640
+ */
641
+ utils.$tree = {
642
+ // 创建树实例
643
+ create,
644
+ }
package/utils/http.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isRef } from 'vue'
2
2
  import axios from 'axios'
3
3
  import createHttp from '@netang/utils/http'
4
- import { stateRole } from '../store'
4
+ import { statePower } from '../store'
5
5
 
6
6
  /**
7
7
  * 初始化 http
@@ -102,9 +102,9 @@ utils.http = createHttp({
102
102
  options.headers.Authorization = token
103
103
 
104
104
  // 如果有权限
105
- if (stateRole.value.v) {
105
+ if (statePower.value.v) {
106
106
  // 头部添加权限版本号
107
- options.headers.Rv = stateRole.value.v
107
+ options.headers.Pv = statePower.value.v
108
108
  }
109
109
 
110
110
  // 否则未登录 && 如果开启强制登录, 则跳转登录页面
@@ -126,8 +126,8 @@ utils.http = createHttp({
126
126
 
127
127
  // 如果请求成功
128
128
  if (res.status && para.checkCode && para.token) {
129
- // 设置角色数据
130
- utils.$role.setData(_.get(res, 'response.data.role'))
129
+ // 设置权限数据
130
+ utils.$power.setData(_.get(res, 'response.data.power'))
131
131
  }
132
132
 
133
133
  return res
package/utils/symbols.js CHANGED
@@ -1,4 +1,7 @@
1
+ export const NPowerKey = '_n_power_'
1
2
  export const NLayoutKey = '_n_layout_'
3
+ export const NTableKey = '_n_table_'
4
+ export const NFormKey = '_n_form_'
2
5
  export const NDialogKey = '_n_dialog_'
3
6
  export const NFieldTableKey = '_n_field_table_'
4
7
  export const NUploaderKey = '_n_uploader_'
@@ -1,126 +0,0 @@
1
- <template>
2
- <q-layout
3
- v-bind="$attrs"
4
- >
5
- <!-- 错误提示 -->
6
- <q-page-container v-if="pageStatus === false">
7
- <q-page class="q-pa-lg flex flex-center">
8
- {{emptyDescription}}
9
- </q-page>
10
- </q-page-container>
11
-
12
- <!-- 插槽 -->
13
- <slot :data="data" v-else-if="pageStatus === true" />
14
- </q-layout>
15
-
16
- <!-- 加载 -->
17
- <q-inner-loading
18
- :showing="pageLoading"
19
- />
20
- </template>
21
-
22
- <script>
23
- import { provide, ref } from 'vue'
24
- import { NLayoutKey } from '../../utils/symbols'
25
-
26
- export default {
27
-
28
- /**
29
- * 标识
30
- */
31
- name: 'NLayout',
32
-
33
- /**
34
- * 声明属性
35
- */
36
- props: {
37
- // 页面加载
38
- pageLoading: Boolean,
39
- // 页面状态
40
- pageStatus: {
41
- type: Boolean,
42
- default: null,
43
- },
44
- // 空状态描述
45
- emptyDescription: {
46
- type: String,
47
- default: '发生未知错误',
48
- },
49
- },
50
-
51
- /**
52
- * 组合式
53
- */
54
- setup() {
55
-
56
- // ==========【注入】============================================================================================
57
-
58
- const leftModelValue = ref(null)
59
- const rightModelValue = ref(null)
60
-
61
- // 布局数据
62
- const data = {
63
- // 左边侧滑菜单数据
64
- left: {
65
- // 是否显示
66
- modelValue: leftModelValue,
67
- // 是否显示切换按钮
68
- showButton() {
69
- return leftModelValue.value !== null
70
- },
71
- // 切换
72
- toggle() {
73
- if (leftModelValue.value !== null) {
74
- leftModelValue.value = ! leftModelValue.value
75
- }
76
- },
77
- },
78
- // 右边侧滑菜单数据
79
- right: {
80
- // 是否显示
81
- modelValue: rightModelValue,
82
- // 是否显示切换按钮
83
- showButton() {
84
- return rightModelValue.value !== null
85
- },
86
- // 切换
87
- toggle() {
88
- if (rightModelValue.value !== null) {
89
- rightModelValue.value = ! rightModelValue.value
90
- }
91
- },
92
- },
93
- // 权限数据
94
- role: {},
95
- // 表格数据
96
- table: {},
97
- // 上传器
98
- uploader: [],
99
- }
100
-
101
- // 向后代注入数据
102
- provide(NLayoutKey, {
103
- // 注入数据
104
- data,
105
- // 更新注入数据
106
- update(cb) {
107
- cb(data)
108
- },
109
- // 检查是否上传中
110
- checkUploading() {
111
- for (const uploader of data.uploader) {
112
- if (uploader.checkUploading()) {
113
- return true
114
- }
115
- }
116
- return false
117
- },
118
- })
119
-
120
- return {
121
- // 布局数据
122
- data,
123
- }
124
- },
125
- }
126
- </script>