@netang/quasar 0.0.31 → 0.0.33

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.
@@ -54,7 +54,7 @@ import { useDialogPluginComponent, useQuasar } from 'quasar'
54
54
 
55
55
  import routers from '@/router/routers'
56
56
 
57
- import components from './components'
57
+ import components from '../private/components'
58
58
  import { NDialogKey } from '../../utils/symbols'
59
59
 
60
60
  export default {
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="q-pa-lg flex flex-center absolute-full">
3
- {{emptyDescription || '发生未知错误'}}
3
+ {{description || '发生未知错误'}}
4
4
  </div>
5
5
  </template>
6
6
 
@@ -17,7 +17,7 @@ export default {
17
17
  */
18
18
  props: {
19
19
  // 空状态描述
20
- emptyDescription: String,
20
+ description: String,
21
21
  },
22
22
  }
23
23
  </script>
@@ -160,6 +160,7 @@
160
160
 
161
161
  <script>
162
162
  import { ref, computed, watch, onMounted, onUpdated } from 'vue'
163
+ import { NRenderKey } from '../../utils/symbols'
163
164
 
164
165
  export default {
165
166
 
@@ -4,7 +4,7 @@
4
4
  >
5
5
  <!-- 空数据 -->
6
6
  <n-empty
7
- :empty-description="emptyDescription"
7
+ :description="emptyDescription"
8
8
  v-if="pageStatus === false"
9
9
  />
10
10
 
@@ -0,0 +1,136 @@
1
+ <template>
2
+ <q-layout
3
+ class="absolute-full"
4
+ view="hHh lpr fFf"
5
+ container
6
+ >
7
+ <q-page-container>
8
+ <slot
9
+ :query="query"
10
+ v-bind="props"
11
+ v-if="$slots.default"
12
+ />
13
+ <component
14
+ :is="comp"
15
+ :query="query"
16
+ v-bind="props"
17
+ v-else
18
+ />
19
+ </q-page-container>
20
+ </q-layout>
21
+ </template>
22
+
23
+ <script>
24
+ import { computed, defineAsyncComponent, provide } from 'vue'
25
+
26
+ import routers from '@/router/routers'
27
+ import components from '../private/components'
28
+
29
+ import { NRenderKey } from '../../utils/symbols'
30
+
31
+ export default {
32
+
33
+ /**
34
+ * 标识
35
+ */
36
+ name: 'NRender',
37
+
38
+ /**
39
+ * 声明属性
40
+ */
41
+ props: {
42
+ // 组件标识
43
+ name: String,
44
+ // 组件路径
45
+ path: String,
46
+ // 参数
47
+ query: Object,
48
+ // 组件传参
49
+ props: Object,
50
+ },
51
+
52
+ /**
53
+ * 组合式
54
+ */
55
+ setup(props) {
56
+
57
+ // ==========【计算属性】=========================================================================================
58
+
59
+ /**
60
+ * 获取当前组件
61
+ */
62
+ const comp = computed(function () {
63
+
64
+ // 组件
65
+ let comp
66
+
67
+ // 如果是路由路径
68
+ if (props.path) {
69
+ // 获取路由组件
70
+ comp = _.get(routers, `${utils.slash(props.path, 'start', false)}.component`)
71
+
72
+ // 如果有组件标识
73
+ } else if (props.name && _.has(components, props.name)) {
74
+ // 获取自定义组件
75
+ comp = components[props.name]
76
+ }
77
+
78
+ // 如果没有组件
79
+ if (! comp) {
80
+ return
81
+ }
82
+
83
+ // 如果是方法, 则说明是异步组件
84
+ if (_.isFunction(comp)) {
85
+ return defineAsyncComponent(comp)
86
+ }
87
+
88
+ // 返回组件
89
+ return comp
90
+ })
91
+
92
+ // ==========【注入】============================================================================================
93
+
94
+ // 注入数据
95
+ const data = {
96
+ // 组件标识
97
+ name: props.name,
98
+ // 参数
99
+ query: utils.isValidObject(props.query) ? props.query : {},
100
+ // 组件传参
101
+ props: props.props,
102
+ }
103
+
104
+ // 如果有路由路径
105
+ if (utils.isValidString(props.path)) {
106
+
107
+ // 获取页面路由
108
+ const $route = utils.router.resolve({
109
+ path: props.path,
110
+ query: data.query,
111
+ })
112
+
113
+ Object.assign(data, {
114
+ // 当前路由全路径
115
+ routeFullPath: $route.fullPath,
116
+ // 当前路由路径
117
+ routePath: $route.path,
118
+ // 当前路由参数
119
+ routeQuery: $route.query,
120
+ // 当前路由,
121
+ $route,
122
+ })
123
+ }
124
+
125
+ // 向后代注入数据
126
+ provide(NRenderKey, data)
127
+
128
+ // ==========【返回】=============================================================================================
129
+
130
+ return {
131
+ // 组件
132
+ comp,
133
+ }
134
+ }
135
+ }
136
+ </script>
@@ -74,18 +74,6 @@
74
74
 
75
75
  <!-- 输入框 -->
76
76
  <template v-else-if="item.searchType === 'input'">
77
- <!-- 输入框 数字 -->
78
- <n-input-number
79
- class="n-field-fieldset"
80
- :label="label"
81
- v-model="modelValue[itemIndex][index].value"
82
- dense
83
- outlined
84
- clearable
85
- v-bind="item.input"
86
- v-if="item.type === 'number'"
87
- />
88
- <!-- 输入框 文字 -->
89
77
  <q-input
90
78
  class="n-field-fieldset"
91
79
  :label="label"
@@ -94,7 +82,6 @@
94
82
  outlined
95
83
  clearable
96
84
  v-bind="item.input"
97
- v-else
98
85
  />
99
86
  </template>
100
87
 
@@ -176,8 +163,6 @@
176
163
  </template>
177
164
 
178
165
  <script>
179
- import { computed } from 'vue'
180
-
181
166
  export default {
182
167
 
183
168
  /**
@@ -161,28 +161,20 @@ export default {
161
161
  /**
162
162
  * 监听声明值
163
163
  */
164
- if (utils.indexOf(['select', 'tree'], props.data.searchType) > -1) {
165
-
166
- watch(()=>props.modelValue[0].type, function(val) {
167
-
168
- const modelValue = _.cloneDeep(props.modelValue)
169
-
170
- // 如果类型为 in / not in, 则为多选
171
- if (utils.indexOf([dicts.SEARCH_TYPE__IN, dicts.SEARCH_TYPE__NOT_IN], val) > -1) {
172
-
173
- // 如果值不为数组
174
- if (! Array.isArray(modelValue[0].value)) {
175
- modelValue[0].value = utils.isValidValue(modelValue[0].value) ? [modelValue[0].value] : []
176
- emit('update:modelValue', modelValue)
177
- }
178
-
179
- // 否则为单选, 并且如果值为数组
180
- } else if (Array.isArray(modelValue[0].value)) {
181
- modelValue[0].value = utils.isValidValue(modelValue[0].value[0]) ? modelValue[0].value[0] : ''
182
- emit('update:modelValue', modelValue)
164
+ watch(()=>props.modelValue[0].type, function(val) {
165
+ // 如果类型不为 in / not in, 为单选
166
+ if (utils.indexOf([dicts.SEARCH_TYPE__IN, dicts.SEARCH_TYPE__NOT_IN], val) === -1) {
167
+ const arr = utils.split(props.modelValue[0].value, ',')
168
+ if (arr.length !== 1) {
169
+ // 克隆值
170
+ const _modelValue = _.cloneDeep(props.modelValue)
171
+
172
+ // 更新值
173
+ _modelValue[0].value = arr.length > 1 ? arr[0] : ''
174
+ emit('update:modelValue', _modelValue)
183
175
  }
184
- })
185
- }
176
+ }
177
+ })
186
178
 
187
179
  // ==========【返回】=============================================================================================
188
180
 
@@ -1,24 +1,31 @@
1
1
  <template>
2
- <!-- 默认插槽 -->
3
- <slot
4
- :name="currentSlot.defaultName"
5
- v-if="!! currentSlot.defaultName"
6
- />
7
-
8
2
  <!-- 拆分器 -->
9
3
  <q-splitter
10
4
  v-model="currentValue"
11
5
  v-bind="$attrs"
12
- v-else
6
+ v-if="$slots.before && $slots.after"
13
7
  >
14
8
  <!-- 插槽 -->
15
9
  <template
16
- v-for="slotName in currentSlot.keys"
10
+ v-for="slotName in slotNames"
17
11
  v-slot:[slotName]
18
12
  >
19
13
  <slot :name="slotName" />
20
14
  </template>
21
15
  </q-splitter>
16
+
17
+ <!-- before 插槽 -->
18
+ <slot
19
+ name="before"
20
+ v-else-if="$slots.before"
21
+ />
22
+
23
+ <!-- after 插槽 -->
24
+ <slot
25
+ name="after"
26
+ v-else-if="$slots.after"
27
+ />
28
+
22
29
  </template>
23
30
 
24
31
  <script>
@@ -57,33 +64,10 @@ export default {
57
64
  // ==========【计算属性】=========================================================================================
58
65
 
59
66
  /**
60
- * 当前插槽
67
+ * 插槽标识
61
68
  */
62
- const currentSlot = computed(function() {
63
-
64
- let keys = []
65
- let defaultName = ''
66
-
67
- if (utils.isValidObject(slots)) {
68
-
69
- keys = Object.keys(slots)
70
-
71
- const hasBefore = _.has(slots, 'before')
72
- const hasAfter = _.has(slots, 'after')
73
-
74
- if (hasBefore) {
75
- if (! hasAfter) {
76
- defaultName = 'before'
77
- }
78
- } else if (hasAfter && ! hasBefore) {
79
- defaultName = 'after'
80
- }
81
- }
82
-
83
- return {
84
- keys,
85
- defaultName,
86
- }
69
+ const slotNames = computed(function() {
70
+ return utils.isValidObject(slots) ? Object.keys(slots) : []
87
71
  })
88
72
 
89
73
  // ==========【数据】============================================================================================
@@ -118,8 +102,8 @@ export default {
118
102
  // ==========【返回】=============================================================================================
119
103
 
120
104
  return {
121
- // 当前插槽
122
- currentSlot,
105
+ // 插槽标识
106
+ slotNames,
123
107
  // 当前值
124
108
  currentValue,
125
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/$power.js CHANGED
@@ -2,7 +2,7 @@ import { provide, inject, ref, computed } from 'vue'
2
2
  import { useQuasar } from 'quasar'
3
3
 
4
4
  import { statePower } from '../store'
5
- import { NPowerKey, NFormKey, NTableKey } from './symbols'
5
+ import { NRenderKey, NPowerKey, NFormKey, NTableKey } from './symbols'
6
6
 
7
7
  /**
8
8
  * 创建权限实例
@@ -23,6 +23,10 @@ function create(params) {
23
23
  emptyDescription: '',
24
24
  // 是否开启权限
25
25
  power: true,
26
+ // 是否显示权限按钮
27
+ showPowerBtns: true,
28
+ // 是否显示工具栏权限按钮
29
+ showToolbarPowerBtns: true,
26
30
  // 左边侧滑菜单图标
27
31
  leftDrawerIcon: 'format_list_bulleted',
28
32
  // 右边侧滑菜单图标
@@ -38,25 +42,51 @@ function create(params) {
38
42
  requestAfter: null,
39
43
  }, params)
40
44
 
41
- // 获取权限路由
42
- const $route = o.path === false
43
- // 如果没有路由
44
- ? {
45
+ // 获取渲染注入
46
+ const $render = inject(NRenderKey)
47
+
48
+ // 如果有渲染注入
49
+ const hasRender = !! $render
50
+ if (hasRender) {
51
+ // 如果有权限传参, 则合并参数
52
+ const powerProps = _.get($render, 'props.powerProps')
53
+ if (utils.isValidObject(powerProps)) {
54
+ _.merge(o, powerProps)
55
+ }
56
+ }
57
+
58
+ // 权限路由
59
+ let $route
60
+
61
+ // 如果没有路由
62
+ if (o.path === false) {
63
+
64
+ // 设为空路由
65
+ $route = {
45
66
  fullPath: '',
46
67
  path: '',
47
68
  query: utils.isValidObject(o.query) ? o.query : {},
48
69
  }
49
- // 否则获取路由
50
- : (
51
- utils.isValidString(o.path) ?
52
- // 如果为自定义路由
53
- utils.router.resolve({
54
- path: o.path,
55
- query: utils.isValidObject(o.query) ? o.query : {},
56
- })
57
- // 否则获取当前路由
58
- : utils.router.getRoute()
59
- )
70
+
71
+ // 如果有自定义路径
72
+ } else if (utils.isValidString(o.path)) {
73
+
74
+ // 获取自定义路由
75
+ $route = utils.router.resolve({
76
+ path: o.path,
77
+ query: utils.isValidObject(o.query) ? o.query : {},
78
+ })
79
+
80
+ // 如果在渲染组件内 && 该渲染组件有自定义路由
81
+ } else if (hasRender && _.has($render, '$route')) {
82
+
83
+ // 设为渲染组件的路由
84
+ $route = $render.$route
85
+
86
+ // 否则获取当前路由
87
+ } else {
88
+ $route = utils.router.getRoute()
89
+ }
60
90
 
61
91
  // quasar 对象
62
92
  const $q = useQuasar()
@@ -165,12 +195,16 @@ function create(params) {
165
195
  // 当前页面权限
166
196
  data.powerPage = res.page
167
197
  // 当前页面权限按钮
168
- data.powerBtns = ref(res.btns)
198
+ data.powerBtns = ref(o.showPowerBtns ? res.btns : [])
169
199
  // 当前页面工具栏权限按钮
170
200
  data.toolbarPowerBtns = computed(function() {
171
201
 
172
- // 有权限按钮数据
173
- if (utils.isValidArray(data.powerBtns.value)) {
202
+ if (
203
+ // 如果显示工具栏权限按钮
204
+ o.showToolbarPowerBtns
205
+ // 有权限按钮数据
206
+ && utils.isValidArray(data.powerBtns.value)
207
+ ) {
174
208
 
175
209
  const lists = _.filter(formatBtns(data.powerBtns.value), e => e.type > 2)
176
210
 
@@ -673,7 +707,7 @@ function getRequestQuery(o) {
673
707
  }
674
708
  }
675
709
 
676
- return _.merge({}, query)
710
+ return _.cloneDeep(utils.numberDeep(query))
677
711
  }
678
712
 
679
713
  /**
@@ -696,15 +730,25 @@ function formatQuery(query, isJoinArr) {
696
730
 
697
731
  // 如果是数组
698
732
  } else if (utils.isValidArray(value)) {
733
+
699
734
  const arr = []
700
735
  for (const val of value) {
701
- // 如果是数字
702
- if (utils.isNumeric(val)) {
703
- arr.push(_.isNumber(val) ? val : Number(val))
704
736
 
705
- // 如果是字符串
706
- } else if (utils.isValidString(val)) {
707
- arr.push(utils.trimString(val))
737
+ // 如果为有效值
738
+ if (utils.isRequired(val)) {
739
+
740
+ // 如果是数字
741
+ if (utils.isNumeric(val)) {
742
+ arr.push(_.isNumber(val) ? val : Number(val))
743
+
744
+ // 如果是字符串
745
+ } else if (utils.isValidString(val)) {
746
+ arr.push(utils.trimString(val))
747
+
748
+ // 否则为数组或对象
749
+ } else {
750
+ arr.push(val)
751
+ }
708
752
  }
709
753
  }
710
754
  if (arr.length) {
package/utils/$search.js CHANGED
@@ -25,7 +25,14 @@ export function setItemValue(value, val) {
25
25
  // 比较类型为 in
26
26
  value[0].type = dicts.SEARCH_TYPE__IN
27
27
  // 设置值为将数组转为逗号分隔的字符串
28
- value[0].value = val.join(',')
28
+ value[0].value = utils.join(val, ',')
29
+
30
+ // 如果值是逗号隔开
31
+ } else if (utils.split(val, ',').length > 1) {
32
+ // 比较类型为 in
33
+ value[0].type = dicts.SEARCH_TYPE__IN
34
+ // 设置值为将数组转为逗号分隔的字符串
35
+ value[0].value = val
29
36
 
30
37
  // 否则为单个值
31
38
  } else {
package/utils/$table.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  setItemValue,
10
10
  } from './$search'
11
11
 
12
- import { NPowerKey, NTableKey, NDialogKey } from './symbols'
12
+ import { NRenderKey, NPowerKey, NTableKey } from './symbols'
13
13
 
14
14
  /**
15
15
  * 创建表格
@@ -67,8 +67,6 @@ function create(params) {
67
67
  request: null,
68
68
  // 格式化单条数据
69
69
  formatRow: null,
70
- // 格式化参数
71
- // formatQuery: null,
72
70
  // http 设置
73
71
  httpSettings: {},
74
72
  // 是否开启初始搜素
@@ -85,8 +83,25 @@ function create(params) {
85
83
  cache: true,
86
84
  // 刷新后清空已选数据
87
85
  refreshResetSelected: true,
86
+
87
+ // 单击表格行事件
88
+ rowClick: null,
89
+ // 双击表格行事件
90
+ rowDblClick: null,
88
91
  }, params)
89
92
 
93
+ // 获取渲染注入
94
+ const $render = inject(NRenderKey)
95
+
96
+ // 如果有渲染注入
97
+ if (!! $render) {
98
+ // 如果有表格传参, 则合并参数
99
+ const tableProps = _.get($render, 'props.tableProps')
100
+ if (utils.isValidObject(tableProps)) {
101
+ _.merge(o, tableProps)
102
+ }
103
+ }
104
+
90
105
  // 获取权限注入
91
106
  const $power = _.has(params, '$power') ? params.$power : inject(NPowerKey)
92
107
  const hasPowr = !! $power
@@ -732,7 +747,7 @@ function create(params) {
732
747
  /**
733
748
  * 单击表格行
734
749
  */
735
- function tableRowClick(e, row) {
750
+ function _tableRowClick(e, row) {
736
751
 
737
752
  // 如果选择类型为无
738
753
  if (o.selection === 'none') {
@@ -763,11 +778,21 @@ function create(params) {
763
778
  tableSelected.value.splice(itemIndex, 1)
764
779
  }
765
780
  }
781
+ function tableRowClick(...e) {
782
+
783
+ // 单击表格行
784
+ _tableRowClick(...e)
785
+
786
+ // 如果有自定义单击事件
787
+ if (_.isFunction(o.rowClick)) {
788
+ o.rowClick(...e)
789
+ }
790
+ }
766
791
 
767
792
  /**
768
793
  * 双击表格行
769
794
  */
770
- function tableRowDblclick(e, row) {
795
+ function _tableRowDblclick(e, row) {
771
796
 
772
797
  // 如果选择类型为无
773
798
  if (o.selection === 'none') {
@@ -784,6 +809,16 @@ function create(params) {
784
809
  $power.powerBtnClick(tableDbClickPowerBtn.value, [ row ])
785
810
  }
786
811
  }
812
+ function tableRowDblclick(...e) {
813
+
814
+ // 双击表格行
815
+ _tableRowDblclick(...e)
816
+
817
+ // 如果有自定义双击表格行事件
818
+ if (_.isFunction(o.tableRowDblclick)) {
819
+ o.tableRowDblclick(...e)
820
+ }
821
+ }
787
822
 
788
823
  /**
789
824
  * 设置表格搜索参数
package/utils/symbols.js CHANGED
@@ -1,3 +1,4 @@
1
+ export const NRenderKey = '_n_render_'
1
2
  export const NPowerKey = '_n_power_'
2
3
  export const NLayoutKey = '_n_layout_'
3
4
  export const NTableKey = '_n_table_'