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
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minor",
|
||||
"comment": "update onboarding experience ",
|
||||
"packageName": "@zhishuyun/hub",
|
||||
"email": "cqc@germey.cn",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -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 });
|
||||
|
||||
@@ -8,3 +8,4 @@ export const ERROR_CODE_CANCELED = 'canceled';
|
||||
export const ERROR_CODE_TIMEOUT = 'timeout';
|
||||
export const ERROR_CODE_CONTENT_TOO_LARGE = 'content_too_large';
|
||||
export const ERROR_CODE_TOO_MANY_REQUESTS = 'too_many_requests';
|
||||
export const ERROR_CODE_NOT_APPLIED = 'not_applied';
|
||||
@@ -17,5 +17,7 @@ export default {
|
||||
rotateCredentialSuccessfully: '密钥重置成功',
|
||||
rotateCredentialFailed: '密钥重置失败,请联系客服处理',
|
||||
updateFailed: '修改失败',
|
||||
updateSuccessfully: '修改成功'
|
||||
updateSuccessfully: '修改成功',
|
||||
applyDescription: '申请之后即可立即使用,同时您会获赠一定的免费次数。',
|
||||
applyDescription2: '本次申请不会产生任何费用,请放心使用。'
|
||||
};
|
||||
@@ -24,6 +24,7 @@ export default {
|
||||
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
|
||||
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
|
||||
errorTimeout: '回答问题超时,请稍后重试',
|
||||
errorNotApplied: '您尚未申请该服务,请先申请再继续提问',
|
||||
howToUse: '按 Shift+Enter 键可以换行',
|
||||
noConversations: '没有历史会话,请先发起一个新的会话'
|
||||
};
|
||||
@@ -18,6 +18,7 @@ export default {
|
||||
buy: '购买',
|
||||
try: '测试',
|
||||
startForFree: '免费体验',
|
||||
applyForFree: '免费申请',
|
||||
apply: '申请',
|
||||
refresh: '刷新',
|
||||
pay: '支付',
|
||||
|
||||
@@ -44,7 +44,7 @@ export interface IChatMessageContentItem {
|
||||
|
||||
export interface IChatMessage {
|
||||
state?: IChatMessageState;
|
||||
content: string | IChatMessageContentItem[];
|
||||
content?: string | IChatMessageContentItem[];
|
||||
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
|
||||
error?: IError;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const httpClient: AxiosInstance = axios.create({
|
||||
});
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.state.token?.access;
|
||||
const accessToken = store.getters.token?.access;
|
||||
if (accessToken) {
|
||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,25 @@
|
||||
<api-status
|
||||
:initializing="initializing"
|
||||
:application="application"
|
||||
:need-apply="needApply"
|
||||
:api-id="model.apiId"
|
||||
@refresh="$store.dispatch('chat/getApplications')"
|
||||
/>
|
||||
<div class="dialogue">
|
||||
<introduction v-if="messages.length === 0" @draft="onDraft" />
|
||||
<div v-else class="messages">
|
||||
<message v-for="(message, messageIndex) in messages" :key="messageIndex" :message="message" class="message" />
|
||||
<message
|
||||
v-for="(message, messageIndex) in messages"
|
||||
:key="messageIndex"
|
||||
:message="message"
|
||||
:application="application"
|
||||
class="message"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<input-box
|
||||
:disabled="answering"
|
||||
:question="question"
|
||||
:references="references"
|
||||
@update:question="question = $event"
|
||||
@@ -44,17 +52,19 @@ import {
|
||||
} from '@/operators';
|
||||
import InputBox from '@/components/chat/InputBox.vue';
|
||||
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
||||
import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
||||
import { ERROR_CODE_CANCELED, ERROR_CODE_NOT_APPLIED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
||||
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router';
|
||||
import { Status } from '@/store/common/models';
|
||||
import { log } from '@/utils/log';
|
||||
import Introduction from '@/components/chat/Introduction.vue';
|
||||
import Layout from '@/layouts/Chat.vue';
|
||||
import { isJSONString } from '@/utils/is';
|
||||
|
||||
export interface IData {
|
||||
question: string;
|
||||
references: string[];
|
||||
answering: boolean;
|
||||
messages: IChatMessage[];
|
||||
}
|
||||
|
||||
@@ -72,6 +82,7 @@ export default defineComponent({
|
||||
return {
|
||||
question: '',
|
||||
references: [],
|
||||
answering: false,
|
||||
messages:
|
||||
this.$store.state.chat.conversations?.find(
|
||||
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
||||
@@ -93,6 +104,9 @@ export default defineComponent({
|
||||
application() {
|
||||
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.chat.getApplicationsStatus === Status.Success && !this.application;
|
||||
},
|
||||
applications() {
|
||||
return this.$store.state.chat.applications;
|
||||
},
|
||||
@@ -177,14 +191,21 @@ export default defineComponent({
|
||||
const path = this.application?.api?.path;
|
||||
const question = this.question;
|
||||
const references = this.references;
|
||||
if (!token || !endpoint || !question || !path) {
|
||||
console.error('no token or endpoint or question');
|
||||
return;
|
||||
}
|
||||
log(this.onFetchAnswer, 'validated', question, references);
|
||||
// reset question and references
|
||||
this.question = '';
|
||||
this.references = [];
|
||||
if (!token || !endpoint || !question || !path) {
|
||||
console.error('no token or endpoint or question');
|
||||
this.messages.push({
|
||||
error: {
|
||||
code: ERROR_CODE_NOT_APPLIED
|
||||
},
|
||||
role: ROLE_ASSISTANT,
|
||||
state: IChatMessageState.FAILED
|
||||
});
|
||||
return;
|
||||
}
|
||||
let conversationId = this.conversationId;
|
||||
this.messages.push({
|
||||
content: '',
|
||||
@@ -194,6 +215,7 @@ export default defineComponent({
|
||||
log(this.onFetchAnswer, 'start to get answer', this.messages);
|
||||
this.onScrollDown();
|
||||
// request server to get answer
|
||||
this.answering = true;
|
||||
chatOperator
|
||||
.askQuestion(
|
||||
{
|
||||
@@ -224,6 +246,7 @@ export default defineComponent({
|
||||
id: conversationId,
|
||||
messages: this.messages
|
||||
});
|
||||
this.answering = false;
|
||||
if (!this.conversationId) {
|
||||
await this.$router.push({
|
||||
name: ROUTE_CHAT_CONVERSATION,
|
||||
@@ -240,12 +263,16 @@ export default defineComponent({
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
this.messages[this.messages.length - 1].state = IChatMessageState.FAILED;
|
||||
}
|
||||
console.error(error);
|
||||
if (axios.isCancel(error)) {
|
||||
this.messages[this.messages.length - 1].error = {
|
||||
code: ERROR_CODE_CANCELED
|
||||
};
|
||||
} else if (error?.response?.data && error?.response?.data.code) {
|
||||
const data = error?.response?.data;
|
||||
} else if (error?.response?.data) {
|
||||
let data = error?.response?.data;
|
||||
if (isJSONString(data)) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
this.messages[this.messages.length - 1].error = data;
|
||||
}
|
||||
@@ -256,6 +283,7 @@ export default defineComponent({
|
||||
};
|
||||
}
|
||||
}
|
||||
this.answering = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<api-status
|
||||
:initializing="initializing"
|
||||
:application="application"
|
||||
:need-apply="needApply"
|
||||
class="mb-4"
|
||||
:api-id="channel.apiId"
|
||||
@refresh="onGetApplications"
|
||||
@@ -62,6 +63,9 @@ export default defineComponent({
|
||||
initializing() {
|
||||
return this.$store.state.midjourney.getApplicationsStatus === Status.Request;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.midjourney.getApplicationsStatus === Status.Success && !this.application;
|
||||
},
|
||||
application() {
|
||||
if (this.applications && this.applications.length > 0) {
|
||||
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
:initializing="initializing"
|
||||
:application="application"
|
||||
:api-id="channel.apiId"
|
||||
:need-apply="needApply"
|
||||
class="mb-4"
|
||||
@apply="onGetApplications"
|
||||
@refresh="onGetApplications"
|
||||
/>
|
||||
<div class="pt-4">
|
||||
<reference-image class="mb-4" @change="references = $event" />
|
||||
@@ -98,6 +99,9 @@ export default defineComponent({
|
||||
applications() {
|
||||
return this.$store.state.midjourney.applications;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.midjourney.getApplicationsStatus === Status.Success && !this.application;
|
||||
},
|
||||
application() {
|
||||
if (this.applications && this.applications.length > 0) {
|
||||
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
||||
|
||||
@@ -17,6 +17,10 @@ import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatState } from './models';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IChatState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
};
|
||||
|
||||
export const setModel = async ({ commit }: any, payload: IChatModel): Promise<void> => {
|
||||
commit('setModel', payload);
|
||||
};
|
||||
@@ -96,6 +100,7 @@ export const getConversations = async ({
|
||||
};
|
||||
|
||||
export default {
|
||||
resetAll,
|
||||
setModel,
|
||||
setApplications,
|
||||
setConversation,
|
||||
|
||||
@@ -2,6 +2,13 @@ import { IApplication, IChatConversation, IChatModel } from '@/operators';
|
||||
import { IChatState } from './models';
|
||||
import { Status } from '../common/models';
|
||||
|
||||
export const resetAll = (state: IChatState): void => {
|
||||
state.applications = [];
|
||||
state.getApplicationsStatus = Status.None;
|
||||
state.conversations = [];
|
||||
state.getConversationsStatus = Status.None;
|
||||
};
|
||||
|
||||
export const setModel = (state: IChatState, payload: IChatModel): void => {
|
||||
state.model = payload;
|
||||
};
|
||||
@@ -27,5 +34,6 @@ export default {
|
||||
setApplications,
|
||||
setGetApplicationsStatus,
|
||||
setConversations,
|
||||
setGetConversationsStatus
|
||||
setGetConversationsStatus,
|
||||
resetAll
|
||||
};
|
||||
@@ -1,9 +1,22 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState, IToken } from '../common/models';
|
||||
import { IApplication, IUser, userOperator } from '@/operators';
|
||||
import { IUser, userOperator } from '@/operators';
|
||||
import { log } from '@/utils/log';
|
||||
import { oauthOperator } from '@/operators/auth/operator';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetToken');
|
||||
commit('resetUser');
|
||||
};
|
||||
|
||||
export const resetUser = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetUser');
|
||||
};
|
||||
|
||||
export const resetSetting = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetSetting');
|
||||
};
|
||||
|
||||
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetToken');
|
||||
};
|
||||
@@ -41,6 +54,9 @@ export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>
|
||||
|
||||
export default {
|
||||
resetToken,
|
||||
resetAll,
|
||||
resetUser,
|
||||
resetSetting,
|
||||
setToken,
|
||||
setUser,
|
||||
getToken,
|
||||
|
||||
@@ -5,7 +5,8 @@ import { IChatState } from '../chat/models';
|
||||
export enum Status {
|
||||
Request = 'Request',
|
||||
Success = 'Success',
|
||||
Error = 'Error'
|
||||
Error = 'Error',
|
||||
None = 'None'
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
|
||||
@@ -19,6 +19,14 @@ export const resetToken = (state: IRootState): void => {
|
||||
state.token = {};
|
||||
};
|
||||
|
||||
export const resetSetting = (state: IRootState): void => {
|
||||
state.setting = {};
|
||||
};
|
||||
|
||||
export const resetUser = (state: IRootState): void => {
|
||||
state.user = {};
|
||||
};
|
||||
|
||||
export const setSetting = (state: IRootState, payload: any): void => {
|
||||
state.setting = {
|
||||
...state.setting,
|
||||
@@ -28,7 +36,9 @@ export const setSetting = (state: IRootState, payload: any): void => {
|
||||
|
||||
export default {
|
||||
setUser,
|
||||
resetUser,
|
||||
setToken,
|
||||
resetToken,
|
||||
setSetting
|
||||
setSetting,
|
||||
resetSetting
|
||||
};
|
||||
@@ -15,6 +15,10 @@ import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IRootState, Status } from '../common/models';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
};
|
||||
|
||||
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
|
||||
commit('setPreset', payload);
|
||||
};
|
||||
@@ -79,6 +83,7 @@ export const getImagineTasks = async (
|
||||
};
|
||||
|
||||
export default {
|
||||
resetAll,
|
||||
setPreset,
|
||||
setChannel,
|
||||
setApplications,
|
||||
|
||||
@@ -2,6 +2,13 @@ import { IApplication, IMidjourneyChannel, IMidjourneyPreset } from '@/operators
|
||||
import { IMidjourneyState } from './models';
|
||||
import { Status } from '../common/models';
|
||||
|
||||
export const resetAll = (state: IMidjourneyState): void => {
|
||||
state.applications = [];
|
||||
state.preset = {};
|
||||
state.getApplicationsStatus = Status.None;
|
||||
state.imagineTasks = [];
|
||||
};
|
||||
|
||||
export const setApplications = (state: IMidjourneyState, payload: IApplication[]): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
@@ -37,5 +44,6 @@ export default {
|
||||
setGetApplicationsStatus,
|
||||
setImagineTasks,
|
||||
setGetImagineTasksStatus,
|
||||
setImagineTasksTotal
|
||||
setImagineTasksTotal,
|
||||
resetAll
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Js JSON string
|
||||
*/
|
||||
|
||||
export const isJSONString = (str: string): boolean => {
|
||||
try {
|
||||
JSON.parse(str);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Reference in new issue
Block a user