fix 保存后进入目录更新不正确的问题
This commit is contained in:
@@ -945,7 +945,7 @@ export default {
|
||||
const oDocument = Api.GetDocument()
|
||||
// 处理编号格式,.SetSuff('none')为关键代码,不然会出现标题后面的空格变大的问题
|
||||
const aNumberedParagraphs = oDocument.GetAllNumberedParagraphs()
|
||||
for (let i = 0; i < aNumberedParagraphs.length ;i++) {
|
||||
for (let i = 0; i < aNumberedParagraphs.length; i++) {
|
||||
const oNumLvl = aNumberedParagraphs[i].GetNumbering()
|
||||
oNumLvl.SetSuff('none')
|
||||
}
|
||||
@@ -1133,54 +1133,19 @@ export default {
|
||||
oParagraph9.SetColor(0, 0, 0)
|
||||
oDocument.InsertContent([oParagraph9])
|
||||
|
||||
// setTimeout(() => {
|
||||
// Api.asc_UpdateTableOfContents()
|
||||
// const allElement = oDocument.GetElementsCount()
|
||||
// let ContentsPr = null
|
||||
// for (let index = 0; index < allElement; index++) {
|
||||
// const element = oDocument.GetElement(index)
|
||||
// if ('blockLvlSdt' === element.GetClassType()) {
|
||||
// if (element.GetPlaceholderText() == '在此输入文字') {
|
||||
// ContentsPr = element
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (ContentsPr) {
|
||||
// const list = ContentsPr.GetAllParagraphs()
|
||||
// if (list && list.length > 0) {
|
||||
// for (let i = 0; i < list.length; i++) {
|
||||
// list[i].SetFontFamily('宋体')
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }, 700)
|
||||
Api.GoToFooter(1)
|
||||
Api.asc_SetSectionStartPage(1)
|
||||
Api.GoToFooter(4)
|
||||
Api.asc_SetSectionStartPage(1)
|
||||
// Api.GoToFooter(1)
|
||||
Api.ExitHeader_Footer(3)
|
||||
console.log('初始化正文,end')
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
})
|
||||
let timer = setTimeout(() => {
|
||||
clearTimeout(timer)
|
||||
timer = null
|
||||
this.reorderSort()
|
||||
}, 500)
|
||||
},
|
||||
reorderSort () {
|
||||
this.ctx.callCommand(() => {
|
||||
try {
|
||||
console.log('页码操作,start')
|
||||
Api.GoToFooter(1)
|
||||
Api.asc_SetSectionStartPage(1)
|
||||
Api.GoToFooter(4)
|
||||
Api.asc_SetSectionStartPage(1)
|
||||
// Api.GoToFooter(1)
|
||||
Api.ExitHeader_Footer(4)
|
||||
console.log('页码操作,end')
|
||||
} catch (e) {
|
||||
}
|
||||
})
|
||||
let timer = setTimeout(() => {
|
||||
this.equationOne()
|
||||
this.initializeDirectory()
|
||||
this.replaceData()
|
||||
this.initReferences()
|
||||
clearTimeout(timer)
|
||||
@@ -1668,6 +1633,9 @@ export default {
|
||||
handleReplace () {
|
||||
this.initModalVisible = true
|
||||
},
|
||||
/**
|
||||
* 更新目录
|
||||
*/
|
||||
equationOne: debounce(function () {
|
||||
let that = this
|
||||
that.ctx.callCommand(() => {
|
||||
@@ -1811,7 +1779,163 @@ export default {
|
||||
}
|
||||
})
|
||||
}, 500),
|
||||
|
||||
/**
|
||||
* 初始化进入处理目录
|
||||
*/
|
||||
initializeDirectory () {
|
||||
let that = this
|
||||
that.ctx.callCommand(() => {
|
||||
try {
|
||||
console.log('目录更新,start')
|
||||
const oDocument = Api.GetDocument()
|
||||
const tables = oDocument.GetAllTables()
|
||||
if (tables && tables.length > 0) {
|
||||
for (let i = 0; i < tables.length; i++) {
|
||||
const cell = tables[i].GetCell(0, 0)
|
||||
const cellContent = cell.GetContent().GetContent()
|
||||
for (let j = 0; j < cellContent.length; j++) {
|
||||
const text = cellContent[j].GetText()
|
||||
if (text.indexOf('附') !== -1 && text.indexOf('录') !== -1) {
|
||||
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
|
||||
cellContent[j].SetStyle(oNewDocumentStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const allElement = oDocument.GetElementsCount()
|
||||
let ContentsPr = null
|
||||
for (let index = 0; index < allElement; index++) {
|
||||
const element = oDocument.GetElement(index)
|
||||
if ('paragraph' === element.GetClassType()) {
|
||||
const getNumbering = element.GetNumbering()
|
||||
const text = element.GetSpacingAfter()
|
||||
// 前言
|
||||
if (text === 597 && (element.GetText().indexOf('前 言') !== -1 || element.GetText().indexOf('前言') !== -1)) {
|
||||
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
|
||||
element.SetStyle(oNewDocumentStyle)
|
||||
element.SetFontSize(32)
|
||||
element.SetSpacing(1.8)
|
||||
element.SetSpacingBefore(549)
|
||||
element.SetSpacingAfter(597)
|
||||
element.SetFontFamily('黑体')
|
||||
element.SetColor(0, 0, 0)
|
||||
element.SetJc('center')
|
||||
element.SetBold(false)
|
||||
}
|
||||
// 引言
|
||||
if (text === 597 && (element.GetText().indexOf('引 言') !== -1 || element.GetText().indexOf('引言') !== -1)) {
|
||||
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
|
||||
element.SetStyle(oNewDocumentStyle)
|
||||
element.SetFontSize(32)
|
||||
element.SetSpacing(1.8)
|
||||
element.SetSpacingBefore(549)
|
||||
element.SetSpacingAfter(597)
|
||||
element.SetFontFamily('黑体')
|
||||
element.SetColor(0, 0, 0)
|
||||
element.SetJc('center')
|
||||
element.SetBold(false)
|
||||
}
|
||||
// 一级
|
||||
if (text === 267) {
|
||||
const oNewDocumentStyle = oDocument.GetStyle('Heading 1')
|
||||
const oTextPr3 = oNewDocumentStyle.GetTextPr()
|
||||
element.SetStyle(oNewDocumentStyle)
|
||||
element.SetFontSize(21)
|
||||
element.SetFontFamily(element.GetFontNames()[0])
|
||||
}
|
||||
// 二级及以下
|
||||
const serialNumber = element.GetText().split(' ')[0]
|
||||
const serialNumberList = serialNumber.split('.')
|
||||
if (text === 127) {
|
||||
const oNewDocumentStyle = oDocument.GetStyle('Heading ' + serialNumberList.length)
|
||||
const oTextPr3 = oNewDocumentStyle.GetTextPr()
|
||||
oTextPr3.SetFontFamily('黑体')
|
||||
element.SetStyle(oNewDocumentStyle)
|
||||
element.SetFontFamily(element.GetFontNames()[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < allElement; index++) {
|
||||
const element = oDocument.GetElement(index)
|
||||
if ('blockLvlSdt' === element.GetClassType()) {
|
||||
if (element.GetPlaceholderText() === '在此输入文字' || element.GetPlaceholderText() === '在这输入文字') {
|
||||
ContentsPr = element
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ContentsPr) {
|
||||
// 文档中没有标题
|
||||
const tempList = ContentsPr.GetAllParagraphs()
|
||||
if (tempList.some(tt => tt.GetText().indexOf('文档中没有标题') !== -1)) {
|
||||
Api.asc_UpdateTableOfContents()
|
||||
}
|
||||
const list = ContentsPr.GetAllParagraphs()
|
||||
if (list && list.length > 0) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
list[i].SetFontFamily('宋体')
|
||||
list[i].SetFontSize(21)
|
||||
list[i].SetBold(false)
|
||||
if (list[i].GetText().indexOf('前 言') !== -1 || list[i].GetText().indexOf('前言') !== -1) {
|
||||
let text = list[i].GetText()
|
||||
text = text.replace(/\s*/g, '')
|
||||
text = text.substring(0, 2)
|
||||
const aSearch = list[i].Search('前 言')
|
||||
if (aSearch[0]) {
|
||||
aSearch[0].AddText('前言')
|
||||
}
|
||||
const aSearch1 = list[i].Search('前 言')
|
||||
if (aSearch1[0]) {
|
||||
aSearch1[0].Delete()
|
||||
}
|
||||
}
|
||||
if (list[i].GetText().indexOf('引 言') !== -1 || list[i].GetText().indexOf('引言') !== -1) {
|
||||
let text = list[i].GetText()
|
||||
text = text.replace(/\s*/g, '')
|
||||
text = text.substring(0, 2)
|
||||
const aSearch = list[i].Search('引 言')
|
||||
if (aSearch[0]) {
|
||||
aSearch[0].AddText('引言')
|
||||
}
|
||||
const aSearch1 = list[i].Search('引 言')
|
||||
if (aSearch1[0]) {
|
||||
aSearch1[0].Delete()
|
||||
}
|
||||
}
|
||||
if (list[i].GetText().indexOf('附 录') !== -1 || list[i].GetText().indexOf('附录') !== -1) {
|
||||
let text = list[i].GetText()
|
||||
text = text.replace(/\s*/g, '')
|
||||
text = text.substring(0, 2)
|
||||
oDocument.SearchAndReplace({ 'searchString': '附 录 ', 'replaceString': text })
|
||||
list[i].SetPosition(0)
|
||||
}
|
||||
// 3.1
|
||||
if (list[i].GetIndLeft() == 283) {
|
||||
list[i].SetIndLeft(320)
|
||||
let textOne = list[i].GetText()
|
||||
let textTwo = textOne.replace(/\s+/g, ' ')
|
||||
let index = textTwo.indexOf(' ')
|
||||
let name = textTwo.slice(0, index)
|
||||
oDocument.SearchAndReplace({
|
||||
'searchString': name + ' ', 'replaceString': name
|
||||
})
|
||||
} else if (list[i].GetIndLeft() == 567) { // 3.1.1
|
||||
list[i].SetIndLeft(420)
|
||||
} else if (list[i].GetIndLeft() == 850) {
|
||||
list[i].SetIndLeft(520)
|
||||
} else if (list[i].GetIndLeft() == 1134) {
|
||||
list[i].SetIndLeft(620)
|
||||
} else if (list[i].GetIndLeft() == 1417) {
|
||||
list[i].SetIndLeft(720)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('目录更新,end')
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 添加新制定标准化文件格式前言
|
||||
*/
|
||||
@@ -2007,6 +2131,8 @@ export default {
|
||||
// 参考文献标题文本
|
||||
const oRunTitle = Api.CreateRun()
|
||||
const oParagraphTitle = Api.CreateParagraph()
|
||||
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
|
||||
oParagraphTitle.SetStyle(oNewDocumentStyle)
|
||||
oRunTitle.AddText('参考文献')
|
||||
const inlineLvlSdtReferences = Api.CreateInlineLvlSdt()
|
||||
inlineLvlSdtReferences.SetAlias('sinotruk.references')
|
||||
|
||||
Reference in New Issue
Block a user