From e7d76d371384bf0fb9a8638ad1919be0902127ec Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期一, 22 七月 2024 11:51:04 +0800
Subject: [PATCH] fix: 修改模板列表一直调用接口的问题

---
 src/components/drawer/CustomDrawer.vue |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/components/drawer/CustomDrawer.vue b/src/components/drawer/CustomDrawer.vue
index 5909c6a..f6bf61f 100644
--- a/src/components/drawer/CustomDrawer.vue
+++ b/src/components/drawer/CustomDrawer.vue
@@ -129,11 +129,10 @@
 
 <script setup lang="ts">
 import { Search } from '@element-plus/icons-vue';
-import { computed, onMounted, reactive, ref, toRefs, watch } from 'vue';
+import { computed, onMounted, reactive, ref, watch } from 'vue';
 import { getSelectSample, getUserTemplateList } from '/@/api/ai/chat';
 import { useSearch } from '/@/hooks/useSearch';
 import { activeRoomId, activeSampleId, setRoomConfig } from '/@/stores/chatRoom';
-import emitter from '/@/utils/mitt';
 import { debounce } from '/@/utils/util';
 let state = reactive({
 	tabNameList: [
@@ -217,6 +216,10 @@
 	inputInstruct: '', //鍙慨鏀规寚浠�
 	exampleRandomContent: [],
 	exampleContent: [],
+	listSampleLoading: false,
+	listInstructLoading: false,
+	listSampleExpand: false,
+	listInstructExpand: false,
 });
 const instructContentList = ref([]); //鎸囦护鍒楄〃
 const exampleList = ref([]); //绀轰緥鍒楄〃
@@ -227,15 +230,15 @@
 
 const emit = defineEmits(['updateChatInput']);
 const rightBox = computed(() => (isShow.value ? 354 : 0));
-onMounted(() => {
-	getSelectListSample();
-	getUserTemplate();
-});
+onMounted(() => {});
 
 //鑾峰彇妯$増鍒楄〃
 const getSelectListSample = async () => {
+	state.listSampleLoading = true;
 	const res = await getSelectSample({
 		section_b_id: '',
+	}).finally(() => {
+		state.listSampleLoading = false;
 	});
 	// console.log(res, 63);
 	state.exampleRandomContent = res.samples;
@@ -250,6 +253,7 @@
 	});
 	exampleList.value = res.samples;
 	state.exampleContent = array;
+	state.listSampleExpand = true;
 };
 //闅忔満鐢熸垚棰滆壊
 const randomHexColor = () => {
@@ -264,12 +268,16 @@
 };
 //鑾峰彇鐢ㄦ埛妯℃澘
 const getUserTemplate = async () => {
-	const res = await getUserTemplateList();
+	state.listInstructLoading = true;
+	const res = await getUserTemplateList().finally(() => {
+		state.listInstructLoading = false;
+	});
 	instructContentList.value = res.templates;
 };
 //鍒囨崲鍒版寚浠�/鎻愰棶
 const handleTabClick = (item) => {
 	state.activeName = item.ID;
+	getTableData();
 };
 //鏍囩鐐瑰嚮浜嬩欢(鎻愰棶绀轰緥)
 const handleLabelClick = (item) => {
@@ -290,6 +298,22 @@
 };
 const toggleShow = () => {
 	isShow.value = !isShow.value;
+	if (!isShow.value) {
+		getTableData();
+	}
+};
+const getTableData = () => {
+	console.log('馃殌 ~ state.activeName:', state.activeName);
+	if (state.activeName == 1) {
+		if (state.listSampleExpand) return;
+		getSelectListSample();
+		state.listSampleExpand = true;
+	}
+	if (state.activeName == 2) {
+		if (state.listInstructExpand) return;
+		getUserTemplate();
+		state.listInstructExpand = true;
+	}
 };
 //鍏抽棴楂樼骇绀轰緥
 const handleCloseTemplate = () => {
@@ -339,6 +363,7 @@
 	}
 );
 //#endregion
+defineExpose({ getTableData });
 </script>
 <style scoped lang="scss">
 .exampleSlide {

--
Gitblit v1.9.3