@opentiny/vue-search-box 0.0.2 → 0.1.1-alpha.1

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.
Files changed (105) hide show
  1. package/README.md +25 -28
  2. package/README.zh-CN.md +107 -0
  3. package/__tests__/search-box.spec.ts +0 -0
  4. package/{es → dist/es}/index.es.js +5 -1
  5. package/{es → dist/es}/index.vue.es2.js +1 -12
  6. package/{lib → dist/lib}/index.cjs.js +4 -0
  7. package/{lib → dist/lib}/index.vue.cjs2.js +53 -64
  8. package/package.json +66 -64
  9. package/scripts/pre-release.cjs +8 -0
  10. package/src/composables/use-checkbox.ts +90 -0
  11. package/src/composables/use-custom.ts +53 -0
  12. package/src/composables/use-datepicker.ts +90 -0
  13. package/src/composables/use-dropdown.ts +251 -0
  14. package/src/composables/use-edit.ts +119 -0
  15. package/src/composables/use-init.ts +69 -0
  16. package/src/composables/use-match.ts +193 -0
  17. package/src/composables/use-num-range.ts +86 -0
  18. package/src/composables/use-placeholder.ts +43 -0
  19. package/src/composables/use-tag.ts +54 -0
  20. package/src/index.less +376 -0
  21. package/src/index.ts +13 -0
  22. package/src/index.type.ts +192 -0
  23. package/src/index.vue +1138 -0
  24. package/src/smb-theme.ts +15 -0
  25. package/src/theme.json +135 -0
  26. package/src/utils/clone.ts +37 -0
  27. package/src/utils/date.ts +724 -0
  28. package/src/utils/dropdown.ts +27 -0
  29. package/src/utils/en_US.ts +41 -0
  30. package/src/utils/index.ts +11 -0
  31. package/src/utils/tag.ts +80 -0
  32. package/src/utils/type.ts +6 -0
  33. package/src/utils/validate.ts +234 -0
  34. package/src/utils/zh_CN.ts +41 -0
  35. package/src/vars.less +56 -0
  36. package/vite.config.theme.ts +20 -0
  37. package/vite.config.ts +60 -0
  38. /package/{es → dist/es}/composables/use-checkbox.es.js +0 -0
  39. /package/{es → dist/es}/composables/use-custom.es.js +0 -0
  40. /package/{es → dist/es}/composables/use-datepicker.es.js +0 -0
  41. /package/{es → dist/es}/composables/use-dropdown.es.js +0 -0
  42. /package/{es → dist/es}/composables/use-edit.es.js +0 -0
  43. /package/{es → dist/es}/composables/use-init.es.js +0 -0
  44. /package/{es → dist/es}/composables/use-match.es.js +0 -0
  45. /package/{es → dist/es}/composables/use-num-range.es.js +0 -0
  46. /package/{es → dist/es}/composables/use-placeholder.es.js +0 -0
  47. /package/{es → dist/es}/composables/use-tag.es.js +0 -0
  48. /package/{es → dist/es}/index-VrLZbD8H.css +0 -0
  49. /package/{es → dist/es}/index.type.es.js +0 -0
  50. /package/{es → dist/es}/index.vue.es.js +0 -0
  51. /package/{es → dist/es}/smb-theme.es.js +0 -0
  52. /package/{es → dist/es}/utils/clone.es.js +0 -0
  53. /package/{es → dist/es}/utils/date.es.js +0 -0
  54. /package/{es → dist/es}/utils/dropdown.es.js +0 -0
  55. /package/{es → dist/es}/utils/en_US.es.js +0 -0
  56. /package/{es → dist/es}/utils/index.es.js +0 -0
  57. /package/{es → dist/es}/utils/tag.es.js +0 -0
  58. /package/{es → dist/es}/utils/type.es.js +0 -0
  59. /package/{es → dist/es}/utils/validate.es.js +0 -0
  60. /package/{es → dist/es}/utils/zh_CN.es.js +0 -0
  61. /package/{index.css → dist/index.css} +0 -0
  62. /package/{lib → dist/lib}/composables/use-checkbox.cjs.js +0 -0
  63. /package/{lib → dist/lib}/composables/use-custom.cjs.js +0 -0
  64. /package/{lib → dist/lib}/composables/use-datepicker.cjs.js +0 -0
  65. /package/{lib → dist/lib}/composables/use-dropdown.cjs.js +0 -0
  66. /package/{lib → dist/lib}/composables/use-edit.cjs.js +0 -0
  67. /package/{lib → dist/lib}/composables/use-init.cjs.js +0 -0
  68. /package/{lib → dist/lib}/composables/use-match.cjs.js +0 -0
  69. /package/{lib → dist/lib}/composables/use-num-range.cjs.js +0 -0
  70. /package/{lib → dist/lib}/composables/use-placeholder.cjs.js +0 -0
  71. /package/{lib → dist/lib}/composables/use-tag.cjs.js +0 -0
  72. /package/{lib → dist/lib}/index-VrLZbD8H.css +0 -0
  73. /package/{lib → dist/lib}/index.type.cjs.js +0 -0
  74. /package/{lib → dist/lib}/index.vue.cjs.js +0 -0
  75. /package/{lib → dist/lib}/smb-theme.cjs.js +0 -0
  76. /package/{lib → dist/lib}/utils/clone.cjs.js +0 -0
  77. /package/{lib → dist/lib}/utils/date.cjs.js +0 -0
  78. /package/{lib → dist/lib}/utils/dropdown.cjs.js +0 -0
  79. /package/{lib → dist/lib}/utils/en_US.cjs.js +0 -0
  80. /package/{lib → dist/lib}/utils/index.cjs.js +0 -0
  81. /package/{lib → dist/lib}/utils/tag.cjs.js +0 -0
  82. /package/{lib → dist/lib}/utils/type.cjs.js +0 -0
  83. /package/{lib → dist/lib}/utils/validate.cjs.js +0 -0
  84. /package/{lib → dist/lib}/utils/zh_CN.cjs.js +0 -0
  85. /package/{types → dist/types}/composables/use-checkbox.d.ts +0 -0
  86. /package/{types → dist/types}/composables/use-custom.d.ts +0 -0
  87. /package/{types → dist/types}/composables/use-datepicker.d.ts +0 -0
  88. /package/{types → dist/types}/composables/use-dropdown.d.ts +0 -0
  89. /package/{types → dist/types}/composables/use-edit.d.ts +0 -0
  90. /package/{types → dist/types}/composables/use-init.d.ts +0 -0
  91. /package/{types → dist/types}/composables/use-match.d.ts +0 -0
  92. /package/{types → dist/types}/composables/use-num-range.d.ts +0 -0
  93. /package/{types → dist/types}/composables/use-placeholder.d.ts +0 -0
  94. /package/{types → dist/types}/composables/use-tag.d.ts +0 -0
  95. /package/{types → dist/types}/index.type.d.ts +0 -0
  96. /package/{types → dist/types}/smb-theme.d.ts +0 -0
  97. /package/{types → dist/types}/utils/clone.d.ts +0 -0
  98. /package/{types → dist/types}/utils/date.d.ts +0 -0
  99. /package/{types → dist/types}/utils/dropdown.d.ts +0 -0
  100. /package/{types → dist/types}/utils/en_US.d.ts +0 -0
  101. /package/{types → dist/types}/utils/index.d.ts +0 -0
  102. /package/{types → dist/types}/utils/tag.d.ts +0 -0
  103. /package/{types → dist/types}/utils/type.d.ts +0 -0
  104. /package/{types → dist/types}/utils/validate.d.ts +0 -0
  105. /package/{types → dist/types}/utils/zh_CN.d.ts +0 -0
@@ -0,0 +1,90 @@
1
+ import { computed } from 'vue'
2
+ import { hasTagItem, createNewTag, getTagId, emitChangeModelEvent } from '../utils/tag'
3
+ import { deepClone, omitObj } from '../utils/clone'
4
+
5
+ export function useCheckbox({ props, state, emits }) {
6
+ const selectCheckbox = (confirm: boolean) => {
7
+ const { checkboxGroup, prevItem, propItem } = state
8
+ const rest = omitObj(prevItem)
9
+ state.hiden = true
10
+ if (confirm) {
11
+ const tagList = []
12
+ const oldValue = deepClone(state.innerModelValue)
13
+ const { mergeTag, operators, label: prevLabel } = prevItem
14
+ if (mergeTag) {
15
+ let value = ''
16
+ const options = []
17
+ const { indexMap } = state
18
+ const hasTagIndex = indexMap.get(prevLabel)
19
+ hasTagIndex !== undefined && state.innerModelValue.splice(hasTagIndex, 1)
20
+
21
+ state.backupList.forEach((item) => {
22
+ const { label } = item
23
+ const checkboxLabel = `${prevLabel}${label}`
24
+ const hasItem = checkboxGroup.includes(checkboxLabel)
25
+ if (hasItem) {
26
+ delete item.isFilter
27
+ const id = getTagId(props, prevItem, item)
28
+ const newOptions = { label: item.label, ...id }
29
+ value += !value ? label : ` | ${label}`
30
+ options.push(newOptions)
31
+ }
32
+ })
33
+ if (options.length > 0) {
34
+ const newTag = { ...rest, value, options }
35
+ tagList.push(newTag)
36
+ }
37
+ } else {
38
+ const { valueMap } = state
39
+ const indexList = []
40
+ state.backupList.forEach((item) => {
41
+ const { label } = item
42
+ const value = `${prevLabel}${label}`
43
+ const hasItem = checkboxGroup.includes(value)
44
+ if (hasItem && !hasTagItem(state, label)) {
45
+ const id = getTagId(props, prevItem, item)
46
+ const operator = state.operatorValue && operators ? { operator: state.operatorValue } : null
47
+ const newTag = createNewTag({ ...rest, label: propItem.label, value: label, ...id, ...operator })
48
+ tagList.push(newTag)
49
+ item.isChecked = true
50
+ } else if (!hasItem && hasTagItem(state, label)) {
51
+ item.isChecked = false
52
+ const index = valueMap.get(value)
53
+ indexList.push(index)
54
+ }
55
+ })
56
+ if (indexList.length) {
57
+ state.innerModelValue = state.innerModelValue.filter((item, index) => item && !indexList.includes(index))
58
+ }
59
+ }
60
+ emitChangeModelEvent({ emits, state, tagList, oldValue })
61
+ } else {
62
+ propItem.label = ''
63
+ state.inputValue = ''
64
+ }
65
+ }
66
+
67
+ const isIndeterminate = computed(
68
+ () => state.checkboxGroup.length > 0 && state.checkboxGroup.length !== state.filterList.length
69
+ )
70
+
71
+ const checkAll = computed({
72
+ get: () => state.checkboxGroup.length && state.checkboxGroup.length === state.filterList.length,
73
+ set: (val) => {
74
+ if (val) {
75
+ state.checkboxGroup = state.filterList.flatMap((item) => `${state.prevItem.label}${item.label}`)
76
+ } else {
77
+ state.checkboxGroup = []
78
+ }
79
+ }
80
+ })
81
+
82
+ const isShowClose = computed(() => props.modelValue.length || state.propItem.label || state.inputValue)
83
+
84
+ return {
85
+ selectCheckbox,
86
+ isIndeterminate,
87
+ checkAll,
88
+ isShowClose
89
+ }
90
+ }
@@ -0,0 +1,53 @@
1
+ import { resetInput, emitChangeModelEvent, hasTagItem } from '../utils/tag'
2
+ import { showDropdown, showPopover } from '../utils/dropdown'
3
+
4
+ export function useCustom({ state, emits }) {
5
+ const updateCustomValue = (customTag) => {
6
+ const { prevItem, indexMap } = state
7
+ const { replace, label } = prevItem
8
+
9
+ const tagList = []
10
+ if (replace && indexMap.has(label)) {
11
+ const index = indexMap.get(label)
12
+ const newTag = { ...prevItem, ...customTag }
13
+ emitChangeModelEvent({ emits, state, newTag, index })
14
+
15
+ return
16
+ } else if (!replace && Array.isArray(customTag)) {
17
+ customTag.forEach((tag) => {
18
+ if (!hasTagItem(state, tag.value)) {
19
+ tagList.push({ ...prevItem, ...tag })
20
+ }
21
+ })
22
+ } else {
23
+ if (!hasTagItem(state, customTag.value)) {
24
+ tagList.push({ ...prevItem, ...customTag })
25
+ }
26
+ }
27
+ emitChangeModelEvent({ emits, state, tagList })
28
+ }
29
+
30
+ const handleConfirm = (customTag) => {
31
+ if (!customTag) {
32
+ resetInput(state)
33
+ showDropdown(state, false)
34
+ return
35
+ }
36
+
37
+ updateCustomValue(customTag)
38
+ }
39
+
40
+ const handleEditConfirm = (customTag) => {
41
+ if (!customTag) {
42
+ showPopover(state, false)
43
+ return
44
+ }
45
+
46
+ updateCustomValue(customTag)
47
+ }
48
+
49
+ return {
50
+ handleConfirm,
51
+ handleEditConfirm
52
+ }
53
+ }
@@ -0,0 +1,90 @@
1
+ import { showDropdown } from '../utils/dropdown'
2
+ import { getVerifyDateTag } from '../utils/validate'
3
+ import { emitChangeModelEvent } from '../utils/tag'
4
+
5
+ export function useDatePicker({ props, state, emits }) {
6
+ const { instance } = state
7
+ const onConfirmDate = async (confirm: boolean, isDateTimeType = false) => {
8
+ if (!confirm) {
9
+ state.propItem.label = ''
10
+
11
+ return
12
+ }
13
+ const newTag = await getVerifyDateTag(instance, state, props, isDateTimeType)
14
+ if (newTag) {
15
+ const newValue = props.modelValue.filter((prev) => prev.type !== newTag.type || prev.field !== newTag.field)
16
+ newValue.push(newTag)
17
+ emitChangeModelEvent({ emits, state, newValue })
18
+ showDropdown(state, false)
19
+ } else {
20
+ showDropdown(state)
21
+ }
22
+ }
23
+
24
+ const handleDateShow = () => showDropdown(state)
25
+
26
+ const pickerOptions = (startDate, endName = '') => ({
27
+ disabledDate(time) {
28
+ const { maxTimeLength = 0, min, max } = state.prevItem
29
+
30
+ const endDate = state[endName]
31
+ const curTime = time.getTime()
32
+ // 有限制时间跨度timeLength时
33
+ if (maxTimeLength > 0) {
34
+ if (min || max) {
35
+ if (endName && endDate) {
36
+ const end = new Date(endDate).getTime()
37
+ const start = !min && max ? end - maxTimeLength : Math.max(min.getTime(), end - maxTimeLength)
38
+ return curTime < start || curTime > end
39
+ } else if (!endName && startDate) {
40
+ const start = new Date(startDate).getTime()
41
+ const end = min && !max ? start + maxTimeLength : Math.min(max.getTime(), start + maxTimeLength)
42
+ return curTime < start || curTime > end
43
+ } else {
44
+ return (min && curTime < min.getTime()) || (max && curTime > max.getTime())
45
+ }
46
+ } else {
47
+ if (endName && endDate) {
48
+ const end = new Date(endDate).getTime()
49
+ const start = end - maxTimeLength
50
+ return curTime < start || curTime > end
51
+ } else if (!endName && startDate) {
52
+ const start = new Date(startDate).getTime()
53
+ const end = start + maxTimeLength
54
+ return curTime < start || curTime > end
55
+ } else {
56
+ return false
57
+ }
58
+ }
59
+ } else {
60
+ if (min || max) {
61
+ if (endName && endDate) {
62
+ const end = new Date(endDate).getTime()
63
+ return (min && curTime < min.getTime()) || curTime > end
64
+ } else if (!endName && startDate) {
65
+ const start = new Date(startDate).getTime()
66
+ return curTime < start || (max && curTime > max.getTime())
67
+ } else {
68
+ return curTime < min || curTime > max
69
+ }
70
+ } else {
71
+ if (endName && endDate) {
72
+ const end = new Date(endDate).getTime()
73
+ return curTime > end
74
+ } else if (!endName && startDate) {
75
+ const start = new Date(startDate).getTime()
76
+ return curTime < start
77
+ } else {
78
+ return false
79
+ }
80
+ }
81
+ }
82
+ }
83
+ })
84
+
85
+ return {
86
+ onConfirmDate,
87
+ handleDateShow,
88
+ pickerOptions
89
+ }
90
+ }
@@ -0,0 +1,251 @@
1
+ import { hasTagItem, resetInput, createNewTag, getTagId, emitChangeModelEvent } from '../utils/tag'
2
+ import { showDropdown } from '../utils/dropdown'
3
+ import { setStateNumRange } from '../utils/validate'
4
+ import { deepClone, omitObj } from '../utils/clone'
5
+
6
+ export function useDropdown({ props, emits, state, t, format }) {
7
+ const { instance } = state
8
+ const showValueItem = (item) => {
9
+ const { start, end, type } = item
10
+ state.backupList = item.options?.length ? item.options : []
11
+ if (type === 'numRange') {
12
+ setStateNumRange(state, item, t)
13
+ state.hiden = false
14
+ } else if (type === 'dateRange') {
15
+ const { dateRangeFormat } = state
16
+ if (!state.startDate && start) {
17
+ const newStart = format(start, dateRangeFormat)
18
+ state.startDate = state.endDate < newStart ? null : newStart
19
+ }
20
+ if (!state.endDate && end) {
21
+ const newEnd = format(end, dateRangeFormat)
22
+ state.endDate = newEnd < state.startDate ? null : newEnd
23
+ }
24
+ state.hiden = false
25
+ } else if (type === 'datetimeRange') {
26
+ const { datetimeRangeFormat } = state
27
+ if (!state.startDateTime && start) {
28
+ const newStart = format(start, datetimeRangeFormat)
29
+ state.startDateTime = state.endDateTime < newStart ? null : newStart
30
+ }
31
+ if (!state.endDateTime && end) {
32
+ const newEnd = format(end, datetimeRangeFormat)
33
+ state.endDateTime = newEnd < state.startDateTime ? null : newEnd
34
+ }
35
+ state.hiden = false
36
+ } else if (state.backupList && type === 'checkbox') {
37
+ state.filterList = state.backupList
38
+ state.checkboxGroup = []
39
+ state.backupList.forEach((subItem) => {
40
+ if (hasTagItem(state, subItem.label)) {
41
+ state.checkboxGroup.push(`${item.label}${subItem.label}`)
42
+ }
43
+ subItem.isFilter = false
44
+ })
45
+ state.hiden = false
46
+ } else if (type === 'custom') {
47
+ state.hiden = false
48
+ }
49
+
50
+ if (state.backupList.length && type !== 'checkbox') {
51
+ state.backupList.forEach((option) => {
52
+ option.isFilter = false
53
+ option.isChecked = hasTagItem(state, option.label)
54
+ })
55
+ }
56
+
57
+ state.currentOperators = null
58
+
59
+ if (!((type === 'radio' || !type) && !state.backupList.length)) {
60
+ showDropdown(state)
61
+ }
62
+ }
63
+
64
+ const selectPropItem = (item) => {
65
+ const { field, label } = item
66
+ state.propItem.label = label
67
+
68
+ emits('first-level-select', field)
69
+
70
+ const inputRef = instance.refs.inputRef
71
+ state.prevItem = item
72
+ state.backupPrevItem = item
73
+ const { operators } = item
74
+ if (operators?.length) {
75
+ state.operatorValue = ''
76
+ state.currentOperators = operators
77
+ state.isResetFlag = true
78
+ showDropdown(state)
79
+ } else {
80
+ state.operatorValue = ':'
81
+ showValueItem(item)
82
+ }
83
+ state.inputValue = ''
84
+ inputRef.focus()
85
+ }
86
+
87
+ const setOperator = (operator) => {
88
+ state.operatorValue = operator
89
+ showValueItem(state.prevItem)
90
+ }
91
+
92
+ /**
93
+ * 更新modelValue值
94
+ * @param prevItem items数组的第一层元素信息,用来识别此类型标签的某些属性作相应处理
95
+ * @param item 当前选中的标签值信息
96
+ * @param label 标签左侧的label
97
+ * @param value 标签右侧值的value
98
+ */
99
+ const updateModelValue = (prevItem, item, label, value) => {
100
+ const { replace, operators, mergeTag } = prevItem
101
+ const rest = omitObj(prevItem)
102
+ const { indexMap } = state
103
+ const index = indexMap.get(label)
104
+ const id = getTagId(props, prevItem, item)
105
+ const operator = state.operatorValue && operators ? { operator: state.operatorValue } : null
106
+ let newTag = null
107
+
108
+ if (mergeTag) {
109
+ const options = { label: value, ...id }
110
+ if (index >= 0) {
111
+ const newValue = `${state.innerModelValue[index].value} | ${value}`
112
+ const newOptions = [...state.innerModelValue[index].options, options]
113
+ newTag = createNewTag({ ...state.innerModelValue[index], value: newValue, options: newOptions })
114
+ } else {
115
+ newTag = createNewTag({ ...rest, label, value, options: [options] })
116
+ }
117
+ } else {
118
+ newTag = createNewTag({ ...rest, label, value, ...id, ...operator })
119
+ }
120
+ if (hasTagItem(state, value, label)) {
121
+ resetInput(state)
122
+ return
123
+ }
124
+
125
+ const oldValue = deepClone(state.innerModelValue)
126
+ if ((replace || mergeTag) && index >= 0) {
127
+ state.innerModelValue.splice(index, 1)
128
+ }
129
+ state.innerModelValue.push(newTag)
130
+ const newValue = state.innerModelValue
131
+ emitChangeModelEvent({ emits, state, newValue, oldValue })
132
+ }
133
+
134
+ /**
135
+ * 选中单选标签
136
+ * @param item 选中的标签option项
137
+ * @param isPotential 是否为选择潜在匹配项,默认否。参数可选
138
+ */
139
+ const selectRadioItem = (item, isPotential = false) => {
140
+ // 潜在匹配项没有prevItem
141
+ if (isPotential) {
142
+ state.prevItem = item
143
+ state.backupPrevItem = item
144
+ }
145
+
146
+ const { prevItem } = state
147
+ const value = item.value || item.label
148
+ const inputRef = instance.refs.inputRef
149
+ if (!hasTagItem(state, value)) {
150
+ const tagLabel = state.propItem.label || item.label
151
+ updateModelValue(prevItem, item, tagLabel, value)
152
+ }
153
+ inputRef.focus()
154
+ }
155
+ const hasNotInputValueCreateTag = (propItem, prevItem) => {
156
+ // 有label
157
+ if (propItem.label) {
158
+ if (!prevItem.options) {
159
+ return
160
+ }
161
+
162
+ const hasTag = props.modelValue.find((item) => item.value === prevItem.options[0].label)
163
+
164
+ if (!hasTag) {
165
+ const label = prevItem.label
166
+ const value = prevItem.options && prevItem.options[0].label
167
+ updateModelValue(prevItem, prevItem.options[0], label, value)
168
+ return
169
+ }
170
+ } else {
171
+ emits('search', state.innerModelValue)
172
+ }
173
+ }
174
+
175
+ const newTagUpdateModelValue = (prevItem, propItem, tag) => {
176
+ const item = state.backupList.find((subItem) => subItem.label === tag)
177
+ updateModelValue(prevItem, item, propItem.label, tag)
178
+ }
179
+
180
+ const hasInputValueCreateTag = (inputValue, propItem, prevItem) => {
181
+ // 有label的情况
182
+ if (propItem.label) {
183
+ const { regexp, replace, type, mergeTag } = prevItem
184
+ const tagList =
185
+ (type !== 'checkbox' && replace) || (type === 'checkbox' && mergeTag)
186
+ ? [inputValue]
187
+ : inputValue.split(props.splitInputValue)
188
+
189
+ if (regexp) {
190
+ for (const tag of tagList) {
191
+ if (regexp.test(tag)) {
192
+ newTagUpdateModelValue(prevItem, propItem, tag)
193
+ }
194
+ }
195
+ // 有输入且无正则
196
+ } else {
197
+ for (const tag of tagList) {
198
+ newTagUpdateModelValue(prevItem, propItem, tag)
199
+ }
200
+ }
201
+ // 无label的情况
202
+ } else {
203
+ const { items, defaultField } = props
204
+ const currentItem = defaultField ? items.find((item) => item.field === defaultField) : state.allTypeAttri
205
+ const { replace, type, mergeTag } = currentItem
206
+ const tagList =
207
+ (type !== 'checkbox' && replace) || (type === 'checkbox' && mergeTag)
208
+ ? [inputValue]
209
+ : inputValue.split(props.splitInputValue)
210
+
211
+ if (currentItem?.options?.length) {
212
+ state.backupList = [...currentItem.options]
213
+ state.backupList.forEach((item) => {
214
+ const label = item.value || item.label
215
+ if (tagList.includes(label)) {
216
+ item.isChecked = true
217
+ }
218
+ })
219
+ }
220
+ const label = currentItem.label
221
+ for (const tag of tagList) {
222
+ updateModelValue(currentItem, {}, label, tag)
223
+ }
224
+ }
225
+ }
226
+
227
+ const createTag = () => {
228
+ const { inputValue, propItem, prevItem } = state
229
+ showDropdown(state, false)
230
+ if (!inputValue) {
231
+ // 输入为空的情况
232
+ hasNotInputValueCreateTag(propItem, prevItem)
233
+ } else {
234
+ // 输入不为空的情况
235
+ const { maxlength } = props
236
+ if (maxlength && maxlength < inputValue.length) {
237
+ emits('exceed', maxlength)
238
+ return
239
+ }
240
+
241
+ hasInputValueCreateTag(inputValue, propItem, prevItem)
242
+ }
243
+ }
244
+
245
+ // 帮助图标点击事件
246
+ const helpClick = () => {
247
+ emits('help')
248
+ }
249
+
250
+ return { selectPropItem, selectRadioItem, createTag, helpClick, setOperator }
251
+ }
@@ -0,0 +1,119 @@
1
+ import { emitChangeModelEvent } from '../utils/tag'
2
+ import { getVerifyNumTag, getVerifyDateTag, setStateNumRange, getVerifyTag } from '../utils/validate'
3
+ import { showDropdown } from '../utils/dropdown'
4
+
5
+ export function useEdit({ props, state, t, nextTick, format, emits }) {
6
+ const { instance } = state
7
+ const setDropdownProps = (curTag) => {
8
+ const { operator, value, start, end } = curTag
9
+ const { options, operators, type, mergeTag } = state.prevItem
10
+ if (type === 'custom') {
11
+ return
12
+ } else if (type === 'numRange') {
13
+ setStateNumRange(state, curTag, t)
14
+ } else if (type === 'dateRange') {
15
+ const { dateRangeFormat } = state
16
+ state.startDate = format(start, dateRangeFormat)
17
+ state.endDate = format(end, dateRangeFormat)
18
+ } else if (type === 'datetimeRange') {
19
+ const { datetimeRangeFormat } = state
20
+ state.startDateTime = format(start, datetimeRangeFormat)
21
+ state.endDateTime = format(end, datetimeRangeFormat)
22
+ } else {
23
+ if (mergeTag) {
24
+ state.inputEditValue = curTag.options?.flatMap((item) => item.label)
25
+ state.currentEditSelectTags = state.inputEditValue
26
+ } else {
27
+ state.inputEditValue = value
28
+ }
29
+ state.currentEditValue = options
30
+ }
31
+ state.operatorValue = operator
32
+ state.currentOperators = operators
33
+ }
34
+
35
+ const editTag = (tag, index, e) => {
36
+ if (!props.editable || (tag.type && tag.type === 'map')) {
37
+ return
38
+ }
39
+
40
+ showDropdown(state, false)
41
+ state.popoverVisible = false
42
+ const dom = e.target.classList.contains('tiny-tag') ? e.target : e.srcElement.parentElement
43
+
44
+ nextTick(() => {
45
+ const { popoverRef } = instance.refs
46
+ popoverRef.state.referenceElm = dom
47
+ popoverRef.state.popperElm && (popoverRef.state.popperElm.style.display = 'none')
48
+ popoverRef.doDestroy()
49
+ state.popoverVisible = true
50
+ })
51
+
52
+ state.prevItem = state.recordItems.find((item) => item.field === tag.field)
53
+ !state.prevItem && (state.prevItem = tag)
54
+ state.selectValue = tag.label
55
+ state.currentModelValueIndex = index
56
+
57
+ setDropdownProps(tag)
58
+ }
59
+
60
+ const selectPropChange = (item, disabled) => {
61
+ if (disabled) return
62
+ state.prevItem = item
63
+ setDropdownProps(item)
64
+ }
65
+
66
+ const confirmEditTag = async (isConfirm) => {
67
+ if (!isConfirm) {
68
+ state.popoverVisible = false
69
+
70
+ return
71
+ }
72
+
73
+ const { prevItem, currentModelValueIndex: index } = state
74
+
75
+ let newTag = null
76
+ if (prevItem.type === 'numRange') {
77
+ newTag = await getVerifyNumTag(instance, state, props)
78
+ } else if (prevItem.type === 'dateRange') {
79
+ newTag = await getVerifyDateTag(instance, state, props, false)
80
+ } else if (prevItem.type === 'datetimeRange') {
81
+ newTag = await getVerifyDateTag(instance, state, props, true)
82
+ } else {
83
+ newTag = await getVerifyTag(instance, state, props)
84
+ }
85
+
86
+ if (newTag) {
87
+ emitChangeModelEvent({ emits, state, index, newTag, isEdit: true })
88
+ state.popoverVisible = false
89
+ } else {
90
+ state.popoverVisible = true
91
+ }
92
+
93
+ state.currentEditValue = []
94
+ }
95
+
96
+ const selectItemIsDisable = (item) => {
97
+ if (item.type && item.type === 'map') {
98
+ return true
99
+ }
100
+
101
+ if (state.prevItem?.operators || item.operators) {
102
+ return state.prevItem.operators?.length !== item.operators?.length
103
+ }
104
+
105
+ const typeArr = ['radio', 'checkbox']
106
+ if (state.prevItem.type && typeArr.includes(state.prevItem.type)) {
107
+ return !item.type ? false : !typeArr.includes(item.type)
108
+ }
109
+
110
+ return state.prevItem?.type !== item.type
111
+ }
112
+
113
+ return {
114
+ editTag,
115
+ confirmEditTag,
116
+ selectPropChange,
117
+ selectItemIsDisable
118
+ }
119
+ }
@@ -0,0 +1,69 @@
1
+ import { showDropdown, showPopover } from '../utils/dropdown'
2
+
3
+ export function useInit({ props, state }) {
4
+ const { instance } = state
5
+ const initItems = () => {
6
+ state.groupItems = {}
7
+ state.recordItems.forEach((item) => {
8
+ const { groupKey = '0' } = item
9
+ if (state.groupItems[groupKey]) {
10
+ state.groupItems[groupKey].push({ ...item })
11
+ } else {
12
+ state.groupItems[groupKey] = [{ ...item }]
13
+ state.matchItems[groupKey] = { attr: [], attrValue: [] }
14
+ }
15
+ })
16
+ }
17
+
18
+ const handleClick = (e) => {
19
+ const { backupPrevItem, prevItem } = state
20
+ e.stopPropagation()
21
+ state.isResetFlag = true
22
+ if (props.editable) {
23
+ state.popoverVisible = false
24
+ state.currentEditValue = []
25
+ if (state.propItem.label && backupPrevItem && backupPrevItem !== prevItem) {
26
+ state.prevItem = backupPrevItem
27
+ }
28
+ }
29
+
30
+ if (!state.isShowPanel || props.items.length === 0) {
31
+ showDropdown(state, false)
32
+ } else {
33
+ showDropdown(state)
34
+ }
35
+ }
36
+
37
+ const watchOutsideClick = () => {
38
+ if (!state.isMouseDown) {
39
+ return
40
+ }
41
+
42
+ if (props.editable) {
43
+ showPopover(state, false)
44
+ }
45
+
46
+ state.isMouseDown = false
47
+ if (instance?.refs?.dropdownRef?.state?.visible) {
48
+ showDropdown(state, false)
49
+ }
50
+ }
51
+
52
+ const watchMouseDown = () => {
53
+ state.isMouseDown = true
54
+ }
55
+
56
+ const watchMouseMove = () => {
57
+ if (state.isMouseDown) {
58
+ state.isMouseDown = false
59
+ }
60
+ }
61
+
62
+ return {
63
+ initItems,
64
+ watchOutsideClick,
65
+ watchMouseDown,
66
+ watchMouseMove,
67
+ handleClick
68
+ }
69
+ }