统一VarInput变量的管理

This commit is contained in:
fofolee
2025-01-08 14:39:08 +08:00
parent b528cfa97d
commit 7a43695e2d
24 changed files with 190 additions and 516 deletions

View File

@@ -15,6 +15,7 @@ import { defineComponent } from "vue";
import OperationCard from "components/composer/common/OperationCard.vue";
import ParamInput from "components/composer/common/ParamInput.vue";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "MultiParams",
@@ -52,11 +53,7 @@ export default defineComponent({
return [...this.commonConfig, ...this.functionConfig].map((item) => {
const value =
item.type === "varInput"
? item.defaultValue || {
value: "",
isString: true,
__varInputVal__: true,
}
? item.defaultValue || newVarInputVal("str")
: // 其他类型情况复杂不做判断没有默认值返回undefined
item.defaultValue;
return {

View File

@@ -94,35 +94,30 @@
* @example
* // 基础数组
* [
* {
* value: "张三",
* isString: true,
* __varInputVal__: true
* }
* newVarInputVal("str", "张三")
* ]
*
* // 多键对象数组
* options.keys = ['name', 'age', 'email']
* [
* {
* name: { value: "张三", isString: true, __varInputVal__: true },
* age: { value: "18", isString: false, __varInputVal__: true },
* email: { value: "zhangsan@example.com", isString: true, __varInputVal__: true }
* name: newVarInputVal("str", "张三"),
* age: newVarInputVal("str", "18"),
* email: newVarInputVal("str", "zhangsan@example.com")
* }
* ]
*
* // 下拉选择模式
* options.items = ['选项1', '选项2', '选项3']
* [
* {
* value: "选项1",
* isString: true,
* __varInputVal__: true
* }
* newVarInputVal("str", "选项1"),
* newVarInputVal("str", "选项2"),
* newVarInputVal("str", "选项3")
* ]
*/
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "ArrayEditor",
@@ -169,22 +164,12 @@ export default defineComponent({
if (this.optionsKeys?.length) {
const item = {};
this.optionsKeys.forEach((key) => {
item[key] = {
value: "",
isString: true,
__varInputVal__: true,
};
item[key] = newVarInputVal("str");
});
return [item];
}
return [
{
value: "",
isString: true,
__varInputVal__: true,
},
];
return [newVarInputVal("str")];
},
/**
* 添加新的数组项
@@ -195,22 +180,11 @@ export default defineComponent({
if (this.options.keys) {
const newItem = {};
this.options.keys.forEach((key) => {
newItem[key] = {
value: "",
isString: true,
__varInputVal__: true,
};
newItem[key] = newVarInputVal("str");
});
newItems = [...this.items, newItem];
} else {
newItems = [
...this.items,
{
value: "",
isString: true,
__varInputVal__: true,
},
];
newItems = [...this.items, newVarInputVal("str")];
}
this.$emit("update:modelValue", newItems);
},
@@ -225,19 +199,11 @@ export default defineComponent({
if (this.options.keys) {
const newItem = {};
this.options.keys.forEach((key) => {
newItem[key] = {
value: "",
isString: true,
__varInputVal__: true,
};
newItem[key] = newVarInputVal("str");
});
newItems.push(newItem);
} else {
newItems.push({
value: "",
isString: true,
__varInputVal__: true,
});
newItems.push(newVarInputVal("str"));
}
}
this.$emit("update:modelValue", newItems);

View File

@@ -95,6 +95,7 @@
<script>
import { defineComponent } from "vue";
import { newVarInputVal } from "js/composer/varInputValManager";
import VariableInput from "components/composer/common/VariableInput.vue";
/**
@@ -108,21 +109,15 @@ import VariableInput from "components/composer/common/VariableInput.vue";
* @example
* // 基础字典对象
* {
* key: {
* value: "", // 输入框的值
* isString: true, // 是否是字符串
* __varInputVal__: true // 用于标识是变量输入框
* }
* key: newVarInputVal("str"),
* }
*
* // 下拉选择模式
* options.items = ['User-Agent', 'Content-Type', 'Accept']
* {
* "User-Agent": {
* value: "Mozilla/5.0",
* isString: true,
* __varInputVal__: true
* }
* "User-Agent": newVarInputVal("str", "Mozilla/5.0"),
* "Content-Type": newVarInputVal("str", "text/html"),
* "Accept": newVarInputVal("str", "text/html")
* }
*/
export default defineComponent({
@@ -149,11 +144,7 @@ export default defineComponent({
: [
{
key: "",
value: {
value: "",
isString: true,
__varInputVal__: true,
},
value: newVarInputVal("str"),
},
],
filterOptions: this.options?.items || [],
@@ -183,7 +174,7 @@ export default defineComponent({
...this.items,
{
key: "",
value: { value: "", isString: true, __varInputVal__: true },
value: newVarInputVal("str"),
},
];
},
@@ -193,7 +184,7 @@ export default defineComponent({
if (newItems.length === 0) {
newItems.push({
key: "",
value: { value: "", isString: true, __varInputVal__: true },
value: newVarInputVal("str"),
});
}
this.items = newItems;

View File

@@ -138,7 +138,7 @@
<script>
import { defineComponent, inject } from "vue";
import { newVarInputVal } from "js/composer/varInputValManager";
/**
* 变量输入框组件
* @description 支持变量选择和字符串输入的输入框组件
@@ -179,11 +179,7 @@ export default defineComponent({
modelValue: {
type: Object,
required: true,
default: () => ({
value: "",
isString: true,
__varInputVal__: true,
}),
default: () => newVarInputVal("str"),
},
label: String,
icon: String,
@@ -265,22 +261,14 @@ export default defineComponent({
insertVariable(variable) {
this.selectedVariable = variable;
this.isString = false; // 变量模式下不需要字符串处理
this.$emit("update:modelValue", {
isString: false,
value: variable.name,
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("var", variable.name));
},
// 清除变量时的处理
clearVariable() {
this.selectedVariable = null;
this.isString = true; // 恢复到字符串模式
this.$emit("update:modelValue", {
isString: true,
value: "",
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("str"));
},
// 切换类型
@@ -301,11 +289,7 @@ export default defineComponent({
selectItem(option) {
const value = this.getItemValue(option);
this.$emit("update:modelValue", {
value,
isString: true,
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("str", value));
},
escapePath(paths) {
if (!paths) return null;
@@ -319,26 +303,14 @@ export default defineComponent({
const files = this.escapePath(utools.showOpenDialog(options));
if (!files) return;
if (files.length > 1) {
this.$emit("update:modelValue", {
value: files,
isString: false,
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("var", files));
} else if (files.length === 1) {
this.$emit("update:modelValue", {
value: files[0],
isString: true,
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("str", files[0]));
}
} else {
const file = this.escapePath(utools.showSaveDialog(options));
if (!file) return;
this.$emit("update:modelValue", {
value: file,
isString: true,
__varInputVal__: true,
});
this.$emit("update:modelValue", newVarInputVal("str", file));
}
},
},

View File

@@ -186,7 +186,7 @@
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "AsymmetricCryptoEditor",
components: {
@@ -200,11 +200,7 @@ export default defineComponent({
return {
defaultArgvs: {
operation: "encrypt",
text: {
value: "",
isString: true,
__varInputVal__: true,
},
text: newVarInputVal("str"),
algorithm: "RSA",
keyLength: 1024,
padding: "RSAES-PKCS1-V1_5",

View File

@@ -186,6 +186,7 @@
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "SymmetricCryptoEditor",
@@ -200,11 +201,7 @@ export default defineComponent({
return {
defaultArgvs: {
operation: "encrypt",
text: {
value: "",
isString: true,
__varInputVal__: true,
},
text: newVarInputVal("str"),
algorithm: "AES",
keyLength: 128,
mode: "CBC",

View File

@@ -132,6 +132,8 @@ import { stringifyArgv, parseFunction } from "js/composer/formatString";
import VariableInput from "components/composer/common/VariableInput.vue";
import NumberInput from "components/composer/common/NumberInput.vue";
import OperationCard from "components/composer/common/OperationCard.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "ZlibEditor",
components: {
@@ -188,11 +190,7 @@ export default defineComponent({
defaultArgvs: {
operation: "compressData",
method: "gzip",
data: {
value: "",
isString: true,
__varInputVal__: true,
},
data: newVarInputVal("str"),
options: {
level: -1,
memLevel: 8,

View File

@@ -98,6 +98,7 @@ import RegexInput from "./RegexInput.vue";
import RegexBuilder from "./RegexBuilder.vue";
import RegexTester from "./RegexTester.vue";
import { parseToHasType } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "RegexEditor",
@@ -122,17 +123,9 @@ export default defineComponent({
},
showBuilder: false,
defaultArgvs: {
textValue: {
value: "",
isString: true,
__varInputVal__: true,
},
textValue: newVarInputVal("str"),
regexValue: "",
replaceValue: {
value: "",
isString: true,
__varInputVal__: true,
},
replaceValue: newVarInputVal("str"),
isReplace: false,
flags: {
ignoreCase: false,

View File

@@ -43,17 +43,14 @@
<script>
import { defineComponent } from "vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "RegexTester",
props: {
text: {
type: Object,
default: () => ({
value: "",
isString: false,
__varInputVal__: true,
}),
default: () => newVarInputVal("var"),
},
regex: {
type: String,
@@ -65,11 +62,7 @@ export default defineComponent({
},
replace: {
type: Object,
default: () => ({
value: "",
isString: false,
__varInputVal__: true,
}),
default: () => newVarInputVal("var"),
},
isReplace: {
type: Boolean,

View File

@@ -383,6 +383,7 @@ import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import NumberInput from "components/composer/common/NumberInput.vue";
import { stringifyArgv, parseFunction } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
// 静态选项数据
const ENCODING_OPTIONS = [
@@ -463,11 +464,7 @@ export default defineComponent({
manageOperationOptions: MANAGE_OPERATION_OPTIONS,
defaultArgvs: {
operation: "read",
filePath: {
value: "",
isString: true,
__varInputVal__: true,
},
filePath: newVarInputVal("str"),
encoding: "utf8",
readMode: "all",
readFlag: "async",

View File

@@ -162,6 +162,7 @@ import {
methods,
responseTypes,
} from "js/options/httpOptions";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "AxiosConfigEditor",
@@ -187,18 +188,10 @@ export default defineComponent({
.map((h) => h.value),
activeTab: "headers",
defaultArgvs: {
url: {
value: "",
isString: true,
__varInputVal__: true,
},
url: newVarInputVal("str"),
method: "GET",
headers: {
"User-Agent": {
value: userAgent[0].value,
isString: true,
__varInputVal__: true,
},
"User-Agent": newVarInputVal("str", userAgent[0].value),
"Content-Type": contentTypes[0].value,
},
otherHeaders: {},
@@ -208,36 +201,16 @@ export default defineComponent({
maxRedirects: 5,
responseType: "json",
auth: {
username: {
value: "",
isString: true,
__varInputVal__: true,
},
password: {
value: "",
isString: true,
__varInputVal__: true,
},
username: newVarInputVal("str"),
password: newVarInputVal("str"),
},
proxy: {
host: {
value: "",
isString: true,
__varInputVal__: true,
},
port: null,
auth: {
username: {
value: "",
isString: true,
__varInputVal__: true,
},
password: {
value: "",
isString: true,
__varInputVal__: true,
},
},
},
proxy: {
host: newVarInputVal("str"),
port: null,
auth: {
username: newVarInputVal("str"),
password: newVarInputVal("str"),
},
},
commonPanels: [
@@ -483,9 +456,7 @@ export default defineComponent({
const formattedHeaders = Object.entries(headers).reduce(
(acc, [key, value]) => {
acc[key] =
typeof value === "string"
? { value, isString: true, __varInputVal__: true }
: value;
typeof value === "string" ? newVarInputVal("str", value) : value;
return acc;
},
{}
@@ -501,11 +472,7 @@ export default defineComponent({
this.updateArgvs("headers", newHeaders);
},
setUserAgent(value) {
this.updateArgvs("headers.User-Agent", {
value,
isString: true,
__varInputVal__: true,
});
this.updateArgvs("headers.User-Agent", newVarInputVal("str", value));
},
getFieldValue(path) {
return path.split(".").reduce((obj, key) => obj?.[key], this.argvs);

View File

@@ -132,6 +132,7 @@
<script>
import { defineComponent } from "vue";
import { parseFunction, stringifyArgv } from "js/composer/formatString";
import { newVarInputVal } from "js/composer/varInputValManager";
import VariableInput from "components/composer/common/VariableInput.vue";
import NumberInput from "components/composer/common/NumberInput.vue";
import DictEditor from "components/composer/common/DictEditor.vue";
@@ -164,30 +165,18 @@ export default defineComponent({
{ label: "Base64", value: "base64" },
],
defaultArgvs: {
command: {
value: "",
isString: true,
__varInputVal__: true,
command: newVarInputVal("str"),
},
options: {
cwd: {
value: "",
isString: true,
__varInputVal__: true,
},
cwd: newVarInputVal("str"),
env: {},
autoEncoding: true,
encoding: "buffer",
timeout: 0,
maxBuffer: 1024 * 1024, // 1MB
shell: {
value: "",
isString: true,
__varInputVal__: true,
},
windowsHide: true,
},
},
shell: newVarInputVal("str"),
windowsHide: true,
},
};
},
computed: {

View File

@@ -71,7 +71,7 @@ import { defineComponent, ref, computed } from "vue";
import { userAgent } from "js/options/httpOptions";
import VariableInput from "components/composer/common/VariableInput.vue";
import NumberInput from "components/composer/common/NumberInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "UBrowserBasic",
components: {
@@ -109,11 +109,7 @@ export default defineComponent({
if (!newConfigs.goto.headers) {
newConfigs.goto.headers = {};
}
newConfigs.goto.headers.userAgent = {
value: val,
isString: true,
__varInputVal__: true,
};
newConfigs.goto.headers.userAgent = newVarInputVal("str", val);
emit("update:configs", newConfigs);
selectedUA.value = null;
};

View File

@@ -55,7 +55,7 @@
<script>
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "UBrowserCookieList",
components: {
@@ -66,16 +66,8 @@ export default defineComponent({
type: Array,
default: () => [
{
name: {
value: "",
isString: true,
__varInputVal__: true,
},
value: {
value: "",
isString: true,
__varInputVal__: true,
},
name: newVarInputVal("str"),
value: newVarInputVal("str"),
},
],
},
@@ -86,16 +78,8 @@ export default defineComponent({
const newValue = [
...this.modelValue,
{
name: {
value: "",
isString: true,
__varInputVal__: true,
},
value: {
value: "",
isString: true,
__varInputVal__: true,
},
name: newVarInputVal("str"),
value: newVarInputVal("str"),
},
];
this.$emit("update:modelValue", newValue);
@@ -105,16 +89,8 @@ export default defineComponent({
newValue.splice(index, 1);
if (newValue.length === 0) {
newValue.push({
name: {
value: "",
isString: true,
__varInputVal__: true,
},
value: {
value: "",
isString: true,
__varInputVal__: true,
},
name: newVarInputVal("str"),
value: newVarInputVal("str"),
});
}
this.$emit("update:modelValue", newValue);

View File

@@ -33,7 +33,7 @@
import { defineComponent } from "vue";
import { deviceName } from "js/options/httpOptions";
import VariableInput from "components/composer/common/VariableInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "UBrowserDeviceName",
components: {
@@ -42,11 +42,7 @@ export default defineComponent({
props: {
modelValue: {
type: Object,
default: () => ({
value: "",
isString: true,
__varInputVal__: true,
}),
default: () => newVarInputVal("str"),
},
label: {
type: String,

View File

@@ -43,7 +43,7 @@
<script>
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "UBrowserFileList",
components: {
@@ -60,11 +60,7 @@ export default defineComponent({
addFile() {
const newValue = [
...(this.modelValue || []),
{
value: "",
isString: true,
__varInputVal__: true,
},
newVarInputVal("str"),
];
this.$emit("update:modelValue", newValue);
},

View File

@@ -47,7 +47,7 @@
<script>
import { defineComponent } from "vue";
import VariableInput from "components/composer/common/VariableInput.vue";
import { newVarInputVal } from "js/composer/varInputValManager";
export default defineComponent({
name: "UBrowserNamedParamList",
components: {
@@ -56,20 +56,7 @@ export default defineComponent({
props: {
modelValue: {
type: Array,
default: () => [
{
name: {
value: "",
isString: true,
__varInputVal__: true,
},
value: {
value: "",
isString: true,
__varInputVal__: true,
},
},
],
default: () => [newVarInputVal("str"), newVarInputVal("str")],
},
label: String,
},
@@ -79,16 +66,8 @@ export default defineComponent({
const newValue = [
...(this.modelValue || []),
{
name: {
value: "",
isString: true,
__varInputVal__: true,
},
value: {
value: "",
isString: true,
__varInputVal__: true,
},
name: newVarInputVal("str"),
value: newVarInputVal("str"),
},
];
this.$emit("update:modelValue", newValue);

View File

@@ -178,15 +178,8 @@ import VariableInput from "../common/VariableInput.vue";
import ArrayEditor from "../common/ArrayEditor.vue";
import OperationCard from "../common/OperationCard.vue";
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) => ({
id: newVarInputVal("var", index),
@@ -228,11 +221,7 @@ export default defineComponent({
inputMode: "manual",
selects: defaultSelects.json,
optionType: "json",
placeholder: {
value: "搜索...",
isString: true,
__varInputVal__: true,
},
placeholder: newVarInputVal("str", "搜索..."),
enableSearch: true,
showCancelButton: false,
closeOnSelect: true,
@@ -303,7 +292,7 @@ export default defineComponent({
if (!result) return this.defaultArgvs;
const [selects, options = {}] = result.argvs;
const inputMode = selects.__varInputVal__ ? "variable" : "manual";
const inputMode = isVarInputVal(selects) ? "variable" : "manual";
return {
...this.defaultArgvs,
inputMode,