add unit support

This commit is contained in:
AceDataCloud committed 2023-02-26 23:12:11 +08:00
1 parent 46da57bbf9
commit 25649410bc
11 files changed
+79 -126

No files matched your search

@@ -1,8 +1,10 @@
<template>
<div class="price-text">
<span v-if="price > 0" class="unfree">¥{{ price }} {{ unit ? `/${unit}` : '' }}</span>
<span v-if="price > 0" class="unfree"
>¥{{ price }} {{ unit ? `/ ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : '' }}</span
>
<span v-else class="free">
{{ $t('api.message.free') }}
{{ $t('common.message.free') }}
</span>
</div>
</template>
@@ -21,6 +23,11 @@ export default defineComponent({
type: String,
required: false,
default: undefined
},
start: {
type: Boolean,
required: false,
default: false
}
}
});
+34 -20
View File
@@ -7,7 +7,7 @@
<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') }}
{{ pkg.amount }}{{ $t(`api.unit.${application?.api?.unit}`) }}
</el-radio-button>
<el-radio-button label="custom">
{{ $t('application.button.custom') }}
@@ -15,7 +15,7 @@
</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') }}
{{ pkg.amount }}{{ $t(`proxy.unit.${application?.proxy?.unit}`) }}
</el-radio-button>
</el-radio-group>
</el-form-item>
@@ -24,11 +24,15 @@
</el-form-item>
<el-form-item :label="$t('service.field.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" />
<price
v-if="form.packageId === 'custom'"
:price="application?.api?.price"
:unit="$t(`api.unit.${application?.api?.unit}`)"
/>
<price v-else :price="package?.price" />
</div>
<div v-if="application.type === applicationType.PROXY">
<proxy-price :price="package?.price" />
<price :price="package?.price" />
</div>
</el-form-item>
<el-divider />
@@ -67,8 +71,7 @@ import {
ElRadioGroup,
ElRadioButton
} from 'element-plus';
import ApiPrice from '@/components/api/Price.vue';
import ProxyPrice from '@/components/proxy/Price.vue';
import Price from '@/components/common/Price.vue';
interface IData {
form: {
@@ -90,8 +93,7 @@ export default defineComponent({
ElDivider,
ElRadioGroup,
ElRadioButton,
ApiPrice,
ProxyPrice
Price
},
props: {
application: {
@@ -149,21 +151,33 @@ export default defineComponent({
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;
watch: {
visible: {
handler(val) {
if (val) {
this.onInit();
}
}
}
},
mounted() {
this.onInit();
},
methods: {
onInit() {
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;
}
}
},
onChangePackage(pkg: IPackage) {
console.log('pkg', pkg);
},
-50
View File
@@ -1,50 +0,0 @@
<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>
-45
View File
@@ -1,45 +0,0 @@
<template>
<div class="price-text">
<span v-if="price > 0" class="unfree">¥{{ price }} / {{ $t('service.unit.usage') }}</span>
<span v-else class="free">
{{ $t('service.message.free') }}
</span>
</div>
</template>
<script>
import { defineComponent } from 'vue';
export default defineComponent({
name: 'ServicePrice',
props: {
price: {
type: Number,
required: false,
default: 0
}
}
});
</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 -1
View File
@@ -1,3 +1,3 @@
export default {
usage: '次'
Count: '次'
};
+3 -1
View File
@@ -2,5 +2,7 @@ export default {
copied: '复制成功',
confirmDelete: '确认删除吗?',
alert: '警告',
info: '温馨提示'
info: '温馨提示',
free: '免费',
startPrice: '起'
};
+3 -1
View File
@@ -1,3 +1,5 @@
export default {
usage: 'MB'
MB: 'MB',
KB: 'KB',
B: 'B'
};
+5
View File
@@ -50,11 +50,16 @@ export interface IPackage {
price: number;
}
export enum IApiUnit {
COUNT = 'Count'
}
export interface IApi {
id: string;
path: string;
endpoint: string;
price?: number;
unit?: IApiUnit;
title?: string;
introduction?: string;
apply_count?: number;
+5
View File
@@ -2,10 +2,15 @@ import { IPackage } from '../api';
import { IDocument } from '../document';
import { IService } from '../service';
export enum IProxyUnit {
MB = 'MB'
}
export interface IProxy {
id: string;
path: string;
endpoint: string;
unit?: IProxyUnit;
price?: number;
title?: string;
introduction?: string;
+13 -5
View File
@@ -27,7 +27,7 @@
class-name="text-center"
>
<template #default="scope">
<span>{{ getRemainingCount(scope.row) }}</span>
<span>{{ getCount(scope.row) }}</span>
</template>
</el-table-column>
<el-table-column
@@ -35,7 +35,11 @@
:label="$t('application.field.usedCount')"
width="100px"
class-name="text-center"
/>
>
<template #default="scope">
<span>{{ getCount(scope.row) }}</span>
</template>
</el-table-column>
<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">
@@ -230,12 +234,16 @@ export default defineComponent({
this.loading = false;
});
},
getRemainingCount(application: IApplication) {
getCount(application: IApplication) {
if (application.type === IApplicationType.API) {
return application.remaining_count;
const unit = this.$t(`api.unit.${application?.api?.unit}`);
return `${application.remaining_count}${unit}`;
}
if (application.type === IApplicationType.PROXY) {
return `${((application.remaining_count || 0) / 1024 / 1024).toFixed(2)}MB`;
const unit = this.$t(`proxy.unit.${application?.proxy?.unit}`);
if (unit === 'MB') {
return `${((application.remaining_count || 0) / 1024 / 1024).toFixed(2)}${unit}`;
}
}
}
}
+6 -1
View File
@@ -33,7 +33,12 @@
{{ order?.application?.proxy?.title }}
</el-descriptions-item>
<el-descriptions-item :label="$t('order.field.amount')">
{{ order?.amount }}
<span v-if="order?.application?.type === applicationType.API">
{{ order?.amount }}{{ $t(`api.unit.${order?.application?.api?.unit}`) }}
</span>
<span v-if="order?.application?.type === applicationType.PROXY">
{{ order?.amount }}{{ $t(`proxy.unit.${order?.application?.proxy?.unit}`) }}
</span>
</el-descriptions-item>
<el-descriptions-item :label="$t('order.field.createdAt')">
{{ $dayjs.format(order?.created_at) }}