|
@@ -0,0 +1,100 @@
|
|
|
+<template>
|
|
|
+ <div :style="style">
|
|
|
+ <div>
|
|
|
+ <el-input v-model="inputValue" @input="handelInput">
|
|
|
+ <template #append>
|
|
|
+ <el-button icon="RefreshLeft" @click="refreshClick">刷新</el-button>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </div>
|
|
|
+ <div style="flex: 1; height: 0; overflow: auto">
|
|
|
+ <slot :data="tempData" :handelFilter="handelFilter"/>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import {computed, ref, PropType} from 'vue'
|
|
|
+import XEUtils from "xe-utils";
|
|
|
+import {ElInput, ElButton} from "element-plus";
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ width: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: '100%'
|
|
|
+ },
|
|
|
+ height: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: '100%'
|
|
|
+ },
|
|
|
+ remoteMethod: {
|
|
|
+ type: Function as PropType<Promise<any> | null>,
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ type: [Array],
|
|
|
+ default: null
|
|
|
+ },
|
|
|
+ treeRef: {
|
|
|
+ type: [Object],
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const emits = defineEmits(['update:data'])
|
|
|
+
|
|
|
+const inputValue = ref('')
|
|
|
+const treeData = ref([])
|
|
|
+const slots = useSlots()
|
|
|
+const treeRef = ref()
|
|
|
+
|
|
|
+const tempData = computed({
|
|
|
+ get() {
|
|
|
+ return props.data === null ? treeData.value : props.data
|
|
|
+ },
|
|
|
+ set(val: any[]) {
|
|
|
+ if (props.data === null) {
|
|
|
+ treeData.value = val
|
|
|
+ } else {
|
|
|
+ emits('update:data', val)
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+function refreshClick() {
|
|
|
+ if (props.remoteMethod === null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // @ts-ignore
|
|
|
+ (props!.remoteMethod() as Promise<any>).then(res => {
|
|
|
+ tempData.value = res
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function handelInput(val) {
|
|
|
+ props.treeRef!.filter(val)
|
|
|
+}
|
|
|
+
|
|
|
+function handelFilter(val, data) {
|
|
|
+ return data.name.include(val)
|
|
|
+}
|
|
|
+
|
|
|
+const style = computed(() => {
|
|
|
+ return {
|
|
|
+ width: XEUtils.addUnit(props.width),
|
|
|
+ height: XEUtils.addUnit(props.height),
|
|
|
+ display: 'flex',
|
|
|
+ flexFlow: 'column nowrap'
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ console.log(slots)
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+
|
|
|
+</style>
|