add apply

This commit is contained in:
AceDataCloud committed 2023-12-24 00:59:03 +08:00
1 parent 3d1982d533
commit b4a97bf52d
12 files changed
+127 -28

No files matched your search

+66 -6
View File
@@ -8,29 +8,86 @@
<el-button size="small" type="primary" @click="onBuy">{{ $t('common.button.buyMore') }}</el-button>
</span>
</div>
<div v-else 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-model.visible="confirming" :object="api" :type="applicationType.API" @apply="onApply" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IApplication } from '@/operators';
import { ElButton } from 'element-plus';
import { IApplication, IApplicationDetailResponse, applicationOperator } from '@/operators';
import { ElButton, ElMessage } from 'element-plus';
import ApplicationConfirm from '@/components/application/Confirm.vue';
import { IApplicationType } from '@/operators';
import { apiOperator } from '@/operators/api/operator';
import { IApiDetailResponse, IApi } from '@/operators/api';
import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
export interface IData {
confirming: boolean;
applicationType: typeof IApplicationType;
api: IApi | undefined;
}
export default defineComponent({
name: 'ApiStatus',
components: { ElButton },
components: { ElButton, ApplicationConfirm },
props: {
application: {
type: Object as () => IApplication | undefined,
required: true
},
apiId: {
type: String,
required: true
}
},
data() {
return {};
emits: ['apply', 'refresh'],
data(): IData {
return {
confirming: false,
applicationType: IApplicationType,
api: undefined
};
},
computed: {},
mounted() {
apiOperator.get(this.apiId).then(({ data: data }: { data: IApiDetailResponse }) => {
this.api = data;
});
},
methods: {
onBuy() {
const url = `https://data.zhishuyun.com/console/applications/${this.application?.id}/buy`;
window.open(url, '_blank');
},
onApply() {
applicationOperator
.create({
type: IApplicationType.API,
api_id: this.apiId
})
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
// this.application = data;
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;
});
}
}
});
@@ -45,7 +102,7 @@ export default defineComponent({
.info {
font-size: 14px;
color: var(--el-text-color-regular);
display: inline-block;
// display: inline-block;
text-align: center;
}
.actions {
@@ -55,4 +112,7 @@ export default defineComponent({
border-radius: 20px;
}
}
.btn-apply {
border-radius: 20px;
}
</style>
+23 -6
View File
@@ -7,15 +7,22 @@
</el-button>
</div>
</div>
<div class="bottom"></div>
<div class="middle"></div>
<div class="bottom">
<div class="link">
<el-button class="button" @click="onLogout">
<font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" />
</el-button>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElTooltip, ElButton } from 'element-plus';
import { ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ROUTE_CHAT_INDEX, ROUTE_MIDJOURNEY_INDEX } from '@/router/constants';
import { ROUTE_AUTH_LOGIN, ROUTE_CHAT_INDEX, ROUTE_MIDJOURNEY_INDEX } from '@/router/constants';
export default defineComponent({
name: 'Navigator',
@@ -40,6 +47,13 @@ export default defineComponent({
}
]
};
},
methods: {
onLogout() {
console.debug('logout');
this.$store.dispatch('resetToken');
this.$router.push({ name: ROUTE_AUTH_LOGIN });
}
}
});
</script>
@@ -49,7 +63,9 @@ export default defineComponent({
display: flex;
flex-direction: column;
align-items: center;
.top {
.top,
.bottom {
display: flex;
flex-direction: column;
padding-top: 10px;
@@ -71,8 +87,9 @@ export default defineComponent({
}
}
.bottom {
display: flex;
flex-direction: column;
display: block;
position: absolute;
bottom: 0;
}
}
</style>