|
@@ -0,0 +1,98 @@
|
|
|
+<template>
|
|
|
+ <div title="">
|
|
|
+ <a-select v-model:value="showValue" showSearch :filterOption="filterOption" @change="handleChange">
|
|
|
+ <a-select-option v-for="item in option" :key="item.id" :value="item.id">{{ item.label }}</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts">
|
|
|
+ import { computed, defineComponent,ref ,onMounted,watch,emit} from 'vue';
|
|
|
+ export default defineComponent({
|
|
|
+ name: 'JSelect',
|
|
|
+ props:{
|
|
|
+ value:{
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ getOptionUrl: {
|
|
|
+ default: null,
|
|
|
+ },
|
|
|
+ showField:{
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ },
|
|
|
+ emits: ['options-change', 'change', 'input', 'update:value'],
|
|
|
+ setup(props,{ emit}) {
|
|
|
+ const showValue = ref<any[]>(props.value);
|
|
|
+ var option = ref([])
|
|
|
+ watch(
|
|
|
+ () => props.value,
|
|
|
+ (val) => {
|
|
|
+ if (!val) {
|
|
|
+ showValue.value = [];
|
|
|
+ } else {
|
|
|
+ showValue.value = props.value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ onMounted(() => {
|
|
|
+ getOptions()
|
|
|
+ });
|
|
|
+ // onChange 事件
|
|
|
+ function handleChange(event) {
|
|
|
+ emit('change',event );
|
|
|
+ emit('update:value',event);
|
|
|
+ }
|
|
|
+ function filterOption(input, option) {
|
|
|
+ //update-begin-author:taoyan date:2022-11-8 for: issues/218 所有功能表单的下拉搜索框搜索无效
|
|
|
+ let value = '', label = '';
|
|
|
+ try {
|
|
|
+ value = option.value;
|
|
|
+ label = option.children()[0].children;
|
|
|
+ }catch (e) {
|
|
|
+ console.log('获取下拉项失败', e)
|
|
|
+ }
|
|
|
+ let str = input.toLowerCase();
|
|
|
+ return value.toLowerCase().indexOf(str) >= 0 || label.toLowerCase().indexOf(str) >= 0;
|
|
|
+ //update-end-author:taoyan date:2022-11-8 for: issues/218 所有功能表单的下拉搜索框搜索无效
|
|
|
+ }
|
|
|
+ async function getOptions(){
|
|
|
+ let params ={pageSize:-1}
|
|
|
+ option.value = (await props.getOptionUrl(params)).records
|
|
|
+ const arr = props.showField.split("+")
|
|
|
+ option.value.map(item=>{
|
|
|
+ item.label = ''
|
|
|
+ arr.map(event=>{
|
|
|
+ for (let key in item) {
|
|
|
+ if (key == event) {
|
|
|
+ if(item.label == ''){
|
|
|
+ item.label += '('+item[key]+')'
|
|
|
+ }else{
|
|
|
+ item.label +=item[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ handleChange,
|
|
|
+ filterOption,
|
|
|
+ option,
|
|
|
+ showValue
|
|
|
+ };
|
|
|
+ },
|
|
|
+ })
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less">
|
|
|
+ // 关闭动画,防止滚动时动态赋值出现问题
|
|
|
+ .j-vxe-checkbox.no-animation {
|
|
|
+ .ant-checkbox-inner,
|
|
|
+ .ant-checkbox-inner::after {
|
|
|
+ transition: none !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|