feat: optimize custom css (#335)

This commit is contained in:
YangFong 2024-08-21 08:22:28 +08:00 committed by GitHub
parent 4b3d261ecb
commit b43f879c23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 8 deletions

View File

@ -5,15 +5,38 @@ import { useStore } from '@/stores'
const store = useStore() const store = useStore()
function editTabName() {
ElMessageBox.prompt(`请输入新的方案名称`, `编辑方案名称`, {
confirmButtonText: `确认`,
cancelButtonText: `取消`,
inputValue: store.cssContentConfig.active,
inputErrorMessage: `不能与现有方案重名`,
inputValidator: store.validatorTabName,
})
.then(({ value }) => {
if (!(`${value}`).trim()) {
ElMessage.error(`修改失败,方案名不可为空`)
return
}
store.renameTab(value)
ElMessage.success(`修改成功~`)
})
}
function handleTabsEdit(targetName, action) { function handleTabsEdit(targetName, action) {
if (action === `add`) { if (action === `add`) {
ElMessageBox.prompt(`请输入方案名称`, `新建自定义 CSS`, { ElMessageBox.prompt(`请输入方案名称`, `新建自定义 CSS`, {
confirmButtonText: `确认`, confirmButtonText: `确认`,
cancelButtonText: `取消`, cancelButtonText: `取消`,
inputValue: `方案${store.cssContentConfig.tabs.length + 1}`,
inputErrorMessage: `不能与现有方案重名`, inputErrorMessage: `不能与现有方案重名`,
inputValidator: store.validatorTabName, inputValidator: store.validatorTabName,
}) })
.then(({ value }) => { .then(({ value }) => {
if (!(`${value}`).trim()) {
ElMessage.error(`新建失败,方案名不可为空`)
return
}
store.addCssContentTab(value) store.addCssContentTab(value)
ElMessage.success(`新建成功~`) ElMessage.success(`新建成功~`)
}) })
@ -36,7 +59,7 @@ function handleTabsEdit(targetName, action) {
}) })
} }
store.cssContentConfig.active = activeName store.tabChanged(activeName)
store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName) store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName)
} }
} }
@ -47,7 +70,8 @@ function handleTabsEdit(targetName, action) {
<el-col v-show="store.isShowCssEditor" :span="8" class="cssEditor-wrapper order-1 h-full flex flex-col"> <el-col v-show="store.isShowCssEditor" :span="8" class="cssEditor-wrapper order-1 h-full flex flex-col">
<el-tabs <el-tabs
v-model="store.cssContentConfig.active" v-model="store.cssContentConfig.active"
type="card" type="border-card"
stretch
editable editable
@edit="handleTabsEdit" @edit="handleTabsEdit"
@tab-change="store.tabChanged" @tab-change="store.tabChanged"
@ -55,9 +79,19 @@ function handleTabsEdit(targetName, action) {
<el-tab-pane <el-tab-pane
v-for="item in store.cssContentConfig.tabs" v-for="item in store.cssContentConfig.tabs"
:key="item.name" :key="item.name"
:label="item.title"
:name="item.name" :name="item.name"
/> >
<template #label>
{{ item.title }}
<el-icon
v-if="store.cssContentConfig.active === item.name"
class="ml-1"
@click="editTabName(item.name)"
>
<ElIconEditPen />
</el-icon>
</template>
</el-tab-pane>
</el-tabs> </el-tabs>
<textarea <textarea
id="cssEditor" id="cssEditor"
@ -107,12 +141,15 @@ function handleTabsEdit(targetName, action) {
} }
} }
.cssEditor-wrapper { :deep(.el-tabs__content) {
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1); padding: 0;
} }
:deep(.el-tabs__header) { // tab
margin: 0; :deep(.el-tabs__item.is-active) {
.is-icon-close {
display: none;
}
} }
:deep(.el-tabs__new-tab) { :deep(.el-tabs__new-tab) {

View File

@ -163,6 +163,14 @@ export const useStore = defineStore(`store`, () => {
setCssEditorValue(content) setCssEditorValue(content)
} }
// 重命名 css 方案
const renameTab = (name) => {
const tab = getCurrentTab()
tab.title = name
tab.name = name
cssContentConfig.value.active = name
}
const addCssContentTab = (name) => { const addCssContentTab = (name) => {
cssContentConfig.value.tabs.push({ cssContentConfig.value.tabs.push({
name, name,
@ -438,6 +446,7 @@ export const useStore = defineStore(`store`, () => {
validatorTabName, validatorTabName,
setCssEditorValue, setCssEditorValue,
tabChanged, tabChanged,
renameTab,
} }
}) })