Migrate new service (#1)

This commit is contained in:
AceDataCloud committed 2024-03-07 01:09:03 +08:00
1 parent f13ca37d63
commit 28da0263dc
109 files changed
+1160 -1053

No files matched your search

+17 -32
View File
@@ -1,29 +1,30 @@
<template>
<el-dialog :model-value="visible" width="500px" center @close="$emit('update:visible', false)">
<el-dialog
:model-value="visible"
width="500px"
:title="$t('application.message.confirmApplying')"
center
@close="$emit('update:visible', false)"
>
<div class="content">
<el-descriptions :column="1">
<el-descriptions-item :label="$t('application.field.name')">
{{ object?.title }}
{{ service?.title }}
</el-descriptions-item>
<el-descriptions-item :label="$t('application.field.freeAmount')">
<span v-if="type === applicationType.API">
{{ object?.free_amount }}{{ $t(`api.unit.${object?.unit}`) }}
</span>
<span> {{ service?.free_amount }} {{ $t(`service.unit.${service?.unit}`) }} </span>
</el-descriptions-item>
</el-descriptions>
<p class="description">
{{ $t('application.message.applyDescription') }}
</p>
<el-divider class="my-2" />
<div class="policy">
<el-checkbox v-model="checked" size="large" class="policy-checkbox" />
<span class="policy-title"> {{ $t('application.message.readPolicy') }} </span>
<span class="policy-title highlight" @click="showPolicy = true"> {{ $t('application.message.policy') }} </span>
<span class="policy-title highlight" @click="showPolicy = true">
&nbsp;{{ $t('application.message.policy') }}</span
>
<application-policy v-model.visible="showPolicy" />
</div>
<el-button type="primary" class="btn btn-apply" @click="onApply">
{{ $t('common.button.applyForFree') }}
</el-button>
<el-button type="primary" @click="onApply">{{ $t('common.button.apply') }}</el-button>
</div>
</el-dialog>
</template>
@@ -31,11 +32,10 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDialog, ElDescriptions, ElDescriptionsItem, ElDivider, ElCheckbox, ElButton, ElMessage } from 'element-plus';
import { IApi, IApplicationType } from '@/operators';
import { IService } from '@/models';
import ApplicationPolicy from './Policy.vue';
interface IData {
applicationType: typeof IApplicationType;
checked: boolean;
showPolicy: boolean;
}
@@ -52,12 +52,8 @@ export default defineComponent({
ApplicationPolicy
},
props: {
object: {
type: Object as () => IApi | undefined,
required: true
},
type: {
type: Object as () => IApplicationType,
service: {
type: Object as () => IService,
required: true
},
visible: {
@@ -69,8 +65,7 @@ export default defineComponent({
emits: ['update:visible', 'apply'],
data(): IData {
return {
applicationType: IApplicationType,
checked: true,
checked: false,
showPolicy: false
};
},
@@ -90,18 +85,8 @@ export default defineComponent({
<style lang="scss" scoped>
.content {
padding: 10px 40px;
.description {
font-size: 12px;
}
.btn-apply {
border-radius: 20px;
}
.policy {
margin-bottom: 10px;
.policy-checkbox {
margin-right: 10px !important;
}
+149
View File
@@ -0,0 +1,149 @@
<template>
<div v-if="initializing && application === undefined">
<el-skeleton :rows="1" class="text-center">
<template #template>
<el-skeleton-item variant="p" class="shimmer" />
</template>
</el-skeleton>
</div>
<div v-else-if="application" class="status">
<span class="info">
{{ $t('common.message.usedAmount') }}: {{ application?.used_amount?.toFixed(6) }}
{{ $t('common.message.remainingAmount') }}:
{{ application?.remaining_amount?.toFixed(6) }}
</span>
<span class="actions">
<el-button size="small" type="primary" @click="onBuyMore(application)">{{
$t('common.button.buyMore')
}}</el-button>
</span>
</div>
<div v-if="needApply && service" class="text-center info">
<span class="mr-2">{{ $t('chat.message.notApplied') }}</span>
<span>
<el-button type="primary" class="btn btn-apply" size="small" @click="confirming = true">
{{ $t('common.button.apply') }}
</el-button>
</span>
<span class="ml-1">{{ $t('chat.message.tryForFree') }}</span>
<application-confirm v-if="service" v-model.visible="confirming" :service="service" @apply="onApply" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { applicationOperator } from '@/operators';
import { ElButton, ElMessage, ElSkeleton, ElSkeletonItem } from 'element-plus';
import ApplicationConfirm from '@/components/application/Confirm.vue';
import { IApplicationType, IApplication, IApplicationDetailResponse, IService } from '@/models';
import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router';
export interface IData {
confirming: boolean;
applicationType: typeof IApplicationType;
}
export default defineComponent({
name: 'ApplicationStatus',
components: { ElButton, ApplicationConfirm, ElSkeleton, ElSkeletonItem },
props: {
application: {
type: Object as () => IApplication | undefined,
required: true
},
initializing: {
type: Boolean,
default: false
},
service: {
type: Object as () => IService | undefined,
required: true
},
needApply: {
type: Boolean,
default: false
}
},
emits: ['apply', 'refresh'],
data(): IData {
return {
confirming: this.needApply,
applicationType: IApplicationType
};
},
computed: {
authenticated() {
return !!this.$store.state.token.access;
},
user() {
return this.$store.state.user;
}
},
watch: {
needApply(val) {
if (val) {
this.confirming = val;
}
}
},
methods: {
onBuyMore(application: IApplication) {
this.$router.push({
name: ROUTE_CONSOLE_APPLICATION_BUY,
params: {
id: application.id
}
});
},
onApply() {
applicationOperator
.create({
type: IApplicationType.API,
service_id: this.service?.id
})
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
ElMessage.success(this.$t('application.message.applySuccessfully'));
setTimeout(() => {
this.$emit('refresh');
}, 2000);
this.confirming = false;
})
.catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied'));
}
this.confirming = false;
});
}
}
});
</script>
<style lang="scss" scoped>
.shimmer {
width: 300px;
margin: auto;
}
.status {
display: block;
width: fit-content;
margin: auto;
}
.info {
font-size: 14px;
color: var(--el-text-color-regular);
// display: inline-block;
text-align: center;
}
.actions {
margin: 0 5px;
display: inline-block;
.el-button {
border-radius: 20px;
}
}
.btn-apply {
border-radius: 20px;
}
</style>