Skip to content

Commit

Permalink
🐛 修复了点击编辑以后进入指定脚本可以左侧也选中对应的脚步名字,点击保存tab脚本名称和左侧脚本名称同步修改以后的内容
Browse files Browse the repository at this point in the history
  • Loading branch information
duoluodexiaoxiaoyuan committed Dec 10, 2022
1 parent 1073de3 commit 5335869
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/pages/options/routes/script/ScriptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,35 @@ function ScriptEditor() {
.then((newScript) => {
scriptCtrl.upsert(newScript).then(
() => {
if (!newScript.name) {
Message.warning("脚本name不可以设置为空");
return;
}
if (newScript.id === 0) {
Message.success("新建成功,请注意后台脚本不会默认开启");
// 保存的时候如何左侧没有脚本即新建
setScriptList((prev) => {
setSelectSciptButtonAndTab(newScript.uuid);
return [newScript, ...prev];
});
} else {
setScriptList((prev) => {
// eslint-disable-next-line no-shadow, array-callback-return
prev.map((script: Script) => {
if (script.uuid === newScript.uuid) {
script.name = newScript.name;
}
});
return [...prev];
});
Message.success("保存成功");
}
setEditors((prev) => {
for (let i = 0; i < prev.length; i += 1) {
if (prev[i].script.uuid === newScript.uuid) {
prev[i].code = newScript.code;
prev[i].isChanged = false;
prev[i].script.name = newScript.name;
break;
}
}
Expand Down Expand Up @@ -313,6 +332,7 @@ function ScriptEditor() {
hotKeys,
isChanged: false,
});
setSelectSciptButtonAndTab(scripts[i].uuid);
setEditors([...editors]);
break;
}
Expand Down Expand Up @@ -533,7 +553,7 @@ function ScriptEditor() {
</Button>
{scriptList.map((script) => (
<Button
key={`s_${script.id}`}
key={`s_${script.uuid}`}
size="mini"
className="text-left"
style={{
Expand Down Expand Up @@ -698,7 +718,7 @@ function ScriptEditor() {
if (isChanged !== item.isChanged) {
setEditors((prev) => {
prev.forEach((v) => {
if (v.script.id === item.script.id) {
if (v.script.uuid === item.script.uuid) {
v.isChanged = isChanged;
}
});
Expand Down

0 comments on commit 5335869

Please sign in to comment.