优化控制流命令的禁用效果

This commit is contained in:
fofolee 2025-01-21 08:56:12 +08:00
parent 7a224be9f4
commit 7d67ef9ae6
2 changed files with 40 additions and 58 deletions

View File

@ -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,
}); });

View File

@ -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;
// commandschainIdindex // commandschainIdindex
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);
}, },