File tree Expand file tree Collapse file tree 2 files changed +33
-13
lines changed
components/CodemirrorEditor Expand file tree Collapse file tree 2 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -17,26 +17,20 @@ function handleTabsEdit(targetName, action) {
17
17
store .addCssContentTab (value)
18
18
ElMessage .success (` 新建成功~` )
19
19
})
20
+ .catch (() => {
21
+ })
20
22
}
21
23
else if (action === ` remove` ) {
22
24
const tabs = store .cssContentConfig .tabs
23
- if (tabs .length === 1 ) {
25
+ if (tabs .length < 2 ) {
24
26
ElMessage .warning (` 至少保留一个方案` )
25
27
return
26
28
}
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 : ' ' ;
37
33
}
38
-
39
- store .cssContentConfig .active = activeName
40
34
store .cssContentConfig .tabs = tabs .filter (tab => tab .name !== targetName)
41
35
}
42
36
}
Original file line number Diff line number Diff line change @@ -163,6 +163,32 @@ export const useStore = defineStore(`store`, () => {
163
163
setCssEditorValue ( content )
164
164
}
165
165
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
+
166
192
const addCssContentTab = ( name ) => {
167
193
cssContentConfig . value . tabs . push ( {
168
194
name,
You can’t perform that action at this time.
0 commit comments