mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-17 17:24:27 +08:00
统一格式化参数的方法
This commit is contained in:
@@ -67,8 +67,7 @@ import VariableInput from "components/composer/ui/VariableInput.vue";
|
||||
import NumberInput from "components/composer/ui/NumberInput.vue";
|
||||
import ArrayEditor from "components/composer/ui/ArrayEditor.vue";
|
||||
import {
|
||||
stringifyWithType,
|
||||
stringifyObject,
|
||||
stringifyArgv,
|
||||
parseToHasType,
|
||||
parseFunction,
|
||||
} from "js/composer/formatString";
|
||||
@@ -129,11 +128,7 @@ export default defineComponent({
|
||||
},
|
||||
generateCode(funcName, argvs) {
|
||||
const newArgvs = argvs
|
||||
.map((argv) => {
|
||||
return typeof argv === "string"
|
||||
? stringifyWithType(argv)
|
||||
: stringifyObject(argv);
|
||||
})
|
||||
.map((argv) => stringifyArgv(argv))
|
||||
.filter((item) => item != null && item !== "");
|
||||
console.log(newArgvs);
|
||||
return `${funcName}(${newArgvs.join(",")})`;
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import VariableInput from "components/composer/ui/VariableInput.vue";
|
||||
import { stringifyObject, parseFunction } from "js/composer/formatString";
|
||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||
|
||||
export default defineComponent({
|
||||
name: "AsymmetricCryptoEditor",
|
||||
@@ -274,7 +274,7 @@ export default defineComponent({
|
||||
return argvs;
|
||||
},
|
||||
generateCode(argvs = this.argvs) {
|
||||
return `${this.modelValue.value}(${stringifyObject({
|
||||
return `${this.modelValue.value}(${stringifyArgv({
|
||||
text: argvs.text,
|
||||
algorithm: argvs.algorithm,
|
||||
operation: argvs.operation,
|
||||
|
||||
@@ -362,7 +362,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 NumberInput from "components/composer/ui/NumberInput.vue";
|
||||
import ArrayEditor from "components/composer/ui/ArrayEditor.vue";
|
||||
@@ -492,63 +492,63 @@ export default defineComponent({
|
||||
generateCode(argvs = this.argvs) {
|
||||
switch (argvs.operation) {
|
||||
case "from":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.data
|
||||
)}, "${argvs.encoding}")`;
|
||||
|
||||
case "toString":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, "${argvs.encoding}", ${argvs.start}, ${argvs.end})`;
|
||||
|
||||
case "write":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, ${stringifyObject(argvs.string)}, ${argvs.offset}, ${
|
||||
)}, ${stringifyArgv(argvs.string)}, ${argvs.offset}, ${
|
||||
argvs.length
|
||||
}, "${argvs.encoding}")`;
|
||||
|
||||
case "fill":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, ${stringifyObject(argvs.value)}, ${argvs.offset}, ${
|
||||
argvs.end
|
||||
}, "${argvs.encoding}")`;
|
||||
)}, ${stringifyArgv(argvs.value)}, ${argvs.offset}, ${argvs.end}, "${
|
||||
argvs.encoding
|
||||
}")`;
|
||||
|
||||
case "copy":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.source
|
||||
)}, ${stringifyObject(argvs.target)}, ${argvs.targetStart}, ${
|
||||
)}, ${stringifyArgv(argvs.target)}, ${argvs.targetStart}, ${
|
||||
argvs.sourceStart
|
||||
}, ${argvs.sourceEnd})`;
|
||||
|
||||
case "compare":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buf1
|
||||
)}, ${stringifyObject(argvs.buf2)})`;
|
||||
)}, ${stringifyArgv(argvs.buf2)})`;
|
||||
|
||||
case "concat":
|
||||
const buffersStr = argvs.buffers
|
||||
.map((buf) => stringifyObject(buf))
|
||||
.map((buf) => stringifyArgv(buf))
|
||||
.join(", ");
|
||||
return `${this.modelValue.value}.${argvs.operation}([${buffersStr}]${
|
||||
argvs.totalLength !== undefined ? `, ${argvs.totalLength}` : ""
|
||||
})`;
|
||||
|
||||
case "indexOf":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, ${stringifyObject(argvs.value)}, ${argvs.byteOffset}, "${
|
||||
)}, ${stringifyArgv(argvs.value)}, ${argvs.byteOffset}, "${
|
||||
argvs.encoding
|
||||
}")`;
|
||||
|
||||
case "slice":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, ${argvs.start}, ${argvs.end})`;
|
||||
|
||||
case "swap":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.buffer
|
||||
)}, ${argvs.size})`;
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import VariableInput from "components/composer/ui/VariableInput.vue";
|
||||
import { stringifyObject, parseFunction } from "js/composer/formatString";
|
||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||
|
||||
export default defineComponent({
|
||||
name: "SymmetricCryptoEditor",
|
||||
@@ -293,7 +293,7 @@ export default defineComponent({
|
||||
},
|
||||
methods: {
|
||||
generateCode(argvs = this.argvs) {
|
||||
return `${this.modelValue.value}(${stringifyObject({
|
||||
return `${this.modelValue.value}(${stringifyArgv({
|
||||
text: argvs.text,
|
||||
algorithm: argvs.algorithm,
|
||||
mode: argvs.mode,
|
||||
|
||||
@@ -141,7 +141,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 NumberInput from "components/composer/ui/NumberInput.vue";
|
||||
|
||||
@@ -244,9 +244,9 @@ export default defineComponent({
|
||||
strategy: argvs.options.strategy,
|
||||
};
|
||||
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.data
|
||||
)}, "${argvs.method}", ${stringifyObject(options)})`;
|
||||
)}, "${argvs.method}", ${stringifyArgv(options)})`;
|
||||
},
|
||||
parseCodeToArgvs(code) {
|
||||
if (!code) return null;
|
||||
|
||||
@@ -383,7 +383,7 @@
|
||||
import { defineComponent } from "vue";
|
||||
import VariableInput from "components/composer/ui/VariableInput.vue";
|
||||
import NumberInput from "components/composer/ui/NumberInput.vue";
|
||||
import { stringifyObject, parseFunction } from "js/composer/formatString";
|
||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||
|
||||
// 静态选项数据
|
||||
const ENCODING_OPTIONS = [
|
||||
@@ -557,7 +557,7 @@ export default defineComponent({
|
||||
break;
|
||||
}
|
||||
|
||||
return `${this.modelValue.value}(${stringifyObject(params)})`;
|
||||
return `${this.modelValue.value}(${stringifyArgv(params)})`;
|
||||
},
|
||||
updateArgvs(key, value) {
|
||||
const argvs = { ...this.argvs };
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
)})`;
|
||||
}
|
||||
|
||||
@@ -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}()`;
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import { stringifyObject, parseFunction } from "js/composer/formatString";
|
||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||
|
||||
export default defineComponent({
|
||||
name: "OsEditor",
|
||||
@@ -248,7 +248,7 @@ export default defineComponent({
|
||||
return `${this.modelValue.value}.${argvs.operation}()`;
|
||||
}
|
||||
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
params
|
||||
)})`;
|
||||
},
|
||||
|
||||
@@ -161,7 +161,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({
|
||||
@@ -288,33 +288,33 @@ export default defineComponent({
|
||||
case "dirname":
|
||||
case "extname":
|
||||
case "isAbsolute":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.path
|
||||
)})`;
|
||||
|
||||
case "basename":
|
||||
if (argvs.ext && argvs.ext.value) {
|
||||
return `${this.modelValue.value}.${
|
||||
argvs.operation
|
||||
}(${stringifyObject(argvs.path)}, ${stringifyObject(argvs.ext)})`;
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.path
|
||||
)}, ${stringifyArgv(argvs.ext)})`;
|
||||
}
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.path
|
||||
)})`;
|
||||
|
||||
case "join":
|
||||
case "resolve":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${argvs.paths
|
||||
.map((p) => stringifyObject(p))
|
||||
.map((p) => stringifyArgv(p))
|
||||
.join(", ")})`;
|
||||
|
||||
case "relative":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.from
|
||||
)}, ${stringifyObject(argvs.to)})`;
|
||||
)}, ${stringifyArgv(argvs.to)})`;
|
||||
|
||||
case "format":
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyObject(
|
||||
return `${this.modelValue.value}.${argvs.operation}(${stringifyArgv(
|
||||
argvs.pathObject
|
||||
)})`;
|
||||
|
||||
|
||||
@@ -131,11 +131,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import {
|
||||
parseFunction,
|
||||
stringifyObject,
|
||||
stringifyWithType,
|
||||
} from "js/composer/formatString";
|
||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
||||
import VariableInput from "components/composer/ui/VariableInput.vue";
|
||||
import NumberInput from "components/composer/ui/NumberInput.vue";
|
||||
import DictEditor from "components/composer/ui/DictEditor.vue";
|
||||
@@ -239,7 +235,7 @@ export default defineComponent({
|
||||
const args = [];
|
||||
|
||||
// 添加命令
|
||||
args.push(stringifyWithType(argvs.command));
|
||||
args.push(stringifyArgv(argvs.command));
|
||||
|
||||
// 添加选项
|
||||
const options = { ...argvs.options };
|
||||
@@ -254,7 +250,7 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
if (Object.keys(options).length > 0) {
|
||||
args.push(stringifyObject(options));
|
||||
args.push(stringifyArgv(options));
|
||||
}
|
||||
|
||||
return `${this.modelValue.value}(${args.join(", ")})`;
|
||||
|
||||
Reference in New Issue
Block a user