diff --git a/src/apis/paths/conversation.ts b/src/apis/paths/conversation.ts index bfeb68e414fffccad034aa160a1b1d1f1cfbd224..1f5bba1b691b711b77bbe60c4c3d8db6a5e7a3b1 100644 --- a/src/apis/paths/conversation.ts +++ b/src/apis/paths/conversation.ts @@ -1,4 +1,4 @@ -// Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. +// Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. // licensed under the Mulan PSL v2. // You can use this software according to the terms and conditions of the Mulan PSL v2. // You may obtain a copy of Mulan PSL v2 at: @@ -122,26 +122,44 @@ export const getHistoryConversation = ( }; /** - * 评论对话 + * 点踩 * @param params * @returns */ export const commentConversation = (params: { + type: string; qaRecordId: string; - isLike: number; + comment: string; dislikeReason?: string; reasonLink?: string; reasonDescription?: string; + groupId: string | undefined; }): Promise<[any, FcResponse> | undefined]> => { - const { qaRecordId, isLike, dislikeReason, reasonLink, reasonDescription } = - params; - return post(`/api/comment`, { - record_id: qaRecordId, - is_like: isLike, - dislike_reason: dislikeReason, - reason_link: reasonLink, - reason_description: reasonDescription, - }); + const { + qaRecordId, + comment, + dislikeReason, + reasonLink, + reasonDescription, + groupId, + type, + } = params; + if (type === 'disliked') { + return post(`/api/comment`, { + record_id: qaRecordId, + comment: comment, + group_id: groupId, + dislike_reason: dislikeReason, + reason_link: reasonLink, + reason_description: reasonDescription, + }); + } else { + return post(`/api/comment`, { + record_id: qaRecordId, + group_id: groupId, + comment: comment, + }); + } }; export const getRecognitionMode = (): Promise< diff --git a/src/apis/paths/external.ts b/src/apis/paths/external.ts index 7bd1730a4333ee1235662d0e0cc379a58629158b..6f68d17c94d50daea55968d02c0a43e01399c292 100644 --- a/src/apis/paths/external.ts +++ b/src/apis/paths/external.ts @@ -30,6 +30,7 @@ export const feedback = (params: { * @returns */ export const report = (params: { + reason_type: string; record_id: string; reason: string; }): Promise<[any, FcResponse | undefined]> => { diff --git a/src/components/dialoguePanel/DialoguePanel.vue b/src/components/dialoguePanel/DialoguePanel.vue index 8c8c3a2f182074685ec5ba20fb170340db919333..e98e904658925bdb0b48f7fea8cf42cfd9a04e1a 100644 --- a/src/components/dialoguePanel/DialoguePanel.vue +++ b/src/components/dialoguePanel/DialoguePanel.vue @@ -2,6 +2,7 @@ import type { DialoguePanelType } from './type'; import { useDialogueActions } from './hooks/useDialogueActions'; import { useMarkdownParser } from './hooks/useMarkdownParser'; +import { useCommentAndReport } from './hooks/useCommentAndReport'; import { ref, toRef } from 'vue'; import { echartsObj } from 'src/store/conversation'; import { useHistorySessionStore } from 'src/store'; @@ -9,7 +10,7 @@ import AgainstPopover from 'src/views/dialogue/components/AgainstPopover.vue'; import dayjs from 'dayjs'; import ReportPopover from 'src/views/dialogue/components/ReportPopover.vue'; import DialogueThought from './DialogueThought.vue'; -import { onMounted, watch, onBeforeUnmount, reactive } from 'vue'; +import { watch, onBeforeUnmount, reactive } from 'vue'; import * as echarts from 'echarts'; import color from 'src/assets/color'; import { storeToRefs } from 'pinia'; @@ -24,6 +25,8 @@ export interface DialoguePanelProps { key: number; // cid: number; + // groupid + groupId: string; // 用来区分是用户还是ai的输入 type: DialoguePanelType; // 文本内容 @@ -47,7 +50,9 @@ export interface DialoguePanelProps { // recordList?: string[] | undefined; // - isLikeList?: number[] | undefined; + isCommentList: string[] | undefined; + // + comment?: number[] | undefined; // search_suggestions?: any; // @@ -68,6 +73,7 @@ export interface DialoguePanelProps { import JsonFormComponent from './JsonFormComponent.vue'; import { Metadata } from 'src/apis/paths/type'; import DialogueFlow from './DialogueFlow.vue'; +import { api } from 'src/apis'; var option = ref(); var show = ref(false); @@ -75,8 +81,6 @@ const size = reactive({ width: 328, height: 416, }); -const isSupport = ref(false); -const isAgainst = ref(false); const themeStore = useChangeThemeStore(); var myChart; const { pausedStream, reGenerateAnswer, prePage, nextPage } = useSessionStore(); @@ -96,6 +100,21 @@ const { thoughtContent, contentAfterMark } = useMarkdownParser( toRef(props, 'content'), toRef(props, 'currentSelected'), ); + +const { + isComment, + isSupport, + isAgainst, + isAgainstVisible, + isReportVisible, + handleLike, + handleDislike, + handleIsLike, +} = useCommentAndReport( + toRef(props, 'isCommentList'), + toRef(props, 'recordList'), + toRef(props, 'groupId'), +); const index = ref(0); const isLike = ref(props.isLikeList); const emits = defineEmits<{ @@ -117,7 +136,6 @@ const emits = defineEmits<{ (e: 'clearSuggestion', index: number): void; }>(); -// #region ----------------------------------------< pause and regenerate >-------------------------------------- /** * 暂停和重新生成问答 */ @@ -152,10 +170,17 @@ const unbindDocumentClick = () => { }; // 举报功能 目前未实现 -const handleReport = async (reason: string): Promise => { +const handleReport = async (reason_type: string,reason: string): Promise => { const qaRecordId = props.recordList[index.value]; - emits('report', qaRecordId, reason); - isAgainstVisible.value = false; + await api + .report({ + reason_type: reason_type, + reason, + record_id: qaRecordId, + }) + .then((res) => { + isReportVisible.value = false; + }); }; //处理举报逻辑 @@ -173,9 +198,6 @@ const unbindReportClick = () => { document.removeEventListener('click', handleReportClick); }; -const isAgainstVisible = ref(false); -const isReportVisible = ref(false); - const txt2imgPathZoom = ref(''); const prePageHandle = (cid: number) => { @@ -185,7 +207,7 @@ const prePageHandle = (cid: number) => { index.value = 0; } else { index.value--; - // handleIsLike(); + handleIsLike(); } }; @@ -196,7 +218,7 @@ const nextPageHandle = (cid: number) => { index.value = (props.isLikeList as number[]).length - 1; } else { index.value++; - // handleIsLike(); + handleIsLike(); } }; @@ -472,6 +494,7 @@ const searchAppName = (appId) => { class="button-icon" v-if="!isSupport && themeStore.theme === 'dark'" src="@/assets/svgs/dark_support.svg" + @click="handleLike('liked')" /> { (themeStore.theme === 'light' || !themeStore.theme) " src="@/assets/svgs/light_support.svg" + @click="handleLike('liked')" /> { class="button-icon" v-if="!isAgainst && themeStore.theme === 'dark'" src="@/assets/svgs/dark_against.svg" + @click="handleLike('disliked')" /> { (themeStore.theme === 'light' || !themeStore.theme) " src="@/assets/svgs/light_against.svg" + @click="handleLike('disliked')" /> - + { v-if="themeStore.theme === 'dark'" class="button-icon" src="@/assets/svgs/dark_report.svg" + @click="handleLike('report')" /> , + recordList: Ref, + groupId: Ref, +) { + const isComment = ref(isCommentList); + const isSupport = ref(false); + const isAgainst = ref(false); + const isAgainstVisible = ref(false); + const isReportVisible = ref(false); + const index = ref(0); + const qaRecordId = ref(recordList.value[index.value]); + + /** + * 赞同与反对 + */ + const handleLike = async ( + type: 'liked' | 'disliked' | 'report', + ): Promise => { + if (type === 'liked') { + await api + .commentConversation({ + type: !isSupport.value ? 'liked' : 'none', + qaRecordId: qaRecordId.value, + comment: !isSupport.value ? 'liked' : 'none', + groupId: groupId.value, + }) + .then((res) => { + if (res[0].status === 200) { + isComment.value[index.value] = 'liked'; + handleIsLike(); + } + }); + } else if (type === 'disliked') { + isAgainstVisible.value = true; + } else { + isReportVisible.value = true; + } + }; + + const handleDislike = async ( + reason: string, + reasionLink?: string, + reasonDescription?: string, + ): Promise => { + await api.commentConversation( + { + type: 'disliked', + qaRecordId: qaRecordId.value, + comment: reason, + groupId: groupId.value, + reasonLink: reasionLink, + reasonDescription: reasonDescription, + } + ).then((res) => { + if(res[0].status === 200){ + console.log('handleDislike'); + isAgainstVisible.value = false; + isComment.value[index.value] = 'disliked'; + handleIsLike(); + }; + }); + }; + + const handleIsLike = () => { + if (isComment.value === undefined) { + return; + } else { + if ( + index.value <= isComment.value.length && + isComment.value.length !== 0 + ) { + let comment = isComment.value[index.value]; + if (comment !== 'none') { + isSupport.value = comment === 'liked'; + isAgainst.value = !isSupport.value; + } else { + isSupport.value = false; + isAgainst.value = false; + } + } + } + }; + // 监听更新初始状态 + watch( + () => isCommentList, + (val, oldVal) => { + handleIsLike(); + }, + { immediate: true } + ); + return { + isComment, + isSupport, + isAgainst, + isAgainstVisible, + isReportVisible, + handleIsLike, + handleLike, + handleDislike, + }; +} diff --git a/src/components/dialoguePanel/hooks/useDialogueWatch.ts b/src/components/dialoguePanel/hooks/useDialogueWatch.ts deleted file mode 100644 index 36f8ab660079cf64100d3a0173a6e6450d3aed83..0000000000000000000000000000000000000000 --- a/src/components/dialoguePanel/hooks/useDialogueWatch.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { ref, watch } from 'vue'; -import type { Ref } from 'vue'; - -// 判断是否点赞,逻辑待补充 -export function useIslikeList(isLikeList: Ref) { - const isLike = ref(undefined); - const isSupport = ref(false); - const isAgainst = ref(false); - const handleIsLike = () => { - if (isLike.value) { - isSupport.value = true; - isAgainst.value = false; - } else { - isSupport.value = false; - isAgainst.value = true; - } - }; - /** - * 反对 - * @param reason - * @param reasionLink - * @param reasonDescription - */ - watch( - () => isLikeList, - (val, oldVal) => { - handleIsLike(); - }, - ); - return { - isLike, - } -} \ No newline at end of file diff --git a/src/views/createapp/components/workFlow.vue b/src/views/createapp/components/workFlow.vue index aab31aa441f639b966c4ef1a9599aa4701c82fdd..879cbee03bb9e166f3420b213da2b2f6e718dac6 100644 --- a/src/views/createapp/components/workFlow.vue +++ b/src/views/createapp/components/workFlow.vue @@ -908,7 +908,6 @@ defineExpose({ >
{ }); // 需要界面配置校验与工作流校验同时通过 -const handlePulishApp = () => { - loading.value = true; - // 发布接口 - api +const handlePulishApp = async() => { + // 发布接口前,先保存界面配置与工作流 + await handleCreateOrUpdateApp().then((res) => { + api .releaseSingleAppData({ id: route.query?.appId as string, }) @@ -54,6 +54,10 @@ const handlePulishApp = () => { loading.value = false; } }); + }).catch((error) => { + ElMessage.error(`发布失败: ${error.message}`); + }) + ; }; const handleValidateContent = (valid) => { @@ -91,10 +95,9 @@ const judgeAppFlowsDebug = (flowDataList) => { // 初始化时,获取发布的校验结果---必须有工作流且所有工作流必须debug通过 publishValidate.value = flowDataList?.length > 0 && flowsDebug; }; - -// 保存按钮 -const saveConfigOrFlow = () => { - if (createAppType.value === 'appConfig') { +// 保存功能 +const handleCreateOrUpdateApp = (): Promise => { + return new Promise((resolve, reject) => { loading.value = true; let appFormValue = appConfigRef.value.createAppForm; if (appFormValue) { @@ -122,8 +125,19 @@ const saveConfigOrFlow = () => { }); } loading.value = false; + resolve(); }); + }else{ + loading.value = false; + reject(); } + }) +} + +// 保存按钮处理方法 +const saveConfigOrFlow = async () => { + if (createAppType.value === 'appConfig') { + await handleCreateOrUpdateApp(); } else { // 工作流页面保存当前的工作流 workFlowRef.value.saveFlow(); diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index ad31c2643625d9ebd1d2c3b76f605c93db2b109c..e4d1b2daaf8c9285c43bd7b97ac66dd9fddd6007 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -23,11 +23,6 @@ export interface DialogueSession { } const props = withDefaults(defineProps(), {}); - -enum SupportMap { - support = 1, - against = 0, -} const Form = ref(props.createAppForm); const AppForm = ref(props.createAppForm); const { pausedStream } = useSessionStore(); @@ -235,59 +230,6 @@ const getItem = (item: ConversationItem, field: string): T | undefined => { // textarea实例 const inputRef = ref(null); -/** - * 支持、反对 更改逻辑的钩子函数。 - * @param type - * @param cid - */ -const handleCommont = async ( - type: 'support' | 'against', - cid: number, - qaRecordId: number, - index: number, - reason?: string, - reasonLink?: string, - reasonDescription?: string, -) => { - const params: { - qaRecordId: string; - isLike: number; - dislikeReason?: string; - reasonLink?: string; - reasonDescription?: string; - } = { - qaRecordId: qaRecordId, - isLike: SupportMap[type], - dislikeReason: reason, - reasonLink: reasonLink, - reasonDescription: reasonDescription, - }; - - const [_, res] = await api.commentConversation(params); - if (!_ && res) { - successMsg(i18n.global.t('feedback.feedbackSuccesful')); - } -}; - -/** - * 举报逻辑的钩子函数。 - * @param type - * @param cid - */ -const handleReport = async (qaRecordId: string, reason: string) => { - const params: { - qaRecordId: string; - reason: string; - } = { - record_id: qaRecordId, - reason: reason, - }; - const [_, res] = await api.report(params); - if (!_ && res) { - successMsg(i18n.global.t('feedback.feedbackSuccesful')); - } -}; - // 上传按钮对象 const uploadButton = ref(); // 最大上传数量 @@ -781,6 +723,7 @@ watch( v-for="(item, index) in conversationList" :cid="item.cid" :key="index" + :groupId="getItem(item, 'groupId')" :type="item.belong" :inputParams="item.params" :content="item.message" @@ -788,9 +731,8 @@ watch( :recordList=" item.belong === 'robot' ? item.messageList.getRecordIdList() : '' " - :isLikeList=" - item.belong === 'robot' ? item.messageList.getIslikeList() : '' - " + :isCommentList=" + item.belong === 'robot' ? item.messageList.getCommentList() : ''" :is-finish="getItem(item, 'isFinish')" :is-support="getItem(item, 'isSupport')" :is-against="getItem(item, 'isAgainst')" @@ -804,8 +746,6 @@ watch( :search_suggestions="getItem(item, 'search_suggestions')" :paramsList="getItem(item, 'paramsList')" :modeOptions="modeOptions" - @commont="handleCommont" - @report="handleReport" @handleSendMessage="handleSendMessage" @clearSuggestion="clearSuggestion(index)" /> diff --git a/src/views/dialogue/components/InitalPanel.vue b/src/views/dialogue/components/InitalPanel.vue index 4dd881ea3e876b9004c6b9d9e82528d0e373a2b4..445f00eef86c6499fbe1b709f06d8db4a277f5ba 100644 --- a/src/views/dialogue/components/InitalPanel.vue +++ b/src/views/dialogue/components/InitalPanel.vue @@ -7,7 +7,6 @@ import router from 'src/router'; const themeStore = useChangeThemeStore(); import { useRoute } from 'vue-router'; import { api } from 'src/apis'; -import { emit } from 'process'; const route = useRoute(); const appName = ref(); diff --git a/src/views/dialogue/components/ReportPopover.vue b/src/views/dialogue/components/ReportPopover.vue index a0941b6a8165c8290f348e3c0dc24d54c00b2a10..85627433cc0c67c1a0f0e1c099f3cdd70efd8bdd 100644 --- a/src/views/dialogue/components/ReportPopover.vue +++ b/src/views/dialogue/components/ReportPopover.vue @@ -45,20 +45,17 @@ const descText = ref(''); const isErrorInputVisiable = computed(() => list.value[2].isChecked); const emits = defineEmits<{ - (e: 'report', reason: string): void; + (e: 'report', reason_type: string,reason: string): void; (e: 'close'): void; }>(); /** 举报 */ const handleComplaint = () => { - const str = descText.value.length - ? radio.value + ';' + descText.value - : radio.value; if (!isErrorInputVisiable.value) { - emits('report', str); + emits('report', radio.value, descText.value); return; } - emits('report', str); + emits('report', radio.value, descText.value); }; diff --git a/src/views/dialogue/types.ts b/src/views/dialogue/types.ts index 2789fff90ce060dd09246bda74561f31670cc287..9e2dfc4a5fab6ca222608e11d2dab40c8e351ce8 100644 --- a/src/views/dialogue/types.ts +++ b/src/views/dialogue/types.ts @@ -1,4 +1,4 @@ -// Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. +// Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. // licensed under the Mulan PSL v2. // You can use this software according to the terms and conditions of the Mulan PSL v2. // You may obtain a copy of Mulan PSL v2 at: @@ -89,6 +89,7 @@ export interface RobotConversationItem { // 当前选中第n次回答的索引值 currentInd: number; isFinish?: boolean; + comment?: string; isSupport?: boolean; isAgainst?: boolean; createdAt?: string | Date; @@ -103,16 +104,16 @@ export interface RobotConversationItem { export interface MessageRecord { message: string; record_id: string; - is_like: number | undefined; + comment: string; } export class MessageArray { private items: MessageRecord[] = []; - addItem(message: string, record_id: string, is_like: number): void { + addItem(message: string, record_id: string, comment: string): void { const newItem: MessageRecord = { message, record_id, - is_like, + comment, }; this.items.push(newItem); } @@ -137,20 +138,20 @@ export class MessageArray { return this.items.map((item) => item.record_id); } - getIslikeList(): number[] { + getCommentList(): string[] { //类型断言,将undefined转换为0。 - return this.items.map((item) => item.is_like ?? 0); + return this.items.map((item) => item.comment ? item.comment : 'none'); } - getisLikeByIndex(index: number): number { - return this.items.map((item) => item.is_like ?? 0)[index]; + getCommentyIndex(index: number): string { + return this.items.map((item) => item.comment ? item.comment : 'none')[index]; } - changeisLikeByCidAndIndex( + changeCommentByCidAndIndex( cid: number, index: number, - islike: number | boolean, + comment: string, ): void { - this.getisLikeByIndex(index)[cid] = islike; + } }