add abort
This commit is contained in:
1 parent
3ea9f786dc
commit
8b488de9d6
7 files changed
+107
-31
No files matched your search
@@ -12,8 +12,8 @@
|
||||
<el-link type="primary" class="link" :underline="false">
|
||||
<span class="name">{{ document?.title || document?.api?.title }}</span>
|
||||
</el-link>
|
||||
<el-tag v-if="document?.api?.request?.method" type="" class="method" effect="dark">
|
||||
{{ document?.api?.request?.method }}
|
||||
<el-tag class="type" effect="dark">
|
||||
{{ documentType.API.toUpperCase() }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div
|
||||
@@ -24,8 +24,8 @@
|
||||
<el-link type="primary" class="link" :underline="false">
|
||||
<span class="name">{{ document?.title || document?.proxy?.title }}</span>
|
||||
</el-link>
|
||||
<el-tag v-if="document?.api?.request?.method" type="" class="method" effect="dark">
|
||||
{{ document?.api?.request?.method }}
|
||||
<el-tag class="type" effect="dark">
|
||||
{{ documentType.PROXY.toUpperCase() }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
@@ -99,10 +99,12 @@ $height: 35px;
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
.method {
|
||||
.type {
|
||||
display: none;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -57,6 +57,7 @@ export default {
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
box-shadow: 1px 0 0 #eee;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import { httpClient } from '../instance';
|
||||
import { IDocument, IDocumentDetailResponse, IDocumentListResponse } from './models';
|
||||
|
||||
@@ -12,26 +12,32 @@ export interface IDocumentQuery {
|
||||
class DocumentOperator {
|
||||
key = 'documents';
|
||||
|
||||
async getAll(query: IDocumentQuery): Promise<AxiosResponse<IDocumentListResponse>> {
|
||||
async getAll(query: IDocumentQuery, config?: AxiosRequestConfig): Promise<AxiosResponse<IDocumentListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`, {
|
||||
...config,
|
||||
params: query
|
||||
});
|
||||
}
|
||||
|
||||
async get(id: string): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
async get(id: string, config?: AxiosRequestConfig): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
console.log('sss', config);
|
||||
return await httpClient.get(`/${this.key}/${id}`, config);
|
||||
}
|
||||
|
||||
async create(data: IDocument): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
async create(data: IDocument, config?: AxiosRequestConfig): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data, config);
|
||||
}
|
||||
|
||||
async update(id: string, data: IDocument): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||
async update(
|
||||
id: string,
|
||||
data: IDocument,
|
||||
config?: AxiosRequestConfig
|
||||
): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data, config);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
async delete(id: string, config?: AxiosRequestConfig): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`, config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,18 @@
|
||||
:label="$t('application.field.remainingCount')"
|
||||
width="100px"
|
||||
class-name="text-center"
|
||||
/>
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getRemainingCount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="used_count"
|
||||
:label="$t('application.field.usedCount')"
|
||||
width="100px"
|
||||
class-name="text-center"
|
||||
/>
|
||||
<el-table-column :label="$t('application.field.credential')" class-name="api-key" width="330px">
|
||||
<el-table-column :label="$t('application.field.credential')" class-name="credential" width="380px">
|
||||
<template #default="scope">
|
||||
<div v-if="scope?.row?.credential?.type === credentialType.TOKEN">
|
||||
<span class="key">{{ scope?.row?.credential?.token }}</span>
|
||||
@@ -225,6 +229,14 @@ export default defineComponent({
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
getRemainingCount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
return application.remaining_count;
|
||||
}
|
||||
if (application.type === IApplicationType.PROXY) {
|
||||
return `${((application.remaining_count || 0) / 1024 / 1024).toFixed(2)}MB`;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -244,7 +256,7 @@ export default defineComponent({
|
||||
|
||||
.panel {
|
||||
padding: 30px;
|
||||
.api-key {
|
||||
.credential {
|
||||
.copy {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface IData {
|
||||
loading: boolean;
|
||||
form: IForm;
|
||||
documentType: typeof IDocumentType;
|
||||
canceler: AbortController | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -72,7 +73,8 @@ export default defineComponent({
|
||||
document: undefined,
|
||||
loading: false,
|
||||
form: {},
|
||||
documentType: IDocumentType
|
||||
documentType: IDocumentType,
|
||||
canceler: undefined
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -94,8 +96,16 @@ export default defineComponent({
|
||||
getDocument(id: string) {
|
||||
this.loading = true;
|
||||
this.form = {};
|
||||
// cancel existing pending request
|
||||
if (this.canceler) {
|
||||
console.log('abort');
|
||||
this.canceler.abort();
|
||||
}
|
||||
this.canceler = new AbortController();
|
||||
documentOperator
|
||||
.get(id)
|
||||
.get(id, {
|
||||
signal: this.canceler.signal
|
||||
})
|
||||
.then(({ data: data }: { data: IDocumentDetailResponse }) => {
|
||||
this.loading = false;
|
||||
this.document = data;
|
||||
|
||||
Reference in new issue
Block a user