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