remove unused
This commit is contained in:
1 parent
301dab1ca5
commit
ea1c3413a5
88 files changed
+29
-5766
No files matched your search
@@ -1,272 +0,0 @@
|
||||
<template>
|
||||
<div class="wrapper">
|
||||
<div class="options mb-2">
|
||||
<div
|
||||
v-for="(option, optionKey) in options"
|
||||
:key="optionKey"
|
||||
:class="{
|
||||
option: true,
|
||||
active: lang === option.name
|
||||
}"
|
||||
@click="lang = option.name"
|
||||
>
|
||||
<el-image :src="option.icon" class="icon" />
|
||||
<p class="name">{{ option.name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="code" class="code">
|
||||
<code-snippet :code="code" :lang="lang" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import javascript from 'programming-languages-logos/src/javascript/javascript.svg';
|
||||
import python from 'programming-languages-logos/src/python/python.svg';
|
||||
import java from 'programming-languages-logos/src/java/java.svg';
|
||||
import php from 'programming-languages-logos/src/php/php.svg';
|
||||
import { IApi, IForm, IRequest } from '@/operators/api/models';
|
||||
import urlJoin from 'url-join';
|
||||
import Mustache from 'mustache';
|
||||
import pythonTemplate from '@/assets/templates/python.tpl';
|
||||
import javascriptTemplate from '@/assets/templates/javascript.tpl';
|
||||
import phpTemplate from '@/assets/templates/php.tpl';
|
||||
import javaTemplate from '@/assets/templates/java.tpl';
|
||||
import CodeSnippet from '../common/CodeSnippet.vue';
|
||||
import queryString from 'query-string';
|
||||
import { ElImage } from 'element-plus';
|
||||
|
||||
interface IOption {
|
||||
name: ILang;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
const LANG_PYTHON = 'Python';
|
||||
const LANG_JAVA = 'Java';
|
||||
const LANG_JAVASCRIPT = 'JavaScript';
|
||||
const LANG_PHP = 'PHP';
|
||||
|
||||
type ILang = typeof LANG_PYTHON | typeof LANG_JAVA | typeof LANG_JAVASCRIPT | typeof LANG_PHP;
|
||||
|
||||
interface IData {
|
||||
lang: ILang | undefined;
|
||||
options: IOption[];
|
||||
}
|
||||
|
||||
interface IRenderData {
|
||||
headers: {
|
||||
key: string;
|
||||
value: string;
|
||||
}[];
|
||||
body: {
|
||||
key: string;
|
||||
value: string | object | number | object[] | boolean;
|
||||
}[];
|
||||
method: IRequest['method'] | Lowercase<IRequest['method']> | Uppercase<IRequest['method']>;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiCode',
|
||||
components: {
|
||||
CodeSnippet,
|
||||
ElImage
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
form: {
|
||||
type: Object as () => IForm,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
lang: undefined,
|
||||
options: [
|
||||
{
|
||||
name: LANG_PYTHON,
|
||||
icon: python
|
||||
},
|
||||
{
|
||||
name: LANG_JAVASCRIPT,
|
||||
icon: javascript
|
||||
},
|
||||
{
|
||||
name: LANG_JAVA,
|
||||
icon: java
|
||||
},
|
||||
{
|
||||
name: LANG_PHP,
|
||||
icon: php
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
method() {
|
||||
return this.api.request.method;
|
||||
},
|
||||
url() {
|
||||
const getQueryString = () => {
|
||||
if (this.form.queries) {
|
||||
return `?${queryString.stringify(this.form?.queries)}`;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
return urlJoin(this.api?.endpoint, this.api?.path, getQueryString());
|
||||
},
|
||||
headers() {
|
||||
let result = [];
|
||||
for (const key in this.form.headers) {
|
||||
result.push({
|
||||
key,
|
||||
value: this.form.headers[key]
|
||||
});
|
||||
}
|
||||
if (result.length > 0) {
|
||||
const last = result[result.length - 1];
|
||||
result[result.length - 1] = {
|
||||
...last,
|
||||
last: true
|
||||
};
|
||||
}
|
||||
return result;
|
||||
},
|
||||
body() {
|
||||
let result = [];
|
||||
for (const key in this.form.body) {
|
||||
const value = this.form.body[key];
|
||||
result.push({
|
||||
key,
|
||||
value
|
||||
});
|
||||
}
|
||||
if (result.length > 0) {
|
||||
const last = result[result.length - 1];
|
||||
result[result.length - 1] = {
|
||||
...last,
|
||||
last: true
|
||||
};
|
||||
}
|
||||
return result;
|
||||
},
|
||||
code(): string | undefined {
|
||||
let template = undefined;
|
||||
let renderData: IRenderData = JSON.parse(
|
||||
JSON.stringify({
|
||||
headers: this.headers,
|
||||
body: this.body,
|
||||
url: this.url,
|
||||
method: this.method
|
||||
})
|
||||
);
|
||||
if (this.lang === LANG_PYTHON) {
|
||||
template = pythonTemplate;
|
||||
for (const item of renderData.headers) {
|
||||
let value = item.value;
|
||||
item.value = `'${value}'`;
|
||||
}
|
||||
for (const item of renderData.body) {
|
||||
let value = item.value;
|
||||
if (value === true || value === false) {
|
||||
item.value = `${value.toString()[0].toUpperCase() + value.toString().substring(1)}`;
|
||||
} else if (typeof value === 'string') {
|
||||
item.value = `'${value}'`;
|
||||
}
|
||||
}
|
||||
renderData = {
|
||||
...renderData,
|
||||
method: renderData.method.toLowerCase() as Lowercase<IRenderData['method']>
|
||||
};
|
||||
} else if (this.lang === LANG_JAVASCRIPT) {
|
||||
template = javascriptTemplate;
|
||||
for (const item of renderData.headers) {
|
||||
let value = item.value;
|
||||
item.value = `'${value}'`;
|
||||
}
|
||||
for (const item of renderData.body) {
|
||||
let value = item.value;
|
||||
if (typeof value === 'string') {
|
||||
item.value = `'${value}'`;
|
||||
}
|
||||
}
|
||||
} else if (this.lang === LANG_PHP) {
|
||||
template = phpTemplate;
|
||||
for (const item of renderData.headers) {
|
||||
let value = item.value;
|
||||
item.value = `'${value}'`;
|
||||
}
|
||||
for (const item of renderData.body) {
|
||||
let value = item.value;
|
||||
if (typeof value === 'string') {
|
||||
item.value = `"${value}"`;
|
||||
}
|
||||
}
|
||||
} else if (this.lang === LANG_JAVA) {
|
||||
template = javaTemplate;
|
||||
for (const item of renderData.headers) {
|
||||
let value = item.value;
|
||||
item.value = `"${value}"`;
|
||||
}
|
||||
for (const item of renderData.body) {
|
||||
let value = item.value;
|
||||
if (typeof value === 'string') {
|
||||
item.value = `"${value}"`;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (template) return Mustache.render(template, renderData);
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.lang = this.options[0].name;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
width: 100%;
|
||||
// padding: 15px;
|
||||
padding-bottom: 0;
|
||||
overflow-x: scroll;
|
||||
.options {
|
||||
width: fit-content;
|
||||
overflow: hidden;
|
||||
.option {
|
||||
margin: 0 5px;
|
||||
float: left;
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
text-align: center;
|
||||
border: 1px solid transparent;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
&:hover,
|
||||
&.active {
|
||||
border-color: #ccc;
|
||||
cursor: pointer;
|
||||
}
|
||||
.icon {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.name {
|
||||
color: #666;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,296 +0,0 @@
|
||||
<template>
|
||||
<div v-if="schema" class="wrapper">
|
||||
<div v-for="(item, itemKey) in schema?.properties" :key="itemKey" class="item">
|
||||
<div class="left">
|
||||
<div class="info">
|
||||
<span class="key">{{ itemKey }}</span>
|
||||
<span class="type">{{ item?.type }}</span>
|
||||
<span v-if="!item?.optional" class="required">{{ $t('application.message.requiredParameter') }}</span>
|
||||
</div>
|
||||
<div class="description">
|
||||
{{ item?.title }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div v-if="itemKey === 'token'">
|
||||
<div v-if="!applied === true">
|
||||
<application-confirm
|
||||
v-if="api"
|
||||
v-model.visible="confirming"
|
||||
:object="api"
|
||||
:type="applicationType.API"
|
||||
@apply="onApply"
|
||||
/>
|
||||
<el-popover placement="bottom" :width="200" :visible="applied === false">
|
||||
<p class="text-center mb-2">
|
||||
<small>{{ $t('application.message.notApplied') }}</small>
|
||||
</p>
|
||||
<p class="text-center">
|
||||
<el-button size="small" type="primary" @click="confirming = true">{{
|
||||
$t('common.button.apply')
|
||||
}}</el-button>
|
||||
</p>
|
||||
<template #reference>
|
||||
<el-input
|
||||
v-model="value[itemKey?.toString()]"
|
||||
:placeholder="$t('common.title.placeholderOfInput')"
|
||||
class="inline-block w-2/3"
|
||||
/>
|
||||
</template>
|
||||
</el-popover>
|
||||
<el-button type="primary" class="inline-block ml-2" size="small" @click="$emit('refresh-applications')">
|
||||
{{ $t('common.button.acquire') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<el-select
|
||||
v-else
|
||||
v-model="value[itemKey?.toString()]"
|
||||
:clearable="true"
|
||||
:filterable="true"
|
||||
:allow-create="true"
|
||||
class="w-full"
|
||||
:placeholder="$t('common.title.placeholderOfSelect')"
|
||||
>
|
||||
<el-option
|
||||
v-if="appliedApplication?.credential?.token"
|
||||
:label="appliedApplication?.credential?.token"
|
||||
:value="appliedApplication?.credential?.token"
|
||||
class="select-option"
|
||||
>
|
||||
<span class="select-option-main">{{ appliedApplication?.credential?.token }}</span>
|
||||
<span class="select-option-description">{{ $t('application.message.yourApplication') }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-select
|
||||
v-if="item?.enum"
|
||||
v-model="value[itemKey?.toString()]"
|
||||
:default-first-option="item?.enum?.length === 1"
|
||||
clearable
|
||||
class="w-full"
|
||||
:placeholder="$t('common.title.placeholderOfSelect')"
|
||||
>
|
||||
<el-option v-for="e in item?.enum" :key="e" :label="e" :value="e" />
|
||||
</el-select>
|
||||
<el-select
|
||||
v-else-if="item?.type === 'boolean'"
|
||||
v-model="value[itemKey?.toString()]"
|
||||
clearable
|
||||
class="w-full"
|
||||
:placeholder="$t('common.title.placeholderOfSelect')"
|
||||
>
|
||||
<el-option key="true" :label="'true'" :value="true" />
|
||||
<el-option key="false" :label="'false'" :value="false" />
|
||||
</el-select>
|
||||
<div v-else-if="item?.example">
|
||||
<el-input
|
||||
v-model="value[itemKey?.toString()]"
|
||||
class="inline-block w-2/3"
|
||||
:placeholder="$t('common.title.placeholderOfInput')"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
class="inline-block ml-2"
|
||||
size="small"
|
||||
@click="value[itemKey?.toString()] = item.example!"
|
||||
>
|
||||
{{ $t('common.button.fillExample') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<el-input v-else v-model="value[itemKey?.toString()]" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ISchema } from '@/operators/api/models';
|
||||
import { applicationOperator, IApi, IApplication, IApplicationType } from '@/operators';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ElPopover, ElInput, ElSelect, ElButton, ElTooltip, ElOption, ElMessage } from 'element-plus';
|
||||
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants/errorCode';
|
||||
import { getVerificationUrl } from '@/utils';
|
||||
import ApplicationConfirm from '@/components/application/Confirm.vue';
|
||||
|
||||
interface IData {
|
||||
value: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
confirming: boolean;
|
||||
applicationType: typeof IApplicationType;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiForm',
|
||||
components: {
|
||||
ElPopover,
|
||||
ElInput,
|
||||
ElSelect,
|
||||
ElButton,
|
||||
ElOption,
|
||||
ApplicationConfirm
|
||||
},
|
||||
props: {
|
||||
schema: {
|
||||
type: Object as () => ISchema | undefined,
|
||||
required: true
|
||||
},
|
||||
api: {
|
||||
type: Object as () => IApi | undefined,
|
||||
required: true
|
||||
},
|
||||
applications: {
|
||||
type: Array as () => IApplication[],
|
||||
required: true
|
||||
},
|
||||
applied: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
emits: ['update:form', 'refresh-applications'],
|
||||
data(): IData {
|
||||
return {
|
||||
value: {},
|
||||
confirming: false,
|
||||
applicationType: IApplicationType
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
appliedApplication(): IApplication | undefined {
|
||||
const applications = this.applications.filter((application) => application.api?.id === this.api?.id);
|
||||
if (applications.length > 0) {
|
||||
return applications[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: {
|
||||
handler() {
|
||||
this.$emit('update:form', { ...this.value });
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChange(key: string, val: string) {
|
||||
this.value[key] = val;
|
||||
},
|
||||
onRefreshApplications() {
|
||||
this.$emit('refresh-applications');
|
||||
},
|
||||
onApply() {
|
||||
this.confirming = false;
|
||||
applicationOperator
|
||||
.create({
|
||||
type: IApplicationType.API,
|
||||
api_id: this.api?.id
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success(this.$t('application.message.applySuccessfully'));
|
||||
this.$emit('refresh-applications');
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
|
||||
ElMessage.error(this.$t('application.message.alreadyApplied'));
|
||||
}
|
||||
if (error?.response?.data?.code === ERROR_CODE_UNVERIFIED) {
|
||||
ElMessage({
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 0,
|
||||
showClose: true,
|
||||
message: `${this.$t(
|
||||
'application.message.unverified'
|
||||
)} <a class="underline" href="${getVerificationUrl()}">${this.$t('application.message.goVerify')}</a>`,
|
||||
type: 'warning'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
overflow: hidden;
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
background-color: rgb(248, 248, 248);
|
||||
padding: 10px;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.1);
|
||||
|
||||
&:first-child {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
&:not(:first-child):not(:last-child) {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
.left {
|
||||
width: 70%;
|
||||
float: left;
|
||||
.info {
|
||||
.key {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
padding-left: 0;
|
||||
}
|
||||
.type {
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
}
|
||||
.required {
|
||||
font-size: 12px;
|
||||
color: #dd1e2e;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
}
|
||||
}
|
||||
.description {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
width: 30%;
|
||||
float: left;
|
||||
padding-top: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.el-select-dropdown {
|
||||
.select-option {
|
||||
.select-option-main {
|
||||
display: inline-block;
|
||||
font-size: 14px;
|
||||
}
|
||||
.select-option-description {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-left: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,61 +0,0 @@
|
||||
<template>
|
||||
<div class="title">
|
||||
{{ api?.title }}
|
||||
</div>
|
||||
<div class="url">
|
||||
<el-tag class="method" effect="dark">{{ api?.request?.method }}</el-tag>
|
||||
<span v-if="api?.endpoint && api?.path" class="endpoint">{{ urlJoin(api?.endpoint, api?.path) }}</span>
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<p>{{ api?.introduction }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IApi } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import urlJoin from 'url-join';
|
||||
import { ElTag } from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'ApiInfo',
|
||||
components: {
|
||||
ElTag
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
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>
|
||||
@@ -1,158 +0,0 @@
|
||||
<template>
|
||||
<div class="title">
|
||||
<el-button type="primary" size="small" class="mb-1">{{ $t('application.field.api') }}</el-button>
|
||||
{{ api?.title }}
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<p>{{ api?.introduction }}</p>
|
||||
</div>
|
||||
<div class="options">
|
||||
<el-button
|
||||
v-if="showFirstOption"
|
||||
ref="option"
|
||||
type="primary"
|
||||
:plain="activeOption !== 'first'"
|
||||
class="option"
|
||||
@click="activeOption = 'first'"
|
||||
>{{ $t('api.message.firstFree') }}</el-button
|
||||
>
|
||||
<el-button
|
||||
v-for="(pkg, pkgIndex) in api?.packages"
|
||||
ref="option"
|
||||
:key="pkgIndex"
|
||||
type="primary"
|
||||
:plain="!(activeOption == 'package' && activePackage?.id === pkg.id)"
|
||||
class="option"
|
||||
@click="
|
||||
activeOption = 'package';
|
||||
activePackage = pkg;
|
||||
"
|
||||
>
|
||||
{{ pkg.amount }}{{ $t(`api.unit.${api.unit}`) }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="showCustomOption"
|
||||
ref="option"
|
||||
type="primary"
|
||||
:plain="activeOption !== 'custom'"
|
||||
class="option"
|
||||
@click="activeOption = 'custom'"
|
||||
>{{ $t('api.message.custom') }}</el-button
|
||||
>
|
||||
</div>
|
||||
<div class="price">
|
||||
<span v-if="activeOption === 'first'" class="value">¥0</span>
|
||||
<span v-if="activeOption === 'first'" class="remark">
|
||||
({{ $t('api.message.present') + `${api.free_amount}` + $t(`api.unit.${api.unit}`) }})
|
||||
</span>
|
||||
<span v-if="activeOption === 'custom'" class="value">¥{{ api?.price }}</span>
|
||||
<span v-if="activeOption === 'custom'" class="remark">{{ '/' + $t(`api.unit.${api.unit}`) }}</span>
|
||||
<span v-if="activeOption === 'package'" class="value"> ¥{{ activePackage?.price }} </span>
|
||||
<span v-if="activeOption === 'package' && activePackage" class="remark">
|
||||
({{
|
||||
$t('api.message.around') +
|
||||
'¥' +
|
||||
(activePackage?.price / activePackage?.amount).toFixed(4) +
|
||||
'/' +
|
||||
$t(`api.unit.${api.unit}`)
|
||||
}})
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IApi, IPackage } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import urlJoin from 'url-join';
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
activeOption: string | undefined;
|
||||
activePackage: IPackage | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiPreview',
|
||||
components: {
|
||||
ElButton
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
activeOption: undefined,
|
||||
activePackage: undefined
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
showFirstOption() {
|
||||
return this.api.free_amount !== 0;
|
||||
},
|
||||
showPackageOption() {
|
||||
return this.api && this.api.packages && this.api?.packages?.length > 0;
|
||||
},
|
||||
showCustomOption() {
|
||||
return this.api.price === 0 || this.api?.price;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.showFirstOption) {
|
||||
this.activeOption = 'first';
|
||||
} else if (this.showPackageOption) {
|
||||
this.activeOption = 'package';
|
||||
// @ts-ignore
|
||||
this.activePackage = this.api.packages[0];
|
||||
} else if (this.showCustomOption) {
|
||||
this.activeOption = 'custom';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
urlJoin,
|
||||
onSelect(option: string, pkg?: IPackage) {
|
||||
this.activeOption = option;
|
||||
this.activePackage = pkg;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: 500;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.introduction {
|
||||
font-size: 14px;
|
||||
margin-bottom: 15px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.options {
|
||||
.option {
|
||||
border-radius: 5px !important;
|
||||
}
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.price {
|
||||
.value {
|
||||
font-weight: bold;
|
||||
color: #ff5441;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.remark {
|
||||
font-size: 14px;
|
||||
color: #999;
|
||||
display: inline-block;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,86 +0,0 @@
|
||||
<template>
|
||||
<div v-if="schema" class="body">
|
||||
<div v-if="schema.items && schema.type === 'array'" class="items">
|
||||
<h2 class="title">{{ $t('api.entity.arrayOf') }}</h2>
|
||||
<div v-for="(item, itemKey) in schema.items" :key="itemKey" class="item">
|
||||
<response-body :schema="item" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="properties">
|
||||
<div v-for="(item, itemKey) in schema.properties" :key="itemKey" class="property">
|
||||
<div class="info">
|
||||
<span class="key">{{ itemKey }}</span>
|
||||
<span class="type">{{ item?.type }}</span>
|
||||
</div>
|
||||
<div class="description">
|
||||
{{ item?.title }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ISchema } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ResponseBody',
|
||||
props: {
|
||||
schema: {
|
||||
type: Object as () => ISchema,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.items {
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
.title {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
}
|
||||
.properties {
|
||||
margin-bottom: 10px;
|
||||
.property {
|
||||
padding: 10px;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.1);
|
||||
|
||||
&:first-of-type {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
&:not(:first-of-type):not(:last-of-type) {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
.info {
|
||||
.key {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
padding-left: 0;
|
||||
}
|
||||
.type {
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,185 +0,0 @@
|
||||
<template>
|
||||
<el-collapse v-if="responses" id="document-response-item" class="wrapper" accordion>
|
||||
<el-collapse-item v-for="(response, responseKey) in responses" :key="responseKey" class="item" :name="responseKey">
|
||||
<template #title>
|
||||
<span class="badge">
|
||||
<el-tag v-if="response?.is_success" class="ml-2" type="success">{{ $t('api.entity.success') }}</el-tag>
|
||||
<el-tag v-else class="ml-2" type="danger">{{ $t('api.entity.failure') }}</el-tag>
|
||||
</span>
|
||||
<span class="status-code">
|
||||
{{ response?.status_code }}
|
||||
</span>
|
||||
<span class="error-code">
|
||||
{{ response?.error_code }}
|
||||
</span>
|
||||
</template>
|
||||
<div class="item-body">
|
||||
<div>
|
||||
{{ response.description }}
|
||||
</div>
|
||||
<el-divider class="my-3" />
|
||||
<div v-if="response?.headers?.properties" class="headers">
|
||||
<h2 class="title">{{ $t('api.entity.responseHeaders') }}</h2>
|
||||
<div class="properties">
|
||||
<div v-for="(item, itemKey) in response?.headers?.properties" :key="itemKey" class="property">
|
||||
<div class="info">
|
||||
<span class="key">{{ itemKey }}</span>
|
||||
<span class="type">{{ item?.type }}</span>
|
||||
</div>
|
||||
<div class="description">
|
||||
{{ item?.title }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="response?.body" class="body">
|
||||
<h2 class="title">{{ $t('api.entity.responseBody') }}</h2>
|
||||
<response-body :schema="response?.body" />
|
||||
</div>
|
||||
<div v-if="response?.example" class="example">
|
||||
<h2 class="title">{{ $t('api.entity.responseExample') }}</h2>
|
||||
<code-snippet :code="response?.example" />
|
||||
</div>
|
||||
</div>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IResponse } from '@/operators/api/models';
|
||||
import CodeSnippet from '../common/CodeSnippet.vue';
|
||||
import { ElCollapse, ElCollapseItem, ElTag, ElDivider } from 'element-plus';
|
||||
import ResponseBody from './ResponseBody.vue';
|
||||
|
||||
interface IData {
|
||||
value: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiResult',
|
||||
components: {
|
||||
CodeSnippet,
|
||||
ElCollapse,
|
||||
ElCollapseItem,
|
||||
ElTag,
|
||||
ResponseBody,
|
||||
ElDivider
|
||||
},
|
||||
props: {
|
||||
responses: {
|
||||
type: Object as () => IResponse[] | [],
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
value: {}
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
overflow: hidden;
|
||||
border: none;
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
background-color: #f8f8f8;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.1);
|
||||
.status-code,
|
||||
.error-code {
|
||||
display: inline-block;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
&.el-collapse-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
&:not(:first-child):not(:last-child) {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
.item-body {
|
||||
padding: 15px;
|
||||
.body,
|
||||
.headers,
|
||||
.example {
|
||||
.title {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.properties {
|
||||
margin-bottom: 10px;
|
||||
.property {
|
||||
padding: 10px;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-left: 1px solid rgba(0, 0, 0, 0.1);
|
||||
|
||||
&:first-of-type {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
&:not(:first-of-type):not(:last-of-type) {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
.info {
|
||||
.key {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
padding-left: 0;
|
||||
}
|
||||
.type {
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
padding: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
#document-response-item {
|
||||
.el-collapse-item__header {
|
||||
border: none;
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,93 +0,0 @@
|
||||
<template>
|
||||
<div class="wrapper">
|
||||
<div class="operation mb-2">
|
||||
<el-button class="btn-try" type="primary" :loading="loading" @click="onTry">{{
|
||||
$t('common.button.try')
|
||||
}}</el-button>
|
||||
</div>
|
||||
<div v-if="responseData" class="result">
|
||||
<div class="title">{{ $t('api.entity.response') }}</div>
|
||||
<code-snippet :code="responseData" />
|
||||
</div>
|
||||
<div v-if="loading">
|
||||
<el-skeleton animated />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IApi, IForm } from '@/operators/api/models';
|
||||
import { defineComponent } from 'vue';
|
||||
import axios, { Method } from 'axios';
|
||||
import urlJoin from 'url-join';
|
||||
import CodeSnippet from '../common/CodeSnippet.vue';
|
||||
import { ElButton, ElSkeleton } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiTry',
|
||||
components: {
|
||||
CodeSnippet,
|
||||
ElButton,
|
||||
ElSkeleton
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
form: {
|
||||
type: Object as () => IForm,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
apiKeyValue: this.apiKey,
|
||||
responseData: '',
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onTry() {
|
||||
this.loading = true;
|
||||
this.responseData = '';
|
||||
const config = {
|
||||
method: this.api?.request?.method as Method,
|
||||
url: urlJoin(this.api?.endpoint, this.api?.path),
|
||||
params: { ...this.form.queries },
|
||||
data: { ...this.form.body }
|
||||
};
|
||||
axios(config)
|
||||
.then((response) => {
|
||||
this.loading = false;
|
||||
this.responseData = JSON.stringify(response?.data, null, ' ');
|
||||
})
|
||||
.catch((error) => {
|
||||
this.loading = false;
|
||||
this.responseData = JSON.stringify(error?.response?.data, null, ' ');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
margin-top: 15px;
|
||||
padding-bottom: 0;
|
||||
.operation {
|
||||
margin-bottom: 10px;
|
||||
.btn-try {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-bottom: 10px;
|
||||
.title {
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,132 +0,0 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<div v-if="api?.request?.queries" class="queries">
|
||||
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
|
||||
<api-form
|
||||
v-model:form="formValue.queries"
|
||||
:schema="api?.request?.queries"
|
||||
:api="api"
|
||||
:applied="applied"
|
||||
:applications="applications"
|
||||
@refresh-applications="getApplications"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="api?.request?.headers" class="headers">
|
||||
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
|
||||
<api-form
|
||||
v-model:form="formValue.headers"
|
||||
:schema="api?.request?.headers"
|
||||
:api="api"
|
||||
:applications="applications"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="api?.request?.body" class="body">
|
||||
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
|
||||
<api-form v-model:form="formValue.body" :schema="api?.request?.body" :api="api" :applications="applications" />
|
||||
</div>
|
||||
<div v-if="api?.responses" class="responses">
|
||||
<h2 class="title">{{ $t('api.entity.response') }}</h2>
|
||||
<api-responses :responses="api?.responses" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IApi, IForm } from '@/operators/api/models';
|
||||
import ApiForm from './Form.vue';
|
||||
import ApiResponses from './Responses.vue';
|
||||
import { applicationOperator } from '@/operators/application/operator';
|
||||
import { IApplication, IApplicationListResponse } from '@/operators/application/models';
|
||||
|
||||
export interface IData {
|
||||
formValue: IForm;
|
||||
applications: IApplication[];
|
||||
applied: boolean | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiUsage',
|
||||
components: {
|
||||
ApiForm,
|
||||
ApiResponses
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
form: {
|
||||
type: Object as () => IForm,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['update:form'],
|
||||
data(): IData {
|
||||
return {
|
||||
formValue: this.form || {},
|
||||
applications: [],
|
||||
applied: undefined
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
formValue: {
|
||||
handler(val) {
|
||||
this.$emit('update:form', { ...val });
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
getApplications() {
|
||||
applicationOperator
|
||||
.getAll({
|
||||
user_id: this.$store.getters.user?.id,
|
||||
api_id: this.api.id
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationListResponse }) => {
|
||||
this.applications = data.items;
|
||||
this.applied = this.applications.filter((item) => item?.api?.id === this.api.id).length > 0;
|
||||
})
|
||||
.catch((error) => {});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.item {
|
||||
.queries {
|
||||
margin-bottom: 10px;
|
||||
.title {
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.headers {
|
||||
margin-bottom: 10px;
|
||||
.title {
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
margin-bottom: 10px;
|
||||
.title {
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.responses {
|
||||
margin-bottom: 10px;
|
||||
.title {
|
||||
font-size: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -12,9 +12,6 @@
|
||||
<span>
|
||||
{{ $t('application.field.api') }}
|
||||
</span>
|
||||
<span v-if="type === applicationType.PROXY">
|
||||
{{ $t('application.field.proxy') }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('application.field.name')">
|
||||
{{ object?.title }}
|
||||
@@ -23,9 +20,6 @@
|
||||
<span v-if="type === applicationType.API">
|
||||
{{ object?.free_amount }}{{ $t(`api.unit.${object?.unit}`) }}
|
||||
</span>
|
||||
<span v-if="type === applicationType.PROXY">
|
||||
{{ object?.free_amount }}{{ $t(`proxy.unit.${object?.unit}`) }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<el-divider class="my-2" />
|
||||
@@ -43,7 +37,7 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDialog, ElDescriptions, ElDescriptionsItem, ElDivider, ElCheckbox, ElButton, ElMessage } from 'element-plus';
|
||||
import { IApi, IApplicationType, IProxy } from '@/operators';
|
||||
import { IApi, IApplicationType } from '@/operators';
|
||||
import ApplicationPolicy from './Policy.vue';
|
||||
|
||||
interface IData {
|
||||
@@ -65,7 +59,7 @@ export default defineComponent({
|
||||
},
|
||||
props: {
|
||||
object: {
|
||||
type: Object as () => IApi | IProxy,
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
type: {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<template>
|
||||
<el-tooltip effect="dark" :content="$t('application.message.rotateCredential')" placement="top-start">
|
||||
<el-popconfirm
|
||||
:title="$t('application.message.rotateCredentialConfirm')"
|
||||
:confirm-button-text="$t('common.button.confirm')"
|
||||
:cancel-button-text="$t('common.button.cancel')"
|
||||
:width="290"
|
||||
@confirm="onConfirm"
|
||||
>
|
||||
<template #reference>
|
||||
<font-awesome-icon icon="fa-solid fa-arrows-rotate" class="icon-rotate" />
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ElTooltip, ElPopconfirm } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RotateCredential',
|
||||
components: {
|
||||
FontAwesomeIcon,
|
||||
ElTooltip,
|
||||
ElPopconfirm
|
||||
},
|
||||
emits: ['rotate'],
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
methods: {
|
||||
onConfirm() {
|
||||
this.$emit('rotate');
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.icon-rotate {
|
||||
cursor: pointer;
|
||||
margin-left: 5px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,78 +0,0 @@
|
||||
<template>
|
||||
<el-pagination
|
||||
class="mt-3 mb-3"
|
||||
background
|
||||
:hide-on-single-page="false"
|
||||
layout="prev, pager, next"
|
||||
:current-page="currentPage"
|
||||
:total="total"
|
||||
:page-size="pageSize"
|
||||
@current-change="onPageChange"
|
||||
>
|
||||
</el-pagination>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElPagination } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Pagination',
|
||||
components: {
|
||||
ElPagination
|
||||
},
|
||||
props: {
|
||||
total: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: undefined
|
||||
},
|
||||
currentPage: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
pageSize: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['change'],
|
||||
data(): IData {
|
||||
return {
|
||||
loaded: false
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
setTimeout(() => {
|
||||
// use this flag to fix the bug of el-pagination,
|
||||
// always emit page 1 when load first time.
|
||||
this.loaded = true;
|
||||
}, 1000);
|
||||
},
|
||||
methods: {
|
||||
onPageChange(val: number): void {
|
||||
// if not finished loading, ignore the wrong emit event
|
||||
if (!this.loaded) {
|
||||
return;
|
||||
}
|
||||
this.$emit('change', val);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.el-pagination {
|
||||
button {
|
||||
border-radius: 50% !important;
|
||||
}
|
||||
li {
|
||||
border-radius: 50% !important;
|
||||
outline: none !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,57 +0,0 @@
|
||||
<template>
|
||||
<div class="price-text">
|
||||
<span v-if="price > 0" class="unfree"
|
||||
>¥{{ price }} {{ unit ? `/ ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : '' }}</span
|
||||
>
|
||||
<span v-else class="free">
|
||||
{{ $t('common.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
|
||||
},
|
||||
start: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
});
|
||||
</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,163 +0,0 @@
|
||||
<template>
|
||||
<el-row class="header">
|
||||
<el-col :md="4" :xs="24">
|
||||
<img src="@/assets/images/logo.svg" class="logo" @click="onHome" />
|
||||
</el-col>
|
||||
<el-col :md="16" :xs="12">
|
||||
<el-menu :default-active="active" class="el-menu-demo" mode="horizontal" @select="onSelect">
|
||||
<el-menu-item v-t="'common.nav.service'" index="/services"></el-menu-item>
|
||||
<el-menu-item v-t="'common.nav.document'" index="/documents"></el-menu-item>
|
||||
</el-menu>
|
||||
</el-col>
|
||||
<el-col :md="4" :xs="12">
|
||||
<div v-if="!$store.getters.authenticated" class="mt-4 pr-10">
|
||||
<el-button type="primary" class="float-right" size="small" round @click="onLogin">{{
|
||||
$t('common.button.login')
|
||||
}}</el-button>
|
||||
</div>
|
||||
<div v-else class="float-right">
|
||||
<div class="console" @click="onConsole">
|
||||
{{ $t('common.button.console') }}
|
||||
</div>
|
||||
<el-dropdown trigger="click">
|
||||
<img :src="user?.avatar || defaultAvatar" class="avatar" />
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="onProfile">{{ $t('common.button.profile') }}</el-dropdown-item>
|
||||
<el-dropdown-item @click="onVerify">{{ $t('common.button.verify') }}</el-dropdown-item>
|
||||
<el-dropdown-item @click="onLogout">{{ $t('common.button.logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import defaultAvatar from '@/assets/images/avatar.png';
|
||||
import { getAuthBaseUrl } from '@/utils';
|
||||
import { ROUTE_AUTH_LOGIN, ROUTE_CONSOLE_ROOT, ROUTE_INDEX } from '@/router';
|
||||
import {
|
||||
ElContainer,
|
||||
ElAside,
|
||||
ElMain,
|
||||
ElCol,
|
||||
ElRow,
|
||||
ElDropdown,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElDropdownItem,
|
||||
ElButton
|
||||
} from 'element-plus';
|
||||
export default defineComponent({
|
||||
name: 'TopHeader',
|
||||
components: {
|
||||
ElCol,
|
||||
ElRow,
|
||||
ElDropdown,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElDropdownItem,
|
||||
ElButton
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
defaultAvatar
|
||||
// defaultAvatar: new URL('@/assets/images/avatar.png', import.meta.url).href
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
active() {
|
||||
return this.$route.matched[0].path;
|
||||
},
|
||||
user() {
|
||||
return this.$store.getters.user;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSelect(val: string) {
|
||||
this.$router.push(val);
|
||||
},
|
||||
onHome() {
|
||||
this.$router.push({
|
||||
name: ROUTE_INDEX
|
||||
});
|
||||
},
|
||||
onLogin() {
|
||||
this.$router.push({
|
||||
name: ROUTE_AUTH_LOGIN
|
||||
});
|
||||
},
|
||||
onProfile() {
|
||||
const authBaseUrl = getAuthBaseUrl();
|
||||
window.open(`${authBaseUrl}/user/profile`, '_blank');
|
||||
},
|
||||
onVerify() {
|
||||
const authBaseUrl = getAuthBaseUrl();
|
||||
window.open(`${authBaseUrl}/user/verify`, '_blank');
|
||||
},
|
||||
onConsole() {
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_ROOT
|
||||
});
|
||||
},
|
||||
onLogout() {
|
||||
this.$store.dispatch('resetAuth');
|
||||
this.$router.push({
|
||||
name: ROUTE_INDEX
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
$height: 60px;
|
||||
.header {
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
background: radial-gradient(circle at 0 2%, #111827, #1a125d 99%);
|
||||
.logo {
|
||||
height: $height - 5px;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
--el-menu-hover-bg-color: rgba(255, 255, 255, 0);
|
||||
--el-menu-active-color: white;
|
||||
background: none;
|
||||
border: none;
|
||||
.el-menu-item {
|
||||
height: $height;
|
||||
color: white;
|
||||
&.is-active {
|
||||
border-bottom: 3px solid var(--el-menu-active-color);
|
||||
}
|
||||
&:hover {
|
||||
border-bottom: 3px solid var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
margin-top: 10px;
|
||||
margin-right: 20px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.console {
|
||||
color: white;
|
||||
height: 60px;
|
||||
line-height: 60px;
|
||||
margin: 0 10px;
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,197 +0,0 @@
|
||||
<template>
|
||||
<el-row class="mb-10">
|
||||
<el-col :span="24">
|
||||
<img src="@/assets/images/logo2.svg" class="logo" @click="onHome" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<div class="links">
|
||||
<a
|
||||
v-for="(link, linkIndex) in links"
|
||||
:key="linkIndex"
|
||||
:class="{ link: true, active: $route.name === link.name }"
|
||||
@click="onNavigate(link)"
|
||||
>
|
||||
<span class="icon">
|
||||
<font-awesome-icon :icon="link.icon" class="text-sm" />
|
||||
</span>
|
||||
<span class="text">{{ link.text }}</span>
|
||||
<span class="outer">
|
||||
<font-awesome-icon
|
||||
v-if="!link.name && link.href"
|
||||
icon="fa-solid fa-up-right-from-square"
|
||||
class="text-sm ml-2"
|
||||
/>
|
||||
</span>
|
||||
<span class="suffix"> </span>
|
||||
</a>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import {
|
||||
ROUTE_CONSOLE_ADMIN_APPLICATION,
|
||||
ROUTE_CONSOLE_APPLICATION_LIST,
|
||||
ROUTE_CONSOLE_ORDER_LIST,
|
||||
ROUTE_INDEX
|
||||
} from '@/router';
|
||||
import { ElRow, ElCol } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { getAuthBaseUrl } from '@/utils';
|
||||
|
||||
interface ILink {
|
||||
key: string;
|
||||
text: string;
|
||||
name?: string;
|
||||
href?: string;
|
||||
icon: string;
|
||||
admin?: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Navigator',
|
||||
components: {
|
||||
ElRow,
|
||||
ElCol,
|
||||
FontAwesomeIcon
|
||||
},
|
||||
computed: {
|
||||
active() {
|
||||
return this.$route.matched[0].path;
|
||||
},
|
||||
user() {
|
||||
return this.$store.getters.user;
|
||||
},
|
||||
links(): ILink[] {
|
||||
let commonLinks: ILink[] = [
|
||||
{
|
||||
key: 'profile',
|
||||
text: this.$t('console.menu.userProfile'),
|
||||
href: `${getAuthBaseUrl()}/user/profile`,
|
||||
icon: 'fa-regular fa-user'
|
||||
},
|
||||
{
|
||||
key: 'verify',
|
||||
text: this.$t('console.menu.idVerify'),
|
||||
href: `${getAuthBaseUrl()}/user/verify`,
|
||||
icon: 'fa-regular fa-id-card'
|
||||
},
|
||||
{
|
||||
key: 'application-list',
|
||||
text: this.$t('console.menu.applicationList'),
|
||||
name: ROUTE_CONSOLE_APPLICATION_LIST,
|
||||
icon: 'fa-solid fa-cube'
|
||||
},
|
||||
{
|
||||
key: 'order-list',
|
||||
text: this.$t('console.menu.orderList'),
|
||||
name: ROUTE_CONSOLE_ORDER_LIST,
|
||||
icon: 'fa-solid fa-store'
|
||||
}
|
||||
];
|
||||
let adminLinks: ILink[] = [
|
||||
{
|
||||
key: 'admin-application',
|
||||
text: this.$t('console.menu.manageApplication'),
|
||||
name: ROUTE_CONSOLE_ADMIN_APPLICATION,
|
||||
icon: 'fa-solid fa-cubes'
|
||||
}
|
||||
];
|
||||
if (this.user.is_superuser) {
|
||||
return [...commonLinks, ...adminLinks];
|
||||
}
|
||||
return commonLinks;
|
||||
}
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
onHome() {
|
||||
this.$router.push({
|
||||
name: ROUTE_INDEX
|
||||
});
|
||||
},
|
||||
onNavigate(link: ILink) {
|
||||
if (link.name) {
|
||||
this.$router.push({
|
||||
name: link.name
|
||||
});
|
||||
} else if (link.href) {
|
||||
window.open(link.href, '_blank');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.logo {
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
display: block;
|
||||
margin: 30px auto 20px auto;
|
||||
}
|
||||
|
||||
.nickname {
|
||||
display: block;
|
||||
margin: auto;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.links {
|
||||
width: 100%;
|
||||
.link {
|
||||
$height: 40px;
|
||||
height: $height;
|
||||
display: block;
|
||||
// padding: 5px 8px;
|
||||
width: 100%;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
margin-bottom: 5px;
|
||||
position: relative;
|
||||
color: #444;
|
||||
line-height: $height;
|
||||
padding-left: 10px;
|
||||
.suffix {
|
||||
width: 3px;
|
||||
height: $height;
|
||||
// position: relative;
|
||||
// top: 2px;
|
||||
position: absolute;
|
||||
right: -20px;
|
||||
margin-right: 5px;
|
||||
border-radius: 3px;
|
||||
display: inline-block;
|
||||
}
|
||||
.icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
margin-right: 10px;
|
||||
// top: -1px;
|
||||
transform: translateY(-2%);
|
||||
}
|
||||
.text {
|
||||
font-size: 14px;
|
||||
}
|
||||
&.active {
|
||||
.suffix {
|
||||
background-color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
&:hover {
|
||||
background-color: #ebedf1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,67 +0,0 @@
|
||||
<template>
|
||||
<div v-if="loading">
|
||||
<el-skeleton animated />
|
||||
</div>
|
||||
<div v-else-if="documents" class="wrapper">
|
||||
<document-list-item
|
||||
v-for="(document, documentIndex) in documents"
|
||||
:key="documentIndex"
|
||||
:document="document"
|
||||
></document-list-item>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IDocument, IDocumentListResponse } from '@/operators/document/models';
|
||||
import DocumentListItem from './ListItem.vue';
|
||||
import { documentOperator } from '@/operators/document';
|
||||
import { ElSkeleton } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
documents: IDocument[];
|
||||
limit: number;
|
||||
offset: number;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DocumentList',
|
||||
components: {
|
||||
DocumentListItem,
|
||||
ElSkeleton
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
documents: [],
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
mounted() {
|
||||
this.getDocuments(this.offset, this.limit);
|
||||
},
|
||||
methods: {
|
||||
getDocuments(offset: number, limit: number) {
|
||||
this.loading = true;
|
||||
documentOperator
|
||||
.getAll({
|
||||
offset,
|
||||
limit,
|
||||
ordering: 'rank',
|
||||
private: false
|
||||
})
|
||||
.then(({ data: data }: { data: IDocumentListResponse }) => {
|
||||
this.loading = false;
|
||||
this.documents = data.items;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.loading = false;
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -1,110 +0,0 @@
|
||||
<template>
|
||||
<div v-if="document.type === documentType.TEXT" :class="{ item: true, active: id === document?.id }" @click="onClick">
|
||||
<el-link type="primary" class="link" :underline="false">
|
||||
<span class="name">{{ document?.title }}</span>
|
||||
</el-link>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="document.type === documentType.API"
|
||||
:class="{ item: true, active: id === document?.id }"
|
||||
@click="onClick"
|
||||
>
|
||||
<el-link type="primary" class="link" :underline="false">
|
||||
<span class="name">{{ document?.title || document?.api?.title }}</span>
|
||||
</el-link>
|
||||
<el-tag class="type" effect="dark">
|
||||
{{ documentType.API.toUpperCase() }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="document.type === documentType.PROXY"
|
||||
:class="{ item: true, active: id === document?.id }"
|
||||
@click="onClick"
|
||||
>
|
||||
<el-link type="primary" class="link" :underline="false">
|
||||
<span class="name">{{ document?.title || document?.proxy?.title }}</span>
|
||||
</el-link>
|
||||
<el-tag class="type" effect="dark">
|
||||
{{ documentType.PROXY.toUpperCase() }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IDocument, IDocumentType } from '@/operators/document/models';
|
||||
import { ROUTE_DOCUMENT_DETAIL } from '@/router';
|
||||
import { ElLink, ElTag } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiListItem',
|
||||
components: {
|
||||
ElLink,
|
||||
ElTag
|
||||
},
|
||||
props: {
|
||||
document: {
|
||||
type: Object as () => IDocument,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
documentType: IDocumentType
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
id() {
|
||||
return this.$route.params?.id?.toString();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onClick() {
|
||||
this.$router.push({
|
||||
name: ROUTE_DOCUMENT_DETAIL,
|
||||
params: {
|
||||
id: this.document.id
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
$height: 35px;
|
||||
.item {
|
||||
height: $height;
|
||||
line-height: $height;
|
||||
padding-left: 10px;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border-left: 3px solid transparent;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
&.active {
|
||||
border-left: 3px solid var(--el-color-primary);
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #333;
|
||||
.name {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
.type {
|
||||
display: none;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,208 +0,0 @@
|
||||
<template>
|
||||
<el-form label-width="100px">
|
||||
<el-form-item :label="$t('application.field.service')">
|
||||
<span v-if="application.type === applicationType.API">
|
||||
{{ application?.api?.title }}
|
||||
</span>
|
||||
<span v-if="application.type === applicationType.PROXY">
|
||||
{{ application?.proxy?.title }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
<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.${application?.api?.unit}`) }}
|
||||
</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.${application?.proxy?.unit}`) }}
|
||||
</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')">
|
||||
<div v-if="application.type === applicationType.API">
|
||||
<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">
|
||||
<price :price="package?.price" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-divider border-style="dashed" />
|
||||
<el-form-item :label="$t('application.field.shouldPayPrice')">
|
||||
<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-item>
|
||||
<el-button type="primary" size="large" class="btn-create" :loading="creating" @click="onCreateOrder">
|
||||
{{ $t('application.button.createOrder') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
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 { ElForm, ElFormItem, ElButton, ElInputNumber, ElDivider, ElRadioGroup, ElRadioButton } from 'element-plus';
|
||||
import Price from '@/components/common/Price.vue';
|
||||
|
||||
interface IData {
|
||||
form: {
|
||||
amount: number;
|
||||
packageId: string | undefined;
|
||||
};
|
||||
creating: boolean;
|
||||
applicationType: typeof IApplicationType;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CreateOrderDialog',
|
||||
components: {
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInputNumber,
|
||||
ElButton,
|
||||
ElDivider,
|
||||
ElRadioGroup,
|
||||
ElRadioButton,
|
||||
Price
|
||||
},
|
||||
props: {
|
||||
application: {
|
||||
type: Object as () => IApplication,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
form: {
|
||||
amount: 1000,
|
||||
packageId: undefined
|
||||
},
|
||||
creating: false,
|
||||
applicationType: IApplicationType
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
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() {
|
||||
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);
|
||||
},
|
||||
onCreateOrder() {
|
||||
if (!this.application?.id) {
|
||||
return;
|
||||
}
|
||||
this.creating = true;
|
||||
orderOperator
|
||||
.create({
|
||||
application_id: this.application?.id,
|
||||
amount: this.form.amount,
|
||||
...(this.form.packageId !== 'custom' && this.package
|
||||
? {
|
||||
package_id: this.package.id
|
||||
}
|
||||
: {})
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.creating = false;
|
||||
const order = data;
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_ORDER_DETAIL,
|
||||
params: {
|
||||
id: order.id
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error(this.$t('order.message.createFailed'));
|
||||
this.creating = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.price {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
&.unfree {
|
||||
color: #ff5441;
|
||||
}
|
||||
&.free {
|
||||
color: #29c287;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-create {
|
||||
width: 150px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,111 +0,0 @@
|
||||
<template>
|
||||
<el-dialog :model-value="visible" :title="$t('application.title.buyService')" width="500px" center>
|
||||
<el-row class="paycodes">
|
||||
<el-col :span="12">
|
||||
<div class="paycode wechat">
|
||||
<qr-code v-if="modelValue?.wechatpay_url" :value="modelValue?.wechatpay_url" :size="200" class="m-auto" />
|
||||
<p class="help-text">{{ $t('order.message.wechatPayHelp') }}</p>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<div class="help-img">
|
||||
<img src="https://midas.gtimg.cn/enterprise/images/ep_sys_wx_tip.jpg" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IOrder, IOrderDetailResponse, orderOperator, OrderState } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDialog, ElRow, ElCol } from 'element-plus';
|
||||
import QrCode from 'qrcode.vue';
|
||||
|
||||
interface IData {
|
||||
refreshTimer: number | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PayOrderDialog',
|
||||
components: {
|
||||
ElDialog,
|
||||
QrCode,
|
||||
ElRow,
|
||||
ElCol
|
||||
},
|
||||
props: {
|
||||
modelValue: {
|
||||
type: Object as () => IOrder,
|
||||
required: true
|
||||
},
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
emits: ['hide', 'update:modelValue'],
|
||||
data(): IData {
|
||||
return {
|
||||
refreshTimer: undefined
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.onRefresh();
|
||||
},
|
||||
unmounted() {
|
||||
if (this.refreshTimer) {
|
||||
clearTimeout(this.refreshTimer);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onRefresh() {
|
||||
if (!this.modelValue.id) {
|
||||
console.error('id does not exist');
|
||||
return;
|
||||
}
|
||||
orderOperator
|
||||
.refresh(this.modelValue.id)
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
// if not paid, check for next loop
|
||||
if (data.state !== OrderState.PAID) {
|
||||
setTimeout(() => {
|
||||
this.onRefresh();
|
||||
}, 2000);
|
||||
} else {
|
||||
// paid, just notify parent, and hide the dialog
|
||||
this.$emit('hide');
|
||||
}
|
||||
this.$emit('update:modelValue', data);
|
||||
})
|
||||
.catch(() => {
|
||||
setTimeout(() => {
|
||||
this.onRefresh();
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.paycodes {
|
||||
padding: 30px 0;
|
||||
width: 500px;
|
||||
margin: auto;
|
||||
.wechat {
|
||||
.help-text {
|
||||
display: block;
|
||||
background-color: #00c800;
|
||||
color: white;
|
||||
font-size: 14px;
|
||||
height: 35px;
|
||||
width: 240px;
|
||||
text-align: center;
|
||||
line-height: 35px;
|
||||
margin: 10px auto 0 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="title">
|
||||
{{ proxy?.title }}
|
||||
</div>
|
||||
<div class="url">
|
||||
<span v-if="proxy?.endpoint" class="endpoint">{{ proxy?.endpoint }}</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';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ProxyInfo',
|
||||
components: {},
|
||||
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 0px;
|
||||
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>
|
||||
@@ -1,158 +0,0 @@
|
||||
<template>
|
||||
<div class="title">
|
||||
<el-button type="primary" size="small">{{ $t('application.field.proxy') }}</el-button>
|
||||
{{ proxy?.title }}
|
||||
</div>
|
||||
<div class="introduction">
|
||||
<p>{{ proxy?.introduction }}</p>
|
||||
</div>
|
||||
<div class="options">
|
||||
<el-button
|
||||
v-if="showFirstOption"
|
||||
ref="option"
|
||||
type="primary"
|
||||
:plain="activeOption !== 'first'"
|
||||
class="option"
|
||||
@click="activeOption = 'first'"
|
||||
>{{ $t('proxy.message.firstFree') }}</el-button
|
||||
>
|
||||
<el-button
|
||||
v-for="(pkg, pkgIndex) in proxy?.packages"
|
||||
ref="option"
|
||||
:key="pkgIndex"
|
||||
type="primary"
|
||||
:plain="!(activeOption == 'package' && activePackage?.id === pkg.id)"
|
||||
class="option"
|
||||
@click="
|
||||
activeOption = 'package';
|
||||
activePackage = pkg;
|
||||
"
|
||||
>
|
||||
{{ pkg.amount }}{{ $t(`proxy.unit.${proxy.unit}`) }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="showCustomOption"
|
||||
ref="option"
|
||||
type="primary"
|
||||
:plain="activeOption !== 'custom'"
|
||||
class="option"
|
||||
@click="activeOption = 'custom'"
|
||||
>{{ $t('proxy.message.custom') }}</el-button
|
||||
>
|
||||
</div>
|
||||
<div class="price">
|
||||
<span v-if="activeOption === 'first'" class="value">¥0</span>
|
||||
<span v-if="activeOption === 'first'" class="remark">
|
||||
({{ $t('proxy.message.present') + `${proxy.free_amount}` + $t(`proxy.unit.${proxy.unit}`) }})
|
||||
</span>
|
||||
<span v-if="activeOption === 'custom'" class="value">¥{{ proxy?.price }}</span>
|
||||
<span v-if="activeOption === 'custom'" class="remark">{{ '/' + $t(`proxy.unit.${proxy.unit}`) }}</span>
|
||||
<span v-if="activeOption === 'package'" class="value"> ¥{{ activePackage?.price }} </span>
|
||||
<span v-if="activeOption === 'package' && activePackage" class="remark">
|
||||
({{
|
||||
$t('proxy.message.around') +
|
||||
'¥' +
|
||||
(activePackage?.price / activePackage?.amount).toFixed(2) +
|
||||
'/' +
|
||||
$t(`proxy.unit.${proxy.unit}`)
|
||||
}})
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IProxy, IPackage } from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import urlJoin from 'url-join';
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
activeOption: string | undefined;
|
||||
activePackage: IPackage | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ProxyPreview',
|
||||
components: {
|
||||
ElButton
|
||||
},
|
||||
props: {
|
||||
proxy: {
|
||||
type: Object as () => IProxy,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
activeOption: undefined,
|
||||
activePackage: undefined
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
showFirstOption() {
|
||||
return this.proxy.free_amount !== 0;
|
||||
},
|
||||
showPackageOption() {
|
||||
return this.proxy && this.proxy.packages && this.proxy?.packages?.length > 0;
|
||||
},
|
||||
showCustomOption() {
|
||||
return this.proxy.price === 0 || this.proxy?.price;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.showFirstOption) {
|
||||
this.activeOption = 'first';
|
||||
} else if (this.showPackageOption) {
|
||||
this.activeOption = 'package';
|
||||
// @ts-ignore
|
||||
this.activePackage = this.proxy.packages[0];
|
||||
} else if (this.showCustomOption) {
|
||||
this.activeOption = 'custom';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
urlJoin,
|
||||
onSelect(option: string, pkg?: IPackage) {
|
||||
this.activeOption = option;
|
||||
this.activePackage = pkg;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: 500;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.introduction {
|
||||
font-size: 14px;
|
||||
margin-bottom: 15px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.options {
|
||||
.option {
|
||||
border-radius: 5px !important;
|
||||
}
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.price {
|
||||
.value {
|
||||
font-weight: bold;
|
||||
color: #ff5441;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.remark {
|
||||
font-size: 14px;
|
||||
color: #999;
|
||||
display: inline-block;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user