Refine chatdoc and base code interface (#2)
This commit is contained in:
1 parent
28da0263dc
commit
09ee60aa6e
21 files changed
+352
-168
No files matched your search
@@ -88,6 +88,7 @@ export default defineComponent({
|
||||
ElMessage.success(this.$t('chatdoc.message.createDocumentSuccess'));
|
||||
this.dialogVisible = false;
|
||||
this.$store.dispatch('chatdoc/getDocuments', { repositoryId: this.$route.params.repositoryId });
|
||||
this.$store.dispatch('chatdoc/getApplication');
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error(this.$t('chatdoc.message.createDocumentError'));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<template>
|
||||
<div class="price-text">
|
||||
<span v-if="price > 0" class="unfree"
|
||||
>¥{{ price }} {{ unit ? ` / ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : ''
|
||||
}}{{ $t('common.message.startPrice') }}
|
||||
>${{ price }} {{ unit ? ` / ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : '' }}
|
||||
</span>
|
||||
<span v-else class="free">
|
||||
{{ $t('common.message.free') }}
|
||||
@@ -12,7 +11,6 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiPrice',
|
||||
props: {
|
||||
|
||||
@@ -3,4 +3,3 @@ export const ACTION_UPDATE = 'update';
|
||||
export const ACTION_DELETE = 'delete';
|
||||
export const ACTION_RETRIEVE = 'retrieve';
|
||||
export const ACTION_RETRIEVE_BATCH = 'retrieve_batch';
|
||||
export const ACTION_RETRIEVE_ALL = 'retrieve_all';
|
||||
@@ -9,9 +9,11 @@ import order from './order';
|
||||
import distribution from './distribution';
|
||||
import user from './user';
|
||||
import chatdoc from './chatdoc';
|
||||
import service from './service';
|
||||
|
||||
export default {
|
||||
chat,
|
||||
service,
|
||||
chatdoc,
|
||||
user,
|
||||
order,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
learnMore: 'Learn More',
|
||||
apply: 'Apply Now',
|
||||
introduction: 'Service Introduction',
|
||||
apis: 'API Description',
|
||||
pricing: 'Pricing'
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
price: 'Price',
|
||||
introduction: 'Introduction',
|
||||
apis: 'API',
|
||||
proxies: 'Proxy'
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import message from './message';
|
||||
import unit from './unit';
|
||||
import button from './button';
|
||||
import field from './field';
|
||||
import title from './title';
|
||||
|
||||
export default {
|
||||
message,
|
||||
unit,
|
||||
button,
|
||||
field,
|
||||
title
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
export default {
|
||||
free: 'Free',
|
||||
around: 'Around',
|
||||
welcomeCredits: 'Welcome Credits',
|
||||
appliedCount: 'Number of Applications',
|
||||
indexTitle: 'Your smart choice for digital services',
|
||||
indexSubtitle: 'Empower your work and life with standardized excellence in services.',
|
||||
fromPrice: 'From ',
|
||||
packages: 'We offer a variety of packages for credits, the more packages you buy, the more discounts you get.',
|
||||
offer: 'Offer',
|
||||
partnersTitle: 'Trusted by leading partners'
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
apis: 'API',
|
||||
proxies: 'Proxy',
|
||||
packages: 'Packages'
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
export default {
|
||||
credit: 'Credit',
|
||||
Credit: 'Credit',
|
||||
credits: 'Credits',
|
||||
Credits: 'Credits',
|
||||
call: 'Call',
|
||||
Call: 'Call',
|
||||
calls: 'Calls',
|
||||
Calls: 'Calls',
|
||||
MB: 'MB',
|
||||
GB: 'GB'
|
||||
};
|
||||
+31
-23
@@ -15,6 +15,16 @@ export interface IChatdocRepository {
|
||||
conversations?: IChatdocConversation[];
|
||||
}
|
||||
|
||||
export interface IChatdocRepositoryRequest extends IChatdocRepository {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
}
|
||||
|
||||
export interface IChatdocRepositoryResponse extends IChatdocRepository {}
|
||||
export type IChatdocRepositoriesResponse = {
|
||||
items: IChatdocRepository[];
|
||||
count: number;
|
||||
};
|
||||
|
||||
export interface IChatdocDocument {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
@@ -22,10 +32,23 @@ export interface IChatdocDocument {
|
||||
file_name: string;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentRequest extends IChatdocDocument {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
callback_url?: string;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentResponse extends IChatdocDocument {}
|
||||
|
||||
export type IChatdocDocumentsResponse = {
|
||||
items: IChatdocDocument[];
|
||||
count: number;
|
||||
};
|
||||
|
||||
export interface IChatdocConversation {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
messages: IChatdocMessage[];
|
||||
question: string;
|
||||
editing?: boolean;
|
||||
deleting?: boolean;
|
||||
}
|
||||
@@ -44,36 +67,21 @@ export enum IChatdocMessageState {
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IChatdocChatRequest {
|
||||
export interface IChatdocConversationRequest {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
messages: IChatdocMessage[];
|
||||
question: string;
|
||||
temperature?: number;
|
||||
knowledge_fallback?: boolean;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentRequest extends IChatdocDocument {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
callback_url?: string;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentResponse extends IChatdocDocument {}
|
||||
|
||||
export type IChatdocConversationsResponse = IChatdocConversation[];
|
||||
|
||||
export interface IChatdocRepositoryRequest extends IChatdocRepository {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
}
|
||||
|
||||
export interface IChatdocRepositoryResponse extends IChatdocRepository {}
|
||||
export type IChatdocRepositoriesResponse = {
|
||||
items: IChatdocRepository[];
|
||||
export type IChatdocConversationsResponse = {
|
||||
items: IChatdocConversation[];
|
||||
count: number;
|
||||
};
|
||||
export type IChatdocDocumentsResponse = IChatdocDocument[];
|
||||
|
||||
export interface IChatdocChatResponse {
|
||||
export interface IChatdocConversationResponse {
|
||||
id: string;
|
||||
answer: string;
|
||||
delta_answer: string;
|
||||
repository_id?: string;
|
||||
conversation_id?: string;
|
||||
delta_answer?: string;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { getBaseUrlAuth } from '@/utils';
|
||||
|
||||
class AuthOperator {
|
||||
async refreshToken(payload: IToken): Promise<AxiosResponse<ITokenResponse>> {
|
||||
return httpClient.post('/token/refresh/', payload);
|
||||
return httpClient.post('/auth/refresh/', payload);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
IChatdocRepositoriesResponse,
|
||||
IChatdocRepositoryResponse
|
||||
} from '@/models';
|
||||
import { ACTION_RETRIEVE_ALL, ACTION_UPDATE, BASE_URL_API } from '@/constants';
|
||||
import { ACTION_UPDATE, BASE_URL_API } from '@/constants';
|
||||
import { ACTION_CREATE, ACTION_DELETE, ACTION_RETRIEVE, ACTION_RETRIEVE_BATCH } from '@/constants';
|
||||
|
||||
class ChatdocOperator {
|
||||
@@ -77,7 +77,7 @@ class ChatdocOperator {
|
||||
return await axios.post(
|
||||
`/chatdoc/repositories`,
|
||||
{
|
||||
action: ACTION_RETRIEVE_ALL
|
||||
action: ACTION_RETRIEVE_BATCH
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -97,7 +97,7 @@ class ChatdocOperator {
|
||||
return await axios.post(
|
||||
`/chatdoc/documents`,
|
||||
{
|
||||
action: ACTION_RETRIEVE_ALL,
|
||||
action: ACTION_RETRIEVE_BATCH,
|
||||
repository_id: repositoryId
|
||||
},
|
||||
{
|
||||
@@ -111,15 +111,19 @@ class ChatdocOperator {
|
||||
);
|
||||
}
|
||||
|
||||
async getAllConversations(repositoryId: string): Promise<AxiosResponse<IChatdocConversationsResponse>> {
|
||||
async getAllConversations(
|
||||
repositoryId: string,
|
||||
options: { token: string }
|
||||
): Promise<AxiosResponse<IChatdocConversationsResponse>> {
|
||||
return await axios.post(
|
||||
`/chatdoc/conversations`,
|
||||
{
|
||||
action: ACTION_RETRIEVE_ALL,
|
||||
action: ACTION_RETRIEVE_BATCH,
|
||||
repository_id: repositoryId
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${options.token}`,
|
||||
accept: 'application/json',
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
@@ -273,16 +277,16 @@ class ChatdocOperator {
|
||||
);
|
||||
}
|
||||
|
||||
async chat(
|
||||
payload: { repositoryId: string; question: string; conversationId?: string; knowledgeFallback?: boolean },
|
||||
async chatConversation(
|
||||
payload: { repositoryId: string; question: string; id?: string; knowledgeFallback?: boolean },
|
||||
options: { token: string; stream: (response: IChatdocChatResponse) => void }
|
||||
): Promise<AxiosResponse<IChatdocChatResponse>> {
|
||||
return await axios.post(
|
||||
`/chatdoc/chat`,
|
||||
`/chatdoc/conversations`,
|
||||
{
|
||||
repository_id: payload.repositoryId,
|
||||
question: payload.question,
|
||||
conversation_id: payload.conversationId,
|
||||
id: payload.id,
|
||||
stateful: true
|
||||
},
|
||||
{
|
||||
|
||||
@@ -10,25 +10,25 @@ export interface IInviteesQuery {
|
||||
|
||||
class UserOperator {
|
||||
async getMe(): Promise<AxiosResponse<IUserDetailResponse>> {
|
||||
return httpClient.get('/me');
|
||||
return httpClient.get('/users/me');
|
||||
}
|
||||
|
||||
async getInvitees(query: IInviteesQuery): Promise<AxiosResponse<IUserListResponse>> {
|
||||
return httpClient.get('/me/invitees', {
|
||||
return httpClient.get('/users/me/invitees', {
|
||||
params: query
|
||||
});
|
||||
}
|
||||
|
||||
async updateMe(data: IUser): Promise<AxiosResponse<IUserDetailResponse>> {
|
||||
return httpClient.put('/me', data);
|
||||
return httpClient.put('/users/me', data);
|
||||
}
|
||||
|
||||
async getVerify(): Promise<AxiosResponse<IUserDetailResponse>> {
|
||||
return httpClient.get('/verify');
|
||||
return httpClient.get('/users/verify');
|
||||
}
|
||||
|
||||
async updateVerify(data: IUser): Promise<AxiosResponse<IUserDetailResponse>> {
|
||||
return httpClient.put('/verify', data);
|
||||
return httpClient.put('/users/verify', data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@ import { log } from '@/utils';
|
||||
import { ROUTE_CHATDOC_CONVERSATION } from '@/router';
|
||||
import axios from 'axios';
|
||||
import { isJSONString } from '@/utils/is';
|
||||
import { Status } from '@/models';
|
||||
import { IService, Status } from '@/models';
|
||||
import ApplicationStatus from '@/components/application/Status.vue';
|
||||
import { IChatdocChatResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models';
|
||||
import { IChatdocConversationResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ChatdocChat',
|
||||
name: 'ChatdocConversation',
|
||||
components: {
|
||||
Layout,
|
||||
Conversations,
|
||||
@@ -92,7 +92,7 @@ export default defineComponent({
|
||||
repository(): IChatdocRepository | undefined {
|
||||
return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.repositoryId);
|
||||
},
|
||||
conversations() {
|
||||
conversations(): IChatdocConversation[] | undefined {
|
||||
return this.repository?.conversations;
|
||||
},
|
||||
conversationId(): string | undefined {
|
||||
@@ -107,21 +107,16 @@ export default defineComponent({
|
||||
initializing() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Request;
|
||||
},
|
||||
service() {
|
||||
service(): IService | undefined {
|
||||
return this.$store.state.chatdoc.service;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
console.log('start get conversations');
|
||||
this.loading = true;
|
||||
this.$store
|
||||
.dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId })
|
||||
.then(() => {
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
this.$store.dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId }).finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
async onSubmit() {
|
||||
@@ -129,7 +124,6 @@ export default defineComponent({
|
||||
content: this.question,
|
||||
role: ROLE_USER
|
||||
});
|
||||
console.debug('onSubmit', this.question);
|
||||
await this.onFetchAnswer();
|
||||
},
|
||||
async onScrollDown() {
|
||||
@@ -169,21 +163,21 @@ export default defineComponent({
|
||||
// request server to get answer
|
||||
this.answering = true;
|
||||
chatdocOperator
|
||||
.chat(
|
||||
.chatConversation(
|
||||
{
|
||||
repositoryId: this.repositoryId,
|
||||
question,
|
||||
conversationId: this.conversationId
|
||||
id: this.conversationId
|
||||
},
|
||||
{
|
||||
token,
|
||||
stream: (response: IChatdocChatResponse) => {
|
||||
stream: (response: IChatdocConversationResponse) => {
|
||||
this.messages[this.messages.length - 1] = {
|
||||
role: ROLE_ASSISTANT,
|
||||
content: response.answer,
|
||||
state: IChatdocMessageState.ANSWERING
|
||||
};
|
||||
conversationId = response.conversation_id;
|
||||
conversationId = response.id;
|
||||
this.onScrollDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,46 @@
|
||||
<el-row>
|
||||
<el-col :span="12" :offset="6">
|
||||
<el-skeleton v-if="loading" />
|
||||
<create-order v-else-if="application" :application="application" />
|
||||
<el-form v-else-if="application" label-width="100px">
|
||||
<el-form-item :label="$t('application.field.service')">
|
||||
{{ application?.service?.title }}
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('application.field.package')">
|
||||
<el-radio-group v-if="application?.service?.packages" v-model="form.packageId">
|
||||
<el-radio-button
|
||||
v-for="(pkg, pkgIndex) in application?.service.packages"
|
||||
:key="pkgIndex"
|
||||
:label="pkg.id"
|
||||
>
|
||||
{{ pkg.amount }} {{ $t(`service.unit.${application?.service?.unit}s`) }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('service.field.price')">
|
||||
<price :price="package?.price" />
|
||||
</el-form-item>
|
||||
<el-divider border-style="dashed" />
|
||||
<el-form-item :label="$t('application.field.shouldPayPrice')">
|
||||
<span
|
||||
v-if="package"
|
||||
:class="{ price: true, unfree: package?.price > 0, free: package?.price === 0 }"
|
||||
>
|
||||
${{ package?.price?.toFixed(2) }}
|
||||
</span>
|
||||
<span v-else :class="{ price: true, free: true }"> $ 0 </span>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
class="btn-create"
|
||||
:loading="creating"
|
||||
@click="onCreateOrder"
|
||||
>
|
||||
{{ $t('application.button.createOrder') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
@@ -24,51 +63,136 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { applicationOperator } from '@/operators';
|
||||
import CreateOrder from '@/components/order/Create.vue';
|
||||
import { ElRow, ElCol, ElCard, ElSkeleton } from 'element-plus';
|
||||
import { IApplication, IApplicationDetailResponse } from '@/models';
|
||||
import {
|
||||
applicationOperator,
|
||||
IApplication,
|
||||
IApplicationDetailResponse,
|
||||
IOrderDetailResponse,
|
||||
orderOperator
|
||||
} from '@/operators';
|
||||
import {
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElCard,
|
||||
ElSkeleton,
|
||||
ElMessage,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElButton,
|
||||
ElInputNumber,
|
||||
ElDivider,
|
||||
ElRadioGroup,
|
||||
ElRadioButton
|
||||
} from 'element-plus';
|
||||
import { ROUTE_CONSOLE_ORDER_DETAIL } from '@/router';
|
||||
import Price from '@/components/common/Price.vue';
|
||||
|
||||
interface IData {
|
||||
application: IApplication | undefined;
|
||||
loading: boolean;
|
||||
form: {
|
||||
amount: number;
|
||||
packageId: string | undefined;
|
||||
};
|
||||
creating: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConsoleApplicationBuy',
|
||||
components: {
|
||||
CreateOrder,
|
||||
ElSkeleton,
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElCard
|
||||
ElCard,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInputNumber,
|
||||
ElButton,
|
||||
ElDivider,
|
||||
ElRadioGroup,
|
||||
ElRadioButton,
|
||||
Price
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
application: undefined,
|
||||
loading: false
|
||||
loading: false,
|
||||
form: {
|
||||
amount: 1000,
|
||||
packageId: undefined
|
||||
},
|
||||
creating: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
id() {
|
||||
return this.$route.params?.id?.toString();
|
||||
},
|
||||
price() {
|
||||
if (this.application?.service?.price && this.form.amount) {
|
||||
return this.form.amount * this.application.service?.price;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
package() {
|
||||
if (this.application?.service?.packages && this.form.packageId) {
|
||||
const filterPackages = this.application.service?.packages.filter((item) => item.id === this.form.packageId);
|
||||
if (filterPackages.length > 0) {
|
||||
return filterPackages[0];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchData();
|
||||
this.onFetchApplication();
|
||||
},
|
||||
methods: {
|
||||
onFetchData() {
|
||||
onFetchApplication() {
|
||||
this.loading = true;
|
||||
applicationOperator
|
||||
.get(this.id)
|
||||
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
|
||||
this.application = data;
|
||||
this.loading = false;
|
||||
// by default select first packageId
|
||||
this.form.packageId = this.application?.service?.packages?.[0]?.id;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onCreateOrder() {
|
||||
if (!this.application?.id) {
|
||||
return;
|
||||
}
|
||||
this.creating = true;
|
||||
const unit = this.$t(`service.unit.${this.application?.service?.unit}s`);
|
||||
orderOperator
|
||||
.create({
|
||||
application_id: this.application?.id,
|
||||
amount: this.form.amount,
|
||||
...(this.form.packageId !== 'custom' && this.package
|
||||
? {
|
||||
package_id: this.package.id
|
||||
}
|
||||
: {}),
|
||||
description: `${this.application?.service?.title} x ${this.form.amount} ${unit}`
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.creating = false;
|
||||
const order = data;
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_ORDER_DETAIL,
|
||||
params: {
|
||||
id: order.id
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error(this.$t('order.message.createFailed'));
|
||||
this.creating = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -9,24 +9,30 @@
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-card shadow="hover">
|
||||
<el-table v-loading="loading" :data="applications" stripe table-layout="fixed">
|
||||
<el-table-column prop="id" :label="$t('application.field.id')" width="300px" class-name="text-center">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="applications"
|
||||
stripe
|
||||
table-layout="fixed"
|
||||
:empty-text="$t('common.message.noData')"
|
||||
>
|
||||
<el-table-column prop="id" :label="$t('application.field.id')" width="220px" class-name="text-center">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.id }}</span>
|
||||
<span class="copy">
|
||||
<copy-to-clipboard :content="scope?.row?.id" />
|
||||
<copy-to-clipboard :content="scope?.row?.id" class="inline-block" />
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('application.field.name')" width="220px">
|
||||
<el-table-column :label="$t('application.field.name')" width="180px">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.type === applicationType.API">{{ scope.row?.api?.title }}</span>
|
||||
<span>{{ scope.row?.service?.title }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="remaining_amount"
|
||||
:label="$t('application.field.remainingAmount')"
|
||||
width="120px"
|
||||
width="160px"
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
@@ -36,22 +42,13 @@
|
||||
<el-table-column
|
||||
prop="used_amount"
|
||||
:label="$t('application.field.usedAmount')"
|
||||
width="120px"
|
||||
width="160px"
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getUsedAmount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column fixed="right" width="100px">
|
||||
<template #default="scope">
|
||||
<div class="float-right">
|
||||
<el-button type="primary" @click="onBuyMore(scope?.row)">
|
||||
{{ $t('application.button.buyMore') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
@@ -74,7 +71,7 @@ import Pagination from '@/components/common/Pagination.vue';
|
||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||
import { ElTable, ElRow, ElCol, ElTableColumn, ElButton, ElCard } from 'element-plus';
|
||||
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router/constants';
|
||||
import { IApplication, IApplicationListResponse, IApplicationType, ICredentialType } from '@/models';
|
||||
import { IApplication, IApplicationListResponse, IApplicationType, ICredentialType, IService } from '@/models';
|
||||
|
||||
interface IData {
|
||||
applications: IApplication[];
|
||||
@@ -86,9 +83,9 @@ interface IData {
|
||||
amount: number | undefined;
|
||||
};
|
||||
active: {
|
||||
service: IService | undefined;
|
||||
application: IApplication | undefined;
|
||||
};
|
||||
applicationType: typeof IApplicationType;
|
||||
credentialType: typeof ICredentialType;
|
||||
}
|
||||
|
||||
@@ -107,17 +104,16 @@ export default defineComponent({
|
||||
data(): IData {
|
||||
return {
|
||||
credentialType: ICredentialType,
|
||||
applicationType: IApplicationType,
|
||||
applications: [],
|
||||
loading: false,
|
||||
total: undefined,
|
||||
buying: false,
|
||||
// dynamic calculate the limit according to window height
|
||||
limit: Math.floor((window.innerHeight - 300) / 50),
|
||||
limit: 10,
|
||||
form: {
|
||||
amount: 1
|
||||
},
|
||||
active: {
|
||||
service: undefined,
|
||||
application: undefined
|
||||
}
|
||||
};
|
||||
@@ -128,9 +124,6 @@ export default defineComponent({
|
||||
},
|
||||
page() {
|
||||
return parseInt(this.$route.query.page?.toString() || '1');
|
||||
},
|
||||
type() {
|
||||
return (this.$route.query.type?.toString() || IApplicationType.API) as IApplicationType;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -149,19 +142,6 @@ export default defineComponent({
|
||||
this.onFetchData();
|
||||
},
|
||||
methods: {
|
||||
onFilterType(type: string) {
|
||||
if (type === this.type) {
|
||||
return;
|
||||
}
|
||||
this.$router.push({
|
||||
...this.$route,
|
||||
query: {
|
||||
...this.$route.query,
|
||||
page: 1,
|
||||
type
|
||||
}
|
||||
});
|
||||
},
|
||||
onBuyMore(application: IApplication) {
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_APPLICATION_BUY,
|
||||
@@ -186,7 +166,6 @@ export default defineComponent({
|
||||
limit: this.limit,
|
||||
offset: (this.page - 1) * this.limit,
|
||||
user_id: this.$store.getters.user.id,
|
||||
type: this.type,
|
||||
ordering: '-created_at'
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationListResponse }) => {
|
||||
@@ -199,16 +178,18 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
getRemainingAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.remaining_amount}${unit}`;
|
||||
if (application.remaining_amount === undefined || application.remaining_amount === null) {
|
||||
return '';
|
||||
}
|
||||
const unit = this.$t(`service.unit.${application?.service?.unit}s`);
|
||||
return `${application.remaining_amount?.toFixed(6)} ${unit}`;
|
||||
},
|
||||
getUsedAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.used_amount}${unit}`;
|
||||
if (application.used_amount === undefined || application.used_amount === null) {
|
||||
return '';
|
||||
}
|
||||
const unit = this.$t(`service.unit.${application?.service?.unit}s`);
|
||||
return `${application.used_amount?.toFixed(6)} ${unit}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,22 +19,22 @@ export default {
|
||||
component: () => import('@/pages/chatdoc/Index.vue')
|
||||
},
|
||||
{
|
||||
path: 'repository/:repositoryId/conversation',
|
||||
path: 'repositories/:repositoryId/conversations',
|
||||
name: ROUTE_CHATDOC_CONVERSATION_NEW,
|
||||
component: () => import('@/pages/chatdoc/Conversation.vue')
|
||||
},
|
||||
{
|
||||
path: 'repository/:repositoryId/conversation/:conversationId',
|
||||
path: 'repositories/:repositoryId/conversations/:conversationId',
|
||||
name: ROUTE_CHATDOC_CONVERSATION,
|
||||
component: () => import('@/pages/chatdoc/Conversation.vue')
|
||||
},
|
||||
{
|
||||
path: 'repository/:repositoryId/manage',
|
||||
path: 'repositories/:repositoryId/manage',
|
||||
name: ROUTE_CHATDOC_MANAGE,
|
||||
component: () => import('@/pages/chatdoc/Manage.vue')
|
||||
},
|
||||
{
|
||||
path: 'repository/:repositoryId',
|
||||
path: 'repositories/:repositoryId',
|
||||
name: ROUTE_CHATDOC_SETTING,
|
||||
component: () => import('@/pages/chatdoc/Setting.vue')
|
||||
}
|
||||
|
||||
@@ -2,15 +2,7 @@ import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatdocState } from './models';
|
||||
import {
|
||||
IApplication,
|
||||
IChatdocConversation,
|
||||
IChatdocDocument,
|
||||
IChatdocRepositoriesResponse,
|
||||
IChatdocRepository,
|
||||
IService,
|
||||
Status
|
||||
} from '@/models';
|
||||
import { IApplication, IChatdocConversation, IChatdocDocument, IChatdocRepository, IService, Status } from '@/models';
|
||||
import { chatdocOperator, applicationOperator, serviceOperator } from '@/operators';
|
||||
import { CHATDOC_SERVICE_ID } from '@/constants';
|
||||
|
||||
@@ -195,7 +187,7 @@ export const getDocuments = async (
|
||||
await chatdocOperator.getAllDocuments(payload.repositoryId, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
).data.items;
|
||||
log(getRepositories, 'get documents success', documents);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
@@ -219,7 +211,11 @@ export const getConversations = async (
|
||||
});
|
||||
return [];
|
||||
}
|
||||
const conversations = (await chatdocOperator.getAllConversations(payload.repositoryId)).data;
|
||||
const conversations = (
|
||||
await chatdocOperator.getAllConversations(payload.repositoryId, {
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
log(getConversations, 'get conversations success', conversations);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
|
||||
Reference in new issue
Block a user