update template code
This commit is contained in:
1 parent
ba74345be1
commit
df76f2b35a
8 files changed
+78
-21
No files matched your search
@@ -1,6 +1,6 @@
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
{{#body}}
|
||||
jsonObject.put("{{{key}}}", "{{{value}}}");
|
||||
jsonObject.put("{{{key}}}", {{{value}}});
|
||||
{{/body}}
|
||||
MediaType mediaType = "application/json; charset=utf-8".toMediaType();
|
||||
RequestBody body = jsonObject.toString().toRequestBody(mediaType);
|
||||
@@ -8,7 +8,7 @@ Request request = new Request.Builder()
|
||||
.url("{{{url}}}")
|
||||
.{{{method}}}(body)
|
||||
{{#headers}}
|
||||
.addHeader("{{{key}}}", "{{{value}}}")
|
||||
.addHeader("{{{key}}}", {{{value}}})
|
||||
{{/headers}}
|
||||
.build();
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ const options = {
|
||||
method: '{{{method}}}',
|
||||
headers: {
|
||||
{{#headers}}
|
||||
'{{{key}}}': '{{{value}}}'{{^last}},{{/last}}
|
||||
'{{{key}}}': {{{value}}}{{^last}},{{/last}}
|
||||
{{/headers}}
|
||||
},
|
||||
body: JSON.stringify({
|
||||
{{#body}}
|
||||
{{{key}}}: '{{{value}}}'{{^last}},{{/last}}
|
||||
'{{{key}}}': {{{value}}}{{^last}},{{/last}}
|
||||
{{/body}}
|
||||
})
|
||||
};
|
||||
|
||||
@@ -6,12 +6,12 @@ $client = new \GuzzleHttp\Client();
|
||||
$response = $client->request('{{{method}}}', '{{{url}}}', [
|
||||
'body' => '{
|
||||
{{#body}}
|
||||
"{{{key}}}": "{{{value}}}"{{^last}},{{/last}}
|
||||
"{{{key}}}": {{{value}}}{{^last}},{{/last}}
|
||||
{{/body}}
|
||||
}',
|
||||
'headers' => [
|
||||
{{#headers}}
|
||||
'{{{key}}}': '{{{value}}}'{{^last}},{{/last}}
|
||||
'{{{key}}}': {{{value}}}{{^last}},{{/last}}
|
||||
{{/headers}}
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -4,13 +4,13 @@ url = '{{{url}}}'
|
||||
|
||||
headers = {
|
||||
{{#headers}}
|
||||
'{{{key}}}': '{{{value}}}'{{^last}},{{/last}}
|
||||
'{{{key}}}': {{{value}}}{{^last}},{{/last}}
|
||||
{{/headers}}
|
||||
}
|
||||
|
||||
payload = {
|
||||
{{#body}}
|
||||
'{{{key}}}': '{{{value}}}'{{^last}},{{/last}}
|
||||
'{{{key}}}': {{{value}}}{{^last}},{{/last}}
|
||||
{{/body}}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ interface IRenderData {
|
||||
}[];
|
||||
body: {
|
||||
key: string;
|
||||
value: string | object | number | object[];
|
||||
value: string | object | number | object[] | boolean;
|
||||
}[];
|
||||
method: IRequest['method'] | Lowercase<IRequest['method']> | Uppercase<IRequest['method']>;
|
||||
url: string;
|
||||
@@ -139,9 +139,10 @@ export default defineComponent({
|
||||
body() {
|
||||
let result = [];
|
||||
for (const key in this.form.body) {
|
||||
const value = this.form.body[key];
|
||||
result.push({
|
||||
key,
|
||||
value: this.form.body[key]
|
||||
value
|
||||
});
|
||||
}
|
||||
if (result.length > 0) {
|
||||
@@ -155,24 +156,68 @@ export default defineComponent({
|
||||
},
|
||||
code(): string | undefined {
|
||||
let template = undefined;
|
||||
let renderData: IRenderData = {
|
||||
headers: this.headers,
|
||||
body: this.body,
|
||||
url: this.url,
|
||||
method: this.method
|
||||
};
|
||||
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;
|
||||
|
||||
@@ -36,7 +36,7 @@ import { defineComponent } from 'vue';
|
||||
import { 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, getEnv } from '@/utils';
|
||||
import { getAuthBaseUrl } from '@/utils';
|
||||
|
||||
interface ILink {
|
||||
key: string;
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface IForm {
|
||||
[key: string]: string;
|
||||
};
|
||||
body?: {
|
||||
[key: string]: string | object | number | object[];
|
||||
[key: string]: string | object | boolean | number | object[];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getCount(scope.row) }}</span>
|
||||
<span>{{ getRemainingAmount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
@@ -37,7 +37,7 @@
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getCount(scope.row) }}</span>
|
||||
<span>{{ getUsedAmount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('application.field.credential')" class-name="credential" width="380px">
|
||||
@@ -234,7 +234,7 @@ export default defineComponent({
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
getCount(application: IApplication) {
|
||||
getRemainingAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.remaining_amount}${unit}`;
|
||||
@@ -245,6 +245,18 @@ export default defineComponent({
|
||||
return `${((application.remaining_amount || 0) / 1024 / 1024).toFixed(2)}${unit}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
getUsedAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.used_amount}${unit}`;
|
||||
}
|
||||
if (application.type === IApplicationType.PROXY) {
|
||||
const unit = this.$t(`proxy.unit.${application?.proxy?.unit}`);
|
||||
if (unit === 'MB') {
|
||||
return `${((application.used_amount || 0) / 1024 / 1024).toFixed(2)}${unit}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user