feat(dropdown-filter): new component
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
<template>
|
||||
<div class="demo">
|
||||
<div class="stage">
|
||||
<div class="tui-page-content list">
|
||||
<t-pull-down-refresh class="pull-refresh" :value="false">
|
||||
<dropdown-filter
|
||||
v-model="keyword"
|
||||
:filters="filters"
|
||||
placeholder="搜索产品名称或编码"
|
||||
@filter-change="handleFilterChange"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<t-button size="extra-small" theme="primary" variant="outline" content="选择" />
|
||||
</template>
|
||||
</dropdown-filter>
|
||||
<div class="list-body">
|
||||
<t-cell-group v-if="visibleList.length" theme="card">
|
||||
<t-cell
|
||||
v-for="item in visibleList"
|
||||
:key="item.id"
|
||||
:title="item.name"
|
||||
:description="item.code"
|
||||
:note="item.status === 'on' ? '在售' : '停售'"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<p v-else class="empty" v-text="'没有匹配的产品'" />
|
||||
</div>
|
||||
</t-pull-down-refresh>
|
||||
</div>
|
||||
</div>
|
||||
<p class="log">
|
||||
<span v-text="'最近一次 filter-change:'" />
|
||||
<code v-text="lastChange" />
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
DropdownFilter,
|
||||
type DropdownFilterChange,
|
||||
type DropdownFilterItem,
|
||||
type DropdownFilterOption
|
||||
} from "timi-tdesign-mobile";
|
||||
|
||||
const keyword = ref("");
|
||||
const category = ref("all");
|
||||
const status = ref("all");
|
||||
const lastChange = ref("—");
|
||||
|
||||
const productList = [
|
||||
{ id: "p1", name: "氨基酸洁面慕斯", code: "P-1001", category: "cleanser", status: "on" },
|
||||
{ id: "p2", name: "玻尿酸精华液", code: "P-1002", category: "serum", status: "on" },
|
||||
{ id: "p3", name: "烟酰胺原液", code: "P-1003", category: "serum", status: "off" },
|
||||
{ id: "p4", name: "舒缓修护面霜", code: "P-1004", category: "cream", status: "on" },
|
||||
{ id: "p5", name: "清透防晒乳", code: "P-1005", category: "cream", status: "off" },
|
||||
{ id: "p6", name: "氨基酸洗发水", code: "P-1006", category: "body", status: "on" }
|
||||
];
|
||||
|
||||
const categoryOptions: DropdownFilterOption[] = [
|
||||
{ label: "全部品类", value: "all" },
|
||||
{ label: "洁面", value: "cleanser" },
|
||||
{ label: "精华", value: "serum" },
|
||||
{ label: "面霜", value: "cream" },
|
||||
{ label: "身体护理", value: "body" }
|
||||
];
|
||||
|
||||
const statusOptions: DropdownFilterOption[] = [
|
||||
{ label: "全部状态", value: "all" },
|
||||
{ label: "在售", value: "on" },
|
||||
{ label: "停售", value: "off" }
|
||||
];
|
||||
|
||||
const filters = computed<DropdownFilterItem[]>(() => [
|
||||
{
|
||||
key: "category",
|
||||
label: categoryOptions.find(item => item.value === category.value)?.label || "全部品类",
|
||||
value: category.value,
|
||||
options: categoryOptions
|
||||
},
|
||||
{
|
||||
key: "status",
|
||||
label: statusOptions.find(item => item.value === status.value)?.label || "全部状态",
|
||||
value: status.value,
|
||||
options: statusOptions
|
||||
}
|
||||
]);
|
||||
|
||||
const visibleList = computed(() => {
|
||||
const text = keyword.value.trim().toLowerCase();
|
||||
return productList.filter(item => {
|
||||
const matchedText = !text || `${item.name}${item.code}`.toLowerCase().includes(text);
|
||||
const matchedCategory = category.value === "all" || item.category === category.value;
|
||||
const matchedStatus = status.value === "all" || item.status === status.value;
|
||||
return matchedText && matchedCategory && matchedStatus;
|
||||
});
|
||||
});
|
||||
|
||||
function handleFilterChange(change: DropdownFilterChange): void {
|
||||
lastChange.value = `${change.key} = ${String(change.value)}`;
|
||||
if (change.key === "category") {
|
||||
category.value = String(change.value);
|
||||
}
|
||||
if (change.key === "status") {
|
||||
status.value = String(change.value);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.demo {
|
||||
.stage {
|
||||
height: 20rem;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: .75rem;
|
||||
background: var(--vp-c-bg-alt);
|
||||
|
||||
.tui-page-content {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.pull-refresh {
|
||||
padding-top: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.list-body {
|
||||
margin: 0 1rem 1rem;
|
||||
|
||||
.empty {
|
||||
margin: 0;
|
||||
padding: 2rem 0;
|
||||
font-size: .8125rem;
|
||||
text-align: center;
|
||||
color: var(--vp-c-text-3);
|
||||
}
|
||||
}
|
||||
|
||||
.log {
|
||||
margin: .75rem 0 0;
|
||||
font-size: .8125rem;
|
||||
color: var(--vp-c-text-3);
|
||||
|
||||
code {
|
||||
font-weight: 600;
|
||||
color: var(--vp-c-brand-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user