Skip to content

Commit

Permalink
feat: update css editor
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Aug 19, 2024
1 parent c4c7b7f commit 1e55533
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/components/CodemirrorEditor/CssEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,20 @@ function handleTabsEdit(targetName, action) {
store.addCssContentTab(value)
ElMessage.success(`新建成功~`)
})
.catch(() => {
})
}
else if (action === `remove`) {
const tabs = store.cssContentConfig.tabs
if (tabs.length === 1) {
if (tabs.length < 2) {
ElMessage.warning(`至少保留一个方案`)
return
}
let activeName = store.cssContentConfig.active
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
const nextTab = tabs[index + 1] || tabs[index - 1]
if (nextTab) {
activeName = nextTab.name
}
}
})
if (store.cssContentConfig.active === targetName) {
const currentIndex = tabs.findIndex(tab => tab.name === targetName);
const nextTab = tabs[currentIndex + 1] || tabs[currentIndex - 1];
store.cssContentConfig.active = nextTab ? nextTab.name : '';
}
store.cssContentConfig.active = activeName
store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName)
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ export const useStore = defineStore(`store`, () => {
setCssEditorValue(content)
}

function startEditing(name) {
editingTab.value = name;
const tab = store.cssContentConfig.tabs.find(tab => tab.name === name);
if (tab) {
newTabName.value = tab.title;
}
}

function saveTabName(oldName) {
if (newTabName.value.trim() !== '' && newTabName.value !== oldName) {
if (store.cssContentConfig.tabs.some(tab => tab.title === newTabName.value)) {
ElMessage.error('不能与现有方案重名');
return;
}
const tab = store.cssContentConfig.tabs.find(tab => tab.name === oldName);
if (tab) {
tab.title = newTabName.value;
}
editingTab.value = null;
ElMessage.success('重命名成功~');
} else {
editingTab.value = null;
ElMessage.info('取消重命名');
}
}

const addCssContentTab = (name) => {
cssContentConfig.value.tabs.push({
name,
Expand Down

0 comments on commit 1e55533

Please sign in to comment.