提交 fcb8e0d8 编写于 作者: I InsCode

Auto Commit

上级 16230c15
registry='https://registry.npmmirror.com/'
\ No newline at end of file
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"openai": "^4.77.0", "openai": "^4.77.0",
"sass": "^1.83.0", "sass": "^1.83.0",
"vue": "^3.5.13", "vue": "^3.5.13",
"vue-charts": "^0.2.1",
"vue-devui": "^1.6.29", "vue-devui": "^1.6.29",
"vue-i18n": "^11.0.0-beta.2", "vue-i18n": "^11.0.0-beta.2",
"vue3-sfc-loader": "^0.9.5", "vue3-sfc-loader": "^0.9.5",
...@@ -4903,6 +4904,40 @@ ...@@ -4903,6 +4904,40 @@
} }
} }
}, },
"node_modules/vue-charts": {
"version": "0.2.1",
"resolved": "https://registry.npmmirror.com/vue-charts/-/vue-charts-0.2.1.tgz",
"integrity": "sha512-SVJauURVJCgC3LWIdzI5d0waKPHm+/uQTNyKWj4Ehfn/VirZWdqkFaWtf5Xk2VQCV7CrPA43JCTtYjnj8R7pcw==",
"license": "MIT",
"dependencies": {
"lodash": "^4.3.0",
"vue": "^2.0.3"
}
},
"node_modules/vue-charts/node_modules/@vue/compiler-sfc": {
"version": "2.7.16",
"resolved": "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-2.7.16.tgz",
"integrity": "sha512-KWhJ9k5nXuNtygPU7+t1rX6baZeqOYLEforUPjgNDBnLicfHCoi48H87Q8XyLZOrNNsmhuwKqtpDQWjEFe6Ekg==",
"dependencies": {
"@babel/parser": "^7.23.5",
"postcss": "^8.4.14",
"source-map": "^0.6.1"
},
"optionalDependencies": {
"prettier": "^1.18.2 || ^2.0.0"
}
},
"node_modules/vue-charts/node_modules/vue": {
"version": "2.7.16",
"resolved": "https://registry.npmmirror.com/vue/-/vue-2.7.16.tgz",
"integrity": "sha512-4gCtFXaAA3zYZdTp5s4Hl2sozuySsgz4jy1EnpBHNfpMa9dK1ZCG7viqBPCwXtmgc8nHqUsAu3G4gtmXkkY3Sw==",
"deprecated": "Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details.",
"license": "MIT",
"dependencies": {
"@vue/compiler-sfc": "2.7.16",
"csstype": "^3.1.0"
}
},
"node_modules/vue-devui": { "node_modules/vue-devui": {
"version": "1.6.29", "version": "1.6.29",
"resolved": "https://registry.npmmirror.com/vue-devui/-/vue-devui-1.6.29.tgz", "resolved": "https://registry.npmmirror.com/vue-devui/-/vue-devui-1.6.29.tgz",
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div v-if="startChat" ref="conversationRef" class="conversation-area"> <div v-if="startChat" ref="conversationRef" class="conversation-area">
<template v-for="(msg, idx) in messages" :key="idx"> <template v-for="(msg, idx) in messages" :key="idx">
<McBubble v-if="msg.from === 'user'" :content="msg.content" :align="'right'" :avatarConfig="msg.avatarConfig"></McBubble> <McBubble v-if="msg.from === 'user'" :content="msg.content" :align="'right'" :avatarConfig="msg.avatarConfig"></McBubble>
<McBubble v-else :loading="msg.loading" :avatarPosition="msg.avatarPosition" :avatarConfig="msg.avatarConfig"> <McBubble v-else :loading="msg.loading" :avatarPosition="msg.avatarPosition" :avatarConfig="msg.avatarConfig" style="max-width: 540px">
<RenderMarkdown v-if="msg.type === 'common'" :content="msg.content"></RenderMarkdown> <RenderMarkdown v-if="msg.type === 'common'" :content="msg.content"></RenderMarkdown>
<div :id="'demoChart'+idx" <div :id="'demoChart'+idx"
draggable="true" draggable="true"
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
<span>添加知识</span> <span>添加知识</span>
</div> </div>
</div> </div>
<d-button icon="stop" shape="circle" title="中止对话" size="sm" @click="stop" />
<d-button icon="add" shape="circle" title="新建对话" size="sm" @click="onNewConvo" /> <d-button icon="add" shape="circle" title="新建对话" size="sm" @click="onNewConvo" />
</div> </div>
<div style="padding: 0 12px 12px 12px"> <div style="padding: 0 12px 12px 12px">
...@@ -114,6 +115,7 @@ ...@@ -114,6 +115,7 @@
}, },
emits: ['closeDrawer', 'chartStrChange'], emits: ['closeDrawer', 'chartStrChange'],
setup(props, { emit }) { setup(props, { emit }) {
let abortController = null;
const inputValue = ref(''); const inputValue = ref('');
const startChat = ref(false); const startChat = ref(false);
const conversationRef = ref(); const conversationRef = ref();
...@@ -171,6 +173,12 @@ ...@@ -171,6 +173,12 @@
}; };
const onSubmit = (e, answer = undefined, type = 'common') => { const onSubmit = (e, answer = undefined, type = 'common') => {
if (abortController) {
messages.value.at(-1).loading = false;
messages.value.at(-1).content = '对话中止';
abortController.abort();
abortController = null;
}
inputValue.value = ''; inputValue.value = '';
if (!messages.value.length) { if (!messages.value.length) {
startChat.value = true; startChat.value = true;
...@@ -196,7 +204,6 @@ ...@@ -196,7 +204,6 @@
}; };
const getMockAnswer = (answer, type) => { const getMockAnswer = (answer, type) => {
console.log('getmock')
const aiAnswer = { const aiAnswer = {
from: 'ai-model', from: 'ai-model',
content: answer, content: answer,
...@@ -218,6 +225,7 @@ ...@@ -218,6 +225,7 @@
} }
const getAIAnswer = (content, type) => { const getAIAnswer = (content, type) => {
abortController = new AbortController();
const aiAnswer = { const aiAnswer = {
from: 'ai-model', from: 'ai-model',
content: '', content: '',
...@@ -241,6 +249,7 @@ ...@@ -241,6 +249,7 @@
], ],
apikey: apiKey apikey: apiKey
}), }),
signal: abortController.signal,
onopen: (response) => { onopen: (response) => {
}, },
onmessage: (msg) => { onmessage: (msg) => {
...@@ -266,6 +275,18 @@ ...@@ -266,6 +275,18 @@
}); });
}; };
const stop = () => {
if (abortController) {
abortController.abort();
abortController = null;
// 更新最后一条消息的状态
if (messages.value.length > 0) {
messages.value.at(-1).loading = false;
messages.value.at(-1).content += '已中止对话';
}
}
}
const onNewConvo = () => { const onNewConvo = () => {
startChat.value = false; startChat.value = false;
messages.value = []; messages.value = [];
...@@ -371,7 +392,8 @@ ...@@ -371,7 +392,8 @@
selectedAgent, selectedAgent,
agentList, agentList,
onInputIconClick, onInputIconClick,
copyContent copyContent,
stop
}; };
}, },
}); });
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import { createApp, watch, onBeforeUnmount } from "vue"; import { createApp, watch, onBeforeUnmount } from "vue";
import { loadModule } from 'vue3-sfc-loader' import { loadModule } from 'vue3-sfc-loader'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import VChart from 'vue-charts';
const props = defineProps({ const props = defineProps({
...@@ -25,7 +26,12 @@ let currentApp = null; ...@@ -25,7 +26,12 @@ let currentApp = null;
let currentStyle = null; let currentStyle = null;
const processComponentString = (str) => { const processComponentString = (str) => {
return str.replace(/import.*from.*['"]echarts['"];?\n?/g, ''); str = str.replace(/import.*from.*['"]vue-echarts['"];?\n?/g, '');
str = str.replace(/import.*from.*['"]echarts['"];?\n?/g, '');
str = str.replace(/components:\s*{\s*VChart,?\s*},?/g, '');
str = str.replace(/<v-chart/g, '<vue-echarts');
str = str.replace(/<\/v-chart>/g, '</vue-echarts>');
return str
}; };
onBeforeUnmount(() => { onBeforeUnmount(() => {
...@@ -74,7 +80,7 @@ watch( ...@@ -74,7 +80,7 @@ watch(
// 加载组件 // 加载组件
const component = await loadModule('file.vue', options); const component = await loadModule('file.vue', options);
// 创建新实例 // 创建新实例
const app = createApp(component).use(echarts); const app = createApp(component).use(echarts).component('vue-echarts', VChart);
app.config.globalProperties.$echarts = echarts; app.config.globalProperties.$echarts = echarts;
app.config.globalProperties.echarts = echarts; app.config.globalProperties.echarts = echarts;
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
</d-layout> </d-layout>
</d-layout> </d-layout>
<d-drawer v-model="visible" position="right" style="padding: 20px; width: 650px" :show-overlay="false" :close-on-click-overlay="false"> <d-drawer v-model="visible" position="right" style="padding: 20px; width: 650px" :show-overlay="false" :close-on-click-overlay="false">
<keep-alive> <!-- <keep-alive>
<!-- <Demo @closeDrawer="visible = false" @chartStrChange="chartStrChange($event)"/> --> <Demo @closeDrawer="visible = false" @chartStrChange="chartStrChange($event)"/>
</keep-alive> </keep-alive> -->
<SimpleDemo @closeDrawer="visible = false"/> <SimpleDemo @closeDrawer="visible = false"/>
</d-drawer> </d-drawer>
</template> </template>
...@@ -40,6 +40,7 @@ import Footer from './Footer.vue'; ...@@ -40,6 +40,7 @@ import Footer from './Footer.vue';
import Demo from './MateChat/Demo.vue'; import Demo from './MateChat/Demo.vue';
import SimpleDemo from './MateChat/SimpleDemo.vue'; import SimpleDemo from './MateChat/SimpleDemo.vue';
import { loadModule } from 'vue3-sfc-loader'; import { loadModule } from 'vue3-sfc-loader';
import VChart from 'vue-charts';
export default defineComponent({ export default defineComponent({
components: { components: {
...@@ -124,7 +125,12 @@ export default defineComponent({ ...@@ -124,7 +125,12 @@ export default defineComponent({
// 预处理组件字符串,移除 import 语句 // 预处理组件字符串,移除 import 语句
const processComponentString = (str) => { const processComponentString = (str) => {
return str.replace(/import.*from.*['"]echarts['"];?\n?/g, ''); str = str.replace(/import.*from.*['"]vue-echarts['"];?\n?/g, '');
str = str.replace(/import.*from.*['"]echarts['"];?\n?/g, '');
str = str.replace(/components:\s*{\s*VChart,?\s*},?/g, '');
str = str.replace(/<v-chart/g, '<vue-echarts');
str = str.replace(/<\/v-chart>/g, '</vue-echarts>');
return str
}; };
...@@ -155,7 +161,7 @@ export default defineComponent({ ...@@ -155,7 +161,7 @@ export default defineComponent({
// 加载组件 // 加载组件
const component = await loadModule('file.vue', options); const component = await loadModule('file.vue', options);
// 创建新实例 // 创建新实例
const app = createApp(component); const app = createApp(component).component('vue-echarts', VChart);
app.config.globalProperties.$echarts = echarts; app.config.globalProperties.$echarts = echarts;
app.config.globalProperties.echarts = echarts; app.config.globalProperties.echarts = echarts;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册