|
@@ -1,13 +1,69 @@
|
|
|
<script setup lang="ts">
|
|
|
-import type { TableSelectProps } from './props'
|
|
|
-import { tableSelectEmits } from './props'
|
|
|
import { ElPopover } from 'element-plus'
|
|
|
import type { VxeTableInstance } from 'vxe-table'
|
|
|
+import type { PopoverProps, TagProps } from 'element-plus'
|
|
|
+
|
|
|
+interface TableColumn {
|
|
|
+ // 类型
|
|
|
+ type?: string
|
|
|
+ // 列名
|
|
|
+ field?: string
|
|
|
+ // 表格宽度
|
|
|
+ width?: number | string
|
|
|
+ // 对齐方式
|
|
|
+ align?: string
|
|
|
+ // 标题
|
|
|
+ title?: string
|
|
|
+ // 插槽
|
|
|
+ slot?: string
|
|
|
+}
|
|
|
+
|
|
|
+interface TableConfig {
|
|
|
+ // 表格列
|
|
|
+ column?: Array<TableColumn>
|
|
|
+ // 表格数据
|
|
|
+ request: (...args: any) => Promise<any>
|
|
|
+ // 每页显示条数
|
|
|
+ pageSize?: Number
|
|
|
+}
|
|
|
+
|
|
|
+interface TableSelectProps {
|
|
|
+ // 绑定值
|
|
|
+ modelValue: any
|
|
|
+ // 是否多选
|
|
|
+ multiple?: boolean
|
|
|
+ // 是否禁用
|
|
|
+ disabled?: boolean
|
|
|
+ // 是否支持清除
|
|
|
+ clearable?: boolean
|
|
|
+ // value 的属性名
|
|
|
+ valueKey?: string
|
|
|
+ // label 的属性名
|
|
|
+ labelKey?: string
|
|
|
+ // 回显数据,用于后端分页显示
|
|
|
+ initValue?: any
|
|
|
+ // 气泡位置
|
|
|
+ placement?: PopoverProps['placement']
|
|
|
+ // 占位符
|
|
|
+ placeholder?: string
|
|
|
+ // popover 宽度
|
|
|
+ popperWidth?: number | string
|
|
|
+ // 自定义 popper 类名
|
|
|
+ popperClass?: string
|
|
|
+ // popper 配置项
|
|
|
+ popperOptions?: PopoverProps['popperOptions']
|
|
|
+ // 表格配置
|
|
|
+ tableConfig?: TableConfig
|
|
|
+ // tag 类型
|
|
|
+ tagType?: TagProps['type']
|
|
|
+ // 最多显示多少个tag
|
|
|
+ maxTagCount?: number
|
|
|
+ // 自定义数据转换方法
|
|
|
+ transformData?: Function
|
|
|
+}
|
|
|
|
|
|
-const emits = defineEmits(tableSelectEmits)
|
|
|
const props = withDefaults(defineProps<TableSelectProps>(), {
|
|
|
modelValue: '',
|
|
|
- size: 'default',
|
|
|
clearable: true,
|
|
|
valueKey: 'id',
|
|
|
labelKey: 'name',
|
|
@@ -17,6 +73,7 @@ const props = withDefaults(defineProps<TableSelectProps>(), {
|
|
|
tagType: 'info',
|
|
|
maxTagCount: 5
|
|
|
})
|
|
|
+const emits = defineEmits(['update:modelValue', 'change', 'clear', 'item-clear', 'focus', 'blur'])
|
|
|
|
|
|
/* 格式化提交数据 */
|
|
|
const transformData = (value: any) => {
|
|
@@ -182,13 +239,13 @@ const tableDone = () => {
|
|
|
|
|
|
/* 请求数据 */
|
|
|
const request = (where?: any) => {
|
|
|
- if (typeof props.tableConfig?.datasource === 'function') {
|
|
|
+ if (typeof props.tableConfig?.request === 'function') {
|
|
|
loading.value = true
|
|
|
if (where && where.pageNo) {
|
|
|
pageNo.value = where.pageNo
|
|
|
}
|
|
|
props.tableConfig
|
|
|
- .datasource({
|
|
|
+ .request({
|
|
|
pageNo: pageNo.value,
|
|
|
pageSize: props.tableConfig.pageSize,
|
|
|
...where
|
|
@@ -205,7 +262,7 @@ const request = (where?: any) => {
|
|
|
loading.value = false
|
|
|
})
|
|
|
} else {
|
|
|
- console.warn('tableConfig.datasource 必须为 Promise')
|
|
|
+ console.warn('tableConfig.request 必须为 Promise')
|
|
|
}
|
|
|
}
|
|
|
request()
|
|
@@ -260,7 +317,6 @@ defineExpose({
|
|
|
<template #reference>
|
|
|
<div class="table-select-container" :class="{ 'is-multiple': multiple, 'is-visible': visible }">
|
|
|
<el-input
|
|
|
- :size="size"
|
|
|
:disabled="disabled"
|
|
|
:placeholder="multiple && !isEmpty ? '' : placeholder"
|
|
|
:readonly="true"
|
|
@@ -279,7 +335,7 @@ defineExpose({
|
|
|
<CircleClose />
|
|
|
</slot>
|
|
|
</ElIcon>
|
|
|
- <ElIcon class="select-down" :class="{ 'select-down-rotate': visible }">
|
|
|
+ <ElIcon class="select-down" :class="{ 'select-down-rotate': visible }" v-else>
|
|
|
<slot name="suffixIcon">
|
|
|
<ArrowDown />
|
|
|
</slot>
|
|
@@ -358,11 +414,9 @@ defineExpose({
|
|
|
border-radius: 50%;
|
|
|
overflow: hidden;
|
|
|
z-index: 2;
|
|
|
- color: #fff;
|
|
|
- background-color: var(--el-color-info-light-3);
|
|
|
opacity: 0;
|
|
|
&:hover {
|
|
|
- background-color: var(--el-color-info);
|
|
|
+ opacity: 100;
|
|
|
}
|
|
|
}
|
|
|
.select-down {
|