@netang/quasar 0.0.20
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/LICENSE +21 -0
- package/README.md +17 -0
- package/components/column-title/index.vue +32 -0
- package/components/dialog/components/index.js +6 -0
- package/components/dialog/components/move-to-tree/index.vue +150 -0
- package/components/dialog/index.vue +330 -0
- package/components/dialog-table/index.vue +92 -0
- package/components/dragger/index.vue +202 -0
- package/components/drawer/index.vue +262 -0
- package/components/field-date/index.vue +844 -0
- package/components/field-date/methods.js +100 -0
- package/components/field-table/index.vue +468 -0
- package/components/field-text/index.vue +167 -0
- package/components/field-tree/index.vue +435 -0
- package/components/input-number/index.vue +324 -0
- package/components/input-number/number.js +67 -0
- package/components/input-price-cent/index.vue +213 -0
- package/components/input-price-yuan/index.vue +179 -0
- package/components/layout/index.vue +119 -0
- package/components/list-menu/index.vue +137 -0
- package/components/list-menu-item/index.vue +79 -0
- package/components/power-data/index.vue +667 -0
- package/components/search/index.vue +176 -0
- package/components/search-item/index.vue +219 -0
- package/components/select/index.vue +71 -0
- package/components/select-filter/index.vue +75 -0
- package/components/table/index.vue +347 -0
- package/components/table-column-fixed/index.vue +68 -0
- package/components/table-pagination/index.vue +83 -0
- package/components/table-summary/index.vue +91 -0
- package/components/thumbnail/index.vue +87 -0
- package/components/toolbar/container.vue +31 -0
- package/components/toolbar/index.vue +405 -0
- package/components/uploader/index.vue +157 -0
- package/components/uploader-query/index.vue +731 -0
- package/package.json +21 -0
- package/sass/common.scss +165 -0
- package/sass/index.scss +14 -0
- package/sass/line.scss +39 -0
- package/sass/quasar/btn.scss +46 -0
- package/sass/quasar/common.scss +3 -0
- package/sass/quasar/dialog.scss +7 -0
- package/sass/quasar/drawer.scss +6 -0
- package/sass/quasar/field.scss +210 -0
- package/sass/quasar/loading.scss +6 -0
- package/sass/quasar/menu.scss +8 -0
- package/sass/quasar/table.scss +112 -0
- package/sass/quasar/toolbar.scss +22 -0
- package/store/index.js +32 -0
- package/utils/$area.js +387 -0
- package/utils/$auth.js +135 -0
- package/utils/$dialog.js +43 -0
- package/utils/$role.js +807 -0
- package/utils/$rule.js +17 -0
- package/utils/$search.js +336 -0
- package/utils/$table.js +802 -0
- package/utils/$tree.js +620 -0
- package/utils/$uploader.js +1029 -0
- package/utils/alert.js +10 -0
- package/utils/bus.js +6 -0
- package/utils/config.js +22 -0
- package/utils/confrim.js +11 -0
- package/utils/dict.js +44 -0
- package/utils/getData.js +61 -0
- package/utils/getFile.js +30 -0
- package/utils/getImage.js +136 -0
- package/utils/getTime.js +94 -0
- package/utils/http.js +251 -0
- package/utils/loading.js +13 -0
- package/utils/notify.js +13 -0
- package/utils/previewImage.js +8 -0
- package/utils/symbols.js +3 -0
- package/utils/timestamp.js +18 -0
- package/utils/toast.js +13 -0
- package/utils/uploader/aliyun.js +6 -0
- package/utils/uploader/local.js +8 -0
- package/utils/uploader/qiniu.js +311 -0
- package/utils/useAuth.js +26 -0
- package/utils/useRouter.js +36 -0
- package/utils/useUploader.js +58 -0
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<q-field
|
|
3
|
+
:class="fieldFocused ? 'q-field--float q-field--focused q-field--highlighted' : ''"
|
|
4
|
+
:model-value="modelValue"
|
|
5
|
+
:readonly="readonly"
|
|
6
|
+
@clear="onClear"
|
|
7
|
+
v-bind="$attrs"
|
|
8
|
+
>
|
|
9
|
+
<template v-slot:control>
|
|
10
|
+
|
|
11
|
+
<!-- 显示值 -->
|
|
12
|
+
<div v-if="showValue">{{showValue}}</div>
|
|
13
|
+
|
|
14
|
+
<!-- 显示占位符 -->
|
|
15
|
+
<div class="n-placeholder" v-else-if="placeholder">{{placeholder}}</div>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<template v-slot:before v-if="$slots.before">
|
|
19
|
+
<slot name="before" />
|
|
20
|
+
</template>
|
|
21
|
+
<template v-slot:prepend v-if="$slots.prepend">
|
|
22
|
+
<slot name="prepend" />
|
|
23
|
+
</template>
|
|
24
|
+
<template v-slot:append v-if="$slots.append">
|
|
25
|
+
<slot name="append" />
|
|
26
|
+
</template>
|
|
27
|
+
<template v-slot:after v-if="$slots.after">
|
|
28
|
+
<slot name="after" />
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<q-popup-proxy
|
|
32
|
+
ref="popupRef"
|
|
33
|
+
@before-show="onPopupBeforeShow"
|
|
34
|
+
@before-hide="onPopupBeforeHide"
|
|
35
|
+
@hide="onPopupHide"
|
|
36
|
+
v-if="! readonly"
|
|
37
|
+
>
|
|
38
|
+
<!-- 单选 -->
|
|
39
|
+
<template v-if="isSelect">
|
|
40
|
+
<div class="date__select">
|
|
41
|
+
<div class="row flex">
|
|
42
|
+
<q-scroll-area
|
|
43
|
+
ref="scrollRef"
|
|
44
|
+
:style="{
|
|
45
|
+
width: selectLists.length === 1 ? '136px' : '80px',
|
|
46
|
+
height: '300px',
|
|
47
|
+
}"
|
|
48
|
+
v-for="(selectItem, selectItemIndex) in selectLists"
|
|
49
|
+
:key="`list-${selectItemIndex}`"
|
|
50
|
+
>
|
|
51
|
+
<q-list>
|
|
52
|
+
<q-item
|
|
53
|
+
v-for="(item, itemIndex) in selectItem.lists"
|
|
54
|
+
:key="`item-${selectItemIndex}-${itemIndex}`"
|
|
55
|
+
:active="dateValue[selectItem.type] !== '' && dateValue[selectItem.type] == item[0]"
|
|
56
|
+
:active-class="$q.dark.isActive ? 'bg-grey-14 text-white' : 'bg-grey-3 text-dark'"
|
|
57
|
+
@click="onSelect(selectItem.type, item[0])"
|
|
58
|
+
dense
|
|
59
|
+
clickable
|
|
60
|
+
>
|
|
61
|
+
<q-item-section>{{item[1]}}</q-item-section>
|
|
62
|
+
</q-item>
|
|
63
|
+
</q-list>
|
|
64
|
+
</q-scroll-area>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<!-- 底部按钮 -->
|
|
68
|
+
<div class="date__footer row items-center justify-end q-pa-sm" v-if="type !== 'year'">
|
|
69
|
+
<q-btn label="取消" color="primary" flat @click="onCancel" v-close-popup />
|
|
70
|
+
<q-btn label="确定" color="primary" flat v-close-popup />
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
74
|
+
|
|
75
|
+
<!-- 选择日期范围 -->
|
|
76
|
+
<q-date
|
|
77
|
+
:model-value="dateValue"
|
|
78
|
+
:range="isRange"
|
|
79
|
+
@update:model-value="onUpdateDateValue"
|
|
80
|
+
minimal
|
|
81
|
+
v-else
|
|
82
|
+
>
|
|
83
|
+
<div class="date__time row q-gutter-sm" v-if="isDatetime">
|
|
84
|
+
<q-input
|
|
85
|
+
class="n-field-fieldset n-flex-1"
|
|
86
|
+
:model-value="timeValue.from"
|
|
87
|
+
@update:model-value="onUpdateTimeValueFrom"
|
|
88
|
+
outlined
|
|
89
|
+
:label="type === 'datetimerange' ? `时间 起` : '选择时间'"
|
|
90
|
+
stack-label
|
|
91
|
+
type="time"
|
|
92
|
+
:step="showSecond ? '1' : '0'"
|
|
93
|
+
dense
|
|
94
|
+
/>
|
|
95
|
+
<q-input
|
|
96
|
+
class="n-field-fieldset n-flex-1"
|
|
97
|
+
:model-value="timeValue.to"
|
|
98
|
+
@update:model-value="onUpdateTimeValueTo"
|
|
99
|
+
outlined
|
|
100
|
+
label="时间 止"
|
|
101
|
+
stack-label
|
|
102
|
+
:step="showSecond ? '1' : '0'"
|
|
103
|
+
type="time"
|
|
104
|
+
dense
|
|
105
|
+
v-if="type === 'datetimerange'"
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<!-- 操作 -->
|
|
110
|
+
<div class="date__settings" v-if="isRange">
|
|
111
|
+
<q-scroll-area style="height:40px;">
|
|
112
|
+
<div class="row no-wrap">
|
|
113
|
+
<q-chip
|
|
114
|
+
v-for="(item, index) in quickRange"
|
|
115
|
+
:key="`quick-${index}`"
|
|
116
|
+
size="sm"
|
|
117
|
+
:ripple="false"
|
|
118
|
+
clickable
|
|
119
|
+
@click="onQuickRange(index)"
|
|
120
|
+
flat
|
|
121
|
+
>{{item}}</q-chip>
|
|
122
|
+
</div>
|
|
123
|
+
</q-scroll-area>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<!-- 底部按钮 -->
|
|
127
|
+
<div class="date__settings row items-center justify-end" v-if="isDatetime || type === 'daterange'">
|
|
128
|
+
<q-btn label="取消" color="primary" flat @click="onCancel" v-close-popup />
|
|
129
|
+
<q-btn label="确定" color="primary" flat v-close-popup />
|
|
130
|
+
</div>
|
|
131
|
+
</q-date>
|
|
132
|
+
|
|
133
|
+
</q-popup-proxy>
|
|
134
|
+
</q-field>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
137
|
+
<script>
|
|
138
|
+
import { ref, reactive, computed, watch, nextTick } from 'vue'
|
|
139
|
+
import { date as quasarDate } from 'quasar'
|
|
140
|
+
|
|
141
|
+
import { quickRange, getQuickRange } from './methods'
|
|
142
|
+
|
|
143
|
+
export default {
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 标识
|
|
147
|
+
*/
|
|
148
|
+
name: 'NFieldDate',
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 声明属性
|
|
152
|
+
*/
|
|
153
|
+
props: {
|
|
154
|
+
// 值
|
|
155
|
+
modelValue: [String, Number],
|
|
156
|
+
// 结束值
|
|
157
|
+
end: [String, Number],
|
|
158
|
+
// 占位符
|
|
159
|
+
placeholder: String,
|
|
160
|
+
// 类型, 可选值 year month day time datetime daterange datetimerange
|
|
161
|
+
type: {
|
|
162
|
+
type: String,
|
|
163
|
+
default: 'day',
|
|
164
|
+
},
|
|
165
|
+
// 是否截止时间
|
|
166
|
+
endDate: Boolean,
|
|
167
|
+
// 显示在输入框中的格式
|
|
168
|
+
format: String,
|
|
169
|
+
// 绑定值的格式(默认:秒时间戳)
|
|
170
|
+
// 格式 YYYY-MM-DD HH:mm:ss
|
|
171
|
+
valueFormat: {
|
|
172
|
+
type: String,
|
|
173
|
+
default: 'X',
|
|
174
|
+
},
|
|
175
|
+
// 是否只读
|
|
176
|
+
readonly: Boolean,
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 声明事件
|
|
181
|
+
*/
|
|
182
|
+
emits: [
|
|
183
|
+
'update:modelValue',
|
|
184
|
+
'update:end',
|
|
185
|
+
],
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 组合式
|
|
189
|
+
*/
|
|
190
|
+
setup(props, { emit }) {
|
|
191
|
+
|
|
192
|
+
// ==========【计算属性】=========================================================================================
|
|
193
|
+
|
|
194
|
+
// 是否为选择
|
|
195
|
+
const isSelect = computed(function() {
|
|
196
|
+
return utils.indexOf(['year', 'month', 'time'], props.type) > -1
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
// 是否为范围
|
|
200
|
+
const isRange = computed(function() {
|
|
201
|
+
return utils.indexOf(['daterange', 'datetimerange'], props.type) > -1
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// 是否为选择时间
|
|
205
|
+
const isDatetime = computed(function() {
|
|
206
|
+
return utils.indexOf(['datetime', 'datetimerange'], props.type) > -1
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// 选择数据列表
|
|
210
|
+
const selectLists = computed(function () {
|
|
211
|
+
|
|
212
|
+
const arr = []
|
|
213
|
+
|
|
214
|
+
// 如果是选择时间
|
|
215
|
+
if (props.type === 'time') {
|
|
216
|
+
const hh = {
|
|
217
|
+
type: 'hh',
|
|
218
|
+
lists: []
|
|
219
|
+
}
|
|
220
|
+
for (let i = 0; i <= 23; i++) {
|
|
221
|
+
hh.lists.push([i, _.padStart(String(i), 2, '0')])
|
|
222
|
+
}
|
|
223
|
+
const ii = {
|
|
224
|
+
type: 'ii',
|
|
225
|
+
lists: []
|
|
226
|
+
}
|
|
227
|
+
for (let i = 0; i <= 59; i++) {
|
|
228
|
+
ii.lists.push([i, _.padStart(String(i), 2, '0')])
|
|
229
|
+
}
|
|
230
|
+
arr.push(hh, ii)
|
|
231
|
+
if (props.showSecond) {
|
|
232
|
+
const ss = {
|
|
233
|
+
type: 'ss',
|
|
234
|
+
lists: []
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i <= 59; i++) {
|
|
237
|
+
ss.lists.push([i, _.padStart(String(i), 2, '0')])
|
|
238
|
+
}
|
|
239
|
+
arr.push(ss)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return arr
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 如果是选择年
|
|
246
|
+
const year = new Date().getFullYear()
|
|
247
|
+
|
|
248
|
+
const y = {
|
|
249
|
+
type: 'y',
|
|
250
|
+
lists: []
|
|
251
|
+
}
|
|
252
|
+
for (let j = year + 10; j >= year - 80; j--) {
|
|
253
|
+
y.lists.push([j, j])
|
|
254
|
+
}
|
|
255
|
+
arr.push(y)
|
|
256
|
+
|
|
257
|
+
if (props.type === 'year') {
|
|
258
|
+
return arr
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const mm = {
|
|
262
|
+
type: 'mm',
|
|
263
|
+
lists: []
|
|
264
|
+
}
|
|
265
|
+
for (let i = 1; i <= 12; i++) {
|
|
266
|
+
mm.lists.push([i, _.padStart(String(i), 2, '0')])
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
arr.push(mm)
|
|
270
|
+
|
|
271
|
+
return arr
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
// ==========【数据】============================================================================================
|
|
275
|
+
|
|
276
|
+
// 字段组件获取焦点
|
|
277
|
+
const fieldFocused = ref(false)
|
|
278
|
+
|
|
279
|
+
// 弹出层节点
|
|
280
|
+
const popupRef = ref(null)
|
|
281
|
+
|
|
282
|
+
// 滚动层节点
|
|
283
|
+
const scrollRef = ref(null)
|
|
284
|
+
|
|
285
|
+
// 日期值
|
|
286
|
+
const dateValue = ref(formatDateValue())
|
|
287
|
+
|
|
288
|
+
// 时间值
|
|
289
|
+
const timeValue = reactive(formatTimeValue())
|
|
290
|
+
|
|
291
|
+
// 显示值
|
|
292
|
+
const showValue = ref(updateValue(dateValue.value, timeValue, false))
|
|
293
|
+
|
|
294
|
+
// 记录原始值
|
|
295
|
+
let oldModelValue = props.modelValue
|
|
296
|
+
let oldEnd = props.end
|
|
297
|
+
|
|
298
|
+
// ==========【监听数据】=========================================================================================
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 监听声明值
|
|
302
|
+
*/
|
|
303
|
+
watch([()=>props.modelValue, ()=>props.end, ()=>props.type], function() {
|
|
304
|
+
dateValue.value = formatDateValue()
|
|
305
|
+
Object.assign(timeValue, formatTimeValue())
|
|
306
|
+
showValue.value = updateValue(dateValue.value, timeValue, false)
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
// ==========【方法】=============================================================================================
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 格式化日期值
|
|
313
|
+
*/
|
|
314
|
+
function formatDateValue() {
|
|
315
|
+
|
|
316
|
+
let val = props.modelValue
|
|
317
|
+
if (val === null) {
|
|
318
|
+
return null
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// 如果是选择数据
|
|
322
|
+
if (isSelect.value) {
|
|
323
|
+
|
|
324
|
+
const obj = {}
|
|
325
|
+
|
|
326
|
+
// 如果是选择时间
|
|
327
|
+
if (props.type === 'time') {
|
|
328
|
+
|
|
329
|
+
// 初始化时间数据
|
|
330
|
+
Object.assign(obj, {
|
|
331
|
+
hh: '',
|
|
332
|
+
ii: '',
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
if (utils.isDate(val)) {
|
|
336
|
+
|
|
337
|
+
const { hh, ii, ss } = utils.dateObject(val)
|
|
338
|
+
|
|
339
|
+
// 设置时间数据
|
|
340
|
+
Object.assign(obj, {
|
|
341
|
+
hh,
|
|
342
|
+
ii,
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
// 设置秒数据
|
|
346
|
+
if (props.showSecond) {
|
|
347
|
+
obj.ss = ss
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
} else if (props.showSecond) {
|
|
351
|
+
obj.ss = ''
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// 否则是选择年月
|
|
355
|
+
} else {
|
|
356
|
+
|
|
357
|
+
obj.y = ''
|
|
358
|
+
|
|
359
|
+
// 如果是选择年
|
|
360
|
+
if (props.type === 'year') {
|
|
361
|
+
|
|
362
|
+
// 如果有值
|
|
363
|
+
if (val) {
|
|
364
|
+
|
|
365
|
+
// 如果值长度为 4
|
|
366
|
+
if (String(val).length === 4) {
|
|
367
|
+
obj.y = val
|
|
368
|
+
|
|
369
|
+
// 否则如果是日期格式
|
|
370
|
+
} else if (utils.isDate(val)) {
|
|
371
|
+
const { y } = utils.dateObject(val)
|
|
372
|
+
obj.y = y
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return obj
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// 否则是选择月
|
|
380
|
+
|
|
381
|
+
// 如果是这样的格式 202207, 则转换为 2022-07
|
|
382
|
+
const newVal = utils.ymd.toString(val)
|
|
383
|
+
if (newVal) {
|
|
384
|
+
val = newVal
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (utils.isDate(val)) {
|
|
388
|
+
const { y, mm } = utils.dateObject(val)
|
|
389
|
+
Object.assign(obj, {
|
|
390
|
+
y,
|
|
391
|
+
mm,
|
|
392
|
+
})
|
|
393
|
+
} else {
|
|
394
|
+
obj.mm = ''
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return obj
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// 否则是日期选择
|
|
402
|
+
let from = ''
|
|
403
|
+
let to = ''
|
|
404
|
+
|
|
405
|
+
// 如果是这样的格式 20220708, 则转换为 2022-07-08
|
|
406
|
+
const newVal = utils.ymd.toString(val)
|
|
407
|
+
if (newVal) {
|
|
408
|
+
val = newVal
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (utils.isDate(val)) {
|
|
412
|
+
const { y, mm, dd } = utils.dateObject(val)
|
|
413
|
+
from = `${y}/${mm}/${dd}`
|
|
414
|
+
|
|
415
|
+
// 如果不是日期选择范围, 则返回单个日期
|
|
416
|
+
if (! isRange.value) {
|
|
417
|
+
return from
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// 如果是日期选择范围
|
|
422
|
+
if (isRange.value && utils.isDate(props.end)) {
|
|
423
|
+
const { y, mm, dd } = utils.dateObject(props.end)
|
|
424
|
+
to = `${y}/${mm}/${dd}`
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
from,
|
|
429
|
+
to,
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 格式化时间值
|
|
435
|
+
*/
|
|
436
|
+
function formatTimeValue() {
|
|
437
|
+
|
|
438
|
+
const obj = {
|
|
439
|
+
from: '',
|
|
440
|
+
to: '',
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (utils.isDate(props.modelValue)) {
|
|
444
|
+
const { hh, ii, ss } = utils.dateObject(props.modelValue)
|
|
445
|
+
obj.from = `${hh}:${ii}`
|
|
446
|
+
if (props.showSecond) {
|
|
447
|
+
obj.from += `:${ss}`
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// 如果不是范围日期 && 是结束日期
|
|
451
|
+
} else if (! isRange.value && props.endDate) {
|
|
452
|
+
obj.from = props.showSecond ? '23:59:59' : '23:59'
|
|
453
|
+
} else {
|
|
454
|
+
obj.from = props.showSecond ? '00:00:00' : '00:00'
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (isRange.value && utils.isDate(props.end)) {
|
|
458
|
+
const { hh, ii, ss } = utils.dateObject(props.end)
|
|
459
|
+
obj.to = `${hh}:${ii}`
|
|
460
|
+
if (props.showSecond) {
|
|
461
|
+
obj.to += `:${ss}`
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
obj.to = props.showSecond ? '23:59:59' : '23:59'
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return obj
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 更新值
|
|
472
|
+
*/
|
|
473
|
+
function updateValue(dateValue, timeValue, isEmit = true) {
|
|
474
|
+
|
|
475
|
+
let format = ''
|
|
476
|
+
|
|
477
|
+
if (isSelect.value) {
|
|
478
|
+
|
|
479
|
+
let val = ''
|
|
480
|
+
|
|
481
|
+
// 如果是选择时间
|
|
482
|
+
if (props.type === 'time') {
|
|
483
|
+
if (
|
|
484
|
+
! utils.isValidValue(dateValue.hh)
|
|
485
|
+
|| ! utils.isValidValue(dateValue.ii)
|
|
486
|
+
|| (props.showSecond && ! utils.isValidValue(dateValue.ss))) {
|
|
487
|
+
return ''
|
|
488
|
+
}
|
|
489
|
+
format = 'HH:mm'
|
|
490
|
+
if (props.showSecond) {
|
|
491
|
+
format += ':ss'
|
|
492
|
+
}
|
|
493
|
+
val = quasarDate.formatDate(Date.now(), `YYYY-MM-DD ${dateValue.hh}:${dateValue.ii}${props.showSecond ? dateValue.ss : (props.endDate ? ':59' : ':00')}`)
|
|
494
|
+
|
|
495
|
+
// 否则是选择年月
|
|
496
|
+
} else {
|
|
497
|
+
if (! utils.isValidValue(dateValue.y)) {
|
|
498
|
+
return ''
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const isMonth = props.type === 'month'
|
|
502
|
+
if (isMonth) {
|
|
503
|
+
if (! utils.isValidValue(dateValue.mm)) {
|
|
504
|
+
return ''
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
format = 'YYYY-MM'
|
|
508
|
+
val = quasarDate[props.endDate ? 'endOfDate' : 'startOfDate'](new Date(`${dateValue.y}-${dateValue.mm}`), 'month')
|
|
509
|
+
|
|
510
|
+
} else {
|
|
511
|
+
format = 'YYYY'
|
|
512
|
+
val = quasarDate[props.endDate ? 'endOfDate' : 'startOfDate'](new Date(`${dateValue.y}-01`), 'year')
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (props.format) {
|
|
517
|
+
format = props.format
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (isEmit) {
|
|
521
|
+
onEmit('update:modelValue', quasarDate.formatDate(val, props.valueFormat))
|
|
522
|
+
} else {
|
|
523
|
+
return quasarDate.formatDate(val, format)
|
|
524
|
+
}
|
|
525
|
+
return ''
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (! utils.isRequired(dateValue)) {
|
|
529
|
+
return ''
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (isRange.value) {
|
|
533
|
+
|
|
534
|
+
let {
|
|
535
|
+
from,
|
|
536
|
+
to,
|
|
537
|
+
} = dateValue
|
|
538
|
+
|
|
539
|
+
if (
|
|
540
|
+
! utils.isValidValue(from)
|
|
541
|
+
|| ! utils.isValidValue(to)
|
|
542
|
+
) {
|
|
543
|
+
return ''
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
from += ' '
|
|
547
|
+
to += ' '
|
|
548
|
+
format = 'YYYY-MM-DD'
|
|
549
|
+
|
|
550
|
+
if (props.type === 'datetimerange') {
|
|
551
|
+
from += `${timeValue.from}`
|
|
552
|
+
to += `${timeValue.to}`
|
|
553
|
+
format += ' HH:mm'
|
|
554
|
+
if (props.showSecond) {
|
|
555
|
+
format += ':ss'
|
|
556
|
+
} else {
|
|
557
|
+
from += ':59'
|
|
558
|
+
to += ':59'
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
} else {
|
|
562
|
+
from += `00:00`
|
|
563
|
+
to += `23:59`
|
|
564
|
+
if (! props.showSecond) {
|
|
565
|
+
from += ':00'
|
|
566
|
+
to += ':59'
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (props.format) {
|
|
570
|
+
format = props.format
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (isEmit) {
|
|
574
|
+
onEmit('update:modelValue', quasarDate.formatDate(from, props.valueFormat))
|
|
575
|
+
onEmit('update:end', quasarDate.formatDate(to, props.valueFormat))
|
|
576
|
+
} else {
|
|
577
|
+
return quasarDate.formatDate(from, format) + ' - ' + quasarDate.formatDate(to, format)
|
|
578
|
+
}
|
|
579
|
+
return ''
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
let from = `${dateValue} `
|
|
583
|
+
format = 'YYYY-MM-DD'
|
|
584
|
+
|
|
585
|
+
if (props.type === 'datetime') {
|
|
586
|
+
from += `${timeValue.from}`
|
|
587
|
+
format += ' HH:mm'
|
|
588
|
+
if (props.showSecond) {
|
|
589
|
+
format += ':ss'
|
|
590
|
+
} else {
|
|
591
|
+
from += (props.endDate ? ':59' : ':00')
|
|
592
|
+
}
|
|
593
|
+
} else {
|
|
594
|
+
from += (props.endDate ? '23:59' : '00:00')
|
|
595
|
+
if (! props.showSecond) {
|
|
596
|
+
from += (props.endDate ? ':59' : ':00')
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (props.format) {
|
|
600
|
+
format = props.format
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (isEmit) {
|
|
604
|
+
onEmit('update:modelValue', quasarDate.formatDate(from, props.valueFormat))
|
|
605
|
+
} else {
|
|
606
|
+
return quasarDate.formatDate(from, format)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return ''
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* 更新日期后回调
|
|
614
|
+
*/
|
|
615
|
+
function onUpdateDateValue(val) {
|
|
616
|
+
|
|
617
|
+
// 如果为 null, 则清空数据
|
|
618
|
+
if (_.isNil(val)) {
|
|
619
|
+
emit('update:modelValue', null)
|
|
620
|
+
if (isRange.value) {
|
|
621
|
+
emit('update:end', null)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
} else {
|
|
625
|
+
updateValue(val, timeValue)
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// 如是类型是天
|
|
629
|
+
if (props.type === 'day') {
|
|
630
|
+
// 则关闭弹出层
|
|
631
|
+
popupRef.value.hide()
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* 更新日期时间起回调
|
|
637
|
+
*/
|
|
638
|
+
function onUpdateTimeValueFrom(from) {
|
|
639
|
+
updateValue(dateValue.value, Object.assign({}, timeValue, {
|
|
640
|
+
from,
|
|
641
|
+
}))
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* 更新日期时间止回调
|
|
646
|
+
*/
|
|
647
|
+
function onUpdateTimeValueTo(to) {
|
|
648
|
+
updateValue(dateValue.value, Object.assign({}, timeValue, {
|
|
649
|
+
to,
|
|
650
|
+
}))
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* 选择
|
|
655
|
+
*/
|
|
656
|
+
function onSelect(type, value) {
|
|
657
|
+
|
|
658
|
+
// 更新值
|
|
659
|
+
const newValue = {}
|
|
660
|
+
newValue[type] = value
|
|
661
|
+
updateValue(Object.assign({}, dateValue.value, newValue), timeValue)
|
|
662
|
+
|
|
663
|
+
// 如是类型是年
|
|
664
|
+
if (props.type === 'year') {
|
|
665
|
+
// 则关闭弹出层
|
|
666
|
+
popupRef.value.hide()
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* 快捷范围
|
|
672
|
+
*/
|
|
673
|
+
function onQuickRange(index) {
|
|
674
|
+
|
|
675
|
+
const {
|
|
676
|
+
date,
|
|
677
|
+
time,
|
|
678
|
+
} = getQuickRange(index, props.showSecond)
|
|
679
|
+
|
|
680
|
+
if (date) {
|
|
681
|
+
updateValue(date, time)
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* 取消
|
|
687
|
+
*/
|
|
688
|
+
function onCancel() {
|
|
689
|
+
// 还原原始值
|
|
690
|
+
onEmit('update:modelValue', oldModelValue)
|
|
691
|
+
if (isRange.value) {
|
|
692
|
+
onEmit('update:end', oldEnd)
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* 提交
|
|
698
|
+
*/
|
|
699
|
+
function onEmit(key, value) {
|
|
700
|
+
emit(key, utils.numberDeep(value))
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* 弹出层显示前回调
|
|
705
|
+
*/
|
|
706
|
+
function onPopupBeforeShow() {
|
|
707
|
+
|
|
708
|
+
// 字段组件获取焦点
|
|
709
|
+
fieldFocused.value = true
|
|
710
|
+
|
|
711
|
+
// 如果为选择
|
|
712
|
+
if (isSelect.value) {
|
|
713
|
+
// 下次 DOM 更新
|
|
714
|
+
nextTick(function() {
|
|
715
|
+
|
|
716
|
+
// 遍历选择列表
|
|
717
|
+
utils.forEach(selectLists.value, function(selectItem, selectItemIndex) {
|
|
718
|
+
// 遍历选单个列表
|
|
719
|
+
utils.forEach(selectItem.lists, function(item, itemIndex) {
|
|
720
|
+
if (dateValue.value[selectItem.type] !== '' && dateValue.value[selectItem.type] == item[0]) {
|
|
721
|
+
scrollRef.value[selectItemIndex].setScrollPosition('vertical', 32 * itemIndex, 0)
|
|
722
|
+
return true
|
|
723
|
+
}
|
|
724
|
+
})
|
|
725
|
+
})
|
|
726
|
+
|
|
727
|
+
})
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* 弹出层隐藏前回调
|
|
733
|
+
*/
|
|
734
|
+
function onPopupBeforeHide() {
|
|
735
|
+
|
|
736
|
+
// 字段组件失去焦点
|
|
737
|
+
fieldFocused.value = false
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* 弹出层隐藏后回调
|
|
742
|
+
*/
|
|
743
|
+
function onPopupHide() {
|
|
744
|
+
|
|
745
|
+
// 更新原始值
|
|
746
|
+
oldModelValue = props.modelValue
|
|
747
|
+
if (isRange.value) {
|
|
748
|
+
oldEnd = props.end
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* 清空
|
|
754
|
+
*/
|
|
755
|
+
function onClear() {
|
|
756
|
+
emit('update:modelValue', null)
|
|
757
|
+
if (isRange.value) {
|
|
758
|
+
emit('update:end', null)
|
|
759
|
+
}
|
|
760
|
+
popupRef.value.hide()
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// ==========【返回】=============================================================================================
|
|
764
|
+
|
|
765
|
+
return {
|
|
766
|
+
// 是否为选择
|
|
767
|
+
isSelect,
|
|
768
|
+
// 是否为范围
|
|
769
|
+
isRange,
|
|
770
|
+
// 是否为选择时间
|
|
771
|
+
isDatetime,
|
|
772
|
+
// 选择数据列表
|
|
773
|
+
selectLists,
|
|
774
|
+
|
|
775
|
+
// 字段组件获取焦点
|
|
776
|
+
fieldFocused,
|
|
777
|
+
// 弹出层节点
|
|
778
|
+
popupRef,
|
|
779
|
+
// 滚动层节点
|
|
780
|
+
scrollRef,
|
|
781
|
+
// 日期值
|
|
782
|
+
dateValue,
|
|
783
|
+
// 时间值
|
|
784
|
+
timeValue,
|
|
785
|
+
// 显示值
|
|
786
|
+
showValue,
|
|
787
|
+
// 快捷范围
|
|
788
|
+
quickRange,
|
|
789
|
+
|
|
790
|
+
// 更新日期后回调
|
|
791
|
+
onUpdateDateValue,
|
|
792
|
+
// 更新日期时间起回调
|
|
793
|
+
onUpdateTimeValueFrom,
|
|
794
|
+
// 更新日期时间止回调
|
|
795
|
+
onUpdateTimeValueTo,
|
|
796
|
+
|
|
797
|
+
// 选择
|
|
798
|
+
onSelect,
|
|
799
|
+
// 快捷范围
|
|
800
|
+
onQuickRange,
|
|
801
|
+
// 取消
|
|
802
|
+
onCancel,
|
|
803
|
+
|
|
804
|
+
// 弹出层显示前回调
|
|
805
|
+
onPopupBeforeShow,
|
|
806
|
+
// 弹出层隐藏前回调
|
|
807
|
+
onPopupBeforeHide,
|
|
808
|
+
// 弹出层隐藏后回调
|
|
809
|
+
onPopupHide,
|
|
810
|
+
// 清空
|
|
811
|
+
onClear,
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
}
|
|
815
|
+
</script>
|
|
816
|
+
|
|
817
|
+
<style lang="scss" scoped>
|
|
818
|
+
@import "@/assets/sass/var.scss";
|
|
819
|
+
|
|
820
|
+
.date {
|
|
821
|
+
|
|
822
|
+
// 选择容器
|
|
823
|
+
&__select {
|
|
824
|
+
background-color: #ffffff;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// 时间容器
|
|
828
|
+
&__time {
|
|
829
|
+
+ .date__settings {
|
|
830
|
+
// 等同 q-pt-sm
|
|
831
|
+
padding-top: map-get($space-sm, 'y');
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* 暗色
|
|
838
|
+
*/
|
|
839
|
+
.body--dark {
|
|
840
|
+
.date__select {
|
|
841
|
+
background-color: $color-gray-86;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
</style>
|