wms-antdvue/.svn/pristine/52/52fedb558dc2dfd2421fc404a2fdb6d110e52fcf.svn-base
2024-11-07 16:33:03 +08:00

77 lines
2.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<div class="n-layout-page-header">
<a-card :bordered="false" title="选择器">
扩展选择器组件用于各种表单选择器简化使用内置缓存可对相同的数据减少http请求也可手动刷新数据源
</a-card>
</div>
<a-card :bordered="false" class="mt-4 proCard">
<a-alert message="基础使用" type="info">
<template #description>自动加载数据首次加载缓存之后同一个KEY不在获取新数据</template>
</a-alert>
<div class="mt-4">
<a-space align="center">
<BasicSelect
ref="basicSelectRef"
v-model:value="selectValue"
:request="loadSelectData"
@update:value="handleUpdateValue"
cache
cacheKey="SELECT_CLASSIFY"
/>
<a-button @click="setSelectData">设置选中值</a-button>
<a-button @click="getSelectValue">获取选中值</a-button>
<a-button @click="getSelectData">获取数据源</a-button>
<a-button @click="refreshSelectData">刷新数据</a-button>
</a-space>
</div>
</a-card>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { getClassifyList } from '@/api/select/select';
import { BasicSelect } from '@/components/Select';
import { message } from 'ant-design-vue';
const selectValue = ref('hot');
const basicSelectRef = ref();
const params = {
type: 1,
};
async function loadSelectData(res) {
//这里可以进行数据转换处理
return (await getClassifyList({ ...res, ...params })).map((item, index) => {
return {
...item,
index,
};
});
}
function handleUpdateValue(value, option) {
message.info('value: ' + JSON.stringify(value));
message.info('option: ' + JSON.stringify(option));
}
function refreshSelectData() {
basicSelectRef?.value.fetch();
}
function setSelectData() {
selectValue.value = 'new';
}
function getSelectValue() {
message.info('value: ' + JSON.stringify(selectValue.value));
}
function getSelectData() {
message.info('Data: ' + JSON.stringify(basicSelectRef?.value.getData()));
}
</script>
<style lang="less"></style>