feat:【ele】【ai】write 的代码迁移
This commit is contained in:
@@ -12,6 +12,7 @@ const accessStore = useAccessStore();
|
|||||||
|
|
||||||
export namespace AiWriteApi {
|
export namespace AiWriteApi {
|
||||||
export interface Write {
|
export interface Write {
|
||||||
|
id?: number;
|
||||||
type: AiWriteTypeEnum.REPLY | AiWriteTypeEnum.WRITING; // 1:撰写 2:回复
|
type: AiWriteTypeEnum.REPLY | AiWriteTypeEnum.WRITING; // 1:撰写 2:回复
|
||||||
prompt: string; // 写作内容提示 1。撰写 2回复
|
prompt: string; // 写作内容提示 1。撰写 2回复
|
||||||
originalContent: string; // 原文
|
originalContent: string; // 原文
|
||||||
@@ -27,29 +28,12 @@ export namespace AiWriteApi {
|
|||||||
createTime?: Date; // 创建时间
|
createTime?: Date; // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AiWritePageReq extends PageParam {
|
export interface AiWritePageReqVO extends PageParam {
|
||||||
userId?: number; // 用户编号
|
userId?: number; // 用户编号
|
||||||
type?: AiWriteTypeEnum; // 写作类型
|
type?: AiWriteTypeEnum; // 写作类型
|
||||||
platform?: string; // 平台
|
platform?: string; // 平台
|
||||||
createTime?: [string, string]; // 创建时间
|
createTime?: [string, string]; // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AiWriteResp {
|
|
||||||
id: number;
|
|
||||||
userId: number;
|
|
||||||
type: number;
|
|
||||||
platform: string;
|
|
||||||
model: string;
|
|
||||||
prompt: string;
|
|
||||||
generatedContent: string;
|
|
||||||
originalContent: string;
|
|
||||||
length: number;
|
|
||||||
format: number;
|
|
||||||
tone: number;
|
|
||||||
language: number;
|
|
||||||
errorMessage: string;
|
|
||||||
createTime: string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeStream({
|
export function writeStream({
|
||||||
@@ -81,15 +65,14 @@ export function writeStream({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取写作列表
|
/** 获取写作列表 */
|
||||||
export function getWritePage(params: any) {
|
export function getWritePage(params: AiWriteApi.AiWritePageReqVO) {
|
||||||
return requestClient.get<PageResult<AiWriteApi.AiWritePageReq>>(
|
return requestClient.get<PageResult<AiWriteApi.Write>>(`/ai/write/page`, {
|
||||||
`/ai/write/page`,
|
params,
|
||||||
{ params },
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除音乐
|
/** 删除写作记录 */
|
||||||
export function deleteWrite(id: number) {
|
export function deleteWrite(id: number) {
|
||||||
return requestClient.delete(`/ai/write/delete`, { params: { id } });
|
return requestClient.delete(`/ai/write/delete`, { params: { id } });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,20 +17,21 @@ function handleRefresh() {
|
|||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除 */
|
/** 删除写作记录 */
|
||||||
async function handleDelete(row: AiWriteApi.AiWritePageReq) {
|
async function handleDelete(row: AiWriteApi.Write) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteWrite(row.id as number);
|
await deleteWrite(row.id!);
|
||||||
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
@@ -58,7 +59,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
refresh: true,
|
refresh: true,
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<AiWriteApi.AiWritePageReq>,
|
} as VxeTableGridOptions<AiWriteApi.Write>,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import { requestClient } from '#/api/request';
|
|||||||
|
|
||||||
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
|
|
||||||
export namespace AiWriteApi {
|
export namespace AiWriteApi {
|
||||||
export interface Write {
|
export interface Write {
|
||||||
|
id?: number;
|
||||||
type: AiWriteTypeEnum.REPLY | AiWriteTypeEnum.WRITING; // 1:撰写 2:回复
|
type: AiWriteTypeEnum.REPLY | AiWriteTypeEnum.WRITING; // 1:撰写 2:回复
|
||||||
prompt: string; // 写作内容提示 1。撰写 2回复
|
prompt: string; // 写作内容提示 1。撰写 2回复
|
||||||
originalContent: string; // 原文
|
originalContent: string; // 原文
|
||||||
@@ -26,29 +28,12 @@ export namespace AiWriteApi {
|
|||||||
createTime?: Date; // 创建时间
|
createTime?: Date; // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AiWritePageReq extends PageParam {
|
export interface AiWritePageReqVO extends PageParam {
|
||||||
userId?: number; // 用户编号
|
userId?: number; // 用户编号
|
||||||
type?: AiWriteTypeEnum; // 写作类型
|
type?: AiWriteTypeEnum; // 写作类型
|
||||||
platform?: string; // 平台
|
platform?: string; // 平台
|
||||||
createTime?: [string, string]; // 创建时间
|
createTime?: [string, string]; // 创建时间
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AiWriteResp {
|
|
||||||
id: number;
|
|
||||||
userId: number;
|
|
||||||
type: number;
|
|
||||||
platform: string;
|
|
||||||
model: string;
|
|
||||||
prompt: string;
|
|
||||||
generatedContent: string;
|
|
||||||
originalContent: string;
|
|
||||||
length: number;
|
|
||||||
format: number;
|
|
||||||
tone: number;
|
|
||||||
language: number;
|
|
||||||
errorMessage: string;
|
|
||||||
createTime: string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeStream({
|
export function writeStream({
|
||||||
@@ -80,15 +65,14 @@ export function writeStream({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取写作列表
|
/** 获取写作列表 */
|
||||||
export function getWritePage(params: any) {
|
export function getWritePage(params: AiWriteApi.AiWritePageReqVO) {
|
||||||
return requestClient.get<PageResult<AiWriteApi.AiWritePageReq>>(
|
return requestClient.get<PageResult<AiWriteApi.Write>>(`/ai/write/page`, {
|
||||||
`/ai/write/page`,
|
params,
|
||||||
{ params },
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除音乐
|
/** 删除写作记录 */
|
||||||
export function deleteWrite(id: number) {
|
export function deleteWrite(id: number) {
|
||||||
return requestClient.delete(`/ai/write/delete`, { params: { id } });
|
return requestClient.delete(`/ai/write/delete`, { params: { id } });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { nextTick, ref } from 'vue';
|
|||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { WriteExample } from '@vben/constants';
|
import { WriteExample } from '@vben/constants';
|
||||||
|
|
||||||
import { ElMessage as message } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { writeStream } from '#/api/ai/write';
|
import { writeStream } from '#/api/ai/write';
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ function handleSubmit(data: Partial<AiWriteApi.Write>) {
|
|||||||
onMessage: async (res: any) => {
|
onMessage: async (res: any) => {
|
||||||
const { code, data, msg } = JSON.parse(res.data);
|
const { code, data, msg } = JSON.parse(res.data);
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
message.error(`写作异常! ${msg}`);
|
ElMessage.error(`写作异常! ${msg}`);
|
||||||
handleStopStream();
|
handleStopStream();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { getDictOptions } from '@vben/hooks';
|
|||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { createReusableTemplate } from '@vueuse/core';
|
import { createReusableTemplate } from '@vueuse/core';
|
||||||
import { ElButton as Button, ElMessage as message } from 'element-plus';
|
import { ElButton, ElInput, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import Tag from './tag.vue';
|
import Tag from './tag.vue';
|
||||||
|
|
||||||
@@ -99,11 +99,11 @@ function handleSubmit() {
|
|||||||
selectedTab.value === AiWriteTypeEnum.REPLY &&
|
selectedTab.value === AiWriteTypeEnum.REPLY &&
|
||||||
!formData.value.originalContent
|
!formData.value.originalContent
|
||||||
) {
|
) {
|
||||||
message.warning('请输入原文');
|
ElMessage.warning('请输入原文');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!formData.value.prompt) {
|
if (!formData.value.prompt) {
|
||||||
message.warning(`请输入${selectedTab.value === 1 ? '写作' : '回复'}内容`);
|
ElMessage.warning(`请输入${selectedTab.value === 1 ? '写作' : '回复'}内容`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,11 +175,13 @@ function handleSubmit() {
|
|||||||
hint="示例"
|
hint="示例"
|
||||||
label="写作内容"
|
label="写作内容"
|
||||||
/>
|
/>
|
||||||
<el-input
|
<ElInput
|
||||||
v-model="formData.prompt"
|
v-model="formData.prompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:maxlength="500"
|
:maxlength="500"
|
||||||
:rows="5"
|
:rows="5"
|
||||||
|
:input-style="{ boxShadow: 'none' }"
|
||||||
|
resize="none"
|
||||||
placeholder="请输入写作内容"
|
placeholder="请输入写作内容"
|
||||||
show-word-limit
|
show-word-limit
|
||||||
/>
|
/>
|
||||||
@@ -190,20 +192,24 @@ function handleSubmit() {
|
|||||||
hint="示例"
|
hint="示例"
|
||||||
label="原文"
|
label="原文"
|
||||||
/>
|
/>
|
||||||
<el-input
|
<ElInput
|
||||||
v-model="formData.originalContent"
|
v-model="formData.originalContent"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:maxlength="500"
|
:maxlength="500"
|
||||||
:rows="5"
|
:rows="5"
|
||||||
|
:input-style="{ boxShadow: 'none' }"
|
||||||
|
resize="none"
|
||||||
placeholder="请输入原文"
|
placeholder="请输入原文"
|
||||||
show-word-limit
|
show-word-limit
|
||||||
/>
|
/>
|
||||||
<ReuseLabel label="回复内容" />
|
<ReuseLabel label="回复内容" />
|
||||||
<el-input
|
<ElInput
|
||||||
v-model="formData.prompt"
|
v-model="formData.prompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:maxlength="500"
|
:maxlength="500"
|
||||||
:rows="5"
|
:rows="5"
|
||||||
|
:input-style="{ boxShadow: 'none' }"
|
||||||
|
resize="none"
|
||||||
placeholder="请输入回复内容"
|
placeholder="请输入回复内容"
|
||||||
show-word-limit
|
show-word-limit
|
||||||
/>
|
/>
|
||||||
@@ -231,12 +237,12 @@ function handleSubmit() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="mt-3 flex items-center justify-center">
|
<div class="mt-3 flex items-center justify-center">
|
||||||
<Button :disabled="isWriting" class="mr-2" @click="reset">
|
<ElButton :disabled="isWriting" class="mr-2" @click="reset">
|
||||||
重置
|
重置
|
||||||
</Button>
|
</ElButton>
|
||||||
<Button type="primary" :loading="isWriting" @click="handleSubmit">
|
<ElButton type="primary" :loading="isWriting" @click="handleSubmit">
|
||||||
生成
|
生成
|
||||||
</Button>
|
</ElButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { computed, ref, watch } from 'vue';
|
|||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { useClipboard } from '@vueuse/core';
|
import { useClipboard } from '@vueuse/core';
|
||||||
import { ElButton as Button, ElCard as Card, ElMessage as message } from 'element-plus';
|
import { ElButton, ElCard, ElInput, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
content: {
|
content: {
|
||||||
@@ -47,16 +47,16 @@ function copyContent() {
|
|||||||
/** 复制成功的时候 copied.value 为 true */
|
/** 复制成功的时候 copied.value 为 true */
|
||||||
watch(copied, (val) => {
|
watch(copied, (val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
message.success('复制成功');
|
ElMessage.success('复制成功');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Card class="flex h-full flex-col">
|
<ElCard class="flex h-full flex-col">
|
||||||
<template #header>
|
<template #header>
|
||||||
<h3 class="m-0 flex shrink-0 items-center justify-between px-7">
|
<h3 class="m-0 flex shrink-0 items-center justify-between px-7">
|
||||||
<span>预览</span>
|
<span>预览</span>
|
||||||
<Button
|
<ElButton
|
||||||
type="primary"
|
type="primary"
|
||||||
v-show="showCopy"
|
v-show="showCopy"
|
||||||
@click="copyContent"
|
@click="copyContent"
|
||||||
@@ -64,7 +64,7 @@ watch(copied, (val) => {
|
|||||||
>
|
>
|
||||||
<IconifyIcon icon="lucide:copy" />
|
<IconifyIcon icon="lucide:copy" />
|
||||||
复制
|
复制
|
||||||
</Button>
|
</ElButton>
|
||||||
</h3>
|
</h3>
|
||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
@@ -74,7 +74,7 @@ watch(copied, (val) => {
|
|||||||
<div
|
<div
|
||||||
class="bg-card relative box-border min-h-full w-full flex-grow p-2 sm:p-5"
|
class="bg-card relative box-border min-h-full w-full flex-grow p-2 sm:p-5"
|
||||||
>
|
>
|
||||||
<Button
|
<ElButton
|
||||||
v-show="isWriting"
|
v-show="isWriting"
|
||||||
class="absolute bottom-1 left-1/2 z-40 flex -translate-x-1/2 sm:bottom-2"
|
class="absolute bottom-1 left-1/2 z-40 flex -translate-x-1/2 sm:bottom-2"
|
||||||
@click="emits('stopStream')"
|
@click="emits('stopStream')"
|
||||||
@@ -86,17 +86,19 @@ watch(copied, (val) => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
终止生成
|
终止生成
|
||||||
</Button>
|
</ElButton>
|
||||||
<el-input
|
<ElInput
|
||||||
id="inputId"
|
id="inputId"
|
||||||
v-model="compContent"
|
v-model="compContent"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{ minRows: 4, maxRows: 25 }"
|
autosize
|
||||||
|
:input-style="{ boxShadow: 'none' }"
|
||||||
|
resize="none"
|
||||||
placeholder="生成的内容……"
|
placeholder="生成的内容……"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</ElCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { AiWriteApi } from '#/api/ai/write';
|
|||||||
|
|
||||||
import { DocAlert, Page } from '@vben/common-ui';
|
import { DocAlert, Page } from '@vben/common-ui';
|
||||||
|
|
||||||
import { ElMessage as message } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteWrite, getWritePage } from '#/api/ai/write';
|
import { deleteWrite, getWritePage } from '#/api/ai/write';
|
||||||
@@ -17,20 +17,20 @@ function handleRefresh() {
|
|||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除 */
|
/** 删除写作记录 */
|
||||||
async function handleDelete(row: AiWriteApi.AiWritePageReq) {
|
async function handleDelete(row: AiWriteApi.Write) {
|
||||||
const hideLoading = message.loading({
|
const loadingInstance = ElLoading.service({
|
||||||
message: $t('ui.actionMessage.deleting', [row.id]),
|
text: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
duration: 0,
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteWrite(row.id as number);
|
await deleteWrite(row.id!);
|
||||||
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
@@ -58,7 +58,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
refresh: true,
|
refresh: true,
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<AiWriteApi.AiWritePageReq>,
|
} as VxeTableGridOptions<AiWriteApi.Write>,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user