Skip to content

Commit 11aa887

Browse files
authored
feat: ✨ SelectPicker单选模式支持自动完成 (#207)
Closes: #206
1 parent 2c5bf3a commit 11aa887

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/component/select-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ function handleConfirm({ value, selectedItems }) {
341341
| filter-placeholder | 搜索框占位符 | string | - | 搜索 | - |
342342
| ellipsis | 是否超出隐藏 | boolean | - | false | - |
343343
| scroll-into-view | 重新打开是否滚动到选中项 | boolean | - | true | 0.1.34 |
344+
| show-confirm-btn | 确认按钮是否显示(单选生效) | boolean | | true | 1.2.7 |
344345
| prop | 表单域 `model` 字段名,在使用表单校验功能的情况下,该属性是必填的 | string | - | - | - |
345346
| rules | 表单验证规则,结合`wd-form`组件使用 | `FormItemRule []` | - | `[]` | - |
346347

src/pages/selectPicker/Index.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
<wd-select-picker label="必填" required v-model="value12" :columns="columns1" @confirm="handleConfirm12" />
1818
<wd-select-picker label="可搜索" filterable v-model="value13" :columns="columns1" @confirm="handleConfirm13" />
1919
<wd-select-picker label="单选可搜索" filterable v-model="value18" type="radio" :columns="columns1" @confirm="handleConfirm13" />
20+
<wd-select-picker
21+
label="单选取消确认按钮"
22+
type="radio"
23+
:show-confirm-btn="false"
24+
v-model="value19"
25+
:columns="columns1"
26+
@confirm="handleConfirm2"
27+
/>
2028
</wd-cell-group>
2129
</view>
2230
<demo-block title="label不传" transparent>
@@ -126,6 +134,7 @@ const value15 = ref<string[]>(['101'])
126134
const value16 = ref<string[]>(['103'])
127135
const value17 = ref<string[]>(['102'])
128136
const value18 = ref<string>('102')
137+
const value19 = ref<string>('101')
129138
130139
const customShow = ref<string>('奢侈品')
131140

src/uni_modules/wot-design-uni/components/wd-select-picker/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export const selectPickerProps = {
8181
/** 自定义标签样式类 */
8282
customLabelClass: makeStringProp(''),
8383
/** 自定义值样式类 */
84-
customValueClass: makeStringProp('')
84+
customValueClass: makeStringProp(''),
85+
/** 确认按钮是否显示(单选才生效) */
86+
showConfirmBtn: makeBooleanProp(true)
8587
}
8688
export type SelectPickerProps = ExtractPropTypes<typeof selectPickerProps>
8789

src/uni_modules/wot-design-uni/components/wd-select-picker/wd-select-picker.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
</view>
9898
</scroll-view>
9999
<!-- 确认按钮 -->
100-
<view class="wd-select-picker__footer">
100+
<view v-if="showConfirmBtn" class="wd-select-picker__footer">
101101
<wd-button block size="large" @click="onConfirm" :disabled="loading">{{ confirmButtonText || translate('confirm') }}</wd-button>
102102
</view>
103103
</wd-action-sheet>
@@ -319,6 +319,9 @@ function valueFormat(value: string | number | boolean | (string | number | boole
319319
function handleChange({ value }: { value: string | number | boolean | (string | number | boolean)[] }) {
320320
selectList.value = value
321321
emit('change', { value })
322+
if (props.type === 'radio' && !props.showConfirmBtn) {
323+
onConfirm()
324+
}
322325
}
323326
324327
function close() {
@@ -412,6 +415,10 @@ function formatFilterColumns(columns: Record<string, any>[], filterVal: string)
412415
})
413416
}
414417
418+
const showConfirmBtn = computed(() => {
419+
return (props.type === 'radio' && props.showConfirmBtn) || props.type === 'checkbox'
420+
})
421+
415422
defineExpose<SelectPickerExpose>({
416423
close,
417424
open

0 commit comments

Comments
 (0)