diff --git a/plugin/lib/quickcomposer/data/index.js b/plugin/lib/quickcomposer/data/index.js
index c04a047..5a82893 100644
--- a/plugin/lib/quickcomposer/data/index.js
+++ b/plugin/lib/quickcomposer/data/index.js
@@ -4,6 +4,7 @@ const string = require("./string");
const crypto = require("./crypto");
const buffer = require("./buffer");
const zlib = require("./zlib");
+const random = require("./random");
module.exports = {
...encoder,
@@ -12,4 +13,5 @@ module.exports = {
...crypto,
buffer,
zlib,
+ random,
};
diff --git a/plugin/lib/quickcomposer/data/random.js b/plugin/lib/quickcomposer/data/random.js
new file mode 100644
index 0000000..0a335b6
--- /dev/null
+++ b/plugin/lib/quickcomposer/data/random.js
@@ -0,0 +1,23 @@
+const randomInt = (start, end) => {
+ return Math.round(Math.random() * (end - start) + start);
+};
+
+const random = (isInt = false, start, end) => {
+ if (!start && !end) {
+ return isInt ? randomInt(0, 1000000) : Math.random();
+ }
+
+ if (!end) {
+ end = Math.abs(randomInt(0, 1000000) - start);
+ }
+
+ if (!start) {
+ start = 0;
+ }
+
+ // 有start和end:返回区间随机数
+ const random = Math.random() * (end - start) + start;
+ return isInt ? Math.round(random) : random;
+};
+
+module.exports = random;
diff --git a/src/components/composer/MultiParams.vue b/src/components/composer/MultiParams.vue
index c3a365b..ed65fdf 100644
--- a/src/components/composer/MultiParams.vue
+++ b/src/components/composer/MultiParams.vue
@@ -45,6 +45,14 @@
:icon="item.icon"
/>
+
+
+
@@ -110,7 +118,10 @@ export default defineComponent({
this.updateModelValue(this.funcName, newArgvs);
},
generateCode(funcName, argvs) {
- const newArgvs = argvs.map((argv) => stringifyWithType(argv));
+ const newArgvs = argvs
+ .map((argv) => stringifyWithType(argv))
+ .filter((item) => item != null && item !== "");
+ console.log(newArgvs);
return `${funcName}(${newArgvs.join(",")})`;
},
parseCodeToArgvs(code) {
diff --git a/src/js/composer/commands/dataCommands.js b/src/js/composer/commands/dataCommands.js
index facf6ff..27e0dea 100644
--- a/src/js/composer/commands/dataCommands.js
+++ b/src/js/composer/commands/dataCommands.js
@@ -13,7 +13,6 @@ export const dataCommands = {
label: "要编解码的文本",
icon: "text_fields",
type: "varInput",
- width: 8,
},
],
functionSelector: {
@@ -60,7 +59,6 @@ export const dataCommands = {
icon: "html",
},
],
- width: 3,
},
},
{
@@ -83,7 +81,6 @@ export const dataCommands = {
label: "要计算哈希的文本",
icon: "text_fields",
type: "varInput",
- width: 8,
},
],
functionSelector: {
@@ -116,7 +113,118 @@ export const dataCommands = {
},
],
},
- width: 3,
+ },
+ {
+ value: "Math",
+ label: "数学计算",
+ desc: "数学函数计算",
+ icon: "calculate",
+ config: [
+ {
+ label: "要计算的数值",
+ icon: "numbers",
+ type: "numInput",
+ },
+ ],
+ functionSelector: {
+ selectLabel: "计算方式",
+ options: [
+ {
+ label: "正弦(sin)",
+ value: "Math.sin",
+ icon: "functions",
+ },
+ {
+ label: "余弦(cos)",
+ value: "Math.cos",
+ icon: "functions",
+ },
+ {
+ label: "正切(tan)",
+ value: "Math.tan",
+ icon: "functions",
+ },
+ {
+ label: "反正弦(asin)",
+ value: "Math.asin",
+ icon: "functions",
+ },
+ {
+ label: "反余弦(acos)",
+ value: "Math.acos",
+ icon: "functions",
+ },
+ {
+ label: "反正切(atan)",
+ value: "Math.atan",
+ icon: "functions",
+ },
+ {
+ label: "平方根(sqrt)",
+ value: "Math.sqrt",
+ icon: "functions",
+ },
+ {
+ label: "自然对数(ln)",
+ value: "Math.log",
+ icon: "functions",
+ },
+ {
+ label: "10对数(log10)",
+ value: "Math.log10",
+ icon: "functions",
+ },
+ {
+ label: "绝对值(abs)",
+ value: "Math.abs",
+ icon: "functions",
+ },
+ {
+ label: "向上取整(ceil)",
+ value: "Math.ceil",
+ icon: "functions",
+ },
+ {
+ label: "向下取整(floor)",
+ value: "Math.floor",
+ icon: "functions",
+ },
+ {
+ label: "四舍五入(round)",
+ value: "Math.round",
+ icon: "functions",
+ },
+ {
+ label: "幂运算(pow)",
+ value: "Math.pow",
+ icon: "functions",
+ },
+ ],
+ },
+ },
+ {
+ value: "quickcomposer.data.random",
+ label: "随机数",
+ config: [
+ {
+ label: "整数",
+ type: "switch",
+ defaultValue: false,
+ width: 1,
+ },
+ {
+ label: "起始值",
+ icon: "last_page",
+ type: "numInput",
+ width: 10,
+ },
+ {
+ label: "结束值",
+ icon: "first_page",
+ type: "numInput",
+ width: 10,
+ },
+ ],
},
{
value: "quickcomposer.data.reverseString",