From ffbed33d0cdc00ff1699bbc608c6d24f88157706 Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期六, 12 十月 2024 15:52:39 +0800
Subject: [PATCH] 指标管理新增对话操作

---
 src/views/project/yw/systemManage/metricMgr/MetricMgr.vue |   79 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/src/views/project/yw/systemManage/metricMgr/MetricMgr.vue b/src/views/project/yw/systemManage/metricMgr/MetricMgr.vue
index bea1711..67d2bdd 100644
--- a/src/views/project/yw/systemManage/metricMgr/MetricMgr.vue
+++ b/src/views/project/yw/systemManage/metricMgr/MetricMgr.vue
@@ -96,28 +96,48 @@
 										"
 									></i>
 								</el-tooltip>
+								<el-tooltip effect="dark" content="瀵硅瘽娴嬭瘯" placement="top">
+									<i class="ywifont ywicon-ceshi !text-[20px] text-blue-400 cursor-pointer" @click="openChatTest(scope.row)"></i>
+								</el-tooltip>
 							</div>
 						</template>
 					</el-table-column>
 				</el-table>
+				<div
+					v-if="chatTestIsShow"
+					ref="draggableChatRef"
+					:style="style"
+					class="fixed z-50 w-[700px] h-[800px] flex flex-col bg-[rgb(239,244,253)] right-0 bottom-0 rounded-lg"
+				>
+					<div ref="chatDragHandlerRef" class="flex-0">
+						<div class="flex items-center justify-between py-2 px-4">
+							<div class="font-bold cursor-move">
+								WI姘村姟鏅鸿兘绠″鈥斺�斻�恵{ chatTestMapRow?.title }}銆戞祴璇�
+								<!-- <img src="/static/images/logo/logo-mini.svg" width="10" height="10" /> -->
+							</div>
+							<i class="ywifont ywicon-guanbi font-[10px] font-bold cursor-pointer" @click="closeChatTest"></i>
+						</div>
+					</div>
+					<Chat ref="chatRef" class="flex-auto px-2" :questionApi="questionAi"> </Chat>
+				</div>
 			</div>
 		</template>
-
-		<!-- <OptDlg v-model="optDlgIsShow" :item="optDlgMapRow" @insert="insertOpt" @update="updateOpt" :groupId="currentListID"></OptDlg> -->
-		<!-- <MetricPrompt v-model="infoDlgIsShow" :metricItem="infoDlgMapRow"></MetricPrompt>
-		<MetricName v-model="metricNameIsShow" :metricItem="metricNameMapRow"></MetricName> -->
 	</HMContainer>
 </template>
 
 <script setup lang="ts">
-import { computed, onMounted, ref } from 'vue';
+import { useDraggable } from '@vueuse/core';
+import axios, { CancelTokenSource } from 'axios';
+import { computed, nextTick, onMounted, ref } from 'vue';
 import { useRouter } from 'vue-router';
 import { SupervisorPublished } from '../../lowCode/sqlAmis/types';
 import * as agentGroupApi from '/@/api/ai/agentGroup';
 import * as metricApi from '/@/api/metrics';
+import Chat from '/@/components/chat/Chat.vue';
 import HMContainer from '/@/components/layout/HMContainer.vue';
 import { usePageDisplay } from '/@/hooks/usePageDisplay';
 import { useQueryTable } from '/@/hooks/useQueryTable';
+import { useCompRef } from '/@/utils/types';
 import { convertListToTree } from '/@/utils/util';
 import { eMetrics_Ops, eMetrics_Ops_Color } from '/@/views/types/metrics';
 const router = useRouter();
@@ -182,8 +202,55 @@
 	}
 );
 //#endregion
-//#region ====================== 鎿嶄綔鎸夐挳 ======================
+//#region ====================== 鎿嶄綔鎸夐挳  娴嬭瘯 ======================
 const publishStatusChange = async (status: SupervisorPublished, id: number, index: number) => {};
+const chatRef = useCompRef(Chat);
+const chatTestMapRow = ref(null);
+const chatTestIsShow = ref(false);
+const openChatTest = (row) => {
+	chatTestMapRow.value = row;
+	chatTestIsShow.value = true;
+	nextTick(() => {
+		chatRef.value.clear();
+		// setTimeout(() => {
+		// 	chatRef.value.autoSend(row.title);
+		// }, 30);
+	});
+};
+
+const closeChatTest = () => {
+	chatTestMapRow.value = null;
+	chatTestIsShow.value = false;
+};
+
+const draggableChatRef = ref<HTMLElement | null>(null);
+const chatDragHandlerRef = ref<HTMLDivElement>(null);
+const chatDragContainerRef = ref<HTMLDivElement>(null);
+
+// `style` will be a helper computed for `left: ?px; top: ?px;`
+const { x, y, style } = useDraggable(draggableChatRef, {
+	handle: chatDragHandlerRef,
+	initialValue: {
+		x: document.body.clientWidth / 2 - 350,
+		y: document.body.clientHeight / 2 - 400,
+	},
+});
+
+const questionAi = async (text, sourceObj: { source: CancelTokenSource }) => {
+	const currentSource = axios.CancelToken.source();
+	sourceObj.source = currentSource;
+	const res = await metricApi.checkMetricAgentValidateByPost(
+		{
+			agent_id: chatTestMapRow.value.id,
+			question: text,
+		},
+		{
+			loading: false,
+			cancelToken: currentSource.token,
+		}
+	);
+	return res;
+};
 //#endregion
 onMounted(() => {
 	initThemeDomainData();

--
Gitblit v1.9.3