Select 下拉选择框
规则
基础示例
js
const rule = {
type: "select",
field: "cate_id",
title: "产品分类",
value: ["104","105"],
options: [
{"value": "104", "label": "生态蔬菜", "disabled": false},
{"value": "105", "label": "新鲜水果", "disabled": false},
],
props: {
multiple: true
},
}Props 配置示例
单选下拉框
js
const rule = {
type: "select",
field: "category",
title: "商品分类",
value: "104",
options: [
{"value": "104", "label": "生态蔬菜"},
{"value": "105", "label": "新鲜水果"},
{"value": "106", "label": "海鲜水产"},
],
props: {
placeholder: "请选择商品分类",
clearable: true,
},
}多选下拉框
js
const rule = {
type: "select",
field: "tags",
title: "商品标签",
value: ["104","105"],
options: [
{"value": "104", "label": "热销"},
{"value": "105", "label": "新品"},
{"value": "106", "label": "推荐"},
],
props: {
multiple: true,
max: 3,
placeholder: "请选择标签",
},
}可搜索下拉框
js
const rule = {
type: "select",
field: "product",
title: "商品名称",
options: [
{"value": "1", "label": "iPhone 15 Pro"},
{"value": "2", "label": "MacBook Pro"},
{"value": "3", "label": "iPad Air"},
],
props: {
filterable: true,
placeholder: "请输入或选择商品",
clearable: true,
},
}远程搜索
js
const rule = {
type: "select",
field: "user",
title: "选择用户",
options: [],
props: {
filterable: true,
placeholder: "请输入用户名搜索",
clearable: true,
loading: false,
},
inject: true,
on: {
search: ($inject, value) => {
if (value) {
// 调用远程搜索接口
searchUsers(value).then(res => {
// 更新选项
$inject.api.updateRule('user', {
options: res.data.map(item => ({
value: item.id,
label: item.name
}))
});
});
}
},
},
}Events 事件示例
监听选择变化
js
const rule = {
type: "select",
field: "category",
title: "商品分类",
options: [
{"value": "104", "label": "生态蔬菜"},
{"value": "105", "label": "新鲜水果"},
],
props: {
placeholder: "请选择分类",
clearable: true,
},
on: {
change: (value, option) => {
console.log('选择值改变:', value, option);
},
clear: () => {
console.log('清空选择');
},
},
}选择后联动更新其他字段
js
const rule = [
{
type: "select",
field: "category",
title: "商品分类",
options: [
{"value": "1", "label": "电子产品"},
{"value": "2", "label": "服装配饰"},
],
props: {
placeholder: "请选择分类",
},
inject: true,
on: {
change: ($inject, value) => {
// 根据分类加载对应的子分类
if (value === "1") {
$inject.api.updateRule('subcategory', {
options: [
{"value": "11", "label": "手机"},
{"value": "12", "label": "电脑"},
]
});
} else if (value === "2") {
$inject.api.updateRule('subcategory', {
options: [
{"value": "21", "label": "男装"},
{"value": "22", "label": "女装"},
]
});
}
},
},
},
{
type: "select",
field: "subcategory",
title: "子分类",
options: [],
props: {
placeholder: "请先选择分类",
disabled: true,
},
},
]完整配置项:TDesign_Select


