Commit 9eac7b69 by pangchong

style(editor): 优化暂存面板组件代码格式与布局

- 统一调整了CommonButton和CommonModal的模板写法,减少换行使代码更紧凑
- 合并多余换行,修正部分标签内文本换行,保证代码行长度适中
- 优化filterItems和activeItem计算属性的箭头函数格式
- 调整条件返回语句括号位置,增强代码可读性
- 优化XML文本处理逻辑,提升代码简洁度和注释清晰度
- 统一多个模板中的样式和类名换行格式,维护一致的代码风格
- 对NodeTree组件增加括号包裹以适应多行表达式
- 精简StashNodeModal组件模板代码,合并多行属性为单行
- 删除无用空行与空白字符,确保文件结尾无多余空行
parent 7f4a27c3
...@@ -35,4 +35,3 @@ export const useStashStore = defineStore('stash', { ...@@ -35,4 +35,3 @@ export const useStashStore = defineStore('stash', {
}) })
export * from './types' export * from './types'
...@@ -23,15 +23,12 @@ export function useStashModal() { ...@@ -23,15 +23,12 @@ export function useStashModal() {
const filteredItems = computed(() => { const filteredItems = computed(() => {
const query = searchText.value.trim().toLowerCase() const query = searchText.value.trim().toLowerCase()
if (!query) return stashStore.items if (!query) return stashStore.items
return stashStore.items.filter(item => return stashStore.items.filter((item) => item.name.toLowerCase().includes(query) || item.xmlNode.tagName.toLowerCase().includes(query))
item.name.toLowerCase().includes(query) ||
item.xmlNode.tagName.toLowerCase().includes(query)
)
}) })
// 当前选中的项 // 当前选中的项
const activeItem = computed(() => { const activeItem = computed(() => {
const found = stashStore.items.find(item => item.id === activeItemId.value) const found = stashStore.items.find((item) => item.id === activeItemId.value)
if (found) return found if (found) return found
// 默认选中过滤后列表的首项 // 默认选中过滤后列表的首项
return filteredItems.value[0] || null return filteredItems.value[0] || null
...@@ -44,7 +41,7 @@ export function useStashModal() { ...@@ -44,7 +41,7 @@ export function useStashModal() {
let xmlTextTimer: ReturnType<typeof setTimeout> | null = null let xmlTextTimer: ReturnType<typeof setTimeout> | null = null
const isCopied = ref(false) const isCopied = ref(false)
// 动态提示默认生成的暂存别名 // 动态提示默认生成的暂存别名
const defaultNamePlaceholder = computed(() => { const defaultNamePlaceholder = computed(() => {
const timeStr = new Date().toLocaleTimeString('zh-CN', { hour12: false, hour: '2-digit', minute: '2-digit' }) const timeStr = new Date().toLocaleTimeString('zh-CN', { hour12: false, hour: '2-digit', minute: '2-digit' })
...@@ -77,13 +74,11 @@ export function useStashModal() { ...@@ -77,13 +74,11 @@ export function useStashModal() {
try { try {
const xmlText = serializeTreeToXml(item.xmlNode, 0, false) const xmlText = serializeTreeToXml(item.xmlNode, 0, false)
activeItemXmlText.value = xmlText activeItemXmlText.value = xmlText
// 将序列化的树转换为单行文本,并拼装相应的 XML 头以匹配实际导出的字节数 // 将序列化的树转换为单行文本,并拼装相应的 XML 头以匹配实际导出的字节数
const singleLineXml = xmlText.replace(/\r?\n\s*/g, '') const singleLineXml = xmlText.replace(/\r?\n\s*/g, '')
const finalXml = item.type === 'full' const finalXml = item.type === 'full' ? `<?xml version="1.0" encoding="utf-8"?>${singleLineXml}` : singleLineXml
? `<?xml version="1.0" encoding="utf-8"?>${singleLineXml}`
: singleLineXml
const bytes = new Blob([finalXml]).size const bytes = new Blob([finalXml]).size
if (bytes === 0) { if (bytes === 0) {
activeItemSizeStr.value = '0 B' activeItemSizeStr.value = '0 B'
......
...@@ -18,25 +18,13 @@ ...@@ -18,25 +18,13 @@
/> />
</div> </div>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<CommonButton <CommonButton type="primary" size="small" :disabled="!hasXmlTree" class="flex-1" @click="handleStashFull">
type="primary"
size="small"
:disabled="!hasXmlTree"
class="flex-1"
@click="handleStashFull"
>
<template #icon> <template #icon>
<n-icon><ArchiveOutline /></n-icon> <n-icon><ArchiveOutline /></n-icon>
</template> </template>
暂存整个 XML 暂存整个 XML
</CommonButton> </CommonButton>
<CommonButton <CommonButton type="warning" size="small" :disabled="!selectedNode" class="flex-1" @click="handleStashFragment">
type="warning"
size="small"
:disabled="!selectedNode"
class="flex-1"
@click="handleStashFragment"
>
<template #icon> <template #icon>
<n-icon><CodeWorkingOutline /></n-icon> <n-icon><CodeWorkingOutline /></n-icon>
</template> </template>
...@@ -48,24 +36,13 @@ ...@@ -48,24 +36,13 @@
<!-- 搜索与列表头部 --> <!-- 搜索与列表头部 -->
<div class="flex items-center justify-between mb-2 px-1"> <div class="flex items-center justify-between mb-2 px-1">
<div class="flex items-center gap-2 flex-1 max-w-[280px]"> <div class="flex items-center gap-2 flex-1 max-w-[280px]">
<n-input <n-input v-model:value="searchText" placeholder="搜索暂存记录..." size="small" class="text-xs">
v-model:value="searchText"
placeholder="搜索暂存记录..."
size="small"
class="text-xs"
>
<template #prefix> <template #prefix>
<n-icon class="opacity-40"><SearchOutline /></n-icon> <n-icon class="opacity-40"><SearchOutline /></n-icon>
</template> </template>
</n-input> </n-input>
</div> </div>
<CommonButton <CommonButton v-if="stashStore.items.length > 0" size="small" type="error" secondary @click="handleClearAll">
v-if="stashStore.items.length > 0"
size="small"
type="error"
secondary
@click="handleClearAll"
>
<template #icon> <template #icon>
<n-icon><TrashOutline /></n-icon> <n-icon><TrashOutline /></n-icon>
</template> </template>
...@@ -89,7 +66,9 @@ ...@@ -89,7 +66,9 @@
v-for="item in filteredItems" v-for="item in filteredItems"
:key="item.id" :key="item.id"
class="p-3 cursor-pointer hover:bg-fill-2/50 transition-all flex flex-col gap-2 relative group" class="p-3 cursor-pointer hover:bg-fill-2/50 transition-all flex flex-col gap-2 relative group"
:class="activeItem?.id === item.id ? 'bg-fill-3 border-l-2 border-primary pl-2.5' : 'border-l-2 border-transparent pl-3'" :class="
activeItem?.id === item.id ? 'bg-fill-3 border-l-2 border-primary pl-2.5' : 'border-l-2 border-transparent pl-3'
"
@click="activeItemId = item.id" @click="activeItemId = item.id"
> >
<!-- 标题行 --> <!-- 标题行 -->
...@@ -115,9 +94,7 @@ ...@@ -115,9 +94,7 @@
<n-tag size="tiny" :type="item.type === 'full' ? 'info' : 'warning'" :bordered="false" round> <n-tag size="tiny" :type="item.type === 'full' ? 'info' : 'warning'" :bordered="false" round>
{{ item.type === 'full' ? '完整XML' : '片段' }} {{ item.type === 'full' ? '完整XML' : '片段' }}
</n-tag> </n-tag>
<span class="font-mono bg-fill-2 px-1.5 py-0.5 rounded text-color2"> <span class="font-mono bg-fill-2 px-1.5 py-0.5 rounded text-color2">&lt;{{ item.xmlNode.tagName }}&gt;</span>
&lt;{{ item.xmlNode.tagName }}&gt;
</span>
</div> </div>
<span class="font-mono">{{ item.time }}</span> <span class="font-mono">{{ item.time }}</span>
</div> </div>
...@@ -147,12 +124,7 @@ ...@@ -147,12 +124,7 @@
</template> </template>
下载 XML 下载 XML
</CommonButton> </CommonButton>
<CommonButton <CommonButton size="small" :type="isCopied ? 'success' : 'primary'" secondary @click="handleCopyXml(activeItem)">
size="small"
:type="isCopied ? 'success' : 'primary'"
secondary
@click="handleCopyXml(activeItem)"
>
<template #icon> <template #icon>
<n-icon> <n-icon>
<CheckmarkOutline v-if="isCopied" /> <CheckmarkOutline v-if="isCopied" />
...@@ -165,7 +137,9 @@ ...@@ -165,7 +137,9 @@
</div> </div>
<!-- 代码预览区 --> <!-- 代码预览区 -->
<div class="flex-1 overflow-auto border border-divider rounded-lg bg-card p-3 relative font-mono text-[11px] leading-5 select-text custom-scrollbar"> <div
class="flex-1 overflow-auto border border-divider rounded-lg bg-card p-3 relative font-mono text-[11px] leading-5 select-text custom-scrollbar"
>
<div v-if="isXmlTextLoading" class="flex flex-col gap-2 animate-pulse py-1"> <div v-if="isXmlTextLoading" class="flex flex-col gap-2 animate-pulse py-1">
<div class="h-3 bg-fill-3 rounded w-4/5"></div> <div class="h-3 bg-fill-3 rounded w-4/5"></div>
<div class="h-3 bg-fill-3 rounded w-full"></div> <div class="h-3 bg-fill-3 rounded w-full"></div>
...@@ -179,7 +153,7 @@ ...@@ -179,7 +153,7 @@
<!-- 操作面板 --> <!-- 操作面板 -->
<div class="mt-4 p-4 border border-divider rounded-xl bg-card space-y-3"> <div class="mt-4 p-4 border border-divider rounded-xl bg-card space-y-3">
<div class="text-xs font-bold text-color2">应用操作</div> <div class="text-xs font-bold text-color2">应用操作</div>
<!-- 针对完整 XML 的恢复 --> <!-- 针对完整 XML 的恢复 -->
<div v-if="activeItem.type === 'full'" class="flex flex-col space-y-2"> <div v-if="activeItem.type === 'full'" class="flex flex-col space-y-2">
<CommonButton type="primary" class="w-full" @click="handleApplyFull(activeItem)"> <CommonButton type="primary" class="w-full" @click="handleApplyFull(activeItem)">
...@@ -196,15 +170,9 @@ ...@@ -196,15 +170,9 @@
<CommonButton type="warning" secondary @click="handleApplyFragment(activeItem, 'inside')"> <CommonButton type="warning" secondary @click="handleApplyFragment(activeItem, 'inside')">
作为子元素插入内部 作为子元素插入内部
</CommonButton> </CommonButton>
<CommonButton type="warning" secondary @click="handleApplyFragment(activeItem, 'replace')"> <CommonButton type="warning" secondary @click="handleApplyFragment(activeItem, 'replace')">替换当前选中节点</CommonButton>
替换当前选中节点 <CommonButton type="default" secondary @click="handleApplyFragment(activeItem, 'above')">在当前节点上方插入</CommonButton>
</CommonButton> <CommonButton type="default" secondary @click="handleApplyFragment(activeItem, 'below')">在当前节点下方插入</CommonButton>
<CommonButton type="default" secondary @click="handleApplyFragment(activeItem, 'above')">
在当前节点上方插入
</CommonButton>
<CommonButton type="default" secondary @click="handleApplyFragment(activeItem, 'below')">
在当前节点下方插入
</CommonButton>
</div> </div>
</div> </div>
</div> </div>
...@@ -216,12 +184,7 @@ ...@@ -216,12 +184,7 @@
</div> </div>
<!-- 重命名确认对话框 --> <!-- 重命名确认对话框 -->
<CommonModal <CommonModal v-model="showRenameModal" title="重命名暂存记录" :width="400" @confirm="saveRenameConfirm">
v-model="showRenameModal"
title="重命名暂存记录"
:width="400"
@confirm="saveRenameConfirm"
>
<div class="pt-3"> <div class="pt-3">
<n-input v-model:value="editingItemName" placeholder="请输入暂存别名" /> <n-input v-model:value="editingItemName" placeholder="请输入暂存别名" />
</div> </div>
......
import { useStashStore } from '@/store/stash' import { useStashStore } from '@/store/stash'
import type { XmlNode } from '@/types/xmlNode' import type { XmlNode } from '@/types/xmlNode'
import { import { stashModalVisible, stashNodeName, stashDefaultName, stashTargetNode } from '../../../functionals'
stashModalVisible,
stashNodeName,
stashDefaultName,
stashTargetNode
} from '../../../functionals'
export const useStashNodeModal = () => { export const useStashNodeModal = () => {
const handleConfirm = () => { const handleConfirm = () => {
......
<template> <template>
<CommonModal <CommonModal v-model="stashModalVisible" title="新建本地暂存" :width="400" @confirm="handleConfirm">
v-model="stashModalVisible"
title="新建本地暂存"
:width="400"
@confirm="handleConfirm"
>
<div class="pt-3"> <div class="pt-3">
<n-input v-model:value="stashNodeName" :placeholder="stashDefaultName" autofocus /> <n-input v-model:value="stashNodeName" :placeholder="stashDefaultName" autofocus />
</div> </div>
......
...@@ -241,7 +241,9 @@ const editorStore = useEditorStore() ...@@ -241,7 +241,9 @@ const editorStore = useEditorStore()
const insertFragmentModalRef = ref<any>(null) const insertFragmentModalRef = ref<any>(null)
const isAnyModalVisible = computed(() => { const isAnyModalVisible = computed(() => {
return checkRuleVisible.value || viewXmlVisible.value || addNodeVisible.value || stashModalVisible.value || !!insertFragmentModalRef.value?.visible return (
checkRuleVisible.value || viewXmlVisible.value || addNodeVisible.value || stashModalVisible.value || !!insertFragmentModalRef.value?.visible
)
}) })
const { const {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment