feat: ai
This commit is contained in:
@@ -6,8 +6,12 @@ import { ref } from 'vue';
|
||||
import { createReusableTemplate } from '@vueuse/core';
|
||||
import { Button, message, Textarea } from 'ant-design-vue';
|
||||
|
||||
import { DICT_TYPE, getIntDictOptions } from '#/utils';
|
||||
import { AiWriteTypeEnum, WriteExample } from '#/utils/constants';
|
||||
import {
|
||||
AiWriteTypeEnum,
|
||||
DICT_TYPE,
|
||||
getIntDictOptions,
|
||||
WriteExample,
|
||||
} from '#/utils';
|
||||
|
||||
import Tag from './Tag.vue';
|
||||
|
||||
@@ -33,19 +37,19 @@ function omit(obj: Record<string, any>, keysToOmit: string[]) {
|
||||
return result;
|
||||
}
|
||||
/** 点击示例的时候,将定义好的文章作为示例展示出来 */
|
||||
const example = (type: 'reply' | 'write') => {
|
||||
function example(type: 'reply' | 'write') {
|
||||
formData.value = {
|
||||
...initData,
|
||||
...omit(WriteExample[type], ['data']),
|
||||
};
|
||||
emit('example', type);
|
||||
};
|
||||
}
|
||||
|
||||
/** 重置,将表单值作为初选值 */
|
||||
const reset = () => {
|
||||
function reset() {
|
||||
formData.value = { ...initData };
|
||||
emit('reset');
|
||||
};
|
||||
}
|
||||
|
||||
const selectedTab = ref<TabType>(AiWriteTypeEnum.WRITING);
|
||||
const tabs: {
|
||||
@@ -83,7 +87,7 @@ const formData = ref<AiWriteApi.WriteVO>({ ...initData });
|
||||
/** 用来记录切换之前所填写的数据,切换的时候给赋值回来 */
|
||||
const recordFormData = {} as Record<AiWriteTypeEnum, AiWriteApi.WriteVO>;
|
||||
/** 切换tab */
|
||||
const switchTab = (value: TabType) => {
|
||||
function switchTab(value: TabType) {
|
||||
if (value !== selectedTab.value) {
|
||||
// 保存之前的久数据
|
||||
recordFormData[selectedTab.value] = formData.value;
|
||||
@@ -91,10 +95,10 @@ const switchTab = (value: TabType) => {
|
||||
// 将之前的旧数据赋值回来
|
||||
formData.value = { ...initData, ...recordFormData[value] };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 提交写作 */
|
||||
const submit = () => {
|
||||
function submit() {
|
||||
if (selectedTab.value === 2 && !formData.value.originalContent) {
|
||||
message.warning('请输入原文');
|
||||
return;
|
||||
@@ -111,7 +115,7 @@ const submit = () => {
|
||||
/** 使用选中 tab 值覆盖当前的 type 类型 */
|
||||
type: selectedTab.value,
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -40,9 +40,9 @@ defineExpose({
|
||||
|
||||
/** 点击复制的时候复制内容 */
|
||||
const showCopy = computed(() => props.content && !props.isWriting); // 是否展示复制按钮,在生成内容完成的时候展示
|
||||
const copyContent = () => {
|
||||
function copyContent() {
|
||||
copy(props.content);
|
||||
};
|
||||
}
|
||||
|
||||
/** 复制成功的时候 copied.value 为 true */
|
||||
watch(copied, (val) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { nextTick, ref } from 'vue';
|
||||
import { alert, Page } from '@vben/common-ui';
|
||||
|
||||
import { writeStream } from '#/api/ai/write';
|
||||
import { WriteExample } from '#/utils/constants';
|
||||
import { WriteExample } from '#/utils';
|
||||
|
||||
import Left from './components/Left.vue';
|
||||
import Right from './components/Right.vue';
|
||||
@@ -16,15 +16,15 @@ const isWriting = ref(false); // 是否正在写作中
|
||||
const abortController = ref<AbortController>(); // // 写作进行中 abort 控制器(控制 stream 写作)
|
||||
|
||||
/** 停止 stream 生成 */
|
||||
const stopStream = () => {
|
||||
function stopStream() {
|
||||
abortController.value?.abort();
|
||||
isWriting.value = false;
|
||||
};
|
||||
}
|
||||
|
||||
/** 执行写作 */
|
||||
const rightRef = ref<InstanceType<typeof Right>>();
|
||||
|
||||
const submit = (data: Partial<AiWriteApi.WriteVO>) => {
|
||||
function submit(data: Partial<AiWriteApi.WriteVO>) {
|
||||
abortController.value = new AbortController();
|
||||
writeResult.value = '';
|
||||
isWriting.value = true;
|
||||
@@ -51,17 +51,17 @@ const submit = (data: Partial<AiWriteApi.WriteVO>) => {
|
||||
throw error;
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/** 点击示例触发 */
|
||||
const handleExampleClick = (type: keyof typeof WriteExample) => {
|
||||
function handleExampleClick(type: keyof typeof WriteExample) {
|
||||
writeResult.value = WriteExample[type].data;
|
||||
};
|
||||
}
|
||||
|
||||
/** 点击重置的时候清空写作的结果*/
|
||||
const reset = () => {
|
||||
function reset() {
|
||||
writeResult.value = '';
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
@@ -40,8 +40,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user