|
@@ -0,0 +1,118 @@
|
|
|
+<script lang="ts">
|
|
|
+import { tableSelectProps, tableSelectEmits } from './props'
|
|
|
+import { ElPopover } from 'element-plus'
|
|
|
+export default defineComponent({
|
|
|
+ name: 'FsTableSelect',
|
|
|
+ props: tableSelectProps,
|
|
|
+ emits: tableSelectEmits,
|
|
|
+ setup(props, { emit }) {
|
|
|
+ // 是否显示
|
|
|
+ const visible = ref(false)
|
|
|
+ // popover 实例
|
|
|
+ const popoverRef = ref<InstanceType<typeof ElPopover>>()
|
|
|
+
|
|
|
+ // 是否未选中
|
|
|
+ const isEmpty = computed<boolean>(() => {
|
|
|
+ if (!props.multiple) {
|
|
|
+ return props.moduleValue == null || props.moduleValue === ''
|
|
|
+ }
|
|
|
+ return !Array.isArray(props.moduleValue) || !props.moduleValue.length
|
|
|
+ })
|
|
|
+
|
|
|
+ // 是否需要清空图标
|
|
|
+ const closeEnable = computed<boolean>(() => {
|
|
|
+ return props.clearable && !props.disabled && !isEmpty.value
|
|
|
+ })
|
|
|
+
|
|
|
+ /* 打开弹窗 */
|
|
|
+ const onFocus = (e: FocusEvent) => {
|
|
|
+ if (props.automaticDropdown && !visible.value) {
|
|
|
+ visible.value = true
|
|
|
+ }
|
|
|
+ emit('focus', e)
|
|
|
+ }
|
|
|
+
|
|
|
+ const tableData = computed(() => {
|
|
|
+ return props.tableConfig?.datasource.then(res => {
|
|
|
+ return res
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ /* 关闭弹窗 */
|
|
|
+ const onBlur = (e: FocusEvent) => {
|
|
|
+ emit('blur', e)
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 清除事件 */
|
|
|
+ const onClear = () => {
|
|
|
+ emit('clear')
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ popoverRef,
|
|
|
+ visible,
|
|
|
+ tableData,
|
|
|
+ closeEnable,
|
|
|
+ onFocus,
|
|
|
+ onBlur,
|
|
|
+ onClear
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <el-popover
|
|
|
+ ref="popoverRef"
|
|
|
+ v-model:visible="visible"
|
|
|
+ :placement="placement"
|
|
|
+ :width="popperWidth"
|
|
|
+ :popper-class="popperClass"
|
|
|
+ :popper-options="popperOptions"
|
|
|
+ trigger="click"
|
|
|
+ teleported
|
|
|
+ >
|
|
|
+ <template #reference>
|
|
|
+ <div class="table-select-container">
|
|
|
+ <el-input
|
|
|
+ :size="size"
|
|
|
+ :disabled="disabled"
|
|
|
+ :placeholder="placeholder"
|
|
|
+ :readonly="true"
|
|
|
+ :validateEvent="false"
|
|
|
+ :autocomplete="autocomplete"
|
|
|
+ :modelValue="moduleValue"
|
|
|
+ @focus="onFocus"
|
|
|
+ @blur="onBlur"
|
|
|
+ >
|
|
|
+ <template v-if="$slots.prefix" #prefix>
|
|
|
+ <slot name="prefix"></slot>
|
|
|
+ </template>
|
|
|
+ <template #suffix>
|
|
|
+ <div class="select-suffix">
|
|
|
+ <ElIcon v-if="closeEnable" class="select-clear" @click.stop="onClear">
|
|
|
+ <slot name="clearIcon">
|
|
|
+ <CircleClose />
|
|
|
+ </slot>
|
|
|
+ </ElIcon>
|
|
|
+ <ElIcon>
|
|
|
+ <slot name="suffixIcon" :visible="visible">
|
|
|
+ <ArrowDown />
|
|
|
+ </slot>
|
|
|
+ </ElIcon>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <vxe-table :data="tableData">
|
|
|
+ <vxe-column v-for="(item, index) in tableConfig?.column" :key="index" v-bind="item"></vxe-column>
|
|
|
+ </vxe-table>
|
|
|
+ </el-popover>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+.table-select-container {
|
|
|
+ width: 100%;
|
|
|
+}
|
|
|
+</style>
|