Explorar o código

reactor:封装选择热点组件;

zhangchong hai 1 ano
pai
achega
9a7d8033e5
Modificáronse 1 ficheiros con 31 adicións e 27 borrados
  1. 31 27
      src/components/Hotspot/index.vue

+ 31 - 27
src/components/Hotspot/index.vue

@@ -60,7 +60,7 @@
 import { reactive, ref, watch, computed } from 'vue';
 import { hotSpotSearch, hotSpotType } from '@/api/business/order';
 import { removeDuplicate } from '@/utils/arrayOperation';
-import {throttle} from "@/utils/tools";
+import { throttle } from '@/utils/tools';
 
 const props = defineProps({
 	modelValue: {
@@ -126,33 +126,37 @@ const loadNode = async (node: any, resolve: any) => {
 	}
 };
 
-watch(filterText,  throttle((val) => {
-	if (val) {
-		lazyShow.value = false; //当输入框有值时关闭懒加载
-		loading.value = true;
-		hotSpotSearch(val)
-			.then((res) => {
-				//获取后端搜索的数据 	//selectMacTree是我自己的后端接口,你们换成自己的
-				state.hotSpotData.length = 0;
-				state.hotSpotData = res.result ?? [];
+watch(
+	filterText,
+	throttle((val) => {
+		if (val) {
+			lazyShow.value = false; //当输入框有值时关闭懒加载
+			loading.value = true;
+			hotSpotSearch(val)
+				.then((res) => {
+					//获取后端搜索的数据 	//selectMacTree是我自己的后端接口,你们换成自己的
+					state.hotSpotData.length = 0;
+					state.hotSpotData = res.result ?? [];
 
-				treeRef.value!.filter(val);
-				if (props.showCheckbox && state.checkedKeys.length) {
-					treeRef.value.setCheckedKeys(state.checkedKeys);
-				}
-        if(props.modelValue){
-          console.log(props.modelValue,treeRef.value.setCurrentKey)
-          treeRef.value.setCurrentKey(props.modelValue);
-        }
-				loading.value = false;
-			})
-			.catch((e) => {
-				loading.value = false;
-			});
-	} else if (val == '' || val == ' ' || val == null) {
-		lazyShow.value = true; // 懒加载树显示
-	}
-}, 300));
+					treeRef.value!.filter(val);
+					if (props.showCheckbox && state.checkedKeys.length) {
+						treeRef.value.setCheckedKeys(state.checkedKeys);
+					}
+					if (props.modelValue) {
+						setTimeout(() => {
+							treeRef.value.setCurrentKey(props.modelValue);
+						}, 100);
+					}
+					loading.value = false;
+				})
+				.catch((e) => {
+					loading.value = false;
+				});
+		} else if (val == '' || val == ' ' || val == null) {
+			lazyShow.value = true; // 懒加载树显示
+		}
+	}, 300)
+);
 
 const filterNode = (value: string, data: any) => {
 	if (!value) return true;