t20-common-lib 0.10.2 → 0.10.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "t20-common-lib",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -21,6 +21,7 @@
21
21
  :clearable="clearable"
22
22
  v-bind="$attrs"
23
23
  v-on="listeners"
24
+ @focus="onFocus"
24
25
  />
25
26
  </template>
26
27
 
@@ -218,6 +219,7 @@ export default {
218
219
  },
219
220
  data() {
220
221
  let shortcuts = undefined
222
+ let shortcutKeys = []
221
223
  const allShortcuts = getShortcutDefinitions()
222
224
 
223
225
  let config = this.shortcutConfig
@@ -230,8 +232,10 @@ export default {
230
232
  if (config) {
231
233
  shortcuts = config.map(item => {
232
234
  if (typeof item === 'string') {
235
+ shortcutKeys.push(item)
233
236
  return allShortcuts[item]
234
237
  }
238
+ shortcutKeys.push(null)
235
239
  return item
236
240
  }).filter(Boolean)
237
241
  }
@@ -250,9 +254,13 @@ export default {
250
254
  })
251
255
  return {
252
256
  pickerOptionsAs,
253
- listeners
257
+ listeners,
258
+ shortcutKeys
254
259
  }
255
260
  },
261
+ mounted() {
262
+ this.applyDefaultShortcut()
263
+ },
256
264
  computed: {
257
265
  valueC: {
258
266
  get() {
@@ -305,6 +313,78 @@ export default {
305
313
  }
306
314
  },
307
315
  methods: {
316
+ applyDefaultShortcut() {
317
+ const defaultKey = localStorage.getItem('t20-datepicker-default-shortcut')
318
+ if (defaultKey && !this.value) {
319
+ const allShortcuts = getShortcutDefinitions()
320
+ const shortcut = allShortcuts[defaultKey]
321
+ if (shortcut) {
322
+ const picker = {
323
+ $emit: (event, val) => {
324
+ if (event === 'pick') {
325
+ this.valueC = val
326
+ }
327
+ }
328
+ }
329
+ shortcut.onClick(picker)
330
+ }
331
+ }
332
+ },
333
+ onFocus() {
334
+ setTimeout(() => {
335
+ this.injectDefaultButtons()
336
+ }, 100)
337
+ },
338
+ injectDefaultButtons() {
339
+ const picker = this.$refs['date-picker'] && this.$refs['date-picker'].picker
340
+ if (!picker || !picker.$el) return
341
+
342
+ const sidebar = picker.$el.querySelector('.el-picker-panel__sidebar')
343
+ if (!sidebar) return
344
+
345
+ const shortcuts = sidebar.querySelectorAll('.el-picker-panel__shortcut')
346
+ const defaultKey = localStorage.getItem('t20-datepicker-default-shortcut')
347
+
348
+ shortcuts.forEach((el, index) => {
349
+ const key = this.shortcutKeys[index]
350
+ if (!key) return
351
+
352
+ if (el.querySelector('.shortcut-default-icon')) return
353
+
354
+ const icon = document.createElement('i')
355
+ const isDefault = defaultKey === key
356
+ icon.className = isDefault ? 'el-icon-star-on shortcut-default-icon' : 'el-icon-star-off shortcut-default-icon'
357
+ icon.style.marginLeft = '10px'
358
+ icon.style.cursor = 'pointer'
359
+ icon.style.color = isDefault ? '#E6A23C' : '#C0C4CC'
360
+ icon.title = '设为默认'
361
+
362
+ icon.onclick = (e) => {
363
+ e.stopPropagation()
364
+ this.setDefaultShortcut(key, index)
365
+ }
366
+
367
+ el.appendChild(icon)
368
+ })
369
+ },
370
+ setDefaultShortcut(key, index) {
371
+ localStorage.setItem('t20-datepicker-default-shortcut', key)
372
+ this.$message.success('已设置为默认快捷选项')
373
+
374
+ const picker = this.$refs['date-picker'].picker
375
+ if (picker && picker.$el) {
376
+ const icons = picker.$el.querySelectorAll('.shortcut-default-icon')
377
+ icons.forEach((icon, i) => {
378
+ if (i === index) {
379
+ icon.className = 'el-icon-star-on shortcut-default-icon'
380
+ icon.style.color = '#E6A23C'
381
+ } else {
382
+ icon.className = 'el-icon-star-off shortcut-default-icon'
383
+ icon.style.color = '#C0C4CC'
384
+ }
385
+ })
386
+ }
387
+ }
308
388
  }
309
389
  }
310
390
  </script>