jobdone-shared-files 1.0.9 → 1.0.11

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.
@@ -3,14 +3,14 @@
3
3
  <!-- preview input -->
4
4
  <button type="button" class='form-control autocomplete-select-component-display-selecting' :disabled="disabled"
5
5
  :class="[triggerClass, previewInput]">{{
6
- previewText
6
+ selectedPreviewText
7
7
  }}</button>
8
8
  <!-- search input -->
9
9
  <input class='form-control autocomplete-select-component-keyword-filter-input' :class="[triggerClass, searchInput]"
10
10
  type="text" ref="keywordFilterInput" v-model="keyword"
11
- :placeholder="searchPlaceholder == '' ? previewText : searchPlaceholder" maxlength="50"
12
- @keydown.enter="keyboardSelectConfirm()" @keydown.up="keyboardSwitch(-1)" @keydown.down="keyboardSwitch(1)"
13
- @change="keyboardSwitchIndexReset()">
11
+ :placeholder="searchPlaceholder == '' ? selectedPreviewText : searchPlaceholder" maxlength="50"
12
+ @keydown.enter="keyboardSelectConfirm($event)" @keydown.up="keyboardSwitch($event, -1)"
13
+ @keydown.down="keyboardSwitch($event, 1)" @change="keyboardSwitchIndexReset()">
14
14
  <Teleport :to="listPut">
15
15
  <div class="autocomplete-select-component-selector-content" :class="{ 'active': active }"
16
16
  ref="componentContentList" :style="positionStyle">
@@ -27,7 +27,8 @@
27
27
  </div>
28
28
  </li>
29
29
  <template v-if="active">
30
- <li v-for="(opt, idx) in filterList" :key="idx" @click.stop="selectConfirm(opt)" :title="opt.name" :id="`autocomplete-select-component-opt-item_${idx}`">
30
+ <li v-for="(opt, idx) in filterList" :key="idx" @click.stop="selectConfirm(opt)" :title="opt.name"
31
+ :id="`autocomplete-select-component-opt-item_${idx}`">
31
32
  <button class="autocomplete-select-component-opt-item" type="button"
32
33
  :class="idx == keyboardSwitchIndex ? 'active' : ''">
33
34
  <template v-if="htmlOption">
@@ -96,12 +97,12 @@ const props = defineProps({
96
97
  resetValue: {
97
98
  default: ''
98
99
  },
99
- disabled:{
100
- type:Boolean,
100
+ disabled: {
101
+ type: Boolean,
101
102
  default: false
102
103
  },
103
104
 
104
-
105
+
105
106
  previewKey: {
106
107
  type: String,
107
108
  default: '',
@@ -122,7 +123,7 @@ const props = defineProps({
122
123
  type: Boolean,
123
124
  default: false
124
125
  },
125
-
126
+
126
127
 
127
128
  });
128
129
 
@@ -138,7 +139,7 @@ const keywordFilterInput = ref(null)
138
139
  const active = ref(false)
139
140
  const domPosition = ref({ bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0, x: 0, y: 0 })
140
141
  function activeSelector() {
141
- if(props.disabled){
142
+ if (props.disabled) {
142
143
  return
143
144
  }
144
145
  active.value = true
@@ -168,8 +169,6 @@ function leave() {
168
169
  keywordFilterInput.value.blur()
169
170
  }
170
171
 
171
-
172
-
173
172
  // 確認傳入選單列表內的選項Type,只檢查第一個,請內容統一,不要傳奇怪的東西進來
174
173
  const allowOptItemType = ['string', 'number', 'object']
175
174
  const optItemType = computed(() => {
@@ -217,7 +216,7 @@ const filterList = computed(() => {
217
216
  })
218
217
  })
219
218
 
220
- // 從選項列表中挖出整個選中的item。因選中的值(可能是某個key),挖不到就直接吐props的值出來。
219
+ // 從選項列表中挖出整個選中的item,因選中的值(可能是某個key)
221
220
  const selectedItem = computed(() => {
222
221
  if (!props.selectedData) {
223
222
  return
@@ -227,12 +226,11 @@ const selectedItem = computed(() => {
227
226
  if (props.bindingKey !== '') {
228
227
  return props.opts.find(i => i[props.bindingKey.toString()] == props.selectedData) ?? props.selectedData
229
228
  }
230
-
231
229
  return props.selectedData
232
230
  })
233
231
 
234
232
 
235
- // 選項的展示 選中的值
233
+ // 整理 選項與選中值 的顯示文字
236
234
  function previewAdjust(itemObj) {
237
235
  if (props.previewKey !== '') {
238
236
  let strAry = props.previewKey.split('+')
@@ -253,12 +251,22 @@ function previewAdjust(itemObj) {
253
251
  if (isUndefined) {
254
252
  return props.isUndefinedHint
255
253
  }
256
- return finalStr ? finalStr : itemObj
254
+ return finalStr ? finalStr : props.placeholder
257
255
  }
258
256
  return itemObj
259
257
  }
260
258
 
261
- const previewText = computed(() => {
259
+ // 強制更新selectedPreviewText
260
+ const selectedPreviewTextUpdateCount = ref(0)
261
+ function selectedPreviewTextUpdate() {
262
+ selectedPreviewTextUpdateCount.value++
263
+ }
264
+
265
+ // 選中的值的顯示
266
+ const selectedPreviewText = computed(() => {
267
+
268
+ let updateComputed = selectedPreviewTextUpdateCount.value + 1 // 讓外部可以強制更新這個computed,不要刪除
269
+
262
270
  if (!selectedItem.value || Object.keys(selectedItem.value).length === 0) {
263
271
  return props.placeholder
264
272
  }
@@ -267,6 +275,7 @@ const previewText = computed(() => {
267
275
 
268
276
  // 清除選擇內容
269
277
  function clearSelected() {
278
+ selectedPreviewTextUpdateCount.value = 0
270
279
  emit('select', props.resetValue)
271
280
  leave()
272
281
  }
@@ -276,21 +285,29 @@ function selectConfirm(v) {
276
285
  if (!v) {
277
286
  return
278
287
  }
288
+ selectedPreviewTextUpdate()
279
289
  emit('select', JSON.parse(JSON.stringify(v)))
280
290
  leave()
281
291
  keyboardSwitchIndexReset()
282
292
  }
283
293
 
284
294
  // 鍵盤送出
285
- function keyboardSelectConfirm() {
295
+ function keyboardSelectConfirm(event) {
296
+ if (event.isComposing) {
297
+ return
298
+ }
286
299
  if (filterList.value?.length) {
287
300
  selectConfirm(filterList.value[keyboardSwitchIndex.value])
301
+ selectedPreviewTextUpdate()
288
302
  }
289
303
  }
290
304
 
291
305
  // 鍵盤挑選
292
306
  const keyboardSwitchIndex = ref(0)
293
- function keyboardSwitch(v) {
307
+ function keyboardSwitch(event, v) {
308
+ if (event.isComposing) {
309
+ return
310
+ }
294
311
  if (filterList.value?.length < 1) {
295
312
  keyboardSwitchIndexReset()
296
313
  return
@@ -317,7 +334,7 @@ function keyboardSwitchIndexReset() {
317
334
 
318
335
  // 樣式
319
336
  const previewInput = computed(() => {
320
- if (previewText.value == props.placeholder) {
337
+ if (selectedPreviewText.value == props.placeholder) {
321
338
  return 'autocomplete-select-component-value-null'
322
339
  }
323
340
  return ''
@@ -328,7 +345,7 @@ const searchInput = computed(() => {
328
345
  }
329
346
  return ''
330
347
  })
331
- function initTrigger() {
348
+ function initTrigger(event) {
332
349
  if (componentContentInput.value.contains(event.target) || componentContentList.value.contains(event.target)) {
333
350
  activeSelector()
334
351
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jobdone-shared-files",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Shared JS and SCSS for Jobdone Enterprise.",
5
5
  "main": "index.js",
6
6
  "scripts": {