add package support
This commit is contained in:
1 parent
9bd46bbccb
commit
e66cb2196b
20 files changed
+277
-21
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<div class="price-text">
|
||||
<span v-if="price > 0" class="unfree">¥{{ price }} {{ unit ? `/${unit}` : '' }}</span>
|
||||
<span v-else class="free">
|
||||
{{ $t('api.message.free') }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue';
|
||||
export default defineComponent({
|
||||
name: 'ApiPrice',
|
||||
props: {
|
||||
price: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: 0
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: undefined
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.price-text {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
.unfree {
|
||||
color: #ff5441;
|
||||
|
||||
.value {
|
||||
font-weight: bold;
|
||||
color: #ff5441;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: #666;
|
||||
}
|
||||
}
|
||||
.free {
|
||||
color: #29c287;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+115
-14
@@ -4,15 +4,41 @@
|
||||
<el-form-item v-if="application?.api?.title" :label="$t('application.field.service')">
|
||||
{{ application?.api?.title }}
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('application.field.amount')">
|
||||
<el-form-item :label="$t('application.field.package')">
|
||||
<el-radio-group v-if="application.type === applicationType.API" v-model="form.packageId">
|
||||
<el-radio-button v-for="(pkg, pkgIndex) in application?.api?.packages" :key="pkgIndex" :label="pkg.id">
|
||||
{{ pkg.amount }}{{ $t('api.unit.usage') }}
|
||||
</el-radio-button>
|
||||
<el-radio-button label="custom">
|
||||
{{ $t('application.button.custom') }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-radio-group v-else-if="application.type === applicationType.PROXY" v-model="form.packageId">
|
||||
<el-radio-button v-for="(pkg, pkgIndex) in application?.proxy?.packages" :key="pkgIndex" :label="pkg.id">
|
||||
{{ pkg.amount }}{{ $t('proxy.unit.usage') }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.packageId === 'custom'" :label="$t('application.field.amount')">
|
||||
<el-input-number v-model="form.amount" :min="1" :max="10000" controls-position="right" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('service.field.price')">
|
||||
<service-price :price="application?.api?.price" />
|
||||
<div v-if="application.type === applicationType.API">
|
||||
<api-price v-if="form.packageId === 'custom'" :price="application?.api?.price" :unit="$t('api.unit.usage')" />
|
||||
<api-price v-else :price="package?.price" />
|
||||
</div>
|
||||
<div v-if="application.type === applicationType.PROXY">
|
||||
<proxy-price :price="package?.price" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-divider />
|
||||
<el-form-item :label="$t('application.field.shouldPayPrice')">
|
||||
<span :class="{ price: true, unfree: price > 0 }">¥{{ price.toFixed(2) }}</span>
|
||||
<span v-if="form.packageId === 'custom'" :class="{ price: true, unfree: price > 0, free: price === 0 }">
|
||||
¥{{ price.toFixed(2) }}
|
||||
</span>
|
||||
<span v-else-if="package" :class="{ price: true, unfree: package?.price > 0, free: package?.price === 0 }">
|
||||
¥{{ package?.price?.toFixed(2) }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
@@ -27,12 +53,31 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IApplication, IOrderDetailResponse, orderOperator } from '@/operators';
|
||||
import { IApplication, IApplicationType, IOrderDetailResponse, IPackage, orderOperator } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ROUTE_CONSOLE_ORDER_DETAIL } from '@/router';
|
||||
import { ElDialog, ElForm, ElFormItem, ElButton, ElInputNumber, ElDivider } from 'element-plus';
|
||||
import ServicePrice from '@/components/service/Price.vue';
|
||||
import {
|
||||
ElDialog,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElButton,
|
||||
ElInputNumber,
|
||||
ElDivider,
|
||||
ElRadioGroup,
|
||||
ElRadioButton
|
||||
} from 'element-plus';
|
||||
import ApiPrice from '@/components/api/Price.vue';
|
||||
import ProxyPrice from '@/components/proxy/Price.vue';
|
||||
|
||||
interface IData {
|
||||
form: {
|
||||
amount: number;
|
||||
packageId: string | undefined;
|
||||
};
|
||||
creating: boolean;
|
||||
applicationType: typeof IApplicationType;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CreateOrderDialog',
|
||||
@@ -43,7 +88,10 @@ export default defineComponent({
|
||||
ElButton,
|
||||
ElInputNumber,
|
||||
ElDivider,
|
||||
ServicePrice
|
||||
ElRadioGroup,
|
||||
ElRadioButton,
|
||||
ApiPrice,
|
||||
ProxyPrice
|
||||
},
|
||||
props: {
|
||||
application: {
|
||||
@@ -57,23 +105,68 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
emits: ['hide'],
|
||||
data() {
|
||||
data(): IData {
|
||||
return {
|
||||
form: {
|
||||
amount: 1000
|
||||
amount: 1000,
|
||||
packageId: undefined
|
||||
},
|
||||
creating: false
|
||||
creating: false,
|
||||
applicationType: IApplicationType
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
price() {
|
||||
if (this.application.api?.price && this.form.amount) {
|
||||
return this.form.amount * this.application.api?.price;
|
||||
if (this.application?.type === IApplicationType.API) {
|
||||
if (this.application.api?.price && this.form.amount) {
|
||||
return this.form.amount * this.application.api?.price;
|
||||
}
|
||||
}
|
||||
if (this.application?.type === IApplicationType.PROXY) {
|
||||
if (this.application.proxy?.price && this.form.amount) {
|
||||
return this.form.amount * this.application.proxy?.price;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
package() {
|
||||
if (this.application?.type === IApplicationType.API) {
|
||||
if (this.application.api?.packages && this.form.packageId) {
|
||||
const filterPackages = this.application.api?.packages.filter((item) => item.id === this.form.packageId);
|
||||
if (filterPackages.length > 0) {
|
||||
return filterPackages[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.application?.type === IApplicationType.PROXY) {
|
||||
if (this.application.proxy?.packages && this.form.packageId) {
|
||||
const filterPackages = this.application.proxy?.packages.filter((item) => item.id === this.form.packageId);
|
||||
if (filterPackages.length > 0) {
|
||||
return filterPackages[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.application.type === IApplicationType.API) {
|
||||
if (this.application?.api?.packages && this.application?.api?.packages.length > 0) {
|
||||
this.form.packageId = this.application?.api?.packages[0].id;
|
||||
} else {
|
||||
this.form.packageId = 'custom';
|
||||
}
|
||||
}
|
||||
if (this.application.type === IApplicationType.PROXY) {
|
||||
if (this.application?.proxy?.packages && this.application?.proxy?.packages.length > 0) {
|
||||
this.form.packageId = this.application?.proxy?.packages[0].id;
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChangePackage(pkg: IPackage) {
|
||||
console.log('pkg', pkg);
|
||||
},
|
||||
onCreateOrder() {
|
||||
if (!this.application?.id) {
|
||||
return;
|
||||
@@ -82,7 +175,12 @@ export default defineComponent({
|
||||
orderOperator
|
||||
.create({
|
||||
application_id: this.application?.id,
|
||||
amount: this.form.amount
|
||||
amount: this.form.amount,
|
||||
...(this.form.packageId !== 'custom' && this.package
|
||||
? {
|
||||
package_id: this.package.id
|
||||
}
|
||||
: {})
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.creating = false;
|
||||
@@ -107,8 +205,11 @@ export default defineComponent({
|
||||
.price {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
.unfree {
|
||||
&.unfree {
|
||||
color: #ff5441;
|
||||
}
|
||||
&.free {
|
||||
color: #29c287;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<div class="price-text">
|
||||
<span v-if="price > 0" class="unfree">¥{{ price }} {{ unit ? `/${unit}` : '' }}</span>
|
||||
<span v-else class="free">
|
||||
{{ $t('proxy.message.free') }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue';
|
||||
export default defineComponent({
|
||||
name: 'ProxyPrice',
|
||||
props: {
|
||||
price: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: 0
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: undefined
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.price-text {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
.unfree {
|
||||
color: #ff5441;
|
||||
|
||||
.value {
|
||||
font-weight: bold;
|
||||
color: #ff5441;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: #666;
|
||||
}
|
||||
}
|
||||
.free {
|
||||
color: #29c287;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,9 @@
|
||||
import entity from './entity';
|
||||
import unit from './unit';
|
||||
import message from './message';
|
||||
|
||||
export default {
|
||||
entity
|
||||
entity,
|
||||
unit,
|
||||
message
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
free: '免费',
|
||||
appliedCount: '申请次数'
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
usage: '次'
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
goDocument: '查看文档',
|
||||
buyMore: '购买更多',
|
||||
createOrder: '创建订单'
|
||||
createOrder: '创建订单',
|
||||
custom: '自定义'
|
||||
};
|
||||
@@ -9,5 +9,6 @@ export default {
|
||||
api: 'API',
|
||||
proxy: '代理',
|
||||
credential: '密钥',
|
||||
name: '名称'
|
||||
name: '名称',
|
||||
package: '套餐'
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import console from './console';
|
||||
import application from './application';
|
||||
import api from './api';
|
||||
import order from './order';
|
||||
import proxy from './proxy';
|
||||
|
||||
export default {
|
||||
common,
|
||||
@@ -13,5 +14,6 @@ export default {
|
||||
console,
|
||||
application,
|
||||
api,
|
||||
order
|
||||
order,
|
||||
proxy
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
export default {
|
||||
requestQueries: 'URL参数',
|
||||
requestBody: '请求体',
|
||||
responseBody: '响应体',
|
||||
requestHeaders: '请求头',
|
||||
requestHeader: '请求头',
|
||||
responseHeaders: '响应头',
|
||||
response: '响应',
|
||||
success: '成功',
|
||||
failure: '失败',
|
||||
responseExample: '样例',
|
||||
authentication: '认证'
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import entity from './entity';
|
||||
import unit from './unit';
|
||||
import message from './message';
|
||||
|
||||
export default {
|
||||
entity,
|
||||
unit,
|
||||
message
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
free: '免费'
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
usage: 'MB'
|
||||
};
|
||||
@@ -57,7 +57,6 @@ export default {
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
box-shadow: 1px 0 0 #eee;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -44,6 +44,12 @@ export interface IResponse {
|
||||
headers: ISchema;
|
||||
}
|
||||
|
||||
export interface IPackage {
|
||||
id: string;
|
||||
amount: number;
|
||||
price: number;
|
||||
}
|
||||
|
||||
export interface IApi {
|
||||
id: string;
|
||||
path: string;
|
||||
@@ -62,6 +68,7 @@ export interface IApi {
|
||||
document?: IDocument;
|
||||
document_id?: string;
|
||||
service?: IService;
|
||||
packages?: IPackage[];
|
||||
service_id?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
|
||||
@@ -20,7 +20,6 @@ class DocumentOperator {
|
||||
}
|
||||
|
||||
async get(id: string, config?: AxiosRequestConfig): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
console.log('sss', config);
|
||||
return await httpClient.get(`/${this.key}/${id}`, config);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { IOrder, IOrderDetailResponse, IOrderListResponse } from './models';
|
||||
|
||||
export interface IOrderQuery {
|
||||
user_id?: string;
|
||||
package_id?: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
ordering: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { IPackage } from '../api';
|
||||
import { IDocument } from '../document';
|
||||
import { IService } from '../service';
|
||||
|
||||
@@ -15,6 +16,7 @@ export interface IProxy {
|
||||
document?: IDocument;
|
||||
document_id?: string;
|
||||
service?: IService;
|
||||
packages?: IPackage[];
|
||||
service_id?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
|
||||
@@ -47,6 +47,7 @@ import { documentOperator, IDocument, IDocumentDetailResponse, IDocumentType } f
|
||||
import { IForm } from '@/operators/api/models';
|
||||
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
||||
import { ElSkeleton, ElDivider } from 'element-plus';
|
||||
import axios from 'axios';
|
||||
|
||||
export interface IData {
|
||||
document: IDocument | undefined;
|
||||
@@ -110,6 +111,9 @@ export default defineComponent({
|
||||
this.document = data;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (axios.isCancel(error)) {
|
||||
return;
|
||||
}
|
||||
this.loading = false;
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ import { serviceOperator, IService, IServiceListResponse } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import Pagination from '@/components/common/Pagination.vue';
|
||||
import { ElRow, ElCol, ElButton, ElCard, ElSkeleton, ElImage, ElSkeletonItem } from 'element-plus';
|
||||
import ServicePrice from '@/components/service/Price.vue';
|
||||
import ServicePrice from '@/components/api/Price.vue';
|
||||
|
||||
interface IData {
|
||||
services: IService[];
|
||||
|
||||
Reference in new issue
Block a user