@netang/quasar 0.1.50 → 0.1.52
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.
|
@@ -64,18 +64,18 @@
|
|
|
64
64
|
@click="handleActions('zoomIn')"
|
|
65
65
|
/>
|
|
66
66
|
|
|
67
|
-
<!--
|
|
67
|
+
<!-- 切换比例 -->
|
|
68
68
|
<q-icon
|
|
69
69
|
class="cursor-pointer"
|
|
70
|
-
:name="
|
|
71
|
-
@click="
|
|
70
|
+
:name="isContain ? fullscreenIcon : exitFullscreenIcon"
|
|
71
|
+
@click="toggleMode"
|
|
72
72
|
/>
|
|
73
73
|
|
|
74
|
-
<!--
|
|
74
|
+
<!-- 水平反转 -->
|
|
75
75
|
<q-icon
|
|
76
76
|
class="cursor-pointer"
|
|
77
|
-
:name="
|
|
78
|
-
@click="
|
|
77
|
+
:name="flipHorizontalIcon"
|
|
78
|
+
@click="handleActions('flipX')"
|
|
79
79
|
/>
|
|
80
80
|
|
|
81
81
|
<!-- 垂直反转 -->
|
|
@@ -98,20 +98,21 @@
|
|
|
98
98
|
:name="rotateRightIcon"
|
|
99
99
|
@click="handleActions('clockwise')"
|
|
100
100
|
/>
|
|
101
|
+
|
|
101
102
|
</div>
|
|
102
103
|
</div>
|
|
103
104
|
|
|
104
105
|
<!-- 图片列表 -->
|
|
105
106
|
<a
|
|
106
|
-
v-for="(
|
|
107
|
-
:key="`${
|
|
108
|
-
:href="
|
|
107
|
+
v-for="(src, i) in currentImages"
|
|
108
|
+
:key="`${src}-${i}`"
|
|
109
|
+
:href="src"
|
|
109
110
|
target="_blank"
|
|
110
111
|
class="non-selectable no-outline"
|
|
111
112
|
>
|
|
112
113
|
<img
|
|
113
114
|
:ref="(el) => (imgRefs[i] = el)"
|
|
114
|
-
:src="
|
|
115
|
+
:src="src"
|
|
115
116
|
:style="imgStyle"
|
|
116
117
|
@load="handleImgLoad"
|
|
117
118
|
@error="handleImgError"
|
|
@@ -281,10 +282,11 @@ export default {
|
|
|
281
282
|
$n_forEach(props.images, function (url) {
|
|
282
283
|
const origin = $n_getImage(url, { compress: false })
|
|
283
284
|
if (origin) {
|
|
284
|
-
lists.push({
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
lists.push($n_getImage(url, { w: 1000 }))
|
|
286
|
+
// lists.push({
|
|
287
|
+
// src: $n_getImage(url, { w: 1000 }),
|
|
288
|
+
// origin,
|
|
289
|
+
// })
|
|
288
290
|
}
|
|
289
291
|
})
|
|
290
292
|
|
|
@@ -44,12 +44,10 @@
|
|
|
44
44
|
dense
|
|
45
45
|
outlined
|
|
46
46
|
clearable
|
|
47
|
-
|
|
48
47
|
/>
|
|
49
48
|
</div>
|
|
50
49
|
|
|
51
50
|
<!-- 分类树 -->
|
|
52
|
-
<!--selected-color="primary"-->
|
|
53
51
|
<n-tree
|
|
54
52
|
color="grey-5"
|
|
55
53
|
ref="treeRef"
|
|
@@ -61,7 +59,18 @@
|
|
|
61
59
|
no-selection-unset
|
|
62
60
|
default-expand-all
|
|
63
61
|
v-bind="treeProps"
|
|
64
|
-
|
|
62
|
+
>
|
|
63
|
+
<!-- 插槽 -->
|
|
64
|
+
<template
|
|
65
|
+
v-for="slotName in slotNames.search"
|
|
66
|
+
v-slot:[slotName]="props"
|
|
67
|
+
>
|
|
68
|
+
<slot
|
|
69
|
+
:name="`tree-${slotName}`"
|
|
70
|
+
v-bind="props"
|
|
71
|
+
/>
|
|
72
|
+
</template>
|
|
73
|
+
</n-tree>
|
|
65
74
|
|
|
66
75
|
</q-scroll-area>
|
|
67
76
|
</n-drawer>
|
|
@@ -352,6 +361,8 @@ export default {
|
|
|
352
361
|
for (const key in slots) {
|
|
353
362
|
if (key.startsWith('toolbar-')) {
|
|
354
363
|
toolbar.push(key.replace('toolbar-', ''))
|
|
364
|
+
} else if (key.startsWith('tree-')) {
|
|
365
|
+
search.push(key.replace('tree-', ''))
|
|
355
366
|
} else if (key.startsWith('search-')) {
|
|
356
367
|
search.push(key.replace('search-', ''))
|
|
357
368
|
} else if (key === 'left-drawer') {
|
|
@@ -1,415 +1,422 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<!-- 拆分器 -->
|
|
3
|
-
<q-splitter
|
|
4
|
-
class="n-splitter"
|
|
5
|
-
:class="currentClass"
|
|
6
|
-
v-model="currentValue"
|
|
7
|
-
v-bind="$attrs"
|
|
8
|
-
>
|
|
9
|
-
<!-- 插槽 -->
|
|
10
|
-
<template
|
|
11
|
-
v-for="slotName in slotNames"
|
|
12
|
-
v-slot:[slotName]
|
|
13
|
-
>
|
|
14
|
-
<slot
|
|
15
|
-
:name="slotName"
|
|
16
|
-
:before="currentBefore"
|
|
17
|
-
:after="currentAfter"
|
|
18
|
-
:toggleBefore="toggleBefore"
|
|
19
|
-
:toggleAfter="toggleAfter"
|
|
20
|
-
/>
|
|
21
|
-
</template>
|
|
22
|
-
</q-splitter>
|
|
23
|
-
</template>
|
|
24
|
-
|
|
25
|
-
<script>
|
|
26
|
-
import { computed, ref, watch, inject } from 'vue'
|
|
27
|
-
import { useQuasar } from 'quasar'
|
|
28
|
-
|
|
29
|
-
import $n_router from '@netang/utils/vue/router'
|
|
30
|
-
|
|
31
|
-
import $n_storage from '@netang/utils/storage'
|
|
32
|
-
import $n_sleep from '@netang/utils/sleep'
|
|
33
|
-
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
34
|
-
|
|
35
|
-
import { NPowerKey } from '../../utils/symbols'
|
|
36
|
-
|
|
37
|
-
export default {
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 标识
|
|
41
|
-
*/
|
|
42
|
-
name: 'NSplitter',
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 声明属性
|
|
46
|
-
*/
|
|
47
|
-
props: {
|
|
48
|
-
// 值 v-model
|
|
49
|
-
modelValue: {
|
|
50
|
-
type: Number,
|
|
51
|
-
required: true,
|
|
52
|
-
},
|
|
53
|
-
// 显示前置插槽 v-model:before
|
|
54
|
-
// 注意: 如果非双向绑定, 如 :before 并不会影响内部值变化, 仅做初始值使用
|
|
55
|
-
before: {
|
|
56
|
-
type: Boolean,
|
|
57
|
-
default: true,
|
|
58
|
-
},
|
|
59
|
-
// 显示后置插槽 v-model:after
|
|
60
|
-
// 注意: 如果非双向绑定, 如 :after 并不会影响内部值变化, 仅做初始值使用
|
|
61
|
-
after: {
|
|
62
|
-
type: Boolean,
|
|
63
|
-
default: true,
|
|
64
|
-
},
|
|
65
|
-
// 手机模式隐藏前置插槽
|
|
66
|
-
hideBeforeInMobile: Boolean,
|
|
67
|
-
// 手机模式隐藏后插槽
|
|
68
|
-
hideAfterInMobile: Boolean,
|
|
69
|
-
// 是否开启缓存
|
|
70
|
-
cache: [ Boolean, String ],
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 声明事件
|
|
75
|
-
*/
|
|
76
|
-
emits: [
|
|
77
|
-
'update:modelValue',
|
|
78
|
-
'update:before',
|
|
79
|
-
'update:after',
|
|
80
|
-
],
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 组合式
|
|
84
|
-
*/
|
|
85
|
-
setup(props, { emit, slots }) {
|
|
86
|
-
|
|
87
|
-
// ==========【数据】============================================================================================
|
|
88
|
-
|
|
89
|
-
// quasar 对象
|
|
90
|
-
const $q = useQuasar()
|
|
91
|
-
|
|
92
|
-
// 获取权限注入
|
|
93
|
-
const $power = inject(NPowerKey)
|
|
94
|
-
|
|
95
|
-
// 缓存名
|
|
96
|
-
let cacheName = ''
|
|
97
|
-
|
|
98
|
-
// 初始值
|
|
99
|
-
let rawValue = props.modelValue
|
|
100
|
-
|
|
101
|
-
// 初始显示前置插槽
|
|
102
|
-
let rawBefore = props.before
|
|
103
|
-
let initEmitBefore = true
|
|
104
|
-
|
|
105
|
-
// 初始显示后置插槽
|
|
106
|
-
let rawAfter = props.after
|
|
107
|
-
let initEmitAfter = true
|
|
108
|
-
|
|
109
|
-
// 如果开启缓存
|
|
110
|
-
if (props.cache) {
|
|
111
|
-
|
|
112
|
-
// 设置缓存名
|
|
113
|
-
cacheName = `splitter:${props.cache === true ? ($power && $power.routePath ? $power.routePath : $n_router.getRoute('path')) : props.cache}:`
|
|
114
|
-
|
|
115
|
-
// 从缓存获取初始值
|
|
116
|
-
let cache = $n_storage.get(cacheName + 'modelValue')
|
|
117
|
-
if (cache !== null) {
|
|
118
|
-
rawValue = cache
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 如果手机模式隐藏前置插槽
|
|
122
|
-
if (props.hideBeforeInMobile && $q.platform.is.mobile) {
|
|
123
|
-
rawBefore = false
|
|
124
|
-
initEmitBefore = false
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
// 从缓存获取初始值
|
|
128
|
-
cache = $n_storage.get(cacheName + 'before')
|
|
129
|
-
if (cache !== null) {
|
|
130
|
-
rawBefore = cache
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 如果手机模式隐藏后置插槽
|
|
135
|
-
if (props.hideAfterInMobile && $q.platform.is.mobile) {
|
|
136
|
-
rawAfter = false
|
|
137
|
-
initEmitAfter = false
|
|
138
|
-
|
|
139
|
-
} else {
|
|
140
|
-
// 从缓存获取初始值
|
|
141
|
-
cache = $n_storage.get(cacheName + 'after')
|
|
142
|
-
if (cache !== null) {
|
|
143
|
-
rawAfter = cache
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// 如果在手机模式
|
|
148
|
-
} else if ($q.platform.is.mobile) {
|
|
149
|
-
|
|
150
|
-
// 手机模式隐藏前置插槽
|
|
151
|
-
if (props.hideBeforeInMobile) {
|
|
152
|
-
rawBefore = false
|
|
153
|
-
initEmitBefore = false
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// 手机模式隐藏后置插槽
|
|
157
|
-
if (props.hideAfterInMobile) {
|
|
158
|
-
rawAfter = false
|
|
159
|
-
initEmitAfter = false
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// 创建睡眠实例
|
|
164
|
-
const sleep = $n_sleep()
|
|
165
|
-
|
|
166
|
-
// 当前值
|
|
167
|
-
const currentValue = ref(rawValue)
|
|
168
|
-
if (rawValue !== props.modelValue) {
|
|
169
|
-
emit('update:modelValue', rawValue)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// 当前是否显示前置插槽
|
|
173
|
-
const currentBefore = ref(rawBefore)
|
|
174
|
-
if (initEmitBefore) {
|
|
175
|
-
emit('update:before', rawBefore)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// 当前是否显示后置插槽
|
|
179
|
-
const currentAfter = ref(rawAfter)
|
|
180
|
-
if (initEmitAfter) {
|
|
181
|
-
emit('update:after', rawAfter)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ==========【计算属性】=========================================================================================
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 插槽标识
|
|
188
|
-
*/
|
|
189
|
-
const slotNames = computed(function() {
|
|
190
|
-
|
|
191
|
-
const keys = []
|
|
192
|
-
|
|
193
|
-
if ($n_isValidObject(slots)) {
|
|
194
|
-
|
|
195
|
-
for (const key in slots) {
|
|
196
|
-
if (key === 'before') {
|
|
197
|
-
if (currentBefore.value) {
|
|
198
|
-
keys.push(key)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
} else if (key === 'after') {
|
|
202
|
-
if (currentAfter.value) {
|
|
203
|
-
keys.push(key)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
} else {
|
|
207
|
-
keys.push(key)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return keys
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* 当前样式
|
|
217
|
-
*/
|
|
218
|
-
const currentClass = computed(function () {
|
|
219
|
-
|
|
220
|
-
if (currentBefore.value) {
|
|
221
|
-
if (! currentAfter.value) {
|
|
222
|
-
return 'n-splitter--hide-before'
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
} else if (currentAfter.value) {
|
|
226
|
-
if (! currentBefore.value) {
|
|
227
|
-
return 'n-splitter--hide-after'
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
} else {
|
|
231
|
-
return 'n-splitter--hide'
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
// ==========【方法】============================================================================================
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* 触发更新值
|
|
239
|
-
*/
|
|
240
|
-
async function emitValue(key, val) {
|
|
241
|
-
|
|
242
|
-
// 更新值
|
|
243
|
-
emit(`update:${key}`, val)
|
|
244
|
-
|
|
245
|
-
// 如果开启缓存
|
|
246
|
-
if (props.cache) {
|
|
247
|
-
|
|
248
|
-
// 延迟执行
|
|
249
|
-
await sleep(500, key)
|
|
250
|
-
|
|
251
|
-
// 设置缓存(永久缓存)
|
|
252
|
-
$n_storage.set(cacheName + key, val, 0)
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* 切换显示前置插槽
|
|
258
|
-
*/
|
|
259
|
-
function toggleBefore() {
|
|
260
|
-
currentBefore.value = ! currentBefore.value
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* 切换显示后置插槽
|
|
265
|
-
*/
|
|
266
|
-
function toggleAfter() {
|
|
267
|
-
currentAfter.value = ! currentAfter.value
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// ==========【监听数据】=========================================================================================
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* 监听声明值
|
|
274
|
-
*/
|
|
275
|
-
watch(() => props.modelValue, function (val) {
|
|
276
|
-
|
|
277
|
-
// 如果值有变化
|
|
278
|
-
if (val !== currentValue.value) {
|
|
279
|
-
|
|
280
|
-
// 更新当前值
|
|
281
|
-
currentValue.value = val
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* 监听声明是否显示前置插槽
|
|
287
|
-
*/
|
|
288
|
-
watch(() => props.before, function (val) {
|
|
289
|
-
|
|
290
|
-
// 如果值有变化
|
|
291
|
-
if (val !== currentBefore.value) {
|
|
292
|
-
|
|
293
|
-
// 设置是否显示前置插槽
|
|
294
|
-
currentBefore.value = val
|
|
295
|
-
}
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* 监听声明是否显示后置插槽
|
|
300
|
-
*/
|
|
301
|
-
watch(() => props.after, function (val) {
|
|
302
|
-
|
|
303
|
-
// 如果值有变化
|
|
304
|
-
if (val !== currentAfter.value) {
|
|
305
|
-
|
|
306
|
-
// 设置是否显示后置插槽
|
|
307
|
-
currentAfter.value = val
|
|
308
|
-
}
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* 监听值
|
|
313
|
-
*/
|
|
314
|
-
watch(currentValue, async function (val) {
|
|
315
|
-
// 触发更新值
|
|
316
|
-
await emitValue('modelValue', val)
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* 监听是否显示前置插槽
|
|
321
|
-
*/
|
|
322
|
-
watch(currentBefore, async function (val) {
|
|
323
|
-
|
|
324
|
-
// 触发更新值
|
|
325
|
-
await emitValue('before', val)
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* 监听是否显示后置插槽
|
|
330
|
-
*/
|
|
331
|
-
watch(currentAfter, async function (val) {
|
|
332
|
-
|
|
333
|
-
// 触发更新值
|
|
334
|
-
await emitValue('after', val)
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
// ==========【返回】=============================================================================================
|
|
338
|
-
|
|
339
|
-
return {
|
|
340
|
-
// 插槽标识
|
|
341
|
-
slotNames,
|
|
342
|
-
// 当前值
|
|
343
|
-
currentValue,
|
|
344
|
-
// 当前是否显示前置插槽
|
|
345
|
-
currentBefore,
|
|
346
|
-
// 当前是否显示后置插槽
|
|
347
|
-
currentAfter,
|
|
348
|
-
// 当前样式
|
|
349
|
-
currentClass,
|
|
350
|
-
|
|
351
|
-
// 切换显示前置插槽
|
|
352
|
-
toggleBefore,
|
|
353
|
-
// 切换显示后置插槽
|
|
354
|
-
toggleAfter,
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
</script>
|
|
359
|
-
|
|
360
|
-
<style lang="scss">
|
|
361
|
-
.n-splitter {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
.q-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<!-- 拆分器 -->
|
|
3
|
+
<q-splitter
|
|
4
|
+
class="n-splitter"
|
|
5
|
+
:class="currentClass"
|
|
6
|
+
v-model="currentValue"
|
|
7
|
+
v-bind="$attrs"
|
|
8
|
+
>
|
|
9
|
+
<!-- 插槽 -->
|
|
10
|
+
<template
|
|
11
|
+
v-for="slotName in slotNames"
|
|
12
|
+
v-slot:[slotName]
|
|
13
|
+
>
|
|
14
|
+
<slot
|
|
15
|
+
:name="slotName"
|
|
16
|
+
:before="currentBefore"
|
|
17
|
+
:after="currentAfter"
|
|
18
|
+
:toggleBefore="toggleBefore"
|
|
19
|
+
:toggleAfter="toggleAfter"
|
|
20
|
+
/>
|
|
21
|
+
</template>
|
|
22
|
+
</q-splitter>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script>
|
|
26
|
+
import { computed, ref, watch, inject } from 'vue'
|
|
27
|
+
import { useQuasar } from 'quasar'
|
|
28
|
+
|
|
29
|
+
import $n_router from '@netang/utils/vue/router'
|
|
30
|
+
|
|
31
|
+
import $n_storage from '@netang/utils/storage'
|
|
32
|
+
import $n_sleep from '@netang/utils/sleep'
|
|
33
|
+
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
34
|
+
|
|
35
|
+
import { NPowerKey } from '../../utils/symbols'
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 标识
|
|
41
|
+
*/
|
|
42
|
+
name: 'NSplitter',
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 声明属性
|
|
46
|
+
*/
|
|
47
|
+
props: {
|
|
48
|
+
// 值 v-model
|
|
49
|
+
modelValue: {
|
|
50
|
+
type: Number,
|
|
51
|
+
required: true,
|
|
52
|
+
},
|
|
53
|
+
// 显示前置插槽 v-model:before
|
|
54
|
+
// 注意: 如果非双向绑定, 如 :before 并不会影响内部值变化, 仅做初始值使用
|
|
55
|
+
before: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: true,
|
|
58
|
+
},
|
|
59
|
+
// 显示后置插槽 v-model:after
|
|
60
|
+
// 注意: 如果非双向绑定, 如 :after 并不会影响内部值变化, 仅做初始值使用
|
|
61
|
+
after: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: true,
|
|
64
|
+
},
|
|
65
|
+
// 手机模式隐藏前置插槽
|
|
66
|
+
hideBeforeInMobile: Boolean,
|
|
67
|
+
// 手机模式隐藏后插槽
|
|
68
|
+
hideAfterInMobile: Boolean,
|
|
69
|
+
// 是否开启缓存
|
|
70
|
+
cache: [ Boolean, String ],
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 声明事件
|
|
75
|
+
*/
|
|
76
|
+
emits: [
|
|
77
|
+
'update:modelValue',
|
|
78
|
+
'update:before',
|
|
79
|
+
'update:after',
|
|
80
|
+
],
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 组合式
|
|
84
|
+
*/
|
|
85
|
+
setup(props, { emit, slots }) {
|
|
86
|
+
|
|
87
|
+
// ==========【数据】============================================================================================
|
|
88
|
+
|
|
89
|
+
// quasar 对象
|
|
90
|
+
const $q = useQuasar()
|
|
91
|
+
|
|
92
|
+
// 获取权限注入
|
|
93
|
+
const $power = inject(NPowerKey)
|
|
94
|
+
|
|
95
|
+
// 缓存名
|
|
96
|
+
let cacheName = ''
|
|
97
|
+
|
|
98
|
+
// 初始值
|
|
99
|
+
let rawValue = props.modelValue
|
|
100
|
+
|
|
101
|
+
// 初始显示前置插槽
|
|
102
|
+
let rawBefore = props.before
|
|
103
|
+
let initEmitBefore = true
|
|
104
|
+
|
|
105
|
+
// 初始显示后置插槽
|
|
106
|
+
let rawAfter = props.after
|
|
107
|
+
let initEmitAfter = true
|
|
108
|
+
|
|
109
|
+
// 如果开启缓存
|
|
110
|
+
if (props.cache) {
|
|
111
|
+
|
|
112
|
+
// 设置缓存名
|
|
113
|
+
cacheName = `splitter:${props.cache === true ? ($power && $power.routePath ? $power.routePath : $n_router.getRoute('path')) : props.cache}:`
|
|
114
|
+
|
|
115
|
+
// 从缓存获取初始值
|
|
116
|
+
let cache = $n_storage.get(cacheName + 'modelValue')
|
|
117
|
+
if (cache !== null) {
|
|
118
|
+
rawValue = cache
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 如果手机模式隐藏前置插槽
|
|
122
|
+
if (props.hideBeforeInMobile && $q.platform.is.mobile) {
|
|
123
|
+
rawBefore = false
|
|
124
|
+
initEmitBefore = false
|
|
125
|
+
|
|
126
|
+
} else {
|
|
127
|
+
// 从缓存获取初始值
|
|
128
|
+
cache = $n_storage.get(cacheName + 'before')
|
|
129
|
+
if (cache !== null) {
|
|
130
|
+
rawBefore = cache
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 如果手机模式隐藏后置插槽
|
|
135
|
+
if (props.hideAfterInMobile && $q.platform.is.mobile) {
|
|
136
|
+
rawAfter = false
|
|
137
|
+
initEmitAfter = false
|
|
138
|
+
|
|
139
|
+
} else {
|
|
140
|
+
// 从缓存获取初始值
|
|
141
|
+
cache = $n_storage.get(cacheName + 'after')
|
|
142
|
+
if (cache !== null) {
|
|
143
|
+
rawAfter = cache
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 如果在手机模式
|
|
148
|
+
} else if ($q.platform.is.mobile) {
|
|
149
|
+
|
|
150
|
+
// 手机模式隐藏前置插槽
|
|
151
|
+
if (props.hideBeforeInMobile) {
|
|
152
|
+
rawBefore = false
|
|
153
|
+
initEmitBefore = false
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 手机模式隐藏后置插槽
|
|
157
|
+
if (props.hideAfterInMobile) {
|
|
158
|
+
rawAfter = false
|
|
159
|
+
initEmitAfter = false
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 创建睡眠实例
|
|
164
|
+
const sleep = $n_sleep()
|
|
165
|
+
|
|
166
|
+
// 当前值
|
|
167
|
+
const currentValue = ref(rawValue)
|
|
168
|
+
if (rawValue !== props.modelValue) {
|
|
169
|
+
emit('update:modelValue', rawValue)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 当前是否显示前置插槽
|
|
173
|
+
const currentBefore = ref(rawBefore)
|
|
174
|
+
if (initEmitBefore) {
|
|
175
|
+
emit('update:before', rawBefore)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 当前是否显示后置插槽
|
|
179
|
+
const currentAfter = ref(rawAfter)
|
|
180
|
+
if (initEmitAfter) {
|
|
181
|
+
emit('update:after', rawAfter)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ==========【计算属性】=========================================================================================
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 插槽标识
|
|
188
|
+
*/
|
|
189
|
+
const slotNames = computed(function() {
|
|
190
|
+
|
|
191
|
+
const keys = []
|
|
192
|
+
|
|
193
|
+
if ($n_isValidObject(slots)) {
|
|
194
|
+
|
|
195
|
+
for (const key in slots) {
|
|
196
|
+
if (key === 'before') {
|
|
197
|
+
if (currentBefore.value) {
|
|
198
|
+
keys.push(key)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
} else if (key === 'after') {
|
|
202
|
+
if (currentAfter.value) {
|
|
203
|
+
keys.push(key)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
} else {
|
|
207
|
+
keys.push(key)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return keys
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 当前样式
|
|
217
|
+
*/
|
|
218
|
+
const currentClass = computed(function () {
|
|
219
|
+
|
|
220
|
+
if (currentBefore.value) {
|
|
221
|
+
if (! currentAfter.value) {
|
|
222
|
+
return 'n-splitter--hide-before'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
} else if (currentAfter.value) {
|
|
226
|
+
if (! currentBefore.value) {
|
|
227
|
+
return 'n-splitter--hide-after'
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
} else {
|
|
231
|
+
return 'n-splitter--hide'
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
// ==========【方法】============================================================================================
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 触发更新值
|
|
239
|
+
*/
|
|
240
|
+
async function emitValue(key, val) {
|
|
241
|
+
|
|
242
|
+
// 更新值
|
|
243
|
+
emit(`update:${key}`, val)
|
|
244
|
+
|
|
245
|
+
// 如果开启缓存
|
|
246
|
+
if (props.cache) {
|
|
247
|
+
|
|
248
|
+
// 延迟执行
|
|
249
|
+
await sleep(500, key)
|
|
250
|
+
|
|
251
|
+
// 设置缓存(永久缓存)
|
|
252
|
+
$n_storage.set(cacheName + key, val, 0)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 切换显示前置插槽
|
|
258
|
+
*/
|
|
259
|
+
function toggleBefore() {
|
|
260
|
+
currentBefore.value = ! currentBefore.value
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 切换显示后置插槽
|
|
265
|
+
*/
|
|
266
|
+
function toggleAfter() {
|
|
267
|
+
currentAfter.value = ! currentAfter.value
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ==========【监听数据】=========================================================================================
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 监听声明值
|
|
274
|
+
*/
|
|
275
|
+
watch(() => props.modelValue, function (val) {
|
|
276
|
+
|
|
277
|
+
// 如果值有变化
|
|
278
|
+
if (val !== currentValue.value) {
|
|
279
|
+
|
|
280
|
+
// 更新当前值
|
|
281
|
+
currentValue.value = val
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 监听声明是否显示前置插槽
|
|
287
|
+
*/
|
|
288
|
+
watch(() => props.before, function (val) {
|
|
289
|
+
|
|
290
|
+
// 如果值有变化
|
|
291
|
+
if (val !== currentBefore.value) {
|
|
292
|
+
|
|
293
|
+
// 设置是否显示前置插槽
|
|
294
|
+
currentBefore.value = val
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 监听声明是否显示后置插槽
|
|
300
|
+
*/
|
|
301
|
+
watch(() => props.after, function (val) {
|
|
302
|
+
|
|
303
|
+
// 如果值有变化
|
|
304
|
+
if (val !== currentAfter.value) {
|
|
305
|
+
|
|
306
|
+
// 设置是否显示后置插槽
|
|
307
|
+
currentAfter.value = val
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 监听值
|
|
313
|
+
*/
|
|
314
|
+
watch(currentValue, async function (val) {
|
|
315
|
+
// 触发更新值
|
|
316
|
+
await emitValue('modelValue', val)
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 监听是否显示前置插槽
|
|
321
|
+
*/
|
|
322
|
+
watch(currentBefore, async function (val) {
|
|
323
|
+
|
|
324
|
+
// 触发更新值
|
|
325
|
+
await emitValue('before', val)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 监听是否显示后置插槽
|
|
330
|
+
*/
|
|
331
|
+
watch(currentAfter, async function (val) {
|
|
332
|
+
|
|
333
|
+
// 触发更新值
|
|
334
|
+
await emitValue('after', val)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
// ==========【返回】=============================================================================================
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
// 插槽标识
|
|
341
|
+
slotNames,
|
|
342
|
+
// 当前值
|
|
343
|
+
currentValue,
|
|
344
|
+
// 当前是否显示前置插槽
|
|
345
|
+
currentBefore,
|
|
346
|
+
// 当前是否显示后置插槽
|
|
347
|
+
currentAfter,
|
|
348
|
+
// 当前样式
|
|
349
|
+
currentClass,
|
|
350
|
+
|
|
351
|
+
// 切换显示前置插槽
|
|
352
|
+
toggleBefore,
|
|
353
|
+
// 切换显示后置插槽
|
|
354
|
+
toggleAfter,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
</script>
|
|
359
|
+
|
|
360
|
+
<style lang="scss">
|
|
361
|
+
.n-splitter {
|
|
362
|
+
|
|
363
|
+
&--narrow {
|
|
364
|
+
&.q-splitter--vertical > .q-splitter__separator > div {
|
|
365
|
+
left: -2px;
|
|
366
|
+
right: -2px;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 分离器激活背景色
|
|
371
|
+
&.q-splitter--active .q-splitter__separator ,
|
|
372
|
+
.q-splitter__separator:hover {
|
|
373
|
+
background-color: var(--q-primary);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 隐藏前置插槽
|
|
377
|
+
&--hide-before {
|
|
378
|
+
&.q-splitter--horizontal {
|
|
379
|
+
.q-splitter__before {
|
|
380
|
+
height: 100% !important;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
&.q-splitter--vertical {
|
|
384
|
+
.q-splitter__before {
|
|
385
|
+
width: 100% !important;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
.q-splitter__after,
|
|
389
|
+
.q-splitter__separator {
|
|
390
|
+
display: none !important;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// 隐藏后置插槽
|
|
395
|
+
&--hide-after {
|
|
396
|
+
&.q-splitter--horizontal {
|
|
397
|
+
.q-splitter__after {
|
|
398
|
+
height: 100% !important;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
&.q-splitter--vertical {
|
|
402
|
+
.q-splitter__after {
|
|
403
|
+
width: 100% !important;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
.q-splitter__before,
|
|
407
|
+
.q-splitter__separator {
|
|
408
|
+
display: none !important;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 隐藏前后置插槽
|
|
413
|
+
&--hide {
|
|
414
|
+
.q-splitter__before,
|
|
415
|
+
.q-splitter__after,
|
|
416
|
+
.q-splitter__separator {
|
|
417
|
+
display: none !important;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
</style>
|
|
422
|
+
|