@netang/quasar 0.1.8 → 0.1.10

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.
@@ -56,6 +56,8 @@ export default {
56
56
  props: {
57
57
  // 组件标识
58
58
  name: String,
59
+ // 组件
60
+ component: Object,
59
61
  // 组件路径
60
62
  path: String,
61
63
  // 参数
@@ -86,8 +88,13 @@ export default {
86
88
 
87
89
  // 如果有组件标识
88
90
  } else if (props.name && $n_has(components, props.name)) {
89
- // 获取自定义组件
91
+ // 设置自定义组件
90
92
  comp = components[props.name]
93
+
94
+ // 如果有声明组件
95
+ } else if (props.component) {
96
+ // 设置声明组件
97
+ comp = props.component
91
98
  }
92
99
 
93
100
  // 如果没有组件
@@ -1,360 +1,370 @@
1
- <template>
2
- <n-splitter
3
- class="absolute-full"
4
- v-model="currentValue"
5
- :reverse="reverse"
6
- :unit="unit"
7
- :limits="limits"
8
- :horizontal="horizontal"
9
-
10
- v-model:after="currentAfter"
11
- @update:after="setSelection"
12
- :hide-after-in-mobile="hideAfterInMobile"
13
- :cache="cache"
14
- >
15
- <!-- 表格 -->
16
- <template v-slot:before="{ after, toggleAfter }">
17
- <n-table
18
- v-bind="$attrs"
19
- >
20
- <!-- 工具栏右边插槽(手机端不显示) -->
21
- <template #toolbar-right v-if="isWatcher">
22
-
23
- <!-- 工具栏右边插槽 -->
24
- <slot name="toolbar-right" />
25
-
26
- <!-- 是否显示详情 -->
27
- <q-toggle
28
- icon="apps"
29
- :model-value="after"
30
- @click="toggleAfter"
31
- >
32
- <q-tooltip anchor="center left" self="center right" :offset="[10, 0]">{{tooltip}}</q-tooltip>
33
- </q-toggle>
34
-
35
- </template>
36
-
37
- <!-- 插槽 -->
38
- <template
39
- v-for="slotName in slotNames"
40
- v-slot:[slotName]="props"
41
- >
42
- <!-- 有传参的插槽 -->
43
- <slot
44
- :name="slotName"
45
- v-bind="props"
46
- v-if="props"
47
- />
48
-
49
- <!-- 无传参的插槽 -->
50
- <slot
51
- :name="slotName"
52
- v-else
53
- />
54
- </template>
55
-
56
- </n-table>
57
- </template>
58
-
59
- <!-- 渲染详情页面(手机端不显示) -->
60
- <template v-slot:after>
61
-
62
- <!-- 渲染 -->
63
- <n-render
64
- :path="renderPath"
65
- :query="currentQuery"
66
- v-if="currentQuery"
67
- />
68
-
69
- <!-- 空状态 -->
70
- <n-empty
71
- :description="renderDescription"
72
- fit
73
- v-else
74
- />
75
-
76
- </template>
77
-
78
- </n-splitter>
79
- </template>
80
-
81
- <script>
82
- import { nextTick, ref, watch, computed, inject } from 'vue'
83
- import { useQuasar } from 'quasar'
84
-
85
- import $n_isFunction from 'lodash/isFunction'
86
-
87
- import $n_isValidObject from '@netang/utils/isValidObject'
88
-
89
- import NSplitter from '../splitter'
90
- import NTable from '../table'
91
- import NRender from '../render'
92
- import NEmpty from '../empty'
93
-
94
- import { NTableKey } from '../../utils/symbols'
95
-
96
- export default {
97
-
98
- /**
99
- * 关闭组件 attribute 透传行为
100
- */
101
- inheritAttrs: false,
102
-
103
- /**
104
- * 标识
105
- */
106
- name: 'NTableSplitter',
107
-
108
- /**
109
- * 组件
110
- */
111
- components: {
112
- NSplitter,
113
- NTable,
114
- NRender,
115
- NEmpty,
116
- },
117
-
118
- /**
119
- * 声明属性
120
- */
121
- props: {
122
- // 值 v-model
123
- modelValue: {
124
- type: Number,
125
- default: 50,
126
- },
127
- // 反转插槽
128
- reverse: Boolean,
129
- // 模型的 CSS 单位
130
- unit: String,
131
- // 两个值的数组,表示两个面板的最小和最大分割大小
132
- limits: Array,
133
- // 是否水平拆分
134
- horizontal: Boolean,
135
-
136
- // 显示后置插槽 v-model:after
137
- // 注意: 如果非双向绑定, 如 :after 并不会影响内部值变化, 仅做初始值使用
138
- after: {
139
- type: Boolean,
140
- default: true,
141
- },
142
- // 手机模式隐藏后插槽
143
- hideAfterInMobile: {
144
- type: Boolean,
145
- default: true,
146
- },
147
- // 是否开启缓存
148
- cache: {
149
- type: [ Boolean, String ],
150
- default: true,
151
- },
152
-
153
- // 工具提示
154
- tooltip: {
155
- type: String,
156
- default: '是否显示详情',
157
- },
158
- // 渲染组件路径
159
- renderPath: {
160
- type: String,
161
- required: true,
162
- },
163
- // 格式化已选表格的数据并返回渲染组件参数
164
- renderQuery: Function,
165
- // 渲染空状态描述
166
- renderDescription: {
167
- type: String,
168
- default: '没有找到任何数据',
169
- },
170
- // 不需要加载渲染页面标识参数
171
- // 额外加载参数 { n_renderpage: 1 }
172
- noRendPageName: Boolean,
173
- },
174
-
175
- /**
176
- * 声明事件
177
- */
178
- emits: [
179
- 'update:modelValue',
180
- 'update:after',
181
- ],
182
-
183
- /**
184
- * 组合式
185
- */
186
- setup(props, { emit, slots }) {
187
-
188
- // ==========【计算属性】=========================================================================================
189
-
190
- /**
191
- * 插槽标识
192
- */
193
- const slotNames = computed(function() {
194
- return $n_isValidObject(slots) ? Object.keys(slots).filter(e => e !== 'toolbar-right') : []
195
- })
196
-
197
- /**
198
- * 是否监听
199
- */
200
- const isWatcher = computed(function () {
201
- return ! props.hideAfterInMobile || ! $q.platform.is.mobile
202
- })
203
-
204
- /**
205
- * 当前传参
206
- */
207
- const currentQuery = computed(function() {
208
-
209
- // 如果有已选数据
210
- if (
211
- currentSelectedItem.value
212
- && $n_isFunction(props.renderQuery)
213
- ) {
214
- const resQuery = props.renderQuery(currentSelectedItem.value)
215
- if ($n_isValidObject(resQuery)) {
216
-
217
- // 如果需要加载渲染页面标识参数
218
- if (! props.noRendPageName) {
219
- // 格式化已选数据, 并返回参数
220
- return Object.assign({}, resQuery, {
221
- // 是否为渲染页面
222
- n_renderpage: 1,
223
- })
224
- }
225
-
226
- return resQuery
227
- }
228
- }
229
-
230
- return null
231
- })
232
-
233
- // ==========【数据】=============================================================================================
234
-
235
- // quasar 对象
236
- const $q = useQuasar()
237
-
238
- // 获取表格注入
239
- const $table = inject(NTableKey)
240
-
241
- // 原始表格选择状态
242
- const rawTableSelection = $table.tableSelection.value
243
-
244
- // 当前已选单条数据
245
- const currentSelectedItem = ref(null)
246
-
247
- // 当前值
248
- const currentValue = ref(props.modelValue)
249
-
250
- // 当前显示前置插槽
251
- const currentAfter = ref(props.after)
252
-
253
- // ==========【监听数据】=========================================================================================
254
-
255
- /**
256
- * 监听声明值
257
- */
258
- watch(() => props.modelValue, function (val) {
259
- currentValue.value = val
260
- })
261
-
262
- /**
263
- * 监听声明显示前置插槽
264
- */
265
- watch(() => props.after, function (val) {
266
- currentAfter.value = val
267
- })
268
-
269
- /**
270
- * 监听当前值
271
- */
272
- watch(currentValue, function (val) {
273
- emit('update:modelValue', val)
274
- })
275
-
276
- /**
277
- * 监听当前显示前置插槽
278
- */
279
- watch(currentAfter, function (val) {
280
- emit('update:after', val)
281
- })
282
-
283
- /**
284
- * 监听表格已选数据(非手机端有效)
285
- */
286
- watch($table.tableSelected, async function (selected) {
287
-
288
- // 先清空当前已选单条数据
289
- currentSelectedItem.value = null
290
-
291
- // 如果不监听
292
- if (! isWatcher.value) {
293
-
294
- // 则无需任何操作
295
- return
296
- }
297
-
298
- // 下次 DOM 更新
299
- await nextTick()
300
-
301
- // 如果有已选单条数据
302
- if (selected.length === 1) {
303
-
304
- // 设置当前已选数据
305
- currentSelectedItem.value = selected[0]
306
- }
307
-
308
- }, {
309
- // 深度监听
310
- deep: true,
311
- })
312
-
313
- // ==========【方法】============================================================================================
314
-
315
- /**
316
- * 设置表格选择类型
317
- */
318
- function setSelection(showAfter) {
319
-
320
- // 如果不监听
321
- if (! isWatcher.value) {
322
-
323
- // 则无需任何操作
324
- return
325
- }
326
-
327
- const selection = showAfter ? 'single' : rawTableSelection
328
- if ($table.tableSelection.value !== selection) {
329
- $table.tableSelection.value = selection
330
-
331
- // 如果显示后置插槽
332
- if (showAfter && $table.tableSelected.value.length > 1) {
333
-
334
- // 如果有多条已选数据, 则只取第一条数据
335
- $table.tableSelected.value = [ $table.tableSelected.value[$table.tableSelected.value.length - 1] ]
336
- }
337
- }
338
- }
339
-
340
- // ==========【返回】=========================================================================================
341
-
342
- return {
343
- // 插槽标识
344
- slotNames,
345
- // 是否监听
346
- isWatcher,
347
- // 当前传参
348
- currentQuery,
349
-
350
- // 当前值
351
- currentValue,
352
- // 当前显示前置插槽
353
- currentAfter,
354
-
355
- // 设置表格选择类型
356
- setSelection,
357
- }
358
- }
359
- }
360
- </script>
1
+ <template>
2
+ <n-splitter
3
+ class="absolute-full"
4
+ v-model="currentValue"
5
+ :reverse="reverse"
6
+ :unit="unit"
7
+ :limits="limits"
8
+ :horizontal="horizontal"
9
+
10
+ v-model:after="currentAfter"
11
+ @update:after="setSelection"
12
+ :hide-after-in-mobile="hideAfterInMobile"
13
+ :cache="cache"
14
+ >
15
+ <!-- 表格 -->
16
+ <template v-slot:before="{ after, toggleAfter }">
17
+ <n-table
18
+ v-bind="$attrs"
19
+ >
20
+ <!-- 工具栏右边插槽(手机端不显示) -->
21
+ <template #toolbar-right v-if="isWatcher">
22
+
23
+ <!-- 工具栏右边插槽 -->
24
+ <slot name="toolbar-right" />
25
+
26
+ <!-- 是否显示详情 -->
27
+ <q-toggle
28
+ icon="apps"
29
+ :model-value="after"
30
+ @click="toggleAfter"
31
+ >
32
+ <q-tooltip anchor="center left" self="center right" :offset="[10, 0]">{{tooltip}}</q-tooltip>
33
+ </q-toggle>
34
+
35
+ </template>
36
+
37
+ <!-- 插槽 -->
38
+ <template
39
+ v-for="slotName in slotNames"
40
+ v-slot:[slotName]="props"
41
+ >
42
+ <!-- 有传参的插槽 -->
43
+ <slot
44
+ :name="slotName"
45
+ v-bind="props"
46
+ v-if="props"
47
+ />
48
+
49
+ <!-- 无传参的插槽 -->
50
+ <slot
51
+ :name="slotName"
52
+ v-else
53
+ />
54
+ </template>
55
+
56
+ </n-table>
57
+ </template>
58
+
59
+ <!-- 渲染详情页面(手机端不显示) -->
60
+ <template v-slot:after>
61
+
62
+ <slot name="after">
63
+
64
+ <!-- 渲染 -->
65
+ <n-render
66
+ :name="renderName"
67
+ :path="renderPath"
68
+ :component="renderComponent"
69
+ :query="currentQuery"
70
+ :props="renderProps"
71
+ v-if="currentQuery"
72
+ />
73
+
74
+ <!-- 空状态 -->
75
+ <n-empty
76
+ :description="renderDescription"
77
+ fit
78
+ v-else
79
+ />
80
+
81
+ </slot>
82
+
83
+ </template>
84
+
85
+ </n-splitter>
86
+ </template>
87
+
88
+ <script>
89
+ import { nextTick, ref, watch, computed, inject } from 'vue'
90
+ import { useQuasar } from 'quasar'
91
+
92
+ import $n_isFunction from 'lodash/isFunction'
93
+
94
+ import $n_isValidObject from '@netang/utils/isValidObject'
95
+
96
+ import NSplitter from '../splitter'
97
+ import NTable from '../table'
98
+ import NRender from '../render'
99
+ import NEmpty from '../empty'
100
+
101
+ import { NTableKey } from '../../utils/symbols'
102
+
103
+ export default {
104
+
105
+ /**
106
+ * 关闭组件 attribute 透传行为
107
+ */
108
+ inheritAttrs: false,
109
+
110
+ /**
111
+ * 标识
112
+ */
113
+ name: 'NTableSplitter',
114
+
115
+ /**
116
+ * 组件
117
+ */
118
+ components: {
119
+ NSplitter,
120
+ NTable,
121
+ NRender,
122
+ NEmpty,
123
+ },
124
+
125
+ /**
126
+ * 声明属性
127
+ */
128
+ props: {
129
+ // v-model
130
+ modelValue: {
131
+ type: Number,
132
+ default: 50,
133
+ },
134
+ // 反转插槽
135
+ reverse: Boolean,
136
+ // 模型的 CSS 单位
137
+ unit: String,
138
+ // 两个值的数组,表示两个面板的最小和最大分割大小
139
+ limits: Array,
140
+ // 是否水平拆分
141
+ horizontal: Boolean,
142
+
143
+ // 显示后置插槽 v-model:after
144
+ // 注意: 如果非双向绑定, 如 :after 并不会影响内部值变化, 仅做初始值使用
145
+ after: {
146
+ type: Boolean,
147
+ default: true,
148
+ },
149
+ // 手机模式隐藏后插槽
150
+ hideAfterInMobile: {
151
+ type: Boolean,
152
+ default: true,
153
+ },
154
+ // 是否开启缓存
155
+ cache: {
156
+ type: [ Boolean, String ],
157
+ default: true,
158
+ },
159
+
160
+ // 工具提示
161
+ tooltip: {
162
+ type: String,
163
+ default: '是否显示详情',
164
+ },
165
+ // 渲染组件标识
166
+ renderName: String,
167
+ // 渲染组件路径
168
+ renderPath: String,
169
+ // 渲染组件的组件
170
+ renderComponent: Object,
171
+ // 格式化已选表格的数据并返回渲染组件参数
172
+ renderQuery: Function,
173
+ // 渲染组件的传参
174
+ renderProps: Object,
175
+ // 渲染空状态描述
176
+ renderDescription: {
177
+ type: String,
178
+ default: '没有找到任何数据',
179
+ },
180
+ // 不需要加载渲染页面标识参数
181
+ // 额外加载参数 { n_render_page: 1 }
182
+ noRendPageName: Boolean,
183
+ },
184
+
185
+ /**
186
+ * 声明事件
187
+ */
188
+ emits: [
189
+ 'update:modelValue',
190
+ 'update:after',
191
+ ],
192
+
193
+ /**
194
+ * 组合式
195
+ */
196
+ setup(props, { emit, slots }) {
197
+
198
+ // ==========【计算属性】=========================================================================================
199
+
200
+ /**
201
+ * 插槽标识
202
+ */
203
+ const slotNames = computed(function() {
204
+ return $n_isValidObject(slots) ? Object.keys(slots).filter(e => e !== 'toolbar-right') : []
205
+ })
206
+
207
+ /**
208
+ * 是否监听
209
+ */
210
+ const isWatcher = computed(function () {
211
+ return ! props.hideAfterInMobile || ! $q.platform.is.mobile
212
+ })
213
+
214
+ /**
215
+ * 当前传参
216
+ */
217
+ const currentQuery = computed(function() {
218
+
219
+ // 如果有已选数据
220
+ if (
221
+ currentSelectedItem.value
222
+ && $n_isFunction(props.renderQuery)
223
+ ) {
224
+ const resQuery = props.renderQuery(currentSelectedItem.value)
225
+ if ($n_isValidObject(resQuery)) {
226
+
227
+ // 如果需要加载渲染页面标识参数
228
+ if (! props.noRendPageName) {
229
+ // 格式化已选数据, 并返回参数
230
+ return Object.assign({}, resQuery, {
231
+ // 是否为渲染页面
232
+ n_render_page: 1,
233
+ })
234
+ }
235
+
236
+ return resQuery
237
+ }
238
+ }
239
+
240
+ return null
241
+ })
242
+
243
+ // ==========【数据】=============================================================================================
244
+
245
+ // quasar 对象
246
+ const $q = useQuasar()
247
+
248
+ // 获取表格注入
249
+ const $table = inject(NTableKey)
250
+
251
+ // 原始表格选择状态
252
+ const rawTableSelection = $table.tableSelection.value
253
+
254
+ // 当前已选单条数据
255
+ const currentSelectedItem = ref(null)
256
+
257
+ // 当前值
258
+ const currentValue = ref(props.modelValue)
259
+
260
+ // 当前显示前置插槽
261
+ const currentAfter = ref(props.after)
262
+
263
+ // ==========【监听数据】=========================================================================================
264
+
265
+ /**
266
+ * 监听声明值
267
+ */
268
+ watch(() => props.modelValue, function (val) {
269
+ currentValue.value = val
270
+ })
271
+
272
+ /**
273
+ * 监听声明显示前置插槽
274
+ */
275
+ watch(() => props.after, function (val) {
276
+ currentAfter.value = val
277
+ })
278
+
279
+ /**
280
+ * 监听当前值
281
+ */
282
+ watch(currentValue, function (val) {
283
+ emit('update:modelValue', val)
284
+ })
285
+
286
+ /**
287
+ * 监听当前显示前置插槽
288
+ */
289
+ watch(currentAfter, function (val) {
290
+ emit('update:after', val)
291
+ })
292
+
293
+ /**
294
+ * 监听表格已选数据(非手机端有效)
295
+ */
296
+ watch($table.tableSelected, async function (selected) {
297
+
298
+ // 先清空当前已选单条数据
299
+ currentSelectedItem.value = null
300
+
301
+ // 如果不监听
302
+ if (! isWatcher.value) {
303
+
304
+ // 则无需任何操作
305
+ return
306
+ }
307
+
308
+ // 下次 DOM 更新
309
+ await nextTick()
310
+
311
+ // 如果有已选单条数据
312
+ if (selected.length === 1) {
313
+
314
+ // 设置当前已选数据
315
+ currentSelectedItem.value = selected[0]
316
+ }
317
+
318
+ }, {
319
+ // 深度监听
320
+ deep: true,
321
+ })
322
+
323
+ // ==========【方法】============================================================================================
324
+
325
+ /**
326
+ * 设置表格选择类型
327
+ */
328
+ function setSelection(showAfter) {
329
+
330
+ // 如果不监听
331
+ if (! isWatcher.value) {
332
+
333
+ // 则无需任何操作
334
+ return
335
+ }
336
+
337
+ const selection = showAfter ? 'single' : rawTableSelection
338
+ if ($table.tableSelection.value !== selection) {
339
+ $table.tableSelection.value = selection
340
+
341
+ // 如果显示后置插槽
342
+ if (showAfter && $table.tableSelected.value.length > 1) {
343
+
344
+ // 如果有多条已选数据, 则只取第一条数据
345
+ $table.tableSelected.value = [ $table.tableSelected.value[$table.tableSelected.value.length - 1] ]
346
+ }
347
+ }
348
+ }
349
+
350
+ // ==========【返回】=========================================================================================
351
+
352
+ return {
353
+ // 插槽标识
354
+ slotNames,
355
+ // 是否监听
356
+ isWatcher,
357
+ // 当前传参
358
+ currentQuery,
359
+
360
+ // 当前值
361
+ currentValue,
362
+ // 当前显示前置插槽
363
+ currentAfter,
364
+
365
+ // 设置表格选择类型
366
+ setSelection,
367
+ }
368
+ }
369
+ }
370
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"