feat: ai
This commit is contained in:
@@ -6,7 +6,7 @@ import { nextTick, onMounted, ref } from 'vue';
|
||||
import { alert, Page } from '@vben/common-ui';
|
||||
|
||||
import { generateMindMap } from '#/api/ai/mindmap';
|
||||
import { MindMapContentExample } from '#/utils/constants';
|
||||
import { MindMapContentExample } from '#/utils';
|
||||
|
||||
import Left from './modules/Left.vue';
|
||||
import Right from './modules/Right.vue';
|
||||
@@ -21,13 +21,13 @@ const leftRef = ref<InstanceType<typeof Left>>(); // 左边组件
|
||||
const rightRef = ref(); // 右边组件
|
||||
|
||||
/** 使用已有内容直接生成 */
|
||||
const directGenerate = (existPrompt: string) => {
|
||||
function directGenerate(existPrompt: string) {
|
||||
isEnd.value = false; // 先设置为 false 再设置为 true,让子组建的 watch 能够监听到
|
||||
generatedContent.value = existPrompt;
|
||||
isEnd.value = true;
|
||||
};
|
||||
}
|
||||
/** 提交生成 */
|
||||
const submit = (data: AiMindmapApi.AiMindMapGenerateReqVO) => {
|
||||
function submit(data: AiMindmapApi.AiMindMapGenerateReqVO) {
|
||||
isGenerating.value = true;
|
||||
isStart.value = true;
|
||||
isEnd.value = false;
|
||||
@@ -59,13 +59,13 @@ const submit = (data: AiMindmapApi.AiMindMapGenerateReqVO) => {
|
||||
},
|
||||
ctrl: ctrl.value,
|
||||
});
|
||||
};
|
||||
}
|
||||
/** 停止 stream 生成 */
|
||||
const stopStream = () => {
|
||||
function stopStream() {
|
||||
isGenerating.value = false;
|
||||
isStart.value = false;
|
||||
ctrl.value?.abort();
|
||||
};
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { reactive, ref } from 'vue';
|
||||
|
||||
import { Button, Textarea } from 'ant-design-vue';
|
||||
|
||||
import { MindMapContentExample } from '#/utils/constants';
|
||||
import { MindMapContentExample } from '#/utils';
|
||||
|
||||
defineProps<{
|
||||
isGenerating: boolean;
|
||||
|
||||
@@ -7,11 +7,10 @@ import {
|
||||
Toolbar,
|
||||
Transformer,
|
||||
} from '@vben/plugins/markmap';
|
||||
import { downloadImageByCanvas } from '@vben/utils';
|
||||
|
||||
import { Button, Card, message } from 'ant-design-vue';
|
||||
|
||||
import { download } from '#/utils/download';
|
||||
|
||||
const props = defineProps<{
|
||||
generatedContent: string; // 生成结果
|
||||
isEnd: boolean; // 是否结束
|
||||
@@ -85,7 +84,7 @@ const update = () => {
|
||||
}
|
||||
};
|
||||
/** 处理内容 */
|
||||
const processContent = (text: string) => {
|
||||
function processContent(text: string) {
|
||||
const arr: string[] = [];
|
||||
const lines = text.split('\n');
|
||||
for (let line of lines) {
|
||||
@@ -97,21 +96,21 @@ const processContent = (text: string) => {
|
||||
arr.push(line);
|
||||
}
|
||||
return arr.join('\n');
|
||||
};
|
||||
}
|
||||
/** 下载图片:download SVG to png file */
|
||||
const downloadImage = () => {
|
||||
function downloadImage() {
|
||||
const svgElement = mindMapRef.value;
|
||||
// 将 SVG 渲染到图片对象
|
||||
const serializer = new XMLSerializer();
|
||||
const source = `<?xml version="1.0" standalone="no"?>\r\n${serializer.serializeToString(svgRef.value!)}`;
|
||||
const base64Url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(source)}`;
|
||||
download.image({
|
||||
downloadImageByCanvas({
|
||||
url: base64Url,
|
||||
canvasWidth: svgElement?.offsetWidth,
|
||||
canvasHeight: svgElement?.offsetHeight,
|
||||
drawWithImageSize: false,
|
||||
});
|
||||
};
|
||||
}
|
||||
defineExpose({
|
||||
scrollBottom() {
|
||||
mdContainerRef.value?.scrollTo(0, mdContainerRef.value?.scrollHeight);
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
@@ -26,8 +27,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -75,13 +75,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
},
|
||||
} as VxeTableGridOptions<AiMindmapApi.MindMapVO>,
|
||||
});
|
||||
const openPreview = async (row: AiMindmapApi.MindMapVO) => {
|
||||
async function openPreview(row: AiMindmapApi.MindMapVO) {
|
||||
previewVisible.value = false;
|
||||
drawerApi.open();
|
||||
await nextTick();
|
||||
previewVisible.value = true;
|
||||
previewContent.value = row.generatedContent;
|
||||
};
|
||||
}
|
||||
onMounted(async () => {
|
||||
// 获得下拉数据
|
||||
userList.value = await getSimpleUserList();
|
||||
|
||||
Reference in New Issue
Block a user