diff --git a/src/assets/templates/java.tpl b/src/assets/templates/java.tpl index 50550c20..710bc18c 100644 --- a/src/assets/templates/java.tpl +++ b/src/assets/templates/java.tpl @@ -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(); diff --git a/src/assets/templates/javascript.tpl b/src/assets/templates/javascript.tpl index 70825253..4bd5ac15 100644 --- a/src/assets/templates/javascript.tpl +++ b/src/assets/templates/javascript.tpl @@ -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}} }) }; diff --git a/src/assets/templates/php.tpl b/src/assets/templates/php.tpl index c391d040..e9bf918e 100644 --- a/src/assets/templates/php.tpl +++ b/src/assets/templates/php.tpl @@ -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}} ], ]); diff --git a/src/assets/templates/python.tpl b/src/assets/templates/python.tpl index 34b36d26..9080ba7a 100644 --- a/src/assets/templates/python.tpl +++ b/src/assets/templates/python.tpl @@ -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}} } diff --git a/src/components/api/Code.vue b/src/components/api/Code.vue index a4b08945..54326775 100644 --- a/src/components/api/Code.vue +++ b/src/components/api/Code.vue @@ -61,7 +61,7 @@ interface IRenderData { }[]; body: { key: string; - value: string | object | number | object[]; + value: string | object | number | object[] | boolean; }[]; method: IRequest['method'] | Lowercase | Uppercase; 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 }; } 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; diff --git a/src/components/console/Navigator.vue b/src/components/console/Navigator.vue index 57d726b6..c2ddcda8 100644 --- a/src/components/console/Navigator.vue +++ b/src/components/console/Navigator.vue @@ -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; diff --git a/src/operators/api/models.ts b/src/operators/api/models.ts index 208d6b5d..05e6ba9b 100644 --- a/src/operators/api/models.ts +++ b/src/operators/api/models.ts @@ -9,7 +9,7 @@ export interface IForm { [key: string]: string; }; body?: { - [key: string]: string | object | number | object[]; + [key: string]: string | object | boolean | number | object[]; }; } diff --git a/src/pages/console/application/List.vue b/src/pages/console/application/List.vue index ce8976d0..15c61193 100644 --- a/src/pages/console/application/List.vue +++ b/src/pages/console/application/List.vue @@ -27,7 +27,7 @@ class-name="text-center" > @@ -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}`; + } + } } } });