统一格式化参数的方法

This commit is contained in:
fofolee
2025-01-06 09:43:48 +08:00
parent d98966a5b0
commit 2dbd6f0c50
16 changed files with 130 additions and 144 deletions

View File

@@ -169,8 +169,7 @@ import VariableInput from "components/composer/ui/VariableInput.vue";
import NumberInput from "components/composer/ui/NumberInput.vue";
import DictEditor from "components/composer/ui/DictEditor.vue";
import {
stringifyObject,
stringifyWithType,
stringifyArgv,
parseFunction,
} from "js/composer/formatString";
import {
@@ -469,13 +468,13 @@ export default defineComponent({
if (!url) return;
const configStr = Object.keys(restConfig).length
? `, ${stringifyObject(restConfig)}`
? `, ${stringifyArgv(restConfig)}`
: "";
return `${
this.modelValue.value
}.${method.toLowerCase()}(${stringifyWithType(url)}${
this.hasRequestData ? `, ${stringifyObject(data)}` : ""
}.${method.toLowerCase()}(${stringifyArgv(url)}${
this.hasRequestData ? `, ${stringifyArgv(data)}` : ""
}${configStr})`;
},
updateArgvs(key, value) {

View File

@@ -73,7 +73,7 @@
<script>
import { defineComponent } from "vue";
import { stringifyObject, parseFunction } from "js/composer/formatString";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import VariableInput from "components/composer/ui/VariableInput.vue";
export default defineComponent({
@@ -151,17 +151,17 @@ export default defineComponent({
generateCode(argvs = this.argvs) {
switch (argvs.operation) {
case "lookupHost":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.hostname
)}, ${stringifyObject(argvs.options)})`;
)}, ${stringifyArgv(argvs.options)})`;
case "reverseResolve":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.ip
)})`;
default:
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.hostname
)})`;
}

View File

@@ -169,7 +169,7 @@
<script>
import { defineComponent } from "vue";
import { stringifyObject, parseFunction } from "js/composer/formatString";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import VariableInput from "components/composer/ui/VariableInput.vue";
import DictEditor from "components/composer/ui/DictEditor.vue";
@@ -305,47 +305,45 @@ export default defineComponent({
case "parse":
case "isAbsolute":
case "parseComponents":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.url
)})`;
case "format":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.urlObject
)})`;
case "parseQuery":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.query
)})`;
case "formatQuery":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.queryParams
)})`;
case "parsePath":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.path
)})`;
case "parseHost":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.host
)})`;
case "getQueryParam":
case "removeQueryParam":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.url
)}, ${stringifyObject(argvs.param)})`;
)}, ${stringifyArgv(argvs.param)})`;
case "addQueryParam":
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
argvs.url
)}, ${stringifyObject(argvs.param)}, ${stringifyObject(
argvs.value
)})`;
)}, ${stringifyArgv(argvs.param)}, ${stringifyArgv(argvs.value)})`;
default:
return `${this.modelValue.value}.${argvs.operation}()`;