From 68994735dddb8d2be65149aa605ec0ac12e8775a Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期二, 10 九月 2024 15:26:59 +0800 Subject: [PATCH] 未滑动到底部 bug;多次点开对话测试 bug;数据对接SQL为选项之一 --- src/components/chat/Chat.vue | 21 +- src/components/chat/chatComponents/summaryCom/components/amisPage/AmisPage.vue | 7 src/components/chat/hooks/useScrollToBottom.ts | 18 + src/views/project/yw/dataManage/knowledge/Knowledge.vue | 10 src/components/amis/AMISRenderer.vue | 412 ++++++++++++++++++++++----------------------- src/utils/request.ts | 3 src/utils/mitt.ts | 1 src/views/project/yw/lowCode/sqlAmis/edit/types.ts | 7 src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue | 12 + src/types/mitt.d.ts | 4 src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue | 44 ++-- 11 files changed, 287 insertions(+), 252 deletions(-) diff --git a/src/components/amis/AMISRenderer.vue b/src/components/amis/AMISRenderer.vue index edc1dd5..f08953a 100644 --- a/src/components/amis/AMISRenderer.vue +++ b/src/components/amis/AMISRenderer.vue @@ -1,16 +1,40 @@ -<template><div class="my-amis-scope">鍔犺浇涓�...</div></template> +<template><div ref="amisRootRef" class="my-amis-scope">鍔犺浇涓�...</div></template> -<script lang="ts"> -import { accessSessionKey, handleNoAuth } from '/@/utils/request'; +<script setup lang="ts"> import { MAIN_URL } from '/@/constants'; import router from '/@/router/index'; - -import { Local } from '/@/utils/storage'; - +import { accessSessionKey, handleNoAuth } from '/@/utils/request'; // 鍙互涓嶅紩鐢�, 濡傛灉浣犱笉鎯宠浠讳綍杈呭姪绫绘牱寮忕殑璇� (姣斿 `m-t-xs` 杩欑) // https://aisuda.bce.baidu.com/amis/zh-CN/style/index // import 'amis/sdk/helper.css'; import qs from 'qs'; +import { onMounted, onUnmounted, reactive, ref, shallowRef, watch } from 'vue'; +const amisRootRef = ref<HTMLDivElement>(null); +import { Local } from '/@/utils/storage'; + +const props = defineProps({ + schema: { + type: Object, + default: () => ({ + type: 'page', + body: 'Hello World!', + }), + }, + locals: { + type: Object, + default: () => ({}), + }, + props: { + type: Object, + default: () => ({}), + }, + env: { + type: Object, + default: () => ({}), + }, +}); + +const emit = defineEmits(['ready']); function loadScript(callback) { window.eventList.amisSdkJsPromise @@ -20,16 +44,6 @@ .catch((error) => { callback(error); }); -} - -function loadStyles(styles) { - for (const path of styles) { - const style = document.createElement('link'); - style.setAttribute('rel', 'stylesheet'); - style.setAttribute('type', 'text/css'); - style.setAttribute('href', path); - document.head.appendChild(style); - } } function loadSDK() { @@ -51,204 +65,174 @@ }); } -export default { - name: 'AMISRenderer', - components: {}, - props: { - schema: { - type: Object, - default: () => ({ - type: 'page', - body: 'Hello World!', - }), - }, - locals: { - type: Object, - default: () => ({}), - }, - props: { - type: Object, - default: () => ({}), - }, - env: { - type: Object, - default: () => ({}), - }, - }, - data() { - return { - // 杩欓噷闈㈢殑鏁版嵁鎵�鏈� amis 椤甸潰閮藉彲浠ヨ幏鍙栧埌 - // 鍙互鐢ㄦ潵鏀句竴涓嬪叕鍏辨暟鎹紝姣斿鐢ㄦ埛淇℃伅绛� - // 涓嶈鏀惧彈鎺ф暟鎹紝鍙楁帶鏁版嵁搴旇閫氳繃 data 涓嬪彂 - context: { - siteName: 'AMIS DEMO', - }, - get location() { - const current = router.currentRoute.value; - return { - pathname: current?.path, - hash: current?.hash, - query: current?.query, - search: `?${qs.stringify(current.query)}`, - }; - // return 'localtion' - }, - loading: false, - amisInstance: null, - unmounted: false, - }; - }, +const context = reactive({ + siteName: 'AMIS DEMO', +}); +const current = router.currentRoute.value; - watch: { - locals: function () { - this.updateProps(); - }, - props: function () { - this.updateProps(); - }, - $route: function () { - this.updateProps(); - }, - }, - async mounted() { - try { - this.loading = true; - await loadSDK(); - } finally { - this.loading = false; - } - if (this.unmounted) { - return; - } - - const scoped = amisRequire('amis/embed'); - const { normalizeLink } = amisRequire('amis'); - const instance = scoped.embed( - this.$el, - this.schema, - { - data: { - ...this.locals, - }, - context: this.context, - location: this.location, - - // todo 涓嬪彂 location 瀵硅薄 - ...this.props, - }, - { - requestAdaptor(api) { - const accessSession = Local.get(accessSessionKey); - if (accessSession) { - // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� - api.headers['hswatersession'] = accessSession; - } else { - handleNoAuth(); - } - api.url = `${MAIN_URL}${api.url}`; - return api; - }, - // 鍏ㄥ眬 api 閫傞厤鍣ㄣ�� - // 鍙﹀鍦� amis 閰嶇疆椤逛腑鐨� api 涔熷彲浠ラ厤缃�傞厤鍣紝閽堝鏌愪釜鐗瑰畾鎺ュ彛鍗曠嫭澶勭悊銆� - responseAdaptor(api, payload, query, request, response) { - // { - // "json_ok": true, - // "sections": [ - // { - // "section_id": "knowledge_base", - // "section_name": "姘村姟鐭ヨ瘑搴�", - // "section_title": "鎷ユ湁姘村姟琛屼笟鐩稿叧鐨勯�氱敤鐭ヨ瘑锛屽寘鎷細娉曞緥娉曡銆佽璁¤鑼冦�佺粰鎺掓按鐩稿叧鐭ヨ瘑绛夌瓑" - // }, - // { - // "section_id": "office_assistant", - // "section_name": "鍔炲叕鍔╂墜", - // "section_title": "鍔炲叕鍔╂墜鑳藉杈呭姪鍐欎細璁�氱煡銆佽鍋囨潯銆佸伐浣滄�荤粨銆丳PT绛夊伐浣溿��" - // }, - // { - // "section_id": "customer_service", - // "section_name": "瀹㈡埛鏈嶅姟", - // "section_title": "閽堝姘村姟浼佷笟瀵瑰瀹㈡埛鏈嶅姟鐩稿叧鐨勫唴瀹癸紝鍖呮嫭锛氭妱琛ㄣ�佸紑璐︺�佹敹璐癸紝浠ュ強鐑嚎鐩稿叧" - // }, - // { - // "section_id": "network_operation", - // "section_name": "绠$綉杩愯", - // "section_title": "閽堝姘村姟浼佷笟绠$綉杩愯涓庣淮鎶ょ鐞嗐�佹按璐ㄧ鐞嗙瓑鐩稿叧" - // }, - // { - // "section_id": "waterworks_operation", - // "section_name": "姘村巶杩愯", - // "section_title": "閽堝姘村姟浼佷笟姘村巶杩愭棩甯歌繍钀ョ鐞嗘湇鍔★紝鍖呮嫭锛氭按鍘傚伐鑹烘祦绋嬨�佹按娉佃繍琛岃皟搴�" - // } - // ] - // } - return payload; - }, - // 瑕嗙洊 amis env - // 鍙傝�� https://aisuda.bce.baidu.com/amis/zh-CN/docs/start/getting-started#sdk - jumpTo: (to, action) => { - return; - if (to === 'goBack') { - return router.go(-1); - } - - to = normalizeLink(to, this.location); - - if (action?.actionType === 'url') { - action.blank === false ? router.push(to) : window.open(to); - return; - } - - // 涓昏鏄敮鎸� nav 涓殑璺宠浆 - if (action && to && action.target) { - window.open(to, action.target); - return; - } - - if (/^https?:\/\//.test(to)) { - window.location.replace(to); - } else { - router.push(to); - } - }, - - updateLocation: (location, replace) => { - // 绂佹璺宠浆 - return; - if (location === 'goBack') { - return router.go(-1); - } - - location = normalizeLink(location, this.location); - replace ? router.replace(location) : router.replace(location); - }, - - ...this.env, - }, - () => { - this.$emit('ready', { - instance, - }); - } - ); - - this.amisInstance = instance; - }, - - methods: { - updateProps() { - this.amisInstance?.updateProps({ - data: { - ...this.locals, - }, - context: this.context, - ...this.props, - }); - }, - }, - - unmounted() { - this.unmounted = true; - this.amisInstance?.unmount(); - }, +const location = { + pathname: current?.path, + hash: current?.hash, + query: current?.query, + search: `?${qs.stringify(current.query)}`, }; + +const loading = ref(false); +const amisInstance = shallowRef(null); +const unmounted = ref(false); + +const updateProps = () => { + amisInstance.value?.updateProps({ + data: { + ...props.locals, + }, + context: context, + ...props.props, + }); +}; +watch( + () => props.locals, + (val) => { + updateProps(); + } +); +watch( + () => props.props, + (val) => { + updateProps(); + } +); + +// watch(() => router.value, (val) => { + +// }) + +onMounted(async () => { + try { + loading.value = true; + await loadSDK(); + } finally { + loading.value = false; + } + if (unmounted.value) { + return; + } + + const scoped = amisRequire('amis/embed'); + const { normalizeLink } = amisRequire('amis'); + const instance = scoped.embed( + amisRootRef.value, + props.schema, + { + data: { + ...props.locals, + }, + context: context, + location: location, + + // todo 涓嬪彂 location 瀵硅薄 + ...props.props, + }, + { + requestAdaptor(api) { + const accessSession = Local.get(accessSessionKey); + if (accessSession) { + // 灏� token 娣诲姞鍒拌姹傛姤鏂囧ご涓� + api.headers['hswatersession'] = accessSession; + } else { + handleNoAuth(); + } + api.url = `${MAIN_URL}${api.url}`; + return api; + }, + // 鍏ㄥ眬 api 閫傞厤鍣ㄣ�� + // 鍙﹀鍦� amis 閰嶇疆椤逛腑鐨� api 涔熷彲浠ラ厤缃�傞厤鍣紝閽堝鏌愪釜鐗瑰畾鎺ュ彛鍗曠嫭澶勭悊銆� + responseAdaptor(api, payload, query, request, response) { + // { + // "json_ok": true, + // "sections": [ + // { + // "section_id": "knowledge_base", + // "section_name": "姘村姟鐭ヨ瘑搴�", + // "section_title": "鎷ユ湁姘村姟琛屼笟鐩稿叧鐨勯�氱敤鐭ヨ瘑锛屽寘鎷細娉曞緥娉曡銆佽璁¤鑼冦�佺粰鎺掓按鐩稿叧鐭ヨ瘑绛夌瓑" + // }, + // { + // "section_id": "office_assistant", + // "section_name": "鍔炲叕鍔╂墜", + // "section_title": "鍔炲叕鍔╂墜鑳藉杈呭姪鍐欎細璁�氱煡銆佽鍋囨潯銆佸伐浣滄�荤粨銆丳PT绛夊伐浣溿��" + // }, + // { + // "section_id": "customer_service", + // "section_name": "瀹㈡埛鏈嶅姟", + // "section_title": "閽堝姘村姟浼佷笟瀵瑰瀹㈡埛鏈嶅姟鐩稿叧鐨勫唴瀹癸紝鍖呮嫭锛氭妱琛ㄣ�佸紑璐︺�佹敹璐癸紝浠ュ強鐑嚎鐩稿叧" + // }, + // { + // "section_id": "network_operation", + // "section_name": "绠$綉杩愯", + // "section_title": "閽堝姘村姟浼佷笟绠$綉杩愯涓庣淮鎶ょ鐞嗐�佹按璐ㄧ鐞嗙瓑鐩稿叧" + // }, + // { + // "section_id": "waterworks_operation", + // "section_name": "姘村巶杩愯", + // "section_title": "閽堝姘村姟浼佷笟姘村巶杩愭棩甯歌繍钀ョ鐞嗘湇鍔★紝鍖呮嫭锛氭按鍘傚伐鑹烘祦绋嬨�佹按娉佃繍琛岃皟搴�" + // } + // ] + // } + return payload; + }, + // 瑕嗙洊 amis env + // 鍙傝�� https://aisuda.bce.baidu.com/amis/zh-CN/docs/start/getting-started#sdk + jumpTo: (to, action) => { + return; + if (to === 'goBack') { + return router.go(-1); + } + + to = normalizeLink(to, this.location); + + if (action?.actionType === 'url') { + action.blank === false ? router.push(to) : window.open(to); + return; + } + + // 涓昏鏄敮鎸� nav 涓殑璺宠浆 + if (action && to && action.target) { + window.open(to, action.target); + return; + } + + if (/^https?:\/\//.test(to)) { + window.location.replace(to); + } else { + router.push(to); + } + }, + + updateLocation: (location, replace) => { + // 绂佹璺宠浆 + return; + if (location === 'goBack') { + return router.go(-1); + } + + location = normalizeLink(location, this.location); + replace ? router.replace(location) : router.replace(location); + }, + + ...props.env, + }, + () => { + emit('ready', { + instance, + }); + } + ); + amisInstance.value = instance; +}); + +onUnmounted(() => { + unmounted.value = true; + + amisInstance.value?.unmount(); +}); </script> diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index 617c4cd..5ad202e 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -119,7 +119,7 @@ </div> </div> - <Loading v-if="isTalking && index === messageList.length - 1" class="w-fit" /> + <Loading v-if="isTalking && index === messageList.length - 1" class="w-fit my-auto" /> </div> </div> </div> @@ -139,7 +139,7 @@ </div> </div> - <div class="sticky bottom-0 w-full pb-3 flex justify-center"> + <div class="sticky bottom-0 w-full py-6 flex justify-center"> <PlayBar v-model:voicePageIsShow="voicePageIsShow" :isTalking="isTalking" @@ -167,11 +167,10 @@ import { GetHistoryAnswer, extCallQuery } from '/@/api/ai/chat'; import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue'; import { ErrorCode } from '/@/utils/request'; - - +import { CancelTokenSource } from 'axios'; const props = defineProps({ - questionApi: Function as PropType<(...params: any[]) => any>, + questionApi: Function as PropType<(text: string, sourceObj: { source: CancelTokenSource }) => any>, }); const chatWidth = '100%'; @@ -194,7 +193,6 @@ type: AnswerType.Text, values: '瑙f瀽澶辫触锛�', }; - switch (res.answer_type) { case AnswerType.RecordSet: content = { @@ -249,8 +247,13 @@ }; let questionRes = null; +// 浣滀负鍙傛暟浼犺繘鍘伙紝鎼哄甫鍙傛暟鍑烘潵 +let lastSourceObj: { source: CancelTokenSource } = { + source:null +}; + const questionAi = async (text) => { - const res = await props.questionApi(text); + const res = await props.questionApi(text, lastSourceObj); questionRes = res?.values; const content = parseContent(res?.values); return content; @@ -267,7 +270,6 @@ history_id: historyId, }); }; - const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any, isCallExtParams?: any) => { if (!content?.values || isTalking.value) return; const isNewChat = messageList.value.length === 0; @@ -326,6 +328,7 @@ }; const clearContent = () => { + lastSourceObj.source?.cancel(); messageList.value = []; // 娓呯┖杈撳叆妗� clearMessageContent(); @@ -333,7 +336,7 @@ defineExpose({ autoSend, - clear:clearContent + clear: clearContent, }); //#region ====================== 鍏宠仈鏌ヨ ====================== diff --git a/src/components/chat/chatComponents/summaryCom/components/amisPage/AmisPage.vue b/src/components/chat/chatComponents/summaryCom/components/amisPage/AmisPage.vue index 4e26c7c..3d3b29b 100644 --- a/src/components/chat/chatComponents/summaryCom/components/amisPage/AmisPage.vue +++ b/src/components/chat/chatComponents/summaryCom/components/amisPage/AmisPage.vue @@ -1,13 +1,14 @@ <template> <div> <span v-if="data?.title" class="text-base font-bold flex-center">{{ data?.title }}</span> - <AMISRenderer :schema="data?.amis_json" :locals="data?.amis_data" /> + <AMISRenderer :schema="data?.amis_json" :locals="data?.amis_data" @ready="amisReady"/> </div> </template> <script setup lang="ts"> import type { PropType } from 'vue'; import AMISRenderer from '/@/components/amis/AMISRenderer.vue'; +import emitter from '/@/utils/mitt'; // import 鍛ㄧぞ浼氬瓨閿�姣� from './testData/鍛ㄧぞ浼氬瓨閿�姣�.json' // import 瀹㈡埛鎯呭喌 from './testData/瀹㈡埛鎯呭喌.json' @@ -23,6 +24,10 @@ }, }); +const amisReady = (val) => { + emitter.emit('amis.page.ready',val); +}; + </script> <style scoped lang="scss"></style> diff --git a/src/components/chat/hooks/useScrollToBottom.ts b/src/components/chat/hooks/useScrollToBottom.ts index b23e8a4..eae8e64 100644 --- a/src/components/chat/hooks/useScrollToBottom.ts +++ b/src/components/chat/hooks/useScrollToBottom.ts @@ -1,6 +1,7 @@ import type { ComputedRef, Ref } from 'vue'; -import { nextTick, onActivated, ref, watch } from 'vue'; +import { nextTick, onActivated, onUnmounted, ref, watch } from 'vue'; import type { ChatMessage } from '../model/types'; +import emitter from '/@/utils/mitt'; export type UseScrollToBottomOption = { chatListDom: Ref<HTMLDivElement>; @@ -12,8 +13,18 @@ const scrollToBottom = () => { if (!chatListDom.value) return; - chatListDom.value.lastElementChild?.scrollIntoView(); + const parent = chatListDom.value.parentElement; + if(!parent)return; + if(parent.scrollHeight>parent.clientHeight){ + parent.scrollTop = parent.scrollHeight - parent.clientHeight; + } }; + + emitter.on('amis.page.ready',({instance})=>{ + nextTick(()=>{ + scrollToBottom(); + }) + }) const forbidScroll = ref(false); watch( displayMessageList, @@ -25,6 +36,9 @@ deep: true, } ); + onUnmounted(()=>{ + emitter.off('amis.page.ready'); + }) onActivated(() => { if (forbidScroll.value) return; diff --git a/src/types/mitt.d.ts b/src/types/mitt.d.ts index 9c56446..b9cb554 100644 --- a/src/types/mitt.d.ts +++ b/src/types/mitt.d.ts @@ -80,6 +80,10 @@ }; //#endregion + + 'amis.page.ready':{ + instance + } }; // mitt 鍙傛暟绫诲瀷瀹氫箟 diff --git a/src/utils/mitt.ts b/src/utils/mitt.ts index f8b46e9..15c0308 100644 --- a/src/utils/mitt.ts +++ b/src/utils/mitt.ts @@ -1,6 +1,7 @@ // https://www.npmjs.com/package/mitt import type { Emitter } from 'mitt'; import mitt from 'mitt'; +import { MittType } from '../types/mitt'; // 绫诲瀷 const emitter: Emitter<MittType> = mitt<MittType>(); diff --git a/src/utils/request.ts b/src/utils/request.ts index 8077272..65cb2ad 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,4 +1,4 @@ -import type { AxiosInstance, AxiosRequestConfig } from 'axios'; +import type { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios'; import axios from 'axios'; import { ElLoadingService, ElMessage } from 'element-plus'; import router from '../router'; @@ -10,6 +10,7 @@ loading?: boolean; noAuth?: boolean; handleFail?: boolean; + cancelToken?: CancelToken | undefined; }; export const checkAuth = () => { const session = Local.get(accessSessionKey); diff --git a/src/views/project/yw/dataManage/knowledge/Knowledge.vue b/src/views/project/yw/dataManage/knowledge/Knowledge.vue index ddf6d4a..a2dd4a2 100644 --- a/src/views/project/yw/dataManage/knowledge/Knowledge.vue +++ b/src/views/project/yw/dataManage/knowledge/Knowledge.vue @@ -88,6 +88,7 @@ import { useCompRef } from '/@/utils/types'; import { SupervisorPublished, supervisorPublishedMap } from '/@/views/project/yw/lowCode/sqlAmis/types'; import knowledgeLeft from '/static/images/knowledge/data_type_1.png'; +import axios, { CancelTokenSource } from 'axios'; const router = useRouter(); //#region ====================== 鑾峰彇鐭ヨ瘑搴搒heet鍒楄〃 ====================== const knowledgeBaseList = ref([]); @@ -168,7 +169,9 @@ chatTestIsShow.value = true; nextTick(() => { chatRef.value.clear(); - chatRef.value.autoSend(row.prompt); + setTimeout(() => { + chatRef.value.autoSend(row.prompt); + }, 30); }); }; @@ -190,7 +193,9 @@ }, }); -const questionAi = async (text) => { +const questionAi = async (text, sourceObj: { source: CancelTokenSource }) => { + const currentSource = axios.CancelToken.source(); + sourceObj.source = currentSource; const res = await check_docvector_validate( { knowlg_id: chatTestMapRow.value.id, @@ -198,6 +203,7 @@ }, { loading: false, + cancelToken: currentSource.token, } ); return res; diff --git a/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue b/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue index 387a057..cdffb9a 100644 --- a/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue +++ b/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue @@ -213,9 +213,10 @@ import { useCompRef } from '/@/utils/types'; import { convertListToTree } from '/@/utils/util'; +import axios, { CancelTokenSource } from 'axios'; import * as supervisorGroupApi from '/@/api/supervisorAdmin/supervisorGroup'; -import LeftTreeByMgr from '/@/components/tree/leftTreeByMgr.vue'; import AHMContainer from '/@/components/layout/AHMContainer.vue'; +import LeftTreeByMgr from '/@/components/tree/leftTreeByMgr.vue'; import { useUpdateData } from '/@/hooks/useUpdateData'; //#region ====================== 宸︿晶鏍戞暟鎹紝tree init ====================== @@ -493,7 +494,9 @@ nextTick(() => { chatRef.value.clear(); - chatRef.value.autoSend(row.prompt); + setTimeout(() => { + chatRef.value.autoSend(row.prompt); + }, 30); }); }; @@ -515,7 +518,9 @@ }, }); -const questionAi = async (text) => { +const questionAi = async (text, sourceObj: { source: CancelTokenSource }) => { + const currentSource = axios.CancelToken.source(); + sourceObj.source = currentSource; const res = await checkSupervisorValidate( { id: chatTestMapRow.value.id, @@ -523,6 +528,7 @@ }, { loading: false, + cancelToken: currentSource.token, } ); return res; diff --git a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue index a6e3cf0..2523bc7 100644 --- a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue +++ b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue @@ -66,18 +66,21 @@ </Pane> <Pane :size="65"> <div class=" h-full"> - <template v-if="currentSql"> + <template v-if="currentDockConfig"> <div class=" flex justify-between items-center my-1 ml-1 h-[36px]"> - <span class="font-bold">SQL</span> + + <el-select class="w-52 font-bold" v-model="currentDockConfig.type"> + <el-option v-for="item in Object.keys(amisDockTypeMap)" :key="item" :value="(item)" :label="amisDockTypeMap[item]"></el-option> + </el-select> - <el-select class="w-40" v-model="currentSql.database" @change="databaseSelectChange"> + <el-select class="w-40" v-model="currentDockConfig.database" @change="databaseSelectChange"> <el-option v-for="item in databaseList" :key="item.id" :value="item.id" :label="item.title"></el-option> </el-select> </div> <codemirror class="overflow-auto" style="height: calc(100% - 36px);" - v-model="currentSql.sql" + v-model="currentDockConfig.sql" :autofocus="true" :indent-with-tab="true" :tab-size="2" @@ -100,20 +103,21 @@ import { sql } from '@codemirror/lang-sql'; import { xml } from '@codemirror/lang-xml'; import { vscodeDark } from '@uiw/codemirror-theme-vscode'; -import _, { debounce } from 'lodash'; -import { onMounted, ref } from 'vue'; -import { Codemirror } from 'vue-codemirror'; -import * as codeExample from './testData'; -import titleBox from '/@/components/titleBox.vue'; -import { Pane, Splitpanes } from 'splitpanes'; -import 'splitpanes/dist/splitpanes.css'; import type { TableInstance } from 'element-plus'; import { ElMessage } from 'element-plus'; +import _, { debounce } from 'lodash'; +import { Pane, Splitpanes } from 'splitpanes'; +import 'splitpanes/dist/splitpanes.css'; import { v4 as uuid } from 'uuid'; +import { onMounted, ref } from 'vue'; +import { Codemirror } from 'vue-codemirror'; +import { SupervisorPublished } from '../types'; +import * as codeExample from './testData'; import * as supervisorApi from '/@/api/supervisorAdmin'; import { updateSqlApi } from '/@/api/supervisorAdmin'; +import titleBox from '/@/components/titleBox.vue'; import { useCompRef } from '/@/utils/types'; -import { SupervisorPublished } from '../types'; +import { amisDockTypeMap } from './types'; const props = defineProps(['supervisor']); const emit = defineEmits(['backLastPage', 'updatePublished']); @@ -134,10 +138,10 @@ let defaultSelectDatabase = null; const databaseSelectChange = (val) => { defaultSelectDatabase = val; - if(currentSql.value){ - currentSql.value.database = val; + if(currentDockConfig.value){ + currentDockConfig.value.database = val; } - updateSqlAndRs(currentSql.value.id,currentSql.value) + updateSqlAndRs(currentDockConfig.value.id,currentDockConfig.value) }; const backLastPage = () => { // setTimeout(() => { @@ -148,14 +152,14 @@ const currentRs = ref<AmisDockConfig>(null); const dockRowChange = (row) => { currentRs.value = row; - currentSql.value = dockConfigList.value.find((item) => item.id === currentRs.value.recordId) ?? { + currentDockConfig.value = dockConfigList.value.find((item) => item.id === currentRs.value.recordId) ?? { id: row.recordId, type: AmisDockType.Sql, sql: '', database: defaultSelectDatabase ?? databaseList.value[0]?.id ?? null, }; }; -const currentSql = ref(null); +const currentDockConfig = ref(null); /** @description 璺緞鍒嗛殧绗� */ const PATH_SEPARATOR = '/'; /** @description 1 閫�鍑烘墍鏈夊惊鐜� -1閫�鍑哄綋娆″惊鐜� 0鎴栧叾浠栧�肩户缁� */ @@ -295,13 +299,13 @@ const sqlCodeChange = debounce((val) => { if (!currentRs.value.recordId) return; - if (currentSql.value) { - if (!currentSql.value.database) { + if (currentDockConfig.value) { + if (!currentDockConfig.value.database) { ElMessage.warning('璇峰厛閫夋嫨鏁版嵁搴�'); return; } } - updateSqlAndRs(currentSql.value.id, currentSql.value); + updateSqlAndRs(currentDockConfig.value.id, currentDockConfig.value); }, 1000); const dockConfigList = ref([]); const rsTableRef = ref<TableInstance>(null); diff --git a/src/views/project/yw/lowCode/sqlAmis/edit/types.ts b/src/views/project/yw/lowCode/sqlAmis/edit/types.ts new file mode 100644 index 0000000..2772f1d --- /dev/null +++ b/src/views/project/yw/lowCode/sqlAmis/edit/types.ts @@ -0,0 +1,7 @@ +export const enum AmisDockType { + Sql = 'SQL', +} + +export const amisDockTypeMap = { + [AmisDockType.Sql]: 'SQL', +}; -- Gitblit v1.9.3