wui-components-v2 1.2.92 → 1.2.93

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.
@@ -27,6 +27,8 @@ const props = defineProps<{
27
27
  smartPaste?: boolean
28
28
  /** 严格模式(筛选场景):entity 中存在 key 即视为用户显式设置的值,空值也生效,不再回落到字段默认值 */
29
29
  strictEntity?: boolean
30
+ /** 弹窗选择类字段的 max 未配置时默认按单选处理(筛选场景使用,不影响配置了 max 的字段) */
31
+ selectDefaultSingle?: boolean
30
32
  }>()
31
33
  const fileTypes = [
32
34
  {
@@ -55,6 +57,14 @@ const { filteredFields: fields } = useCompanyFieldFilter(
55
57
  props.companyFilter, // 是否自适应显示快递公司填充框
56
58
  props.companyFieldSourceId // 快递公司对应字段
57
59
  )
60
+ // 弹窗选择类字段(WuiSelectPopup / WuiTreeCascaderPopup)是否单选:
61
+ // max 配置为 1 时单选;max 未配置时由 selectDefaultSingle 决定(筛选场景默认单选),配置了其他值则多选
62
+ function isSingleSelect(item: Fields) {
63
+ if (item.max === undefined || item.max === null || item.max === '') {
64
+ return props.selectDefaultSingle === true
65
+ }
66
+ return Number(item.max) === 1
67
+ }
58
68
  const giveDefaultValue = (value: any) => {
59
69
  const { extInfo = {} } = uni.getStorageSync('userInfo') || {}
60
70
  const rawDefaultValue = extInfo.fieldMap || {}
@@ -992,7 +1002,7 @@ console.log('clearValueMap', clearValueMap)
992
1002
  v-model="model[item.sourceId]"
993
1003
  :source-id="item.sourceId"
994
1004
  :title="item.title"
995
- :ext-control-type="Number(item.max) === 1 ? 'relselect' : 'ss'"
1005
+ :ext-control-type="isSingleSelect(item) ? 'relselect' : 'ss'"
996
1006
  :readonly="item.disabled || item.rowEditType === 'readonly'"
997
1007
  :clearable="!item.disabled"
998
1008
  :default-select-first="!!item.defaultSelectFirst"
@@ -1034,7 +1044,7 @@ console.log('clearValueMap', clearValueMap)
1034
1044
  v-model="model[item.sourceId]"
1035
1045
  :source-id="item.sourceId"
1036
1046
  :title="item.title"
1037
- :ext-control-type="Number(item.max) === 1 ? 'relselect' : 'ss'"
1047
+ :ext-control-type="isSingleSelect(item) ? 'relselect' : 'ss'"
1038
1048
  :readonly="item.disabled || item.rowEditType === 'readonly'"
1039
1049
  :clearable="!item.disabled"
1040
1050
  :default-select-first="!!item.defaultSelectFirst"
@@ -1142,8 +1152,8 @@ console.log('clearValueMap', clearValueMap)
1142
1152
  v-model="model[item.sourceId]"
1143
1153
  :source-id="item.sourceId"
1144
1154
  :title="item.title"
1145
- :select-mode="Number(item.max) === 1 ? 'single' : 'multiple'"
1146
- :ext-control-type="Number(item.max) === 1 ? 'relselect' : 'ss'"
1155
+ :select-mode="isSingleSelect(item) ? 'single' : 'multiple'"
1156
+ :ext-control-type="isSingleSelect(item) ? 'relselect' : 'ss'"
1147
1157
  :readonly="item.disabled || item.rowEditType === 'readonly'"
1148
1158
  :clearable="!item.disabled"
1149
1159
  :default-select-first="!!item.defaultSelectFirst"
@@ -141,11 +141,25 @@ function emitSubmit(fdata: { [key: string]: any }) {
141
141
  emits('submit', buildQueryData(fdata))
142
142
  handleClose()
143
143
  }
144
- function handleSubmit() {
144
+ async function handleSubmit() {
145
145
  if (!formControlRef.value) {
146
- if (!showSearch.value || !searchCriterion.value?.sourceId) return
147
- // 弹窗未挂载(从未打开或已关闭)时,entity 中仍保留着已选中的筛选条件,
148
- // 不能只提交搜索框关键字,需把搜索框值与 entity 中的筛选值合并后一并提交
146
+ // 弹窗未挂载(从未打开或已关闭)时,外置 preferred 字段选中的值还只存在于
147
+ // 外置 form-control 的内部 model 中(form-control 不回写 entity),
148
+ // 先 submit 同步进 entity,否则没打开过弹窗直接搜索会丢掉上面选中的筛选条件
149
+ if (preferredFormControlRef.value?.submit) {
150
+ try {
151
+ const pdata = await preferredFormControlRef.value.submit()
152
+ Object.assign(entity.value, normalizeForEntity(pdata))
153
+ } catch {
154
+ // 校验失败时仍用原 entity 提交,不阻塞搜索
155
+ }
156
+ }
157
+ if (!showSearch.value || !searchCriterion.value?.sourceId) {
158
+ emitSubmit({ ...entity.value })
159
+ return
160
+ }
161
+ // entity 中仍保留着已选中的筛选条件,不能只提交搜索框关键字,
162
+ // 需把搜索框值与 entity 中的筛选值合并后一并提交
149
163
  const merged = normalizeForEntity({ ...entity.value })
150
164
  merged[searchCriterion.value.sourceId] = search.value
151
165
  emitSubmit(merged)
@@ -187,6 +201,7 @@ function handleSubmit() {
187
201
  :entity="entity"
188
202
  :enum-column="enumColumn"
189
203
  strict-entity
204
+ select-default-single
190
205
  />
191
206
  </view>
192
207
  <view v-if="showSearch" class="w-full">
@@ -237,6 +252,7 @@ function handleSubmit() {
237
252
  :entity="entity"
238
253
  :enum-column="enumColumn"
239
254
  strict-entity
255
+ select-default-single
240
256
  />
241
257
  <view class="h-12" />
242
258
  <view
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.92",
3
+ "version": "1.2.93",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",