mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-07-19 01:09:49 +08:00
优化控制流命令的禁用效果
This commit is contained in:
parent
7a224be9f4
commit
7d67ef9ae6
@ -15,14 +15,15 @@
|
|||||||
}"
|
}"
|
||||||
@click.stop="handleToggleDisable"
|
@click.stop="handleToggleDisable"
|
||||||
>
|
>
|
||||||
<div
|
<div class="enable-btn-wrapper row items-center text-primary">
|
||||||
class="enable-btn-wrapper row items-center text-primary"
|
<q-icon
|
||||||
:style="{
|
name="layers"
|
||||||
fontSize: localCommand.isCollapsed ? '12px' : '16px',
|
class="q-mr-sm"
|
||||||
}"
|
:size="localCommand.isCollapsed ? '14px' : '18px'"
|
||||||
>
|
/>
|
||||||
<q-icon name="layers" class="q-mr-sm" />
|
<div :style="{ fontSize: localCommand.isCollapsed ? '12px' : '15px' }">
|
||||||
<div>点击启用</div>
|
点击启用
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-card class="command-item">
|
<q-card class="command-item">
|
||||||
@ -125,7 +126,7 @@ export default defineComponent({
|
|||||||
"toggle-collapse",
|
"toggle-collapse",
|
||||||
"update:modelValue",
|
"update:modelValue",
|
||||||
"add-command",
|
"add-command",
|
||||||
"toggle-disable",
|
"toggle-chain-disable",
|
||||||
],
|
],
|
||||||
computed: {
|
computed: {
|
||||||
localCommand: {
|
localCommand: {
|
||||||
@ -221,13 +222,8 @@ export default defineComponent({
|
|||||||
handleToggleDisable() {
|
handleToggleDisable() {
|
||||||
if (!this.canToggleDisable) return;
|
if (!this.canToggleDisable) return;
|
||||||
if (this.localCommand.isControlFlow && this.localCommand.chainId) {
|
if (this.localCommand.isControlFlow && this.localCommand.chainId) {
|
||||||
console.log(
|
|
||||||
"handleToggleDisable card",
|
|
||||||
this.localCommand.isControlFlow,
|
|
||||||
this.localCommand.chainId
|
|
||||||
);
|
|
||||||
// 如果是控制流程命令,通知父组件切换整个链的禁用状态
|
// 如果是控制流程命令,通知父组件切换整个链的禁用状态
|
||||||
this.$emit("toggle-disable", {
|
this.$emit("toggle-chain-disable", {
|
||||||
chainId: this.localCommand.chainId,
|
chainId: this.localCommand.chainId,
|
||||||
disabled: !this.localCommand.disabled,
|
disabled: !this.localCommand.disabled,
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
@add-branch="addBranch"
|
@add-branch="addBranch"
|
||||||
@toggle-collapse="(event) => handleControlFlowCollapse(event)"
|
@toggle-collapse="(event) => handleControlFlowCollapse(event)"
|
||||||
@add-command="(event) => handleAddCommand(event, index)"
|
@add-command="(event) => handleAddCommand(event, index)"
|
||||||
@toggle-disable="handleToggleDisable"
|
@toggle-chain-disable="handleToggleChainDisable"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
@ -311,17 +311,11 @@ export default defineComponent({
|
|||||||
.showButtonBox(["全部删除", "保留内部命令", "手抖👋🏻"])
|
.showButtonBox(["全部删除", "保留内部命令", "手抖👋🏻"])
|
||||||
.then(({ id }) => {
|
.then(({ id }) => {
|
||||||
if (id !== 0 && id !== 1) return;
|
if (id !== 0 && id !== 1) return;
|
||||||
const newCommands = [...this.commands];
|
|
||||||
const chainId = command.chainId;
|
const chainId = command.chainId;
|
||||||
const lastIndex = newCommands.findLastIndex(
|
const { startIndex, endIndex } = this.getChainIndex(chainId);
|
||||||
(cmd) => cmd.chainId === chainId
|
|
||||||
);
|
|
||||||
const startIndex = newCommands.findIndex(
|
|
||||||
(cmd) => cmd.chainId === chainId
|
|
||||||
);
|
|
||||||
this.removeRangeCommand(
|
this.removeRangeCommand(
|
||||||
startIndex,
|
startIndex,
|
||||||
lastIndex,
|
endIndex,
|
||||||
id === 0 ? null : chainId
|
id === 0 ? null : chainId
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -362,13 +356,11 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 找到对应的 chainId 的最后一个命令位置
|
// 找到对应的 chainId 的最后一个命令位置
|
||||||
const lastIndex = newCommands.findLastIndex(
|
const { endIndex } = this.getChainIndex(chainId);
|
||||||
(cmd) => cmd.chainId === chainId
|
|
||||||
);
|
|
||||||
|
|
||||||
// 在最后一个命令之前插入新的分支命令
|
// 在最后一个命令之前插入新的分支命令
|
||||||
if (lastIndex !== -1) {
|
if (endIndex !== -1) {
|
||||||
newCommands.splice(lastIndex, 0, branchCommand);
|
newCommands.splice(endIndex, 0, branchCommand);
|
||||||
this.$emit("update:modelValue", newCommands);
|
this.$emit("update:modelValue", newCommands);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -378,12 +370,7 @@ export default defineComponent({
|
|||||||
if (!chainId) return;
|
if (!chainId) return;
|
||||||
|
|
||||||
// 遍历commands找到相同chainId的第一个和最后一个命令的index
|
// 遍历commands找到相同chainId的第一个和最后一个命令的index
|
||||||
const startIndex = this.commands.findIndex(
|
const { startIndex, endIndex } = this.getChainIndex(chainId);
|
||||||
(cmd) => cmd.chainId === chainId
|
|
||||||
);
|
|
||||||
const endIndex = this.commands.findLastIndex(
|
|
||||||
(cmd) => cmd.chainId === chainId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (startIndex === -1 || endIndex === -1) return;
|
if (startIndex === -1 || endIndex === -1) return;
|
||||||
|
|
||||||
@ -437,39 +424,34 @@ export default defineComponent({
|
|||||||
this.$emit("action", action, payload);
|
this.$emit("action", action, payload);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getChainCommands(chainId) {
|
getChainIndex(chainId) {
|
||||||
const startIndex = this.commands.findIndex(
|
const startIndex = this.commands.findIndex(
|
||||||
(cmd) => cmd.chainId === chainId
|
(cmd) => cmd.chainId === chainId
|
||||||
);
|
);
|
||||||
const endIndex = this.commands.findLastIndex(
|
const endIndex = this.commands.findLastIndex(
|
||||||
(cmd) => cmd.chainId === chainId
|
(cmd) => cmd.chainId === chainId
|
||||||
);
|
);
|
||||||
return {
|
return { startIndex, endIndex };
|
||||||
chainCommands: this.commands.slice(startIndex, endIndex + 1),
|
|
||||||
startIndex,
|
|
||||||
endIndex,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
copyChainCommands(chainCommands) {
|
copyCommands(commands) {
|
||||||
// 生成新的chainId
|
// 生成新的chainId
|
||||||
const newChainId = this.$root.getUniqueId();
|
const newChainId = this.getUniqueId();
|
||||||
// 复制并修改每个命令
|
// 复制并修改每个命令
|
||||||
const newChainCommands = [];
|
const newCommands = [];
|
||||||
chainCommands.forEach((cmd) => {
|
commands.forEach((cmd) => {
|
||||||
const copiedCommand = window.lodashM.cloneDeep(cmd);
|
const copiedCommand = window.lodashM.cloneDeep(cmd);
|
||||||
copiedCommand.id = this.$root.getUniqueId();
|
copiedCommand.id = this.getUniqueId();
|
||||||
if (copiedCommand.chainId) copiedCommand.chainId = newChainId;
|
if (copiedCommand.chainId) copiedCommand.chainId = newChainId;
|
||||||
newChainCommands.push(copiedCommand);
|
newCommands.push(copiedCommand);
|
||||||
});
|
});
|
||||||
return newChainCommands;
|
return newCommands;
|
||||||
},
|
},
|
||||||
handleAddCommand({ command, type }, index) {
|
handleAddCommand({ command, type }, index) {
|
||||||
if (type === "chain") {
|
if (type === "chain") {
|
||||||
// 如果是复制链式命令
|
// 如果是复制链式命令
|
||||||
const { chainCommands, endIndex } = this.getChainCommands(
|
const { startIndex, endIndex } = this.getChainIndex(command.chainId);
|
||||||
command.chainId
|
const chainCommands = this.commands.slice(startIndex, endIndex + 1);
|
||||||
);
|
const newChainCommands = this.copyCommands(chainCommands);
|
||||||
const newChainCommands = this.copyChainCommands(chainCommands);
|
|
||||||
const newCommands = [...this.commands];
|
const newCommands = [...this.commands];
|
||||||
newCommands.splice(endIndex + 1, 0, ...newChainCommands);
|
newCommands.splice(endIndex + 1, 0, ...newChainCommands);
|
||||||
this.$emit("update:modelValue", newCommands);
|
this.$emit("update:modelValue", newCommands);
|
||||||
@ -477,19 +459,23 @@ export default defineComponent({
|
|||||||
// 单个命令的复制逻辑
|
// 单个命令的复制逻辑
|
||||||
const newCommand = {
|
const newCommand = {
|
||||||
...command,
|
...command,
|
||||||
id: this.$root.getUniqueId(),
|
id: this.getUniqueId(),
|
||||||
};
|
};
|
||||||
const newCommands = [...this.commands];
|
const newCommands = [...this.commands];
|
||||||
newCommands.splice(index + 1, 0, newCommand);
|
newCommands.splice(index + 1, 0, newCommand);
|
||||||
this.$emit("update:modelValue", newCommands);
|
this.$emit("update:modelValue", newCommands);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleToggleDisable({ chainId, disabled }) {
|
handleToggleChainDisable({ chainId, disabled }) {
|
||||||
console.log("handleToggleDisable", chainId, disabled);
|
// 禁用的话先折叠这个Chain
|
||||||
const { chainCommands } = this.getChainCommands(chainId);
|
this.handleControlFlowCollapse({ chainId, isCollapsed: !disabled });
|
||||||
|
const { startIndex, endIndex } = this.getChainIndex(chainId);
|
||||||
// 更新所有相关命令的禁用状态
|
// 更新所有相关命令的禁用状态
|
||||||
const newCommands = chainCommands.map((cmd) => {
|
const newCommands = [...this.commands];
|
||||||
return { ...cmd, disabled };
|
newCommands.forEach((cmd, idx) => {
|
||||||
|
if (idx >= startIndex && idx <= endIndex) {
|
||||||
|
cmd.disabled = disabled;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.$emit("update:modelValue", newCommands);
|
this.$emit("update:modelValue", newCommands);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user