From 372512d811ba48e244234220e0c09ab666028f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=9C=84?= Date: Fri, 26 Jan 2024 18:03:55 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=9C=A8=E6=96=87=E6=A1=A3=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E6=8F=92=E5=85=A5=E5=8F=82=E8=80=83=E6=96=87=E7=8C=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/page1/saicComponents/Init.vue | 71 ++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/src/pages/page1/saicComponents/Init.vue b/src/pages/page1/saicComponents/Init.vue index 31eae8c..7ddfa49 100644 --- a/src/pages/page1/saicComponents/Init.vue +++ b/src/pages/page1/saicComponents/Init.vue @@ -1291,9 +1291,10 @@ export default { this.reorderSort() this.equationOne() this.replaceData() + this.initReferences() }, 500) }, - reorderSort(){ + reorderSort () { this.ctx.callCommand(() => { try { Api.GoToFooter(1) @@ -1301,7 +1302,8 @@ export default { Api.GoToFooter(4) Api.asc_SetSectionStartPage(1) Api.ExitHeader_Footer(4) - } catch (e) {} + } catch (e) { + } }) }, replaceData () { @@ -2094,6 +2096,71 @@ export default { console.log(e) } }) + }, + /** + * 初始化参考文献 + */ + initReferences () { + this.ctx.callCommand(() => { + try { + const oDocument = Api.GetDocument() + const AllContentControls = oDocument.GetAllContentControls() + let flag = false + for (let i = 0; i < AllContentControls.length; i++) { + console.log(AllContentControls[i].GetAlias()) + // 避免重复创建参考文献 + if (AllContentControls[i].GetAlias() === 'sinotruk.references') { + flag = true + break + } + } + if (flag) { + return + } + // 参考文献是在最后生成的,所以不需要和引言一样校验正文是否存在 + const documentCount = oDocument.GetElementsCount() + // 获取文档最后一个段落 + const lastParagraph = oDocument.GetElement(documentCount - 1) + // 参考文献标题文本 + const oRunTitle = Api.CreateRun() + const oParagraphTitle = Api.CreateParagraph() + oRunTitle.AddText('参考文献') + const inlineLvlSdtReferences = Api.CreateInlineLvlSdt() + inlineLvlSdtReferences.SetAlias('sinotruk.references') + inlineLvlSdtReferences.AddElement(oRunTitle, 0) + oParagraphTitle.AddInlineLvlSdt(inlineLvlSdtReferences) + oParagraphTitle.SetFontSize(32) + oParagraphTitle.SetSpacing(1.8) + oParagraphTitle.SetSpacingBefore(949) + oParagraphTitle.SetSpacingAfter(597) + oParagraphTitle.SetFontFamily('黑体') + oParagraphTitle.SetColor(0, 0, 0) + oParagraphTitle.SetJc('center') + oParagraphTitle.SetBold(false) + lastParagraph.AddPageBreak() + oDocument.Push(oParagraphTitle) + const text = '[1] GB/T 10112-1999 术语工作 原则与方法' + const contentParagraph = Api.CreateParagraph() + contentParagraph.AddText(text) + contentParagraph.SetFontSize(21) + contentParagraph.SetFontFamily('宋体') + contentParagraph.SetColor(0, 0, 0) + contentParagraph.SetSpacingAfter(0) + contentParagraph.SetBold(false) + oDocument.Push(contentParagraph) + // 插入终止线 + const oParagraphLine = Api.CreateParagraph() + const oFill = Api.CreateSolidFill(Api.CreateRGBColor(0, 0, 0)) + const oStroke = Api.CreateStroke(0, Api.CreateNoFill()) + const oDrawing = Api.CreateShape('rect', 1810900, 19000, oFill, oStroke) + oParagraphLine.SetJc('center') + oParagraphLine.SetSpacingBefore(840) + oParagraphLine.AddDrawing(oDrawing) + oDocument.Push(oParagraphLine) + } catch (e) { + console.log(e) + } + }) } }, created () {