Skip to content

Commit 35b2708

Browse files
YunaiVgitee-org
authored andcommitted
!482 [代码优化]AI: 写作页面样式调整,目录更名writer => write,写作管理更改
Merge pull request !482 from hhhero/dev
2 parents 69940e2 + c4ee958 commit 35b2708

File tree

9 files changed

+181
-108
lines changed

9 files changed

+181
-108
lines changed

src/api/ai/write/index.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { fetchEventSource } from '@microsoft/fetch-event-source'
2+
3+
import { getAccessToken } from '@/utils/auth'
4+
import { config } from '@/config/axios/config'
5+
import { AiWriteTypeEnum } from '@/views/ai/utils/constants'
6+
import request from '@/config/axios'
7+
8+
export interface WriteVO {
9+
type: AiWriteTypeEnum.WRITING | AiWriteTypeEnum.REPLY // 1:撰写 2:回复
10+
prompt: string // 写作内容提示 1。撰写 2回复
11+
originalContent: string // 原文
12+
length: number // 长度
13+
format: number // 格式
14+
tone: number // 语气
15+
language: number // 语言
16+
userId?: number // 用户编号
17+
platform?: string // 平台
18+
model?: string // 模型
19+
generatedContent?: string // 生成的内容
20+
errorMessage: string // 错误信息
21+
createTime?: Date // 创建时间
22+
}
23+
24+
export interface AiWritePageReqVO extends PageParam {
25+
userId?: number // 用户编号
26+
type?: AiWriteTypeEnum // 写作类型
27+
platform?: string // 平台
28+
createTime?: [string, string] // 创建时间
29+
}
30+
31+
export interface AiWriteRespVo {
32+
id: number
33+
userId: number
34+
type: number
35+
platform: string
36+
model: string
37+
prompt: string
38+
generatedContent: string
39+
originalContent: string
40+
length: number
41+
format: number
42+
tone: number
43+
language: number
44+
errorMessage: string
45+
createTime: string
46+
}
47+
48+
export const WriteApi = {
49+
writeStream: ({
50+
data,
51+
onClose,
52+
onMessage,
53+
onError,
54+
ctrl
55+
}: {
56+
data: WriteVO
57+
onMessage?: (res: any) => void
58+
onError?: (...args: any[]) => void
59+
onClose?: (...args: any[]) => void
60+
ctrl: AbortController
61+
}) => {
62+
const token = getAccessToken()
63+
return fetchEventSource(`${config.base_url}/ai/write/generate-stream`, {
64+
method: 'post',
65+
headers: {
66+
'Content-Type': 'application/json',
67+
Authorization: `Bearer ${token}`
68+
},
69+
openWhenHidden: true,
70+
body: JSON.stringify(data),
71+
onmessage: onMessage,
72+
onerror: onError,
73+
onclose: onClose,
74+
signal: ctrl.signal
75+
})
76+
},
77+
// 获取写作列表
78+
getWritePage: (params: AiWritePageReqVO) => {
79+
return request.get<PageResult<AiWriteRespVo[]>>({ url: `/ai/write/page`, params })
80+
},
81+
// 删除写作
82+
deleteWrite(id: number) {
83+
return request.delete({ url: `/ai/write/delete`, params: { id } })
84+
}
85+
}

src/api/ai/writer/index.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/views/ai/utils/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export enum AiWriteTypeEnum {
6464
REPLY // 回复
6565
}
6666

67+
// 表格展示对照map
68+
export const AiWriteTypeTableRender = {
69+
[AiWriteTypeEnum.WRITING]: '撰写',
70+
[AiWriteTypeEnum.REPLY]: '回复',
71+
}
72+
6773
// ========== 【图片 UI】相关的枚举 ==========
6874
export const ImageHotWords = [
6975
'中国旗袍',

src/views/ai/writer/index/components/Left.vue renamed to src/views/ai/write/index/components/Left.vue

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,28 @@
2424
</h3>
2525
</DefineLabel>
2626

27-
<div class="relative" v-bind="$attrs">
27+
<div class="flex flex-col" v-bind="$attrs">
2828
<!-- tab -->
29-
<div
30-
class="absolute left-1/2 top-2 -translate-x-1/2 w-[303px] rounded-full bg-[#DDDFE3] p-1 z-10"
31-
>
32-
<div
33-
class="flex items-center relative after:content-[''] after:block after:bg-white after:h-[30px] after:w-1/2 after:absolute after:top-0 after:left-0 after:transition-transform after:rounded-full"
34-
:class="selectedTab === AiWriteTypeEnum.REPLY && 'after:transform after:translate-x-[100%]'"
35-
>
36-
<ReuseTab
37-
v-for="tab in tabs"
38-
:key="tab.value"
39-
:text="tab.text"
40-
:active="tab.value === selectedTab"
41-
:itemClick="() => switchTab(tab.value)"
42-
/>
29+
<div class="w-full pt-2 bg-[#f5f7f9] flex justify-center">
30+
<div class="w-[303px] rounded-full bg-[#DDDFE3] p-1 z-10">
31+
<div
32+
class="flex items-center relative after:content-[''] after:block after:bg-white after:h-[30px] after:w-1/2 after:absolute after:top-0 after:left-0 after:transition-transform after:rounded-full"
33+
:class="
34+
selectedTab === AiWriteTypeEnum.REPLY && 'after:transform after:translate-x-[100%]'
35+
"
36+
>
37+
<ReuseTab
38+
v-for="tab in tabs"
39+
:key="tab.value"
40+
:text="tab.text"
41+
:active="tab.value === selectedTab"
42+
:itemClick="() => switchTab(tab.value)"
43+
/>
44+
</div>
4345
</div>
4446
</div>
4547
<div
46-
class="px-7 pb-2 pt-[46px] overflow-y-auto lg:block w-[380px] box-border bg-[#ECEDEF] h-full"
48+
class="px-7 pb-2 flex-grow overflow-y-auto lg:block w-[380px] box-border bg-[#f5f7f9] h-full"
4749
>
4850
<div>
4951
<template v-if="selectedTab === 1">
@@ -102,7 +104,7 @@
102104
import { createReusableTemplate } from '@vueuse/core'
103105
import { ref } from 'vue'
104106
import Tag from './Tag.vue'
105-
import { WriteVO } from '@/api/ai/writer'
107+
import { WriteVO } from 'src/api/ai/write'
106108
import { omit } from 'lodash-es'
107109
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
108110
import { AiWriteTypeEnum, WriteExample } from '@/views/ai/utils/constants'
@@ -177,10 +179,18 @@ const initData: WriteVO = {
177179
}
178180
const formData = ref<WriteVO>({ ...initData })
179181
182+
/** 用来记录切换之前所填写的数据,切换的时候给赋值回来 **/
183+
const recordFormData = {} as Record<AiWriteTypeEnum, WriteVO>
184+
180185
/** 切换tab **/
181186
const switchTab = (value: TabType) => {
182-
selectedTab.value = value
183-
formData.value = { ...initData }
187+
if (value !== selectedTab.value) {
188+
// 保存之前的久数据
189+
recordFormData[selectedTab.value] = formData.value
190+
selectedTab.value = value
191+
// 将之前的旧数据赋值回来
192+
formData.value = { ...initData, ...recordFormData[value] }
193+
}
184194
}
185195
186196
/** 提交写作 */

src/views/ai/writer/index/components/Right.vue renamed to src/views/ai/write/index/components/Right.vue

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<template>
2-
<div class="h-full box-border flex flex-col px-7">
3-
<h3 class="m-0 h-14 -mx-7 px-7 shrink-0 flex items-center justify-between bg-[#ecedef]">
4-
<span>预览</span>
5-
<!-- 展示在右上角 -->
6-
<el-button color="#846af7" v-show="showCopy" @click="copyContent" size="small">
7-
<template #icon>
8-
<Icon icon="ph:copy-bold" />
9-
</template>
10-
复制
11-
</el-button>
12-
</h3>
2+
<el-card class="my-card h-full">
3+
<template #header
4+
><h3 class="m-0 px-7 shrink-0 flex items-center justify-between">
5+
<span>预览</span>
6+
<!-- 展示在右上角 -->
7+
<el-button color="#846af7" v-show="showCopy" @click="copyContent" size="small">
8+
<template #icon>
9+
<Icon icon="ph:copy-bold" />
10+
</template>
11+
复制
12+
</el-button>
13+
</h3></template
14+
>
1315

14-
<div ref="contentRef" class="hide-scroll-bar flex-grow box-border overflow-y-auto">
16+
<div ref="contentRef" class="hide-scroll-bar h-full box-border overflow-y-auto">
1517
<div class="w-full min-h-full relative flex-grow bg-white box-border p-3 sm:p-7">
1618
<!-- 终止生成内容的按钮 -->
1719
<el-button
@@ -36,7 +38,7 @@
3638
/>
3739
</div>
3840
</div>
39-
</div>
41+
</el-card>
4042
</template>
4143

4244
<script setup lang="ts">
@@ -102,4 +104,17 @@ watch(copied, (val) => {
102104
height: 0;
103105
}
104106
}
107+
108+
.my-card{
109+
display: flex;
110+
flex-direction: column;
111+
112+
:deep(.el-card__body) {
113+
box-sizing: border-box;
114+
flex-grow: 1;
115+
overflow-y: auto;
116+
padding: 0;
117+
@extend .hide-scroll-bar;
118+
}
119+
}
105120
</style>

src/views/ai/writer/index/index.vue renamed to src/views/ai/write/index/index.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
2-
<!-- TODO @hhhero:整体没啥问题了。感觉整体框框的样子可以优化下,可以参考下绘图界面。例如说:1)写作的“预览”和绘图的“绘图任务”的 header;2)左右的边界,有个竖线之类的。 -->
3-
<div class="h-[calc(100vh-var(--top-tool-height)-var(--app-footer-height)-40px)] -m-5 flex">
2+
<div class="absolute top-0 left-0 right-0 bottom-0 flex">
43
<Left
54
:is-writing="isWriting"
65
class="h-full"
@@ -21,7 +20,7 @@
2120
<script setup lang="ts">
2221
import Left from './components/Left.vue'
2322
import Right from './components/Right.vue'
24-
import * as WriteApi from '@/api/ai/writer'
23+
import { WriteApi } from '@/api/ai/write'
2524
import { WriteExample } from '@/views/ai/utils/constants'
2625
2726
const message = useMessage()
@@ -66,7 +65,7 @@ const submit = (data) => {
6665
}
6766
6867
/** 点击示例触发 */
69-
const handleExampleClick = (type: keyof typeof WriteExampleDataJson) => {
68+
const handleExampleClick = (type: keyof typeof WriteExample) => {
7069
writeResult.value = WriteExample[type].data
7170
}
7271

0 commit comments

Comments
 (0)