mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 04:42:45 +08:00
统一VarInput变量的管理
This commit is contained in:
parent
b528cfa97d
commit
7a43695e2d
@ -15,6 +15,7 @@ import { defineComponent } from "vue";
|
|||||||
import OperationCard from "components/composer/common/OperationCard.vue";
|
import OperationCard from "components/composer/common/OperationCard.vue";
|
||||||
import ParamInput from "components/composer/common/ParamInput.vue";
|
import ParamInput from "components/composer/common/ParamInput.vue";
|
||||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "MultiParams",
|
name: "MultiParams",
|
||||||
@ -52,11 +53,7 @@ export default defineComponent({
|
|||||||
return [...this.commonConfig, ...this.functionConfig].map((item) => {
|
return [...this.commonConfig, ...this.functionConfig].map((item) => {
|
||||||
const value =
|
const value =
|
||||||
item.type === "varInput"
|
item.type === "varInput"
|
||||||
? item.defaultValue || {
|
? item.defaultValue || newVarInputVal("str")
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}
|
|
||||||
: // 其他类型情况复杂,不做判断,没有默认值返回undefined
|
: // 其他类型情况复杂,不做判断,没有默认值返回undefined
|
||||||
item.defaultValue;
|
item.defaultValue;
|
||||||
return {
|
return {
|
||||||
|
@ -94,35 +94,30 @@
|
|||||||
* @example
|
* @example
|
||||||
* // 基础数组
|
* // 基础数组
|
||||||
* [
|
* [
|
||||||
* {
|
* newVarInputVal("str", "张三")
|
||||||
* value: "张三",
|
|
||||||
* isString: true,
|
|
||||||
* __varInputVal__: true
|
|
||||||
* }
|
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
* // 多键对象数组
|
* // 多键对象数组
|
||||||
* options.keys = ['name', 'age', 'email']
|
* options.keys = ['name', 'age', 'email']
|
||||||
* [
|
* [
|
||||||
* {
|
* {
|
||||||
* name: { value: "张三", isString: true, __varInputVal__: true },
|
* name: newVarInputVal("str", "张三"),
|
||||||
* age: { value: "18", isString: false, __varInputVal__: true },
|
* age: newVarInputVal("str", "18"),
|
||||||
* email: { value: "zhangsan@example.com", isString: true, __varInputVal__: true }
|
* email: newVarInputVal("str", "zhangsan@example.com")
|
||||||
* }
|
* }
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
* // 下拉选择模式
|
* // 下拉选择模式
|
||||||
* options.items = ['选项1', '选项2', '选项3']
|
* options.items = ['选项1', '选项2', '选项3']
|
||||||
* [
|
* [
|
||||||
* {
|
* newVarInputVal("str", "选项1"),
|
||||||
* value: "选项1",
|
* newVarInputVal("str", "选项2"),
|
||||||
* isString: true,
|
* newVarInputVal("str", "选项3")
|
||||||
* __varInputVal__: true
|
|
||||||
* }
|
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "ArrayEditor",
|
name: "ArrayEditor",
|
||||||
@ -169,22 +164,12 @@ export default defineComponent({
|
|||||||
if (this.optionsKeys?.length) {
|
if (this.optionsKeys?.length) {
|
||||||
const item = {};
|
const item = {};
|
||||||
this.optionsKeys.forEach((key) => {
|
this.optionsKeys.forEach((key) => {
|
||||||
item[key] = {
|
item[key] = newVarInputVal("str");
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
return [item];
|
return [item];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [newVarInputVal("str")];
|
||||||
{
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 添加新的数组项
|
* 添加新的数组项
|
||||||
@ -195,22 +180,11 @@ export default defineComponent({
|
|||||||
if (this.options.keys) {
|
if (this.options.keys) {
|
||||||
const newItem = {};
|
const newItem = {};
|
||||||
this.options.keys.forEach((key) => {
|
this.options.keys.forEach((key) => {
|
||||||
newItem[key] = {
|
newItem[key] = newVarInputVal("str");
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
newItems = [...this.items, newItem];
|
newItems = [...this.items, newItem];
|
||||||
} else {
|
} else {
|
||||||
newItems = [
|
newItems = [...this.items, newVarInputVal("str")];
|
||||||
...this.items,
|
|
||||||
{
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
this.$emit("update:modelValue", newItems);
|
this.$emit("update:modelValue", newItems);
|
||||||
},
|
},
|
||||||
@ -225,19 +199,11 @@ export default defineComponent({
|
|||||||
if (this.options.keys) {
|
if (this.options.keys) {
|
||||||
const newItem = {};
|
const newItem = {};
|
||||||
this.options.keys.forEach((key) => {
|
this.options.keys.forEach((key) => {
|
||||||
newItem[key] = {
|
newItem[key] = newVarInputVal("str");
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
newItems.push(newItem);
|
newItems.push(newItem);
|
||||||
} else {
|
} else {
|
||||||
newItems.push({
|
newItems.push(newVarInputVal("str"));
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$emit("update:modelValue", newItems);
|
this.$emit("update:modelValue", newItems);
|
||||||
|
@ -95,6 +95,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,21 +109,15 @@ import VariableInput from "components/composer/common/VariableInput.vue";
|
|||||||
* @example
|
* @example
|
||||||
* // 基础字典对象
|
* // 基础字典对象
|
||||||
* {
|
* {
|
||||||
* key: {
|
* key: newVarInputVal("str"),
|
||||||
* value: "", // 输入框的值
|
|
||||||
* isString: true, // 是否是字符串
|
|
||||||
* __varInputVal__: true // 用于标识是变量输入框
|
|
||||||
* }
|
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // 下拉选择模式
|
* // 下拉选择模式
|
||||||
* options.items = ['User-Agent', 'Content-Type', 'Accept']
|
* options.items = ['User-Agent', 'Content-Type', 'Accept']
|
||||||
* {
|
* {
|
||||||
* "User-Agent": {
|
* "User-Agent": newVarInputVal("str", "Mozilla/5.0"),
|
||||||
* value: "Mozilla/5.0",
|
* "Content-Type": newVarInputVal("str", "text/html"),
|
||||||
* isString: true,
|
* "Accept": newVarInputVal("str", "text/html")
|
||||||
* __varInputVal__: true
|
|
||||||
* }
|
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@ -149,11 +144,7 @@ export default defineComponent({
|
|||||||
: [
|
: [
|
||||||
{
|
{
|
||||||
key: "",
|
key: "",
|
||||||
value: {
|
value: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
filterOptions: this.options?.items || [],
|
filterOptions: this.options?.items || [],
|
||||||
@ -183,7 +174,7 @@ export default defineComponent({
|
|||||||
...this.items,
|
...this.items,
|
||||||
{
|
{
|
||||||
key: "",
|
key: "",
|
||||||
value: { value: "", isString: true, __varInputVal__: true },
|
value: newVarInputVal("str"),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@ -193,7 +184,7 @@ export default defineComponent({
|
|||||||
if (newItems.length === 0) {
|
if (newItems.length === 0) {
|
||||||
newItems.push({
|
newItems.push({
|
||||||
key: "",
|
key: "",
|
||||||
value: { value: "", isString: true, __varInputVal__: true },
|
value: newVarInputVal("str"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.items = newItems;
|
this.items = newItems;
|
||||||
|
@ -138,7 +138,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, inject } from "vue";
|
import { defineComponent, inject } from "vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
/**
|
/**
|
||||||
* 变量输入框组件
|
* 变量输入框组件
|
||||||
* @description 支持变量选择和字符串输入的输入框组件
|
* @description 支持变量选择和字符串输入的输入框组件
|
||||||
@ -179,11 +179,7 @@ export default defineComponent({
|
|||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
default: () => ({
|
default: () => newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
label: String,
|
label: String,
|
||||||
icon: String,
|
icon: String,
|
||||||
@ -265,22 +261,14 @@ export default defineComponent({
|
|||||||
insertVariable(variable) {
|
insertVariable(variable) {
|
||||||
this.selectedVariable = variable;
|
this.selectedVariable = variable;
|
||||||
this.isString = false; // 变量模式下不需要字符串处理
|
this.isString = false; // 变量模式下不需要字符串处理
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("var", variable.name));
|
||||||
isString: false,
|
|
||||||
value: variable.name,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 清除变量时的处理
|
// 清除变量时的处理
|
||||||
clearVariable() {
|
clearVariable() {
|
||||||
this.selectedVariable = null;
|
this.selectedVariable = null;
|
||||||
this.isString = true; // 恢复到字符串模式
|
this.isString = true; // 恢复到字符串模式
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("str"));
|
||||||
isString: true,
|
|
||||||
value: "",
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 切换类型
|
// 切换类型
|
||||||
@ -301,11 +289,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
selectItem(option) {
|
selectItem(option) {
|
||||||
const value = this.getItemValue(option);
|
const value = this.getItemValue(option);
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("str", value));
|
||||||
value,
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
escapePath(paths) {
|
escapePath(paths) {
|
||||||
if (!paths) return null;
|
if (!paths) return null;
|
||||||
@ -319,26 +303,14 @@ export default defineComponent({
|
|||||||
const files = this.escapePath(utools.showOpenDialog(options));
|
const files = this.escapePath(utools.showOpenDialog(options));
|
||||||
if (!files) return;
|
if (!files) return;
|
||||||
if (files.length > 1) {
|
if (files.length > 1) {
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("var", files));
|
||||||
value: files,
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
} else if (files.length === 1) {
|
} else if (files.length === 1) {
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("str", files[0]));
|
||||||
value: files[0],
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const file = this.escapePath(utools.showSaveDialog(options));
|
const file = this.escapePath(utools.showSaveDialog(options));
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", newVarInputVal("str", file));
|
||||||
value: file,
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -186,7 +186,7 @@
|
|||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "AsymmetricCryptoEditor",
|
name: "AsymmetricCryptoEditor",
|
||||||
components: {
|
components: {
|
||||||
@ -200,11 +200,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
operation: "encrypt",
|
operation: "encrypt",
|
||||||
text: {
|
text: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
algorithm: "RSA",
|
algorithm: "RSA",
|
||||||
keyLength: 1024,
|
keyLength: 1024,
|
||||||
padding: "RSAES-PKCS1-V1_5",
|
padding: "RSAES-PKCS1-V1_5",
|
||||||
|
@ -186,6 +186,7 @@
|
|||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "SymmetricCryptoEditor",
|
name: "SymmetricCryptoEditor",
|
||||||
@ -200,11 +201,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
operation: "encrypt",
|
operation: "encrypt",
|
||||||
text: {
|
text: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
algorithm: "AES",
|
algorithm: "AES",
|
||||||
keyLength: 128,
|
keyLength: 128,
|
||||||
mode: "CBC",
|
mode: "CBC",
|
||||||
|
@ -132,6 +132,8 @@ import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
|||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
import OperationCard from "components/composer/common/OperationCard.vue";
|
import OperationCard from "components/composer/common/OperationCard.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "ZlibEditor",
|
name: "ZlibEditor",
|
||||||
components: {
|
components: {
|
||||||
@ -188,11 +190,7 @@ export default defineComponent({
|
|||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
operation: "compressData",
|
operation: "compressData",
|
||||||
method: "gzip",
|
method: "gzip",
|
||||||
data: {
|
data: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
options: {
|
options: {
|
||||||
level: -1,
|
level: -1,
|
||||||
memLevel: 8,
|
memLevel: 8,
|
||||||
|
@ -98,6 +98,7 @@ import RegexInput from "./RegexInput.vue";
|
|||||||
import RegexBuilder from "./RegexBuilder.vue";
|
import RegexBuilder from "./RegexBuilder.vue";
|
||||||
import RegexTester from "./RegexTester.vue";
|
import RegexTester from "./RegexTester.vue";
|
||||||
import { parseToHasType } from "js/composer/formatString";
|
import { parseToHasType } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "RegexEditor",
|
name: "RegexEditor",
|
||||||
@ -122,17 +123,9 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
showBuilder: false,
|
showBuilder: false,
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
textValue: {
|
textValue: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
regexValue: "",
|
regexValue: "",
|
||||||
replaceValue: {
|
replaceValue: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
isReplace: false,
|
isReplace: false,
|
||||||
flags: {
|
flags: {
|
||||||
ignoreCase: false,
|
ignoreCase: false,
|
||||||
|
@ -43,17 +43,14 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "RegexTester",
|
name: "RegexTester",
|
||||||
props: {
|
props: {
|
||||||
text: {
|
text: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({
|
default: () => newVarInputVal("var"),
|
||||||
value: "",
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
regex: {
|
regex: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -65,11 +62,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
replace: {
|
replace: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({
|
default: () => newVarInputVal("var"),
|
||||||
value: "",
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
isReplace: {
|
isReplace: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -383,6 +383,7 @@ import { defineComponent } from "vue";
|
|||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
// 静态选项数据
|
// 静态选项数据
|
||||||
const ENCODING_OPTIONS = [
|
const ENCODING_OPTIONS = [
|
||||||
@ -463,11 +464,7 @@ export default defineComponent({
|
|||||||
manageOperationOptions: MANAGE_OPERATION_OPTIONS,
|
manageOperationOptions: MANAGE_OPERATION_OPTIONS,
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
operation: "read",
|
operation: "read",
|
||||||
filePath: {
|
filePath: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
readMode: "all",
|
readMode: "all",
|
||||||
readFlag: "async",
|
readFlag: "async",
|
||||||
|
@ -162,6 +162,7 @@ import {
|
|||||||
methods,
|
methods,
|
||||||
responseTypes,
|
responseTypes,
|
||||||
} from "js/options/httpOptions";
|
} from "js/options/httpOptions";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "AxiosConfigEditor",
|
name: "AxiosConfigEditor",
|
||||||
@ -187,18 +188,10 @@ export default defineComponent({
|
|||||||
.map((h) => h.value),
|
.map((h) => h.value),
|
||||||
activeTab: "headers",
|
activeTab: "headers",
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
url: {
|
url: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": {
|
"User-Agent": newVarInputVal("str", userAgent[0].value),
|
||||||
value: userAgent[0].value,
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
"Content-Type": contentTypes[0].value,
|
"Content-Type": contentTypes[0].value,
|
||||||
},
|
},
|
||||||
otherHeaders: {},
|
otherHeaders: {},
|
||||||
@ -208,36 +201,16 @@ export default defineComponent({
|
|||||||
maxRedirects: 5,
|
maxRedirects: 5,
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
auth: {
|
auth: {
|
||||||
username: {
|
username: newVarInputVal("str"),
|
||||||
value: "",
|
password: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
proxy: {
|
},
|
||||||
host: {
|
proxy: {
|
||||||
value: "",
|
host: newVarInputVal("str"),
|
||||||
isString: true,
|
port: null,
|
||||||
__varInputVal__: true,
|
auth: {
|
||||||
},
|
username: newVarInputVal("str"),
|
||||||
port: null,
|
password: newVarInputVal("str"),
|
||||||
auth: {
|
|
||||||
username: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
commonPanels: [
|
commonPanels: [
|
||||||
@ -483,9 +456,7 @@ export default defineComponent({
|
|||||||
const formattedHeaders = Object.entries(headers).reduce(
|
const formattedHeaders = Object.entries(headers).reduce(
|
||||||
(acc, [key, value]) => {
|
(acc, [key, value]) => {
|
||||||
acc[key] =
|
acc[key] =
|
||||||
typeof value === "string"
|
typeof value === "string" ? newVarInputVal("str", value) : value;
|
||||||
? { value, isString: true, __varInputVal__: true }
|
|
||||||
: value;
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
@ -501,11 +472,7 @@ export default defineComponent({
|
|||||||
this.updateArgvs("headers", newHeaders);
|
this.updateArgvs("headers", newHeaders);
|
||||||
},
|
},
|
||||||
setUserAgent(value) {
|
setUserAgent(value) {
|
||||||
this.updateArgvs("headers.User-Agent", {
|
this.updateArgvs("headers.User-Agent", newVarInputVal("str", value));
|
||||||
value,
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getFieldValue(path) {
|
getFieldValue(path) {
|
||||||
return path.split(".").reduce((obj, key) => obj?.[key], this.argvs);
|
return path.split(".").reduce((obj, key) => obj?.[key], this.argvs);
|
||||||
|
@ -132,6 +132,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
import DictEditor from "components/composer/common/DictEditor.vue";
|
import DictEditor from "components/composer/common/DictEditor.vue";
|
||||||
@ -164,30 +165,18 @@ export default defineComponent({
|
|||||||
{ label: "Base64", value: "base64" },
|
{ label: "Base64", value: "base64" },
|
||||||
],
|
],
|
||||||
defaultArgvs: {
|
defaultArgvs: {
|
||||||
command: {
|
command: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
cwd: {
|
cwd: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
env: {},
|
env: {},
|
||||||
autoEncoding: true,
|
autoEncoding: true,
|
||||||
encoding: "buffer",
|
encoding: "buffer",
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
maxBuffer: 1024 * 1024, // 1MB
|
maxBuffer: 1024 * 1024, // 1MB
|
||||||
shell: {
|
shell: newVarInputVal("str"),
|
||||||
value: "",
|
windowsHide: true,
|
||||||
isString: true,
|
},
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
windowsHide: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -71,7 +71,7 @@ import { defineComponent, ref, computed } from "vue";
|
|||||||
import { userAgent } from "js/options/httpOptions";
|
import { userAgent } from "js/options/httpOptions";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "UBrowserBasic",
|
name: "UBrowserBasic",
|
||||||
components: {
|
components: {
|
||||||
@ -109,11 +109,7 @@ export default defineComponent({
|
|||||||
if (!newConfigs.goto.headers) {
|
if (!newConfigs.goto.headers) {
|
||||||
newConfigs.goto.headers = {};
|
newConfigs.goto.headers = {};
|
||||||
}
|
}
|
||||||
newConfigs.goto.headers.userAgent = {
|
newConfigs.goto.headers.userAgent = newVarInputVal("str", val);
|
||||||
value: val,
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
emit("update:configs", newConfigs);
|
emit("update:configs", newConfigs);
|
||||||
selectedUA.value = null;
|
selectedUA.value = null;
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "UBrowserCookieList",
|
name: "UBrowserCookieList",
|
||||||
components: {
|
components: {
|
||||||
@ -66,16 +66,8 @@ export default defineComponent({
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => [
|
default: () => [
|
||||||
{
|
{
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -86,16 +78,8 @@ export default defineComponent({
|
|||||||
const newValue = [
|
const newValue = [
|
||||||
...this.modelValue,
|
...this.modelValue,
|
||||||
{
|
{
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
this.$emit("update:modelValue", newValue);
|
this.$emit("update:modelValue", newValue);
|
||||||
@ -105,16 +89,8 @@ export default defineComponent({
|
|||||||
newValue.splice(index, 1);
|
newValue.splice(index, 1);
|
||||||
if (newValue.length === 0) {
|
if (newValue.length === 0) {
|
||||||
newValue.push({
|
newValue.push({
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.$emit("update:modelValue", newValue);
|
this.$emit("update:modelValue", newValue);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import { deviceName } from "js/options/httpOptions";
|
import { deviceName } from "js/options/httpOptions";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "UBrowserDeviceName",
|
name: "UBrowserDeviceName",
|
||||||
components: {
|
components: {
|
||||||
@ -42,11 +42,7 @@ export default defineComponent({
|
|||||||
props: {
|
props: {
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({
|
default: () => newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "UBrowserFileList",
|
name: "UBrowserFileList",
|
||||||
components: {
|
components: {
|
||||||
@ -60,11 +60,7 @@ export default defineComponent({
|
|||||||
addFile() {
|
addFile() {
|
||||||
const newValue = [
|
const newValue = [
|
||||||
...(this.modelValue || []),
|
...(this.modelValue || []),
|
||||||
{
|
newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
this.$emit("update:modelValue", newValue);
|
this.$emit("update:modelValue", newValue);
|
||||||
},
|
},
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "UBrowserNamedParamList",
|
name: "UBrowserNamedParamList",
|
||||||
components: {
|
components: {
|
||||||
@ -56,20 +56,7 @@ export default defineComponent({
|
|||||||
props: {
|
props: {
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [
|
default: () => [newVarInputVal("str"), newVarInputVal("str")],
|
||||||
{
|
|
||||||
name: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
label: String,
|
label: String,
|
||||||
},
|
},
|
||||||
@ -79,16 +66,8 @@ export default defineComponent({
|
|||||||
const newValue = [
|
const newValue = [
|
||||||
...(this.modelValue || []),
|
...(this.modelValue || []),
|
||||||
{
|
{
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
this.$emit("update:modelValue", newValue);
|
this.$emit("update:modelValue", newValue);
|
||||||
|
@ -178,15 +178,8 @@ import VariableInput from "../common/VariableInput.vue";
|
|||||||
import ArrayEditor from "../common/ArrayEditor.vue";
|
import ArrayEditor from "../common/ArrayEditor.vue";
|
||||||
import OperationCard from "../common/OperationCard.vue";
|
import OperationCard from "../common/OperationCard.vue";
|
||||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
||||||
|
import { newVarInputVal, isVarInputVal} from "js/composer/varInputValManager";
|
||||||
|
|
||||||
const newVarInputVal = (type = "str", val = "") => {
|
|
||||||
if (typeof val !== "string") val = JSON.stringify(val);
|
|
||||||
return {
|
|
||||||
value: val,
|
|
||||||
isString: type === "str",
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const jsonDefaultSelects = new Array(3).fill().map((_, index) => ({
|
const jsonDefaultSelects = new Array(3).fill().map((_, index) => ({
|
||||||
id: newVarInputVal("var", index),
|
id: newVarInputVal("var", index),
|
||||||
@ -228,11 +221,7 @@ export default defineComponent({
|
|||||||
inputMode: "manual",
|
inputMode: "manual",
|
||||||
selects: defaultSelects.json,
|
selects: defaultSelects.json,
|
||||||
optionType: "json",
|
optionType: "json",
|
||||||
placeholder: {
|
placeholder: newVarInputVal("str", "搜索..."),
|
||||||
value: "搜索...",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
enableSearch: true,
|
enableSearch: true,
|
||||||
showCancelButton: false,
|
showCancelButton: false,
|
||||||
closeOnSelect: true,
|
closeOnSelect: true,
|
||||||
@ -303,7 +292,7 @@ export default defineComponent({
|
|||||||
if (!result) return this.defaultArgvs;
|
if (!result) return this.defaultArgvs;
|
||||||
|
|
||||||
const [selects, options = {}] = result.argvs;
|
const [selects, options = {}] = result.argvs;
|
||||||
const inputMode = selects.__varInputVal__ ? "variable" : "manual";
|
const inputMode = isVarInputVal(selects) ? "variable" : "manual";
|
||||||
return {
|
return {
|
||||||
...this.defaultArgvs,
|
...this.defaultArgvs,
|
||||||
inputMode,
|
inputMode,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export const dataCommands = {
|
export const dataCommands = {
|
||||||
label: "数据处理",
|
label: "数据处理",
|
||||||
icon: "format_color_text",
|
icon: "format_color_text",
|
||||||
@ -552,13 +554,7 @@ export const dataCommands = {
|
|||||||
type: "arrayEditor",
|
type: "arrayEditor",
|
||||||
icon: "memory",
|
icon: "memory",
|
||||||
width: 12,
|
width: 12,
|
||||||
defaultValue: [
|
defaultValue: [newVarInputVal("var")],
|
||||||
{
|
|
||||||
value: "",
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "总长度(可选)",
|
label: "总长度(可选)",
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export const uiCommands = {
|
export const uiCommands = {
|
||||||
label: "UI操作",
|
label: "UI操作",
|
||||||
icon: "web",
|
icon: "web",
|
||||||
@ -14,16 +16,8 @@ export const uiCommands = {
|
|||||||
label: "按钮组",
|
label: "按钮组",
|
||||||
type: "arrayEditor",
|
type: "arrayEditor",
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{
|
newVarInputVal("str", "是"),
|
||||||
value: "是",
|
newVarInputVal("str", "否"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: "否",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -53,16 +47,8 @@ export const uiCommands = {
|
|||||||
},
|
},
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{
|
{
|
||||||
label: {
|
label: newVarInputVal("str", "请输入"),
|
||||||
value: "请输入",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -249,8 +249,7 @@ const customComponentGuide = {
|
|||||||
parseToHasType: {
|
parseToHasType: {
|
||||||
description: "将字符串解析为带类型的值",
|
description: "将字符串解析为带类型的值",
|
||||||
usage: "用于解析 VariableInput 类型的值",
|
usage: "用于解析 VariableInput 类型的值",
|
||||||
example:
|
example: "将 '\"text\"' 解析为 newVarInputVal('str', 'text')",
|
||||||
"将 '\"text\"' 解析为 {value: 'text', isString: true, __varInputVal__: true,}",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -292,7 +291,7 @@ const customComponentGuide = {
|
|||||||
description: "变量输入组件",
|
description: "变量输入组件",
|
||||||
usage: "用于输入可能包含变量的字符串",
|
usage: "用于输入可能包含变量的字符串",
|
||||||
props: [
|
props: [
|
||||||
"model-value - 输入值,需要包含 value、isString、__varInputVal__ 属性",
|
"model-value - 输入值,需要包含 value、isString、__varInputVal__ 属性, 通过 varInputValManager 的 newVarInputVal 创建",
|
||||||
"label - 输入框标签",
|
"label - 输入框标签",
|
||||||
"icon - 输入框图标",
|
"icon - 输入框图标",
|
||||||
],
|
],
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
import { parse } from "@babel/parser";
|
import { parse } from "@babel/parser";
|
||||||
|
import {
|
||||||
/**
|
stringifyVarInputVal,
|
||||||
* 处理带有 __varInputVal__ 属性的对象
|
isVarInputVal,
|
||||||
* @param {Object} argv 要处理的对象
|
newVarInputVal,
|
||||||
* @returns {string} 处理后的字符串
|
} from "./varInputValManager";
|
||||||
*/
|
|
||||||
const stringifyVarInputVal = (argv) => {
|
|
||||||
return argv.isString ? `"${argv.value}"` : argv.value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归移除对象中的空值
|
* 递归移除对象中的空值
|
||||||
@ -17,12 +13,10 @@ const stringifyVarInputVal = (argv) => {
|
|||||||
const removeEmptyValues = (obj) => {
|
const removeEmptyValues = (obj) => {
|
||||||
return window.lodashM.omitBy(obj, (value) => {
|
return window.lodashM.omitBy(obj, (value) => {
|
||||||
// 如果value是VariableInput的输出,则取其value值
|
// 如果value是VariableInput的输出,则取其value值
|
||||||
const realValue = value?.hasOwnProperty("__varInputVal__")
|
const realValue = isVarInputVal(value) ? value.value : value;
|
||||||
? value.value
|
|
||||||
: value;
|
|
||||||
if (window.lodashM.isNil(realValue) || realValue === "") return true;
|
if (window.lodashM.isNil(realValue) || realValue === "") return true;
|
||||||
// 如果value是对象,并且不是VariableInput的输出,则递归移除空值
|
// 如果value是对象,并且不是VariableInput的输出,则递归移除空值
|
||||||
if (typeof value === "object" && !value.hasOwnProperty("__varInputVal__"))
|
if (typeof value === "object" && !isVarInputVal(value))
|
||||||
return window.lodashM.isEmpty(removeEmptyValues(value));
|
return window.lodashM.isEmpty(removeEmptyValues(value));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -38,7 +32,7 @@ const processObject = (obj, parentPath = "") => {
|
|||||||
// 移除空值
|
// 移除空值
|
||||||
obj = removeEmptyValues(obj);
|
obj = removeEmptyValues(obj);
|
||||||
// 如果是 VariableInput 的输出,直接用 stringifyVarInputVal 处理
|
// 如果是 VariableInput 的输出,直接用 stringifyVarInputVal 处理
|
||||||
if (obj?.hasOwnProperty("__varInputVal__")) {
|
if (isVarInputVal(obj)) {
|
||||||
return stringifyVarInputVal(obj);
|
return stringifyVarInputVal(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +45,7 @@ const processObject = (obj, parentPath = "") => {
|
|||||||
// 处理对象类型
|
// 处理对象类型
|
||||||
if (value && typeof value === "object") {
|
if (value && typeof value === "object") {
|
||||||
// 如果是 VariableInput 的输出,直接用 stringifyVarInputVal 处理
|
// 如果是 VariableInput 的输出,直接用 stringifyVarInputVal 处理
|
||||||
if (value.hasOwnProperty("__varInputVal__")) {
|
if (isVarInputVal(value)) {
|
||||||
valueStr = stringifyVarInputVal(value);
|
valueStr = stringifyVarInputVal(value);
|
||||||
} else {
|
} else {
|
||||||
valueStr = processObject(value, parentPath + " ");
|
valueStr = processObject(value, parentPath + " ");
|
||||||
@ -83,7 +77,7 @@ const processObject = (obj, parentPath = "") => {
|
|||||||
* @returns {string} 格式化后的JSON字符串
|
* @returns {string} 格式化后的JSON字符串
|
||||||
*/
|
*/
|
||||||
const stringifyObject = (jsonObj) => {
|
const stringifyObject = (jsonObj) => {
|
||||||
if (jsonObj?.hasOwnProperty("__varInputVal__")) {
|
if (isVarInputVal(jsonObj)) {
|
||||||
return stringifyVarInputVal(jsonObj);
|
return stringifyVarInputVal(jsonObj);
|
||||||
}
|
}
|
||||||
if (jsonObj instanceof Array) {
|
if (jsonObj instanceof Array) {
|
||||||
@ -126,23 +120,11 @@ export const stringifyArgv = (argv) => {
|
|||||||
*/
|
*/
|
||||||
export const parseToHasType = (str) => {
|
export const parseToHasType = (str) => {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return {
|
return newVarInputVal("str", "");
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return str.startsWith('"') && str.endsWith('"')
|
return str.startsWith('"') && str.endsWith('"')
|
||||||
? {
|
? newVarInputVal("str", str.slice(1, -1))
|
||||||
value: str.slice(1, -1),
|
: newVarInputVal("var", str);
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
value: str,
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -272,31 +254,23 @@ export const parseFunction = (functionStr, options = {}) => {
|
|||||||
case "StringLiteral":
|
case "StringLiteral":
|
||||||
// 字符串字面量总是带引号的
|
// 字符串字面量总是带引号的
|
||||||
return shouldUseVariableFormat
|
return shouldUseVariableFormat
|
||||||
? { value: node.value, isString: true, __varInputVal__: true }
|
? newVarInputVal("str", node.value)
|
||||||
: node.value;
|
: node.value;
|
||||||
// 数字、布尔
|
// 数字、布尔
|
||||||
case "NumericLiteral":
|
case "NumericLiteral":
|
||||||
case "BooleanLiteral":
|
case "BooleanLiteral":
|
||||||
return shouldUseVariableFormat
|
return shouldUseVariableFormat
|
||||||
? {
|
? newVarInputVal("var", JSON.stringify(node.value))
|
||||||
value: JSON.stringify(node.value),
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}
|
|
||||||
: node.value;
|
: node.value;
|
||||||
// null
|
// null
|
||||||
case "NullLiteral":
|
case "NullLiteral":
|
||||||
return shouldUseVariableFormat
|
return shouldUseVariableFormat
|
||||||
? {
|
? newVarInputVal("var", "null")
|
||||||
value: "null",
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
}
|
|
||||||
: null;
|
: null;
|
||||||
case "Identifier":
|
case "Identifier":
|
||||||
// 标识符(变量)总是不带引号的
|
// 标识符(变量)总是不带引号的
|
||||||
return shouldUseVariableFormat
|
return shouldUseVariableFormat
|
||||||
? { value: node.name, isString: false, __varInputVal__: true }
|
? newVarInputVal("var", node.name)
|
||||||
: node.name;
|
: node.name;
|
||||||
case "ObjectExpression":
|
case "ObjectExpression":
|
||||||
return node.properties.reduce((obj, prop) => {
|
return node.properties.reduce((obj, prop) => {
|
||||||
@ -317,18 +291,14 @@ export const parseFunction = (functionStr, options = {}) => {
|
|||||||
return Object.entries(processedElement).reduce(
|
return Object.entries(processedElement).reduce(
|
||||||
(acc, [key, value]) => {
|
(acc, [key, value]) => {
|
||||||
// 如果值已经是 varInputVal 格式,直接使用
|
// 如果值已经是 varInputVal 格式,直接使用
|
||||||
if (value?.__varInputVal__) {
|
if (isVarInputVal(value)) {
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
} else {
|
} else {
|
||||||
// 否则转换为 varInputVal 格式
|
// 否则转换为 varInputVal 格式
|
||||||
acc[key] = {
|
acc[key] = newVarInputVal(
|
||||||
value:
|
typeof value === "string" ? "str" : "var",
|
||||||
typeof value === "string"
|
typeof value === "string" ? value : JSON.stringify(value)
|
||||||
? value
|
);
|
||||||
: JSON.stringify(value),
|
|
||||||
isString: typeof value === "string",
|
|
||||||
__varInputVal__: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
|
|
||||||
// ubrowser 浏览器操作配置
|
// ubrowser 浏览器操作配置
|
||||||
export const ubrowserOperationConfigs = [
|
export const ubrowserOperationConfigs = [
|
||||||
{
|
{
|
||||||
@ -565,22 +567,10 @@ const defaultUBrowserRunConfigs = {
|
|||||||
export const defaultUBrowserConfigs = {
|
export const defaultUBrowserConfigs = {
|
||||||
// 基础参数
|
// 基础参数
|
||||||
goto: {
|
goto: {
|
||||||
url: {
|
url: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
headers: {
|
headers: {
|
||||||
Referer: {
|
Referer: newVarInputVal("str"),
|
||||||
value: "",
|
userAgent: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
userAgent: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
},
|
},
|
||||||
@ -590,183 +580,87 @@ export const defaultUBrowserConfigs = {
|
|||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
},
|
},
|
||||||
click: {
|
click: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
value: {
|
value: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
press: {
|
press: {
|
||||||
key: {
|
key: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
modifiers: [],
|
modifiers: [],
|
||||||
},
|
},
|
||||||
paste: {
|
paste: {
|
||||||
text: {
|
text: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
screenshot: {
|
screenshot: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
rect: { x: 0, y: 0, width: 0, height: 0 },
|
rect: { x: 0, y: 0, width: 0, height: 0 },
|
||||||
savePath: {
|
savePath: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pdf: {
|
pdf: {
|
||||||
options: {
|
options: {
|
||||||
marginsType: 0,
|
marginsType: 0,
|
||||||
pageSize: "A4",
|
pageSize: "A4",
|
||||||
},
|
},
|
||||||
savePath: {
|
savePath: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
size: { width: 1280, height: 800 },
|
size: { width: 1280, height: 800 },
|
||||||
useragent: {
|
useragent: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
cookies: {
|
cookies: {
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setCookies: {
|
setCookies: {
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
removeCookies: {
|
removeCookies: {
|
||||||
name: {
|
name: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
clearCookies: {
|
clearCookies: {
|
||||||
url: {
|
url: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
evaluate: {
|
evaluate: {
|
||||||
function: "",
|
function: "",
|
||||||
params: [],
|
params: [],
|
||||||
},
|
},
|
||||||
when: {
|
when: {
|
||||||
condition: {
|
condition: newVarInputVal("var"),
|
||||||
value: "",
|
|
||||||
isString: false,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mousedown: {
|
mousedown: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mouseup: {
|
mouseup: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
file: {
|
file: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
value: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
check: {
|
check: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
checked: false,
|
checked: false,
|
||||||
},
|
},
|
||||||
focus: {
|
focus: {
|
||||||
selector: {
|
selector: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
scroll: {
|
scroll: {
|
||||||
target: {
|
target: newVarInputVal("str"),
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
},
|
},
|
||||||
download: {
|
download: {
|
||||||
url: {
|
url: newVarInputVal("str"),
|
||||||
value: "",
|
savePath: newVarInputVal("str"),
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
savePath: {
|
|
||||||
value: "",
|
|
||||||
isString: true,
|
|
||||||
__varInputVal__: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
// 运行参数
|
// 运行参数
|
||||||
run: defaultUBrowserRunConfigs,
|
run: defaultUBrowserRunConfigs,
|
||||||
|
41
src/js/composer/varInputValManager.js
Normal file
41
src/js/composer/varInputValManager.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* 创建一个 VariableInput 对象
|
||||||
|
* @param {string} type - 变量类型,默认为 "str"
|
||||||
|
* @param {string} val - 变量值
|
||||||
|
* @returns {Object} VariableInput 对象
|
||||||
|
*/
|
||||||
|
export const newVarInputVal = (type = "str", val = "") => {
|
||||||
|
if (typeof val !== "string") val = JSON.stringify(val);
|
||||||
|
return {
|
||||||
|
value: val,
|
||||||
|
isString: type === "str",
|
||||||
|
__varInputVal__: true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查一个对象是否是 VariableInput 对象
|
||||||
|
* @param {Object} val - 要检查的对象
|
||||||
|
* @returns {boolean} 是否是 VariableInput 对象
|
||||||
|
*/
|
||||||
|
export const isVarInputVal = (val) => {
|
||||||
|
return val && val.__varInputVal__;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个空的 VariableInput 对象
|
||||||
|
* @param {string} type - 变量类型,默认为 "str"
|
||||||
|
* @returns {Object} 空的 VariableInput 对象
|
||||||
|
*/
|
||||||
|
export const newEmptyVarInputVal = (type = "str") => {
|
||||||
|
return newVarInputVal(type, "");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理带有 __varInputVal__ 属性的对象
|
||||||
|
* @param {Object} argv 要处理的对象
|
||||||
|
* @returns {string} 处理后的字符串
|
||||||
|
*/
|
||||||
|
export const stringifyVarInputVal = (argv) => {
|
||||||
|
return argv.isString ? `"${argv.value}"` : argv.value;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user