mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 06:16:27 +08:00
将唯一ID生成功能提取到单独的具模块中
This commit is contained in:
parent
1a95259aef
commit
039a820952
@ -252,13 +252,6 @@ export default defineComponent({
|
|||||||
.padStart(2, "0")
|
.padStart(2, "0")
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getUniqueId() {
|
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
||||||
const r = (Math.random() * 16) | 0;
|
|
||||||
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// 监听 glassEffect 值变化
|
// 监听 glassEffect 值变化
|
||||||
|
@ -63,6 +63,7 @@ import ComposerCard from "./ComposerCard.vue";
|
|||||||
import ChainStyles from "./flow/ChainStyles.vue";
|
import ChainStyles from "./flow/ChainStyles.vue";
|
||||||
import DropArea from "./flow/DropArea.vue";
|
import DropArea from "./flow/DropArea.vue";
|
||||||
import { findCommandByValue } from "js/composer/composerConfig";
|
import { findCommandByValue } from "js/composer/composerConfig";
|
||||||
|
import { getUniqueId } from "js/common/uuid";
|
||||||
|
|
||||||
// 拖拽前的命令列表,非响应式
|
// 拖拽前的命令列表,非响应式
|
||||||
let commandsBeforeDrag = [];
|
let commandsBeforeDrag = [];
|
||||||
@ -262,7 +263,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 处理链式命令
|
// 处理链式命令
|
||||||
const chainId = this.getUniqueId();
|
const chainId = getUniqueId();
|
||||||
let insertIndex =
|
let insertIndex =
|
||||||
this.dragIndex >= 0 ? this.dragIndex : newCommands.length;
|
this.dragIndex >= 0 ? this.dragIndex : newCommands.length;
|
||||||
|
|
||||||
@ -270,7 +271,7 @@ export default defineComponent({
|
|||||||
for (const commandType of commandChain) {
|
for (const commandType of commandChain) {
|
||||||
const commandItem = {
|
const commandItem = {
|
||||||
...newCommand,
|
...newCommand,
|
||||||
id: this.getUniqueId(),
|
id: getUniqueId(),
|
||||||
commandType,
|
commandType,
|
||||||
chainId,
|
chainId,
|
||||||
};
|
};
|
||||||
@ -286,13 +287,10 @@ export default defineComponent({
|
|||||||
createNewCommand(parsedAction) {
|
createNewCommand(parsedAction) {
|
||||||
const newCommand = {
|
const newCommand = {
|
||||||
...parsedAction,
|
...parsedAction,
|
||||||
id: this.getUniqueId(),
|
id: getUniqueId(),
|
||||||
};
|
};
|
||||||
return newCommand;
|
return newCommand;
|
||||||
},
|
},
|
||||||
getUniqueId() {
|
|
||||||
return this.$root.getUniqueId();
|
|
||||||
},
|
|
||||||
isFirstCommandInChain(command) {
|
isFirstCommandInChain(command) {
|
||||||
if (!command.commandChain) return false;
|
if (!command.commandChain) return false;
|
||||||
return command.commandType === command.commandChain?.[0];
|
return command.commandType === command.commandChain?.[0];
|
||||||
@ -347,7 +345,7 @@ export default defineComponent({
|
|||||||
const newCommands = [...this.commands];
|
const newCommands = [...this.commands];
|
||||||
const branchCommand = {
|
const branchCommand = {
|
||||||
...window.lodashM.cloneDeep(findCommandByValue(value)),
|
...window.lodashM.cloneDeep(findCommandByValue(value)),
|
||||||
id: this.getUniqueId(),
|
id: getUniqueId(),
|
||||||
chainId: chainId,
|
chainId: chainId,
|
||||||
commandType: commandType,
|
commandType: commandType,
|
||||||
};
|
};
|
||||||
@ -409,12 +407,12 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
copyCommands(commands) {
|
copyCommands(commands) {
|
||||||
// 生成新的chainId
|
// 生成新的chainId
|
||||||
const newChainId = this.getUniqueId();
|
const newChainId = getUniqueId();
|
||||||
// 复制并修改每个命令
|
// 复制并修改每个命令
|
||||||
const newCommands = [];
|
const newCommands = [];
|
||||||
commands.forEach((cmd) => {
|
commands.forEach((cmd) => {
|
||||||
const copiedCommand = window.lodashM.cloneDeep(cmd);
|
const copiedCommand = window.lodashM.cloneDeep(cmd);
|
||||||
copiedCommand.id = this.getUniqueId();
|
copiedCommand.id = getUniqueId();
|
||||||
if (copiedCommand.chainId) copiedCommand.chainId = newChainId;
|
if (copiedCommand.chainId) copiedCommand.chainId = newChainId;
|
||||||
newCommands.push(copiedCommand);
|
newCommands.push(copiedCommand);
|
||||||
});
|
});
|
||||||
@ -439,7 +437,7 @@ export default defineComponent({
|
|||||||
// 单个命令的复制逻辑
|
// 单个命令的复制逻辑
|
||||||
const newCommand = {
|
const newCommand = {
|
||||||
...command,
|
...command,
|
||||||
id: this.getUniqueId(),
|
id: getUniqueId(),
|
||||||
};
|
};
|
||||||
const newCommands = [...this.commands];
|
const newCommands = [...this.commands];
|
||||||
newCommands.splice(index + 1, 0, newCommand);
|
newCommands.splice(index + 1, 0, newCommand);
|
||||||
|
@ -102,6 +102,7 @@ import FlowManager from "components/composer/flow/FlowManager.vue";
|
|||||||
import { generateCode } from "js/composer/generateCode";
|
import { generateCode } from "js/composer/generateCode";
|
||||||
import { findCommandByValue } from "js/composer/composerConfig";
|
import { findCommandByValue } from "js/composer/composerConfig";
|
||||||
import { generateUniqSuffix } from "js/composer/variableManager";
|
import { generateUniqSuffix } from "js/composer/variableManager";
|
||||||
|
import { getUniqueId } from "js/common/uuid";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "FlowTabs",
|
name: "FlowTabs",
|
||||||
components: {
|
components: {
|
||||||
@ -228,7 +229,7 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
addFlow(options = {}) {
|
addFlow(options = {}) {
|
||||||
const id = this.$root.getUniqueId();
|
const id = getUniqueId();
|
||||||
const name = options.name || this.generateFlowName();
|
const name = options.name || this.generateFlowName();
|
||||||
const newFlow = {
|
const newFlow = {
|
||||||
id,
|
id,
|
||||||
|
7
src/js/common/uuid.js
Normal file
7
src/js/common/uuid.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export const getUniqueId = () => {
|
||||||
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
||||||
|
const r = (Math.random() * 16) | 0;
|
||||||
|
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
||||||
|
return v.toString(16);
|
||||||
|
});
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user