mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
新增数学计算和随机数
This commit is contained in:
parent
38617df03c
commit
cb85aaa790
@ -4,6 +4,7 @@ const string = require("./string");
|
|||||||
const crypto = require("./crypto");
|
const crypto = require("./crypto");
|
||||||
const buffer = require("./buffer");
|
const buffer = require("./buffer");
|
||||||
const zlib = require("./zlib");
|
const zlib = require("./zlib");
|
||||||
|
const random = require("./random");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...encoder,
|
...encoder,
|
||||||
@ -12,4 +13,5 @@ module.exports = {
|
|||||||
...crypto,
|
...crypto,
|
||||||
buffer,
|
buffer,
|
||||||
zlib,
|
zlib,
|
||||||
|
random,
|
||||||
};
|
};
|
||||||
|
23
plugin/lib/quickcomposer/data/random.js
Normal file
23
plugin/lib/quickcomposer/data/random.js
Normal file
@ -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;
|
@ -45,6 +45,14 @@
|
|||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else-if="item.type === 'switch'">
|
||||||
|
<q-toggle
|
||||||
|
:model-value="argvs[index]"
|
||||||
|
@update:model-value="updateArgv(index, $event)"
|
||||||
|
:label="item.label"
|
||||||
|
:icon="item.icon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -110,7 +118,10 @@ export default defineComponent({
|
|||||||
this.updateModelValue(this.funcName, newArgvs);
|
this.updateModelValue(this.funcName, newArgvs);
|
||||||
},
|
},
|
||||||
generateCode(funcName, argvs) {
|
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(",")})`;
|
return `${funcName}(${newArgvs.join(",")})`;
|
||||||
},
|
},
|
||||||
parseCodeToArgvs(code) {
|
parseCodeToArgvs(code) {
|
||||||
|
@ -13,7 +13,6 @@ export const dataCommands = {
|
|||||||
label: "要编解码的文本",
|
label: "要编解码的文本",
|
||||||
icon: "text_fields",
|
icon: "text_fields",
|
||||||
type: "varInput",
|
type: "varInput",
|
||||||
width: 8,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
functionSelector: {
|
functionSelector: {
|
||||||
@ -60,7 +59,6 @@ export const dataCommands = {
|
|||||||
icon: "html",
|
icon: "html",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
width: 3,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -83,7 +81,6 @@ export const dataCommands = {
|
|||||||
label: "要计算哈希的文本",
|
label: "要计算哈希的文本",
|
||||||
icon: "text_fields",
|
icon: "text_fields",
|
||||||
type: "varInput",
|
type: "varInput",
|
||||||
width: 8,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
functionSelector: {
|
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",
|
value: "quickcomposer.data.reverseString",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user