Skip to content

Commit 1e55533

Browse files
committed
feat: update css editor
1 parent c4c7b7f commit 1e55533

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/components/CodemirrorEditor/CssEditor.vue

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,20 @@ function handleTabsEdit(targetName, action) {
1717
store.addCssContentTab(value)
1818
ElMessage.success(`新建成功~`)
1919
})
20+
.catch(() => {
21+
})
2022
}
2123
else if (action === `remove`) {
2224
const tabs = store.cssContentConfig.tabs
23-
if (tabs.length === 1) {
25+
if (tabs.length < 2) {
2426
ElMessage.warning(`至少保留一个方案`)
2527
return
2628
}
27-
let activeName = store.cssContentConfig.active
28-
if (activeName === targetName) {
29-
tabs.forEach((tab, index) => {
30-
if (tab.name === targetName) {
31-
const nextTab = tabs[index + 1] || tabs[index - 1]
32-
if (nextTab) {
33-
activeName = nextTab.name
34-
}
35-
}
36-
})
29+
if (store.cssContentConfig.active === targetName) {
30+
const currentIndex = tabs.findIndex(tab => tab.name === targetName);
31+
const nextTab = tabs[currentIndex + 1] || tabs[currentIndex - 1];
32+
store.cssContentConfig.active = nextTab ? nextTab.name : '';
3733
}
38-
39-
store.cssContentConfig.active = activeName
4034
store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName)
4135
}
4236
}

src/stores/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,32 @@ export const useStore = defineStore(`store`, () => {
163163
setCssEditorValue(content)
164164
}
165165

166+
function startEditing(name) {
167+
editingTab.value = name;
168+
const tab = store.cssContentConfig.tabs.find(tab => tab.name === name);
169+
if (tab) {
170+
newTabName.value = tab.title;
171+
}
172+
}
173+
174+
function saveTabName(oldName) {
175+
if (newTabName.value.trim() !== '' && newTabName.value !== oldName) {
176+
if (store.cssContentConfig.tabs.some(tab => tab.title === newTabName.value)) {
177+
ElMessage.error('不能与现有方案重名');
178+
return;
179+
}
180+
const tab = store.cssContentConfig.tabs.find(tab => tab.name === oldName);
181+
if (tab) {
182+
tab.title = newTabName.value;
183+
}
184+
editingTab.value = null;
185+
ElMessage.success('重命名成功~');
186+
} else {
187+
editingTab.value = null;
188+
ElMessage.info('取消重命名');
189+
}
190+
}
191+
166192
const addCssContentTab = (name) => {
167193
cssContentConfig.value.tabs.push({
168194
name,

0 commit comments

Comments
 (0)