wui-components-v2 1.2.49 → 1.2.50
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/components/search/search.vue +122 -54
- package/package.json +1 -1
- package/type.ts +2 -0
|
@@ -21,7 +21,12 @@ const theme = computed(() => themeStore.theme)
|
|
|
21
21
|
const show = ref(false)
|
|
22
22
|
const search = ref('')
|
|
23
23
|
const formControlRef = ref()
|
|
24
|
-
|
|
24
|
+
// 外置 preferred 筛选字段的 form-control 实例
|
|
25
|
+
const preferredFormControlRef = ref()
|
|
26
|
+
// 外置 preferred 表单的刷新标识:弹窗提交后递增,强制外置 form-control 重挂载读取最新 entity
|
|
27
|
+
const preferredRefreshKey = ref(0)
|
|
28
|
+
// 共享实体:外置 preferred 字段与弹窗筛选字段通过它进行双向同步
|
|
29
|
+
const entity = ref<{ [key: string]: any }>({})
|
|
25
30
|
// 判断字段实际渲染的控件类型是否为纯文本输入(优先 extControlType,回退 controlType)
|
|
26
31
|
const isTextCriterion = (item: Fields) => ControlTypeSupportor.getControlType(item) === 'text'
|
|
27
32
|
// 用于 wd-search 的搜索字段:primaryCriterion 存在时直接使用,否则取 criteria 中第一个文本类型的筛选项
|
|
@@ -33,79 +38,140 @@ const searchCriterion = computed(() => {
|
|
|
33
38
|
})
|
|
34
39
|
// 仅当 searchCriterion 存在时显示搜索框
|
|
35
40
|
const showSearch = computed(() => searchCriterion.value !== null)
|
|
41
|
+
// tab 筛选字段(split2TabCriterias)的 sourceId,用于从普通筛选中排除
|
|
42
|
+
const split2TabSourceIds = computed(() => props.split2TabCriterias?.map(item => item.sourceId) || [])
|
|
43
|
+
// preferred=true 的字段外置到搜索框上方展示(排除 tab 筛选字段,以及已作为搜索框的 searchCriterion,避免重复展示)
|
|
44
|
+
const preferredCriteria = computed(() => {
|
|
45
|
+
const searchSourceId = showSearch.value ? searchCriterion.value?.sourceId : undefined
|
|
46
|
+
return props.criteria.filter(
|
|
47
|
+
item =>
|
|
48
|
+
item.preferred === true && !split2TabSourceIds.value.includes(item.sourceId) && item.sourceId !== searchSourceId
|
|
49
|
+
)
|
|
50
|
+
})
|
|
36
51
|
const filterCriteria = computed(() => {
|
|
37
|
-
const criteriaSourceIds = props.split2TabCriterias?.map(item => item.sourceId) || []
|
|
38
52
|
// 仅当搜索框真正显示时,才把 searchCriterion 从筛选弹窗中排除;
|
|
39
53
|
// 否则(extControlType 存在)该字段应回落到筛选弹窗中参与筛选
|
|
40
54
|
const searchSourceId = showSearch.value ? searchCriterion.value?.sourceId : undefined
|
|
41
|
-
|
|
42
|
-
return props.criteria.filter(item => !
|
|
55
|
+
// 弹窗筛选需保留 preferred 字段(与外置字段双向绑定),因此不排除 preferredCriteria
|
|
56
|
+
if (!searchSourceId) return props.criteria.filter(item => !split2TabSourceIds.value.includes(item.sourceId))
|
|
57
|
+
return props.criteria.filter(item => ![searchSourceId, ...split2TabSourceIds.value].includes(item.sourceId))
|
|
43
58
|
})
|
|
59
|
+
// 把外部/弹窗表单返回的数据归一化后再写入 entity:
|
|
60
|
+
// 数组值统一转成逗号分隔字符串,避免弹窗 initFormData 对数组调用 split 报错导致空白
|
|
61
|
+
function normalizeForEntity(data: { [key: string]: any }) {
|
|
62
|
+
const result: { [key: string]: any } = {}
|
|
63
|
+
for (const key in data) {
|
|
64
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
65
|
+
const val = data[key]
|
|
66
|
+
result[key] = Array.isArray(val) ? val.join(',') : val
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
71
|
+
// 打开筛选弹窗前,先把外置 preferred 字段的当前值同步进 entity,
|
|
72
|
+
// 再打开弹窗(await 保证先同步完,弹窗 form-control 重挂载时能读取到最新值,避免竞态空白)
|
|
73
|
+
async function handleShowPopup() {
|
|
74
|
+
if (preferredFormControlRef.value?.submit) {
|
|
75
|
+
try {
|
|
76
|
+
const pdata = await preferredFormControlRef.value.submit()
|
|
77
|
+
Object.assign(entity.value, normalizeForEntity(pdata))
|
|
78
|
+
} catch {
|
|
79
|
+
// 校验失败(如必填未填)时仍保留原 entity,不阻塞弹窗打开
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
console.log('[Search] handleShowPopup entity =', entity.value)
|
|
83
|
+
show.value = true
|
|
84
|
+
}
|
|
44
85
|
function handleClose() {
|
|
45
86
|
show.value = false
|
|
46
87
|
}
|
|
88
|
+
// 把合并后的数据对象(fdata)拼接为查询条件字符串
|
|
89
|
+
function buildQueryData(fdata: { [key: string]: any }) {
|
|
90
|
+
let data = ''
|
|
91
|
+
if (showSearch.value && searchCriterion.value?.sourceId) {
|
|
92
|
+
data = `c_${searchCriterion.value.sourceId}=${search.value}`
|
|
93
|
+
}
|
|
94
|
+
filterCriteria.value.forEach(item => {
|
|
95
|
+
const element = fdata[item.sourceId]
|
|
96
|
+
// 空值(空字符串、undefined、null、空数组)仍拼接 `c_${sourceId}=` 空参数,
|
|
97
|
+
// 让父组件识别「该字段已被用户清空」,从而跳过 defaultCriteriaValue 的默认值兜底
|
|
98
|
+
if (element === undefined || element === null || element === '') {
|
|
99
|
+
data = `${data}&c_${item.sourceId}=`
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(element) && element.length === 0) {
|
|
103
|
+
data = `${data}&c_${item.sourceId}=`
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
// 跳过用户未修改的默认值(时间字段常被自动填充当前时间,不应作为查询条件)
|
|
107
|
+
if (item.transDefaultValue && String(element) === String(item.transDefaultValue)) return
|
|
108
|
+
if (item.extControlType === 'relselectvalue') {
|
|
109
|
+
const elements = Array.isArray(element) ? element : [element]
|
|
110
|
+
data = `${data}&c_${item.sourceId}=${elements
|
|
111
|
+
.map((item: string) => {
|
|
112
|
+
return item.split('@R@')[1]
|
|
113
|
+
})
|
|
114
|
+
.join('@,@')}`
|
|
115
|
+
} else if (item.extControlType === 'multiselect') {
|
|
116
|
+
const elements = Array.isArray(element) ? element : [element]
|
|
117
|
+
elements.forEach((subitem: string) => {
|
|
118
|
+
data = `${data}&c_${item.sourceId}=${subitem}`
|
|
119
|
+
})
|
|
120
|
+
} else {
|
|
121
|
+
data = `${data}&c_${item.sourceId}=${element}`
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
return data
|
|
125
|
+
}
|
|
126
|
+
// 对外触发提交(点击搜索/确定时使用)
|
|
127
|
+
function emitSubmit(fdata: { [key: string]: any }) {
|
|
128
|
+
console.log('查询条件', buildQueryData(fdata))
|
|
129
|
+
emits('submit', buildQueryData(fdata))
|
|
130
|
+
handleClose()
|
|
131
|
+
}
|
|
47
132
|
function handleSubmit() {
|
|
48
133
|
if (!formControlRef.value) {
|
|
49
134
|
if (!showSearch.value || !searchCriterion.value?.sourceId) return
|
|
50
|
-
|
|
51
|
-
emits('submit', data)
|
|
52
|
-
handleClose()
|
|
135
|
+
emitSubmit({ [searchCriterion.value.sourceId]: search.value })
|
|
53
136
|
return
|
|
54
137
|
}
|
|
55
138
|
formControlRef.value.submit().then((fdata: any) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
? { [searchCriterion.value.sourceId]: search.value }
|
|
60
|
-
: {}),
|
|
61
|
-
}
|
|
62
|
-
let data = ''
|
|
63
|
-
|
|
139
|
+
// 双向绑定:弹窗内提交的值(含 preferred 字段)写回 entity,供外置字段同步;
|
|
140
|
+
// 数组值归一化为字符串,避免后续 initFormData 对数组 split 报错
|
|
141
|
+
Object.assign(entity.value, normalizeForEntity(fdata))
|
|
64
142
|
if (showSearch.value && searchCriterion.value?.sourceId) {
|
|
65
|
-
|
|
143
|
+
entity.value[searchCriterion.value.sourceId] = search.value
|
|
66
144
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// 空值(空字符串、undefined、null、空数组)仍拼接 `c_${sourceId}=` 空参数,
|
|
71
|
-
// 让父组件识别「该字段已被用户清空」,从而跳过 defaultCriteriaValue 的默认值兜底
|
|
72
|
-
if (element === undefined || element === null || element === '') {
|
|
73
|
-
data = `${data}&c_${item.sourceId}=`
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(element) && element.length === 0) {
|
|
77
|
-
data = `${data}&c_${item.sourceId}=`
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
// 跳过用户未修改的默认值(时间字段常被自动填充当前时间,不应作为查询条件)
|
|
81
|
-
if (item.transDefaultValue && String(element) === String(item.transDefaultValue)) return
|
|
82
|
-
if (item.extControlType === 'relselectvalue') {
|
|
83
|
-
const elements = Array.isArray(element) ? element : [element]
|
|
84
|
-
data = `${data}&c_${item.sourceId}=${elements
|
|
85
|
-
.map((item: string) => {
|
|
86
|
-
return item.split('@R@')[1]
|
|
87
|
-
})
|
|
88
|
-
.join('@,@')}`
|
|
89
|
-
} else if (item.extControlType === 'multiselect') {
|
|
90
|
-
const elements = Array.isArray(element) ? element : [element]
|
|
91
|
-
elements.forEach((subitem: string) => {
|
|
92
|
-
data = `${data}&c_${item.sourceId}=${subitem}`
|
|
93
|
-
})
|
|
94
|
-
} else {
|
|
95
|
-
data = `${data}&c_${item.sourceId}=${element}`
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
console.log('查询条件', data)
|
|
100
|
-
|
|
101
|
-
emits('submit', data)
|
|
102
|
-
handleClose()
|
|
145
|
+
// 递增刷新标识,强制外置 preferred 表单重挂载并读取最新 entity(弹窗 → 外置同步)
|
|
146
|
+
preferredRefreshKey.value++
|
|
147
|
+
emitSubmit(fdata)
|
|
103
148
|
})
|
|
104
149
|
}
|
|
105
150
|
</script>
|
|
106
151
|
|
|
107
152
|
<template>
|
|
108
153
|
<wd-config-provider :theme="theme">
|
|
154
|
+
<!-- preferred=true 的筛选项外置在搜索框上方,常驻展示;与弹窗中的同名筛选双向绑定 -->
|
|
155
|
+
<view v-if="preferredCriteria.length" class="w-full box-border pt-2">
|
|
156
|
+
<formControl
|
|
157
|
+
ref="preferredFormControlRef"
|
|
158
|
+
:key="`preferred-${preferredRefreshKey}`"
|
|
159
|
+
:field-group="{
|
|
160
|
+
fields: preferredCriteria,
|
|
161
|
+
readOnly: false,
|
|
162
|
+
displayConfig: [],
|
|
163
|
+
id: '',
|
|
164
|
+
buttons: [],
|
|
165
|
+
title: '',
|
|
166
|
+
type: '',
|
|
167
|
+
pointSourceId: '',
|
|
168
|
+
mstrucId: '',
|
|
169
|
+
relationNames: [],
|
|
170
|
+
}"
|
|
171
|
+
:entity="entity"
|
|
172
|
+
:enum-column="enumColumn"
|
|
173
|
+
/>
|
|
174
|
+
</view>
|
|
109
175
|
<view v-if="showSearch" class="w-full">
|
|
110
176
|
<wd-search
|
|
111
177
|
v-model="search"
|
|
@@ -120,14 +186,14 @@ function handleSubmit() {
|
|
|
120
186
|
name="filter"
|
|
121
187
|
size="17px"
|
|
122
188
|
class="text-gray-500 dark:text-[var(--wot-dark-color3)]"
|
|
123
|
-
@click="
|
|
189
|
+
@click="handleShowPopup"
|
|
124
190
|
/>
|
|
125
191
|
</view>
|
|
126
192
|
</template>
|
|
127
193
|
</wd-search>
|
|
128
194
|
</view>
|
|
129
195
|
<view v-else-if="filterCriteria.length" class="px-[8px] mt-2">
|
|
130
|
-
<wd-button block custom-class="search-filter-btn" @click="
|
|
196
|
+
<wd-button block custom-class="search-filter-btn" @click="handleShowPopup">
|
|
131
197
|
<wd-icon name="filter" size="17px" class="mr-1" />
|
|
132
198
|
筛选
|
|
133
199
|
</wd-button>
|
|
@@ -135,7 +201,9 @@ function handleSubmit() {
|
|
|
135
201
|
<wd-popup v-model="show" position="bottom" custom-class="h-80vh" closable @close="handleClose">
|
|
136
202
|
<view class="relative box-border h-full p-1 bg-white dark:bg-[var(--wot-dark-background)]">
|
|
137
203
|
<view class="h-34px flex items-center justify-center text-black dark:text-[var(--wot-dark-color)]">筛选</view>
|
|
204
|
+
<!-- v-if="show" 保证每次打开弹窗都重新挂载,读取最新 entity(含外置 preferred 值),实现双向绑定 -->
|
|
138
205
|
<formControl
|
|
206
|
+
v-if="show"
|
|
139
207
|
ref="formControlRef"
|
|
140
208
|
:field-group="{
|
|
141
209
|
fields: filterCriteria,
|
package/package.json
CHANGED