This commit is contained in:
AceDataCloud committed 2023-04-11 02:02:57 +08:00
1 parent c38d6ba67c
commit 62ec02e6c9
9 files changed
+202 -483

No files matched your search

+40 -2
View File
@@ -3,6 +3,12 @@
<el-image :src="author.avatar" class="icon" />
<message-content :content="content" class="content" :error="error" :state="state" />
</div>
<div class="operations">
<el-button v-if="author.type === 'bot' && content.value" class="operation" size="small" @click="onCopy">
<font-awesome-icon icon="fa-regular fa-copy" class="icon-copy" />
{{ $t('common.button.copy') }}
</el-button>
</div>
</template>
<script lang="ts">
@@ -10,13 +16,21 @@ import { IBot, IUser } from '@/operators';
import { IContent, IError, IMessageState } from '@/operators/message/models';
import { defineComponent } from 'vue';
import MessageContent from './MessageContent.vue';
import { ElImage } from 'element-plus';
import { ElImage, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import copy from 'copy-to-clipboard';
interface IData {
copied: boolean;
}
export default defineComponent({
name: 'Message',
components: {
MessageContent,
ElImage
ElImage,
ElButton,
FontAwesomeIcon
},
props: {
content: {
@@ -42,10 +56,26 @@ export default defineComponent({
}
}
},
data(): IData {
return {
copied: false
};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
},
methods: {
onCopy() {
copy(this.content.value, {
debug: true
});
this.copied = true;
setTimeout(() => {
this.copied = false;
}, 3000);
}
}
});
</script>
@@ -65,4 +95,12 @@ export default defineComponent({
flex: 1;
}
}
.operations {
width: fit-content;
margin: auto;
.fa-copy {
margin-right: 5px;
}
}
</style>
@@ -21,7 +21,9 @@ import {
ERROR_CODE_BUSY,
ERROR_CODE_BAD_REQUEST,
ERROR_CODE_NO_CONVERSATION,
ERROR_CODE_USED_UP
ERROR_CODE_USED_UP,
ERROR_CODE_UNKNOWN,
ERROR_CODE_TIMEOUT
} from '@/constants';
import AnsweringMark from './AnsweringMark.vue';
@@ -81,6 +83,12 @@ export default defineComponent({
if (this.error?.code === ERROR_CODE_NO_CONVERSATION) {
return this.$t('conversation.message.errorNoConversation');
}
if (this.error?.code === ERROR_CODE_UNKNOWN) {
return this.$t('conversation.message.errorUnknown');
}
if (this.error?.code === ERROR_CODE_TIMEOUT) {
return this.$t('conversation.message.errorTimeout');
}
return undefined;
}
},
+2
View File
@@ -5,3 +5,5 @@ export const ERROR_CODE_API_ERROR = 'api_error';
export const ERROR_CODE_BAD_REQUEST = 'bad_request';
export const ERROR_CODE_NO_CONVERSATION = 'no_conversation';
export const ERROR_CODE_USED_UP = 'used_up';
export const ERROR_CODE_UNKNOWN = 'unknown';
export const ERROR_CODE_TIMEOUT = 'timeout';
+2 -1
View File
@@ -26,5 +26,6 @@ export default {
acquire: '获取',
fillExample: '填写样例',
buyMore: '购买更多',
update: '更新'
update: '更新',
copy: '复制'
};
+3 -1
View File
@@ -19,5 +19,7 @@ export default {
errorBadRequest: '请求内容不规范,请重新提问',
errorNoConversation: '对话内容不存在或者已经过期,请发起新的会话',
confirmDelete: '确定删除',
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用'
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
errorTimeout: '回答问题超时,请稍后重试'
};
+1 -1
View File
@@ -7,7 +7,7 @@ export interface IContent {
export interface IError {
code: string;
detail: string;
detail?: string;
}
export enum IMessageState {
+7 -1
View File
@@ -65,7 +65,7 @@ import {
IApplicationType
} from '@/operators';
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_DETAIL } from '@/router/constants';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNKNOWN, ERROR_CODE_UNVERIFIED } from '@/constants';
import { getVerificationUrl } from '@/utils';
import { IConversation } from '@/operators/conversation/models';
import Introduction from '@/components/conversation/Introduction.vue';
@@ -334,6 +334,12 @@ export default defineComponent({
if (this.messages && this.messages.length > 0) {
this.messages[this.messages.length - 1].error = data;
}
} else {
if (this.messages && this.messages.length > 0) {
this.messages[this.messages.length - 1].error = {
code: ERROR_CODE_UNKNOWN
};
}
}
});
}