Update onboarding and error handling experience (#29)
This commit is contained in:
1 parent
916df4b482
commit
9c54ffb7a8
23 files changed
+228
-43
No files matched your search
@@ -1,18 +1,7 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
width="500px"
|
||||
:title="$t('application.message.confirmApplying')"
|
||||
center
|
||||
@close="$emit('update:visible', false)"
|
||||
>
|
||||
<el-dialog :model-value="visible" width="500px" center @close="$emit('update:visible', false)">
|
||||
<div class="content">
|
||||
<el-descriptions :column="1">
|
||||
<el-descriptions-item :label="$t('application.field.type')">
|
||||
<span>
|
||||
{{ $t('application.field.api') }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('application.field.name')">
|
||||
{{ object?.title }}
|
||||
</el-descriptions-item>
|
||||
@@ -22,6 +11,9 @@
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<p class="description">
|
||||
{{ $t('application.message.applyDescription') }}
|
||||
</p>
|
||||
<el-divider class="my-2" />
|
||||
<div class="policy">
|
||||
<el-checkbox v-model="checked" size="large" class="policy-checkbox" />
|
||||
@@ -29,7 +21,9 @@
|
||||
<span class="policy-title highlight" @click="showPolicy = true"> {{ $t('application.message.policy') }} </span>
|
||||
<application-policy v-model.visible="showPolicy" />
|
||||
</div>
|
||||
<el-button type="primary" class="btn btn-apply" @click="onApply">{{ $t('common.button.apply') }}</el-button>
|
||||
<el-button type="primary" class="btn btn-apply" @click="onApply">
|
||||
{{ $t('common.button.applyForFree') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -76,7 +70,7 @@ export default defineComponent({
|
||||
data(): IData {
|
||||
return {
|
||||
applicationType: IApplicationType,
|
||||
checked: false,
|
||||
checked: true,
|
||||
showPolicy: false
|
||||
};
|
||||
},
|
||||
@@ -97,6 +91,10 @@ export default defineComponent({
|
||||
.content {
|
||||
padding: 10px 40px;
|
||||
|
||||
.description {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn-apply {
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<el-input
|
||||
v-model="questionValue"
|
||||
:rows="1"
|
||||
:disabled="disabled"
|
||||
class="input"
|
||||
type="textarea"
|
||||
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
||||
@@ -60,6 +61,11 @@ export default defineComponent({
|
||||
ElUpload
|
||||
},
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
},
|
||||
references: {
|
||||
type: Array,
|
||||
required: false,
|
||||
@@ -146,6 +152,10 @@ export default defineComponent({
|
||||
width: 400px;
|
||||
bottom: 45px;
|
||||
}
|
||||
|
||||
.el-textarea.is-disabled .el-textarea__inner {
|
||||
background-color: initial;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<template>
|
||||
<div :class="'message ' + message.role" :role="message.role">
|
||||
<div
|
||||
:class="{
|
||||
message: true,
|
||||
[message.role as string]: true,
|
||||
hidden: errorText && message.role === 'assistant'
|
||||
}"
|
||||
:role="message.role"
|
||||
>
|
||||
<div class="content">
|
||||
<markdown-renderer v-if="!Array.isArray(message.content)" :content="message?.content" />
|
||||
<div v-else>
|
||||
@@ -9,31 +16,37 @@
|
||||
</div>
|
||||
</div>
|
||||
<answering-mark v-if="message.state === messageState.PENDING" />
|
||||
<el-alert v-if="errorText && message.role === 'assistant'" :title="errorText" type="error" :closable="false" />
|
||||
</div>
|
||||
<div class="operations">
|
||||
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content" class="btn-copy" />
|
||||
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content!" class="btn-copy" />
|
||||
</div>
|
||||
</div>
|
||||
<el-alert v-if="errorText" class="error" :title="errorText" type="error" :closable="false" />
|
||||
<el-button v-if="showBuyMore" type="primary" class="btn btn-buy" size="small" @click="onBuyMore">
|
||||
{{ $t('common.button.buyMore') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import AnsweringMark from './AnsweringMark.vue';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { ElAlert } from 'element-plus';
|
||||
import { ElAlert, ElButton } from 'element-plus';
|
||||
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
||||
import { IChatMessage, IChatMessageState } from '@/operators';
|
||||
import { IApplication, IChatMessage, IChatMessageState, ROLE_ASSISTANT } from '@/operators';
|
||||
import CopyToClipboard from '../common/CopyToClipboard.vue';
|
||||
import {
|
||||
ERROR_CODE_API_ERROR,
|
||||
ERROR_CODE_BAD_REQUEST,
|
||||
ERROR_CODE_CONTENT_TOO_LARGE,
|
||||
ERROR_CODE_NOT_APPLIED,
|
||||
ERROR_CODE_TIMEOUT,
|
||||
ERROR_CODE_TOO_MANY_REQUESTS,
|
||||
ERROR_CODE_UNKNOWN,
|
||||
ERROR_CODE_USED_UP
|
||||
} from '@/constants';
|
||||
import message from '@/i18n/zh/common/message';
|
||||
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router';
|
||||
interface IData {
|
||||
copied: boolean;
|
||||
messageState: typeof IChatMessageState;
|
||||
@@ -45,12 +58,17 @@ export default defineComponent({
|
||||
CopyToClipboard,
|
||||
AnsweringMark,
|
||||
MarkdownRenderer,
|
||||
ElAlert
|
||||
ElAlert,
|
||||
ElButton
|
||||
},
|
||||
props: {
|
||||
message: {
|
||||
type: Object as () => IChatMessage,
|
||||
required: true
|
||||
},
|
||||
application: {
|
||||
type: Object as () => IApplication | undefined,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['stop'],
|
||||
@@ -78,21 +96,34 @@ export default defineComponent({
|
||||
return this.$t('chat.message.errorTooManyRequests');
|
||||
case ERROR_CODE_CONTENT_TOO_LARGE:
|
||||
return this.$t('chat.message.errorContentTooLarge');
|
||||
case ERROR_CODE_NOT_APPLIED:
|
||||
return this.$t('chat.message.errorNotApplied');
|
||||
case ERROR_CODE_UNKNOWN:
|
||||
default:
|
||||
return this.$t('chat.message.errorUnknown');
|
||||
}
|
||||
},
|
||||
showBuyMore() {
|
||||
return this.message.role === ROLE_ASSISTANT && this.message.error?.code === ERROR_CODE_USED_UP;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onCopy() {
|
||||
copy(this.message.content.toString(), {
|
||||
copy(this.message.content!.toString(), {
|
||||
debug: true
|
||||
});
|
||||
this.copied = true;
|
||||
setTimeout(() => {
|
||||
this.copied = false;
|
||||
}, 3000);
|
||||
},
|
||||
onBuyMore() {
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_APPLICATION_BUY,
|
||||
params: {
|
||||
id: this.application?.id
|
||||
}
|
||||
});
|
||||
}
|
||||
// onStop() {
|
||||
// this.$emit('stop');
|
||||
@@ -102,12 +133,27 @@ export default defineComponent({
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.error {
|
||||
width: fit-content;
|
||||
padding: 10px 5px 8px 5px;
|
||||
height: 45px;
|
||||
border-radius: 10px;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
|
||||
.btn-buy {
|
||||
margin: 10px auto;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
&[role='system'] {
|
||||
display: none;
|
||||
}
|
||||
&.hidden {
|
||||
display: none;
|
||||
}
|
||||
&.assistant {
|
||||
align-items: start;
|
||||
.content {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
}}</el-button>
|
||||
</span>
|
||||
</div>
|
||||
<div v-else class="text-center info">
|
||||
<div v-if="needApply && api" class="text-center info">
|
||||
<span class="mr-2">{{ $t('chat.message.notApplied') }}</span>
|
||||
<span>
|
||||
<el-button type="primary" class="btn btn-apply" size="small" @click="confirming = true">
|
||||
@@ -61,18 +61,34 @@ export default defineComponent({
|
||||
initializing: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
needApply: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
emits: ['apply', 'refresh'],
|
||||
data(): IData {
|
||||
return {
|
||||
confirming: false,
|
||||
confirming: this.needApply,
|
||||
applicationType: IApplicationType,
|
||||
api: undefined
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
computed: {
|
||||
authenticated() {
|
||||
return !!this.$store.state.token.access;
|
||||
},
|
||||
user() {
|
||||
return this.$store.state.user;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
needApply(val) {
|
||||
if (val) {
|
||||
this.confirming = val;
|
||||
}
|
||||
},
|
||||
apiId() {
|
||||
this.onFetchApi();
|
||||
}
|
||||
|
||||
@@ -89,8 +89,10 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onLogout() {
|
||||
this.$store.dispatch('resetToken');
|
||||
async onLogout() {
|
||||
await this.$store.dispatch('resetAll');
|
||||
await this.$store.dispatch('chat/resetAll');
|
||||
await this.$store.dispatch('midjourney/resetAll');
|
||||
},
|
||||
onConsole() {
|
||||
this.$router.push({ name: ROUTE_CONSOLE_ROOT });
|
||||
|
||||
Reference in new issue
Block a user