Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize custom css #335

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions src/components/CodemirrorEditor/CssEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,38 @@ import { useStore } from '@/stores'

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) {
if (action === `add`) {
ElMessageBox.prompt(`请输入方案名称`, `新建自定义 CSS`, {
confirmButtonText: `确认`,
cancelButtonText: `取消`,
inputValue: `方案${store.cssContentConfig.tabs.length + 1}`,
inputErrorMessage: `不能与现有方案重名`,
inputValidator: store.validatorTabName,
})
.then(({ value }) => {
if (!(`${value}`).trim()) {
ElMessage.error(`新建失败,方案名不可为空`)
return
}
store.addCssContentTab(value)
ElMessage.success(`新建成功~`)
})
Expand All @@ -36,7 +59,7 @@ function handleTabsEdit(targetName, action) {
})
}

store.cssContentConfig.active = activeName
store.tabChanged(activeName)
store.cssContentConfig.tabs = tabs.filter(tab => tab.name !== targetName)
}
}
Expand All @@ -47,17 +70,28 @@ function handleTabsEdit(targetName, action) {
<el-col v-show="store.isShowCssEditor" :span="8" class="cssEditor-wrapper order-1 h-full flex flex-col">
<el-tabs
v-model="store.cssContentConfig.active"
type="card"
type="border-card"
stretch
editable
@edit="handleTabsEdit"
@tab-change="store.tabChanged"
>
<el-tab-pane
v-for="item in store.cssContentConfig.tabs"
:key="item.name"
:label="item.title"
: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>
<textarea
id="cssEditor"
Expand Down Expand Up @@ -107,12 +141,15 @@ function handleTabsEdit(targetName, action) {
}
}

.cssEditor-wrapper {
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
:deep(.el-tabs__content) {
padding: 0;
}

:deep(.el-tabs__header) {
margin: 0;
// 当 tab 为激活状态时,隐藏关闭按钮
:deep(.el-tabs__item.is-active) {
.is-icon-close {
display: none;
}
}

:deep(.el-tabs__new-tab) {
Expand Down
9 changes: 9 additions & 0 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ export const useStore = defineStore(`store`, () => {
setCssEditorValue(content)
}

// 重命名 css 方案
const renameTab = (name) => {
const tab = getCurrentTab()
tab.title = name
tab.name = name
cssContentConfig.value.active = name
}

const addCssContentTab = (name) => {
cssContentConfig.value.tabs.push({
name,
Expand Down Expand Up @@ -438,6 +446,7 @@ export const useStore = defineStore(`store`, () => {
validatorTabName,
setCssEditorValue,
tabChanged,
renameTab,
}
})

Expand Down
Loading