update proxy management

This commit is contained in:
AceDataCloud committed 2023-02-12 01:50:36 +08:00
1 parent d34e578868
commit f22d21bb53
10 files changed
+209 -10

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
<template>
<div class="title">
{{ proxy?.title }}
</div>
<div class="url">
<el-tag class="method" effect="dark">{{ proxy?.request?.method }}</el-tag>
<span v-if="proxy?.endpoint && proxy?.path" class="endpoint">{{ urlJoin(proxy?.endpoint, proxy?.path) }}</span>
</div>
<div class="introduction">
<p>{{ proxy?.introduction }}</p>
</div>
</template>
<script lang="ts">
import { IProxy } from '@/operators';
import { defineComponent } from 'vue';
import urlJoin from 'url-join';
import { ElTag } from 'element-plus';
export default defineComponent({
name: 'ProxyInfo',
components: {
ElTag
},
props: {
proxy: {
type: Object as () => IProxy,
required: true
}
},
methods: {
urlJoin
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: 500;
line-height: 1.2;
margin-bottom: 10px;
}
.url {
margin-bottom: 10px;
.method {
border-radius: 10px;
padding: 1px 8px;
font-size: 10px;
transform: scale(0.8);
transform-origin: left;
}
.endpoint {
font-size: 12px;
}
}
.introduction {
font-size: 16px;
font-weight: bold;
margin-bottom: 10px;
}
</style>
+2 -1
View File
@@ -7,5 +7,6 @@ export default {
createdAt: '创建时间',
service: '服务名称',
payWay: '支付方式',
api: 'API'
api: 'API',
proxy: '代理'
};
+2
View File
@@ -1,4 +1,5 @@
import { IApi } from '../api';
import { IProxy } from '../proxy';
export enum IApplicationType {
API = 'Api',
@@ -23,6 +24,7 @@ export interface ICredential {
export interface IApplication {
id?: string;
api?: IApi;
proxy?: IProxy;
type?: IApplicationType;
api_id?: string;
proxy_id?: string;
+1
View File
@@ -5,3 +5,4 @@ export * from './user';
export * from './api';
export * from './document';
export * from './order';
export * from './proxy';
+2
View File
@@ -0,0 +1,2 @@
export * from './models';
export * from './operator';
+28
View File
@@ -0,0 +1,28 @@
import { IDocument } from '../document';
import { IService } from '../service';
export interface IProxy {
id: string;
path: string;
endpoint: string;
price?: number;
title?: string;
introduction?: string;
apply_count?: number;
free_count?: number;
applied?: boolean;
tags?: string[];
document?: IDocument;
document_id?: string;
service?: IService;
service_id?: string;
created_at?: string;
updated_at?: string;
}
export interface IProxyListResponse {
count: number;
items: IProxy[];
}
export type IProxyDetailResponse = IProxy;
+40
View File
@@ -0,0 +1,40 @@
import { AxiosResponse } from 'axios';
import { httpClient } from '../instance';
import { IProxy, IProxyDetailResponse, IProxyListResponse } from '../proxy/models';
export interface IProxyQuery {
limit: number;
offset: number;
}
class ProxyOperator {
key = 'proxies';
async getAll(query: IProxyQuery): Promise<AxiosResponse<IProxyListResponse>> {
return await httpClient.get(`/${this.key}/`, {
params: query
});
}
async get(id: string): Promise<AxiosResponse<IProxyDetailResponse>> {
return await httpClient.get(`/${this.key}/${id}`);
}
async create(data: IProxy): Promise<AxiosResponse<IProxyDetailResponse>> {
return await httpClient.post(`/${this.key}/`, data);
}
async update(id: string, data: IProxy): Promise<AxiosResponse<IProxyDetailResponse>> {
return await httpClient.put(`/${this.key}/${id}`, data);
}
async delete(id: string): Promise<AxiosResponse<null>> {
return await httpClient.delete(`/${this.key}/${id}`);
}
async getAllForService(serviceId: string): Promise<AxiosResponse<IProxyListResponse>> {
return await httpClient.get(`/services/${serviceId}/${this.key}/`);
}
}
export const proxyOperator = new ProxyOperator();
+2 -1
View File
@@ -12,7 +12,8 @@
<el-table v-loading="loading" :data="applications" stripe>
<el-table-column :label="$t('application.field.api')" width="200px">
<template #default="scope">
<span>{{ scope.row?.api?.title }}</span>
<span v-if="scope.row.type === applicationType.API">{{ scope.row?.api?.title }}</span>
<span v-if="scope.row.type === applicationType.PROXY">{{ scope.row?.proxy?.title }}</span>
</template>
</el-table-column>
<el-table-column
+14 -2
View File
@@ -20,9 +20,18 @@
<el-descriptions-item :label="$t('order.field.description')">
{{ order?.description }}
</el-descriptions-item>
<el-descriptions-item :label="$t('order.field.api')">
<el-descriptions-item
v-if="order?.application?.type === applicationType.API"
:label="$t('order.field.api')"
>
{{ order?.application?.api?.title }}
</el-descriptions-item>
<el-descriptions-item
v-if="order?.application?.type === applicationType.PROXY"
:label="$t('order.field.proxy')"
>
{{ order?.application?.proxy?.title }}
</el-descriptions-item>
<el-descriptions-item :label="$t('order.field.amount')">
{{ order?.amount }}
</el-descriptions-item>
@@ -116,6 +125,7 @@ import {
ElButton
} from 'element-plus';
import PayOrder from '@/components/order/Pay.vue';
import { IApplicationType } from '@/operators';
enum PayWay {
WechatPay = 'WechatPay',
@@ -130,6 +140,7 @@ interface IData {
loading: boolean;
paying: boolean;
prepaying: boolean;
applicationType: typeof IApplicationType;
}
export default defineComponent({
@@ -154,7 +165,8 @@ export default defineComponent({
order: undefined,
loading: false,
paying: false,
prepaying: false
prepaying: false,
applicationType: IApplicationType
};
},
computed: {
+57 -6
View File
@@ -51,7 +51,7 @@
</el-card>
</el-col>
</el-row>
<el-row v-if="service" id="apis" class="apis">
<el-row v-if="service && apis?.length > 0" id="apis" class="apis">
<el-col :span="20" :offset="2">
<el-card shadow="hover" :body-style="{ padding: '50px' }">
<div v-for="(api, apiIndex) in apis" :key="apiIndex">
@@ -73,6 +73,28 @@
</el-card>
</el-col>
</el-row>
<el-row v-if="service && proxies?.length > 0" id="proxies" class="proxies">
<el-col :span="20" :offset="2">
<el-card shadow="hover" :body-style="{ padding: '50px' }">
<div v-for="(proxy, proxyIndex) in proxies" :key="proxyIndex">
<el-row>
<el-col :span="20">
<proxy-info :proxy="proxy" />
</el-col>
<el-col :span="4" class="operations">
<el-button v-if="!proxy.applied" type="primary" @click="onApply(proxy, applicationType.PROXY)">
{{ $t('common.button.apply') }}
</el-button>
<el-button v-else disabled type="primary">
{{ $t('common.button.applied') }}
</el-button>
</el-col>
</el-row>
<el-divider v-if="proxyIndex < apis.length - 1" />
</div>
</el-card>
</el-col>
</el-row>
</template>
<script lang="ts">
@@ -80,8 +102,11 @@ import {
applicationOperator,
IApplication,
IApplicationDetailResponse,
IProxy,
IProxyListResponse,
IService,
IServiceDetailResponse,
proxyOperator,
serviceOperator
} from '@/operators';
import { defineComponent } from 'vue';
@@ -94,13 +119,17 @@ import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
import { ROUTE_CONSOLE_APPLICATION_LIST } from '@/router';
import { ElCol, ElRow, ElButton, ElCard, ElDivider, ElSkeleton, ElSkeletonItem } from 'element-plus';
import ApiInfo from '@/components/api/Info.vue';
import ProxyInfo from '@/components/proxy/Info.vue';
import { getVerificationUrl } from '@/utils';
interface IData {
service: IService | undefined;
apis: IApi[];
proxies: IProxy[];
application: IApplication | undefined;
loading: boolean;
loadingApis: boolean;
loadingProxies: boolean;
activeTab: string;
applicationType: typeof IApplicationType;
}
@@ -115,6 +144,7 @@ export default defineComponent({
ElCard,
ElDivider,
ApiInfo,
ProxyInfo,
ElSkeleton,
ElSkeletonItem
},
@@ -122,8 +152,11 @@ export default defineComponent({
return {
service: undefined,
apis: [],
proxies: [],
application: undefined,
loading: false,
loadingApis: false,
loadingProxies: false,
activeTab: 'introduction',
applicationType: IApplicationType
};
@@ -136,6 +169,7 @@ export default defineComponent({
async mounted() {
this.onFetchService();
this.onFetchApis();
this.onFetchProxies();
},
methods: {
onFetchService() {
@@ -146,10 +180,27 @@ export default defineComponent({
});
},
onFetchApis() {
this.loading = true;
apiOperator.getAllForService(this.id).then(({ data: data }: { data: IApiListResponse }) => {
this.apis = data.items;
});
this.loadingApis = true;
apiOperator
.getAllForService(this.id)
.then(({ data: data }: { data: IApiListResponse }) => {
this.apis = data.items;
this.loadingApis = false;
})
.catch(() => {
this.loadingApis = false;
});
},
onFetchProxies() {
this.loadingProxies = true;
proxyOperator
.getAllForService(this.id)
.then(({ data: data }: { data: IProxyListResponse }) => {
this.proxies = data.items;
})
.catch(() => {
this.loadingProxies = false;
});
},
onToApis() {
window.scrollTo({
@@ -158,7 +209,7 @@ export default defineComponent({
behavior: 'smooth'
});
},
onApply(obj: IApi, type: IApplicationType) {
onApply(obj: IApi | IProxy, type: IApplicationType) {
applicationOperator
.create({
type,