Commit d329ec77 by pangchong

style(utils): 统一函数参数格式调整

- 将 diffJobCardsLines、diffJobCardsWords、diffJobCardsJson 函数参数写法调整为单行格式

style(DocNodeRenderer): 优化模板中span标签排版

- 将多个含 v-for 的 span 标签缩减为单行,提升代码简洁性
parent 50321a59
......@@ -9,10 +9,7 @@ import { serializeTreeToXml } from './xmlParser'
* @param newCard 新工卡(可以是 XML 字符串或 XmlNode 树结构)
* @returns 差异结果数组
*/
export function diffJobCardsLines(
oldCard: string | XmlNode,
newCard: string | XmlNode
): DiffResult[] {
export function diffJobCardsLines(oldCard: string | XmlNode, newCard: string | XmlNode): DiffResult[] {
const oldXml = typeof oldCard === 'string' ? oldCard : serializeTreeToXml(oldCard, 0, false)
const newXml = typeof newCard === 'string' ? newCard : serializeTreeToXml(newCard, 0, false)
......@@ -25,10 +22,7 @@ export function diffJobCardsLines(
* @param newCard 新工卡
* @returns 差异结果数组
*/
export function diffJobCardsWords(
oldCard: string | XmlNode,
newCard: string | XmlNode
): DiffResult[] {
export function diffJobCardsWords(oldCard: string | XmlNode, newCard: string | XmlNode): DiffResult[] {
const oldXml = typeof oldCard === 'string' ? oldCard : serializeTreeToXml(oldCard, 0, false)
const newXml = typeof newCard === 'string' ? newCard : serializeTreeToXml(newCard, 0, false)
......@@ -41,10 +35,7 @@ export function diffJobCardsWords(
* @param newNode 新节点
* @returns 差异结果数组
*/
export function diffJobCardsJson(
oldNode: XmlNode,
newNode: XmlNode
): DiffResult[] {
export function diffJobCardsJson(oldNode: XmlNode, newNode: XmlNode): DiffResult[] {
// 序列化为规范 JSON 字符串,排除 parentId 以免产生循环引用
const replacer = (key: string, value: any) => {
if (key === 'parentId') return undefined
......
......@@ -48,13 +48,11 @@
<template v-else-if="node.tagName === 'EFFECT' || node.tagName === 'CONEFFECT'">
<span v-if="renderInline" class="font-bold text-xs select-none py-1 uppercase mx-1 italic" style="color: red">
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w, true)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w, true)">{{ w.value }}</span>
</template>
<template v-else>
** {{ node.tagName === 'EFFECT' ? 'ON A/C' : 'CONF' }}: {{ formatEff(node.attributes.EFFRG || node.textContent) }}
</template>
<template v-else>** {{ node.tagName === 'EFFECT' ? 'ON A/C' : 'CONF' }}: {{ formatEff(node.attributes.EFFRG || node.textContent) }}</template>
</span>
<div
v-else
......@@ -62,13 +60,11 @@
style="color: red; border-color: rgba(255, 0, 0, 0.3)"
>
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w, true)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w, true)">{{ w.value }}</span>
</template>
<template v-else>
** {{ node.tagName === 'EFFECT' ? 'ON A/C' : 'CONF' }}: {{ formatEff(node.attributes.EFFRG || node.textContent) }}
</template>
<template v-else>** {{ node.tagName === 'EFFECT' ? 'ON A/C' : 'CONF' }}: {{ formatEff(node.attributes.EFFRG || node.textContent) }}</template>
</div>
</template>
......@@ -76,13 +72,11 @@
<template v-else-if="node.tagName === 'SBEFF' || node.tagName === 'SBEFFC'">
<span v-if="renderInline" class="font-bold text-xs select-none py-1 uppercase mx-1 italic" style="color: red">
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w, true)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w, true)">{{ w.value }}</span>
</template>
<template v-else>
** SB: {{ node.attributes.SBCOND }} SB {{ node.attributes.SBNBR }} for A/C {{ formatEff(node.attributes.EFFRG) }}
</template>
<template v-else>** SB: {{ node.attributes.SBCOND }} SB {{ node.attributes.SBNBR }} for A/C {{ formatEff(node.attributes.EFFRG) }}</template>
</span>
<div
v-else
......@@ -90,13 +84,11 @@
style="color: red; border-color: rgba(255, 0, 0, 0.3)"
>
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w, true)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w, true)">{{ w.value }}</span>
</template>
<template v-else>
** SB: {{ node.attributes.SBCOND }} SB {{ node.attributes.SBNBR }} for A/C {{ formatEff(node.attributes.EFFRG) }}
</template>
<template v-else>** SB: {{ node.attributes.SBCOND }} SB {{ node.attributes.SBNBR }} for A/C {{ formatEff(node.attributes.EFFRG) }}</template>
</div>
</template>
......@@ -109,11 +101,7 @@
@keydown.enter.prevent
>
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w)">{{ w.value }}</span>
</template>
<template v-else>{{ node.textContent }}</template>
</div>
......@@ -128,11 +116,7 @@
@keydown.enter.prevent
>
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w)">{{ w.value }}</span>
</template>
<template v-else>{{ node.textContent }}</template>
</div>
......@@ -163,11 +147,7 @@
@blur="handleMixedTextBlur(index, $event)"
>
<template v-if="isDiffMode && item.diffWords && item.diffWords.length > 0">
<span
v-for="(w, idx) in item.diffWords"
:key="idx"
:class="getDiffWordClass(w)"
>{{ w.value }}</span>
<span v-for="(w, idx) in item.diffWords" :key="idx" :class="getDiffWordClass(w)">{{ w.value }}</span>
</template>
<template v-else>{{ item.text }}</template>
</span>
......@@ -201,11 +181,7 @@
@blur="handleTextBlur"
>
<template v-if="isDiffMode && node.mixedContent?.[0]?.diffWords && node.mixedContent[0].diffWords.length > 0">
<span
v-for="(w, idx) in node.mixedContent[0].diffWords"
:key="idx"
:class="getDiffWordClass(w)"
>{{ w.value }}</span>
<span v-for="(w, idx) in node.mixedContent[0].diffWords" :key="idx" :class="getDiffWordClass(w)">{{ w.value }}</span>
</template>
<template v-else>{{ node.textContent }}</template>
</component>
......@@ -1153,9 +1129,7 @@ const props = withDefaults(
import type { Ref } from 'vue'
const injectedDiffMode = inject<boolean | Ref<boolean>>('diffMode', false)
const injectedDiffModeValue = computed(() =>
typeof injectedDiffMode === 'boolean' ? injectedDiffMode : injectedDiffMode.value
)
const injectedDiffModeValue = computed(() => (typeof injectedDiffMode === 'boolean' ? injectedDiffMode : injectedDiffMode.value))
const isDiffMode = computed(() => props.diffMode || injectedDiffModeValue.value)
provide('diffMode', isDiffMode)
......
......@@ -22,4 +22,3 @@ export interface DiffLine {
num?: number
content: string
}
import type { FormInst, FormRules } from 'naive-ui'
import { CHINESE_FIRST_PARA_TAGS } from '@/configs/xmlTags'
export const useCreateTableModal = (
emit: (event: 'confirm', rows: number, cols: number, cellChildTags: string[]) => void
) => {
export const useCreateTableModal = (emit: (event: 'confirm', rows: number, cols: number, cellChildTags: string[]) => void) => {
const show = ref(false)
const formRef = ref<FormInst | null>(null)
......
......@@ -46,7 +46,7 @@ export function useTableEditor(props: { node: XmlNode }) {
const store = useEditorStore()
const appStore = useAppStore()
const isDiffModeRaw = inject<any>('diffMode', false)
const isDiffMode = computed(() => typeof isDiffModeRaw === 'boolean' ? isDiffModeRaw : (isDiffModeRaw?.value ?? false))
const isDiffMode = computed(() => (typeof isDiffModeRaw === 'boolean' ? isDiffModeRaw : (isDiffModeRaw?.value ?? false)))
const structure = ref<TableStructureModel>({
cols: 0,
......@@ -558,9 +558,7 @@ export function useTableEditor(props: { node: XmlNode }) {
// 计算新增列的自适应默认宽度,从偏好设置 store 中读取比重系数,防止权重失衡
const ratio = appStore.defaultNewColWidth ?? 0.2
let defaultWidth = `${ratio}*`
const activeWidths = colSpecs
.map((spec) => spec.attributes.COLWIDTH || spec.attributes.colwidth || '')
.filter((w) => !!w)
const activeWidths = colSpecs.map((spec) => spec.attributes.COLWIDTH || spec.attributes.colwidth || '').filter((w) => !!w)
if (activeWidths.length > 0) {
const starWidths = activeWidths
......@@ -574,9 +572,7 @@ export function useTableEditor(props: { node: XmlNode }) {
const starLimit = Math.max(0.05, ratio / 2)
defaultWidth = `${Math.max(starLimit, Math.round(avgStar * ratio * 10) / 10)}*`
} else {
const absWidths = activeWidths
.map((w) => parseFloat(w))
.filter((v) => !isNaN(v))
const absWidths = activeWidths.map((w) => parseFloat(w)).filter((v) => !isNaN(v))
if (absWidths.length > 0) {
const avgAbs = absWidths.reduce((sum, v) => sum + v, 0) / absWidths.length
// 基于偏好设置的像素比例,下限为 20px
......
......@@ -96,7 +96,13 @@
:data-node-id="para.id"
data-tag-name="PARA"
:contenteditable="!isDiffMode"
:class="[isNodeSelected(para.id) ? 'ring-2 ring-primary bg-primary/5 font-bold' : (!isDiffMode ? 'hover:bg-fill-3 cursor-text' : 'cursor-default')]"
:class="[
isNodeSelected(para.id)
? 'ring-2 ring-primary bg-primary/5 font-bold'
: !isDiffMode
? 'hover:bg-fill-3 cursor-text'
: 'cursor-default'
]"
:style="para.attributes?.MERGED === 'TRUE' ? { backgroundColor: 'yellow' } : {}"
@click.stop="isDiffMode ? null : handleParaClick(para, cell, $event)"
@blur="(e) => handleCellBlur(para.id, e)"
......@@ -195,7 +201,13 @@
:data-node-id="para.id"
data-tag-name="PARA"
:contenteditable="!isDiffMode"
:class="[isNodeSelected(para.id) ? 'ring-2 ring-primary bg-primary/5' : (!isDiffMode ? 'hover:bg-fill-3 cursor-text' : 'cursor-default')]"
:class="[
isNodeSelected(para.id)
? 'ring-2 ring-primary bg-primary/5'
: !isDiffMode
? 'hover:bg-fill-3 cursor-text'
: 'cursor-default'
]"
:style="para.attributes?.MERGED === 'TRUE' ? { backgroundColor: 'yellow' } : {}"
@click.stop="isDiffMode ? null : handleParaClick(para, cell, $event)"
@blur="(e) => handleCellBlur(para.id, e)"
......
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