Skip to content

Commit e7a759f

Browse files
feat: chat share
1 parent 24991b8 commit e7a759f

File tree

11 files changed

+120
-28
lines changed

11 files changed

+120
-28
lines changed

ui/src/api/chat/chat.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,11 @@ const postShareChat: (
361361
data: any,
362362
loading?: Ref<boolean>,
363363
) => Promise<any> = (application_id, chat_id, data, loading) => {
364-
return post(
365-
`${prefix.value}/${application_id}/chat/${chat_id}/share_chat`,
366-
data,
367-
undefined,
368-
loading,
369-
)
364+
return post(`/${application_id}/chat/${chat_id}/share_chat`, data, undefined, loading)
365+
}
366+
367+
const getShareLink: (link: string) => Promise<Result<any>> = (link) => {
368+
return get(`/share/${link}`, undefined)
370369
}
371370

372371
export default {
@@ -401,4 +400,5 @@ export default {
401400
postUploadFile,
402401
getFile,
403402
postShareChat,
403+
getShareLink,
404404
}

ui/src/components/ai-chat/component/answer-content/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const props = defineProps<{
8989
loading: boolean
9090
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => Promise<boolean>
9191
chatManagement: any
92-
type: 'log' | 'ai-chat' | 'debug-ai-chat'
92+
type: 'log' | 'ai-chat' | 'debug-ai-chat' | 'share'
9393
executionIsRightPanel?: boolean
9494
selection?: boolean
9595
}>()

ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const {
180180
const props = withDefaults(
181181
defineProps<{
182182
data: any
183-
type: 'log' | 'ai-chat' | 'debug-ai-chat'
183+
type: 'log' | 'ai-chat' | 'debug-ai-chat' | 'share'
184184
chatId: string
185185
chat_loading: boolean
186186
applicationId: string

ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
v-if="!audioPlayerStatus"
1717
>
1818
<el-button text @click="playAnswerText(data?.answer_text)">
19-
<AppIcon iconName="app-video-play"></AppIcon>
19+
<AppIcon iconName="app-video-play" class="color-secondary"></AppIcon>
2020
</el-button>
2121
</el-tooltip>
2222
<el-tooltip v-else effect="dark" :content="$t('chat.operation.pause')" placement="top">
2323
<el-button type="primary" text @click="pausePlayAnswerText()">
24-
<AppIcon iconName="app-video-pause"></AppIcon>
24+
<AppIcon iconName="app-video-pause" class="color-secondary"></AppIcon>
2525
</el-button>
2626
</el-tooltip>
2727
<el-divider direction="vertical" />
2828
</span>
2929
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
3030
<el-button text @click="copyClick(data?.answer_text)">
31-
<AppIcon iconName="app-copy"></AppIcon>
31+
<AppIcon iconName="app-copy" class="color-secondary"></AppIcon>
3232
</el-button>
3333
</el-tooltip>
3434
<el-divider direction="vertical" />
@@ -40,7 +40,7 @@
4040
placement="top"
4141
>
4242
<el-button text @click="editContent(data)">
43-
<AppIcon iconName="app-edit"></AppIcon>
43+
<AppIcon iconName="app-edit" class="color-secondary"></AppIcon>
4444
</el-button>
4545
</el-tooltip>
4646

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<div>
3+
<div class="flex-between mt-8">
4+
<div>
5+
<el-text type="info">
6+
<span class="ml-4">{{ datetimeFormat(data.create_time) }}</span>
7+
</el-text>
8+
</div>
9+
<div>
10+
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
11+
<el-button text @click="copyClick(data?.answer_text)">
12+
<AppIcon iconName="app-copy" class="color-secondary"></AppIcon>
13+
</el-button>
14+
</el-tooltip>
15+
</div>
16+
</div>
17+
</div>
18+
</template>
19+
<script setup lang="ts">
20+
import { computed, onMounted, ref } from 'vue'
21+
import { copyClick } from '@/utils/clipboard'
22+
23+
import { datetimeFormat } from '@/utils/time'
24+
25+
import { useRoute } from 'vue-router'
26+
27+
const route = useRoute()
28+
const {
29+
params: { id },
30+
} = route as any
31+
32+
const props = defineProps({
33+
data: {
34+
type: Object,
35+
default: () => {},
36+
},
37+
})
38+
</script>
39+
<style lang="scss" scoped></style>

ui/src/components/ai-chat/component/operation-button/index.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
32
<div class="operation-button-container">
3+
<ShareOperationButton v-if="type === 'share'" v-bind:data="chatRecord" />
44

55
<LogOperationButton
6-
v-if="type === 'log'"
6+
v-else-if="type === 'log'"
77
v-bind:data="chatRecord"
88
@update:data="(event: any) => emit('update:chatRecord', event)"
99
:applicationId="application.id"
@@ -42,9 +42,10 @@
4242
<script setup lang="ts">
4343
import ChatOperationButton from '@/components/ai-chat/component/operation-button/ChatOperationButton.vue'
4444
import LogOperationButton from '@/components/ai-chat/component/operation-button/LogOperationButton.vue'
45+
import ShareOperationButton from '@/components/ai-chat/component/operation-button/ShareOperationButton.vue'
4546
import { type chatType } from '@/api/type/application'
4647
defineProps<{
47-
type: 'log' | 'ai-chat' | 'debug-ai-chat'
48+
type: 'log' | 'ai-chat' | 'debug-ai-chat' | 'share'
4849
chatRecord: chatType
4950
application: any
5051
loading: boolean

ui/src/components/ai-chat/component/question-content/index.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,8 @@
165165
</div>
166166
</div>
167167
<div class="question-edit-button text-right mt-4" v-if="!selection">
168-
<div v-if="!isReQuestion && showIcon">
169-
<el-tooltip
170-
effect="dark"
171-
:content="$t('common.edit')"
172-
placement="top"
173-
v-if="props.isLast && props.type !== 'log'"
174-
>
168+
<div v-if="!isReQuestion && showIcon && props.type === 'ai-chat'">
169+
<el-tooltip effect="dark" :content="$t('common.edit')" placement="top" v-if="props.isLast">
175170
<el-button text @click.stop="handleEdit(chatRecord)">
176171
<AppIcon class="color-secondary" iconName="app-edit"></AppIcon>
177172
</el-button>
@@ -201,7 +196,7 @@ const props = defineProps<{
201196
chatRecord: chatType
202197
chatManagement: any
203198
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => Promise<boolean>
204-
type: 'log' | 'ai-chat' | 'debug-ai-chat'
199+
type: 'log' | 'ai-chat' | 'debug-ai-chat' | 'share'
205200
isLast: boolean
206201
selection?: boolean
207202
}>()

ui/src/components/ai-chat/index.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
v-model:chat-id="chartOpenId"
126126
v-model:loading="loading"
127127
v-model:show-user-input="showUserInput"
128-
v-else-if="type !== 'log'"
128+
v-else-if="type !== 'log' && type !== 'share'"
129129
>
130130
<template #userInput>
131131
<el-button
@@ -179,6 +179,7 @@ import type { CheckboxValueType } from 'element-plus'
179179
import { t } from '@/locales'
180180
import bus from '@/bus'
181181
import { throttle } from 'lodash-es'
182+
import { copyClick } from '@/utils/clipboard'
182183
provide('upload', (file: any, loading?: Ref<boolean>) => {
183184
return props.type === 'debug-ai-chat'
184185
? applicationApi.postUploadFile(file, 'TEMPORARY_120_MINUTE', 'TEMPORARY_120_MINUTE', loading)
@@ -194,7 +195,7 @@ const {
194195
const props = withDefaults(
195196
defineProps<{
196197
applicationDetails: any
197-
type?: 'log' | 'ai-chat' | 'debug-ai-chat'
198+
type?: 'log' | 'ai-chat' | 'debug-ai-chat' | 'share'
198199
appId?: string
199200
record?: Array<chatType>
200201
available?: boolean
@@ -308,8 +309,9 @@ function shareChatHandle() {
308309
is_current_all: checkAll.value,
309310
}
310311
chatAPI.postShareChat(id || props.appId, chartOpenId.value, obj, shareLoading).then((res) => {
311-
console.log(res)
312-
312+
if (res.data?.link) {
313+
copyClick(window.location.origin + '/chat/share/' + res.data.link)
314+
}
313315
})
314316
}
315317

ui/src/router/chat/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const router = createRouter({
2020
router.beforeEach(
2121
async (to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
2222
NProgress.start()
23-
if (to.path === '/404') {
23+
if (to.path === '/404' || to.name === 'Share') {
2424
next()
2525
return
2626
}

ui/src/router/chat/routes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ export const routes: Array<RouteRecordRaw> = [
2424
name: 'NoService',
2525
component: () => import('@/views/error/NoService.vue'),
2626
},
27+
// 对话
28+
{
29+
path: '/share/:link',
30+
name: 'Share',
31+
component: () => import('@/views/chat/Share.vue'),
32+
},
2733
]

0 commit comments

Comments
 (0)