Files
plugins_vue/src/pages/page1/saicComponents/Init.vue
T
2024-01-31 17:36:26 +08:00

2355 lines
97 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div>
<a-button-group style="margin-bottom: 10px">
<!-- <a-button @click="handleCreateCover">封面</a-button>-->
<a-button @click="catalogueClick">插入ics</a-button>
<a-button @click="terminationLine">终止线</a-button>
<!-- <a-button @click="handleInit">初始化正文</a-button>-->
<!-- <a-button @click="handleReplace">数据替换</a-button>-->
<!-- <a-button @click="addSeal">添加发布认可章</a-button>-->
</a-button-group>
<a-button-group style="margin-bottom: 10px">
<!-- <a-button @click="handleInsertRow">插入空行</a-button>-->
<!-- <a-dropdown>-->
<!-- <a-menu slot="overlay" @click="handleInsertControl">-->
<!-- <a-menu-item key="forewordCN">前言新制定标准文化文件</a-menu-item>-->
<!-- <a-menu-item key="forewordEN">前言修订标准化文件</a-menu-item>-->
<!-- <a-menu-item key="standCode">企标编号</a-menu-item>-->
<!-- <a-menu-item key="replaceStandCode">代替企标编号</a-menu-item>-->
<!-- <a-menu-item key="standCNName">企标中文名称</a-menu-item>-->
<!-- <a-menu-item key="standENName">企标英文名称</a-menu-item>-->
<!-- <a-menu-item key="primaryDrafter">主要起草人</a-menu-item>-->
<!-- <a-menu-item key="issueDate">发布日期</a-menu-item>-->
<!-- <a-menu-item key="impDate">实施日期</a-menu-item>-->
<!-- <a-menu-item key="fixed">其他</a-menu-item>-->
<!-- </a-menu>-->
<!-- <a-button class="section-btn"-->
<!-- >创建内容控件-->
<!-- <a-icon type="down"/>-->
<!-- </a-button>-->
<!-- </a-dropdown>-->
<a-button @click="doubleSided">双面排版</a-button>
<!-- <a-button @click="equationClick">方程式编号</a-button>-->
<a-button @click="equationOne">目次</a-button>
</a-button-group>
<a-button-group style="margin-bottom: 10px">
<a-button @click="addNewForeword">前言新制定标准</a-button>
<a-button @click="addReviseForeword">前言修订标准</a-button>
</a-button-group>
<a-button-group v-if="!!form.processId">
<a-button @click="addPublicationChapter">添加发布章</a-button>
<a-button @click="insertSignatureInfo">插入签审信息</a-button>
</a-button-group>
<!-- 企标基础信息读取 -->
<a-modal v-model="initModalVisible" title="企标文件初始化" @ok="handleInitModalConfirm">
<a-form-model id="components-form-demo-validate-other" :model="form" v-bind="formItemLayout"
@submit="handleInitModalConfirm">
<a-form-item label="企标编号">
<a-input v-model="form.standCode" placeholder="请填写企标编号" />
</a-form-item>
<a-form-item label="代替企标编号">
<a-input v-model="form.replaceStandCode" placeholder="请填写代替企标编号" />
</a-form-item>
<a-form-item label="标准中文名称">
<a-input v-model="form.standCNName" placeholder="请填写标准中文名称" />
</a-form-item>
<a-form-item label="标准英文名称">
<a-input v-model="form.standENName" placeholder="请填写标准英文名称" />
</a-form-item>
<a-form-item label="发布日期">
<el-date-picker v-model="form.issueDate" placeholder="请选择发布日期" />
</a-form-item>
<a-form-item label="实施日期">
<el-date-picker v-model="form.impDate" placeholder="请选择实施日期" />
</a-form-item>
<a-form-item label="主要起草人">
<a-input v-model="form.primaryDrafter" placeholder="请填写主起草人" />
</a-form-item>
<a-form-item label="起草部门">
<a-input v-model="form.drafterDeptName" placeholder="请填写主起草人" />
</a-form-item>
</a-form-model>
</a-modal>
</div>
</template>
<script>
import { BORDER_DISABLE } from '@/config'
import moment from 'moment'
import { imageSvg } from '@/pages/page1/common/image'
import _axios from '../../../plugins/axios2'
const debounce = function (fn, delay) {
let timer = null
return function () {
let content = this
let args = arguments
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
fn.apply(content, args)
}, delay)
}
}
export default {
data () {
return {
initModalVisible: false,
form: {},
setIntervalOne: null,
isTrue: false,
isDisplay: false,
num: 0,
formItemLayout: {
labelCol: { span: 6 },
wrapperCol: { span: 14 }
},
numData: {
1: 'A',
2: 'B',
3: 'C',
4: 'D',
5: 'E',
6: 'F',
7: 'G',
8: 'H',
9: 'I',
10: 'J',
11: 'K',
12: 'L',
13: 'M',
14: 'N',
15: 'O',
16: 'P',
17: 'Q',
18: 'R',
19: 'S',
20: 'T',
21: 'U',
22: 'V',
23: 'W',
24: 'X',
25: 'Y',
26: 'Z'
}
}
},
methods: {
/**
* 企标文件初始化
**/
handleInitModalConfirm () {
const replaceForm = JSON.parse(JSON.stringify(this.form))
// 日期转换
replaceForm.issueDate = moment(replaceForm.issueDate).format('YYYY-MM-DD')
replaceForm.impDate = moment(replaceForm.impDate).format('YYYY-MM-DD')
Asc.scope.res = replaceForm
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const elementsCount = oDocument.GetElementsCount()
const smtcObj = {}
for (let i = 0; i < elementsCount; i++) {
if (oDocument.GetElement(i).GetClassType() === 'paragraph') {
const control = oDocument.GetElement(i).GetAllContentControls()
if (control.length) {
smtcObj[control[0].GetAlias()] = oDocument.GetElement(i).GetText()
}
} else if (oDocument.GetElement(i).GetClassType() === 'table') {
for (
let rowIndex = 0;
rowIndex < oDocument.GetElement(i).GetRowsCount();
rowIndex++
) {
for (
let cellIndex = 0;
cellIndex <
oDocument.GetElement(i).GetRow(rowIndex).GetCellsCount();
cellIndex++
) {
const cellElementsCount = oDocument.GetElement(i).GetRow(rowIndex).GetCell(cellIndex).GetContent().GetElementsCount()
for (
let cellElementIndex = 0;
cellElementIndex < cellElementsCount;
cellElementIndex++
) {
const cellElement = oDocument.GetElement(i).GetRow(rowIndex).GetCell(cellIndex).GetContent().GetElement(cellElementIndex)
if (cellElement.GetClassType() === 'paragraph') {
const control = cellElement.GetAllContentControls()
if (control.length) {
smtcObj[control[0].GetAlias()] = cellElement.GetText()
}
}
}
}
}
}
}
const oParagraph = oDocument.GetElement(0)
const smtc = Asc.scope.res
for (let key in smtcObj) {
let searchString = smtcObj[key]
const repKey = key.substring(key.indexOf('.') + 1)
let replaceString = smtc[repKey]
if (smtc.hasOwnProperty(repKey)) {
// 封面日期单独处理
if (searchString.indexOf('发布') > -1) {
replaceString = replaceString + ' ' + '发布'
}
if (searchString.indexOf('实施') > -1) {
replaceString = replaceString + ' ' + '实施'
}
oDocument.SearchAndReplace({
searchString: searchString,
replaceString: replaceString
})
}
}
} catch (e) {
console.log(e)
}
})
this.initModalVisible = false
},
// 创建封面
handleCreateCover () {
Asc.scope.standCode = this.form.standCode || 'X/XX xxxx-xxxx'
Asc.scope.replaceStandCode = this.form.dtqbbhbuss || 'X/XX xxxx-xxxx'
Asc.scope.standCNName = this.form.standName || 'xx'
Asc.scope.standENName = this.form.standEnName || 'xx'
Asc.scope.issueDate = this.form.issueTime || 'xxxx-xx-xx'
Asc.scope.impDate = this.form.putTime || 'xxxx-xx-xx'
Asc.scope.standardNumberPrefix = this.form.standardNumberPrefix || 'X/XX'
window.Asc.plugin.callCommand(() => {
try {
const oDocument = Api.GetDocument()
// 封面只创建一次
const AllContentControls = oDocument.GetAllContentControls()
let flag = false
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'foton.standSort') {
flag = true
break
}
}
if (flag) {
return
}
const oTable8 = Api.CreateTable(2, 1)
oTable8.SetTableLayout('fixed')
oTable8.SetWidth('percent', 100)
// 255
oTable8.SetTableBorderTop('single', 0, 0, 255, 255, 255)
oTable8.SetTableBorderBottom('single', 20, 0, 255, 255, 255)
oTable8.SetTableBorderLeft('single', 0, 0, 255, 255, 255)
oTable8.SetTableBorderRight('single', 0, 0, 255, 255, 255)
oTable8.SetTableBorderInsideV('single', 0, 0, 255, 255, 255)
oTable8.SetTableBorderInsideH('single', 0, 0, 255, 255, 255)
const oParagraph8Left = oTable8.GetCell(0, 0).GetContent().GetElement(0)
const oParagraph8Right = oTable8.GetCell(0, 1).GetContent().GetElement(0)
// const oNextParagraph10 = Api.CreateParagraph();
// var oStroke10 = Api.CreateStroke(0, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)));
// var oDrawing10 = Api.CreateShape("rect", 4110900, 102400, null, oStroke10);
// oNextParagraph10.AddDrawing(oDrawing10);
// oParagraph8Left.SetJc("left");
// oParagraph8Left.AddElement(0,oDrawing10)
const oParagraph1 = Api.CreateParagraph()
const oInlineLvlSdtStandSort = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandSort.SetAlias('foton.standSort')
oInlineLvlSdtStandSort.SetLock('sdtLocked')
const oRunStandSort = Api.CreateRun()
oRunStandSort.AddText(Asc.scope.standardNumberPrefix)
oInlineLvlSdtStandSort.AddElement(oRunStandSort, 0)
oParagraph8Right.AddInlineLvlSdt(oInlineLvlSdtStandSort)
oParagraph8Right.SetFontSize(96)
oParagraph8Right.SetBold(true)
oParagraph8Right.SetPosition(2)
oParagraph8Right.SetFontFamily('Times New Roman')
// oParagraph8Right.AddElement(1,oParagraph1)
oParagraph8Right.SetJc('right')
oParagraph8Right.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oTable8])
const oParagraph2 = Api.CreateParagraph()
oParagraph2.AddText('中国重型汽车集团有限公司企业标准')
oParagraph2.SetFontSize(48)
oParagraph2.SetSpacing(0.8)
oParagraph2.SetFontFamily('黑体')
oParagraph2.SetJc('center')
oParagraph2.SetBold(false)
oParagraph2.SetPosition(6)
oParagraph2.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oParagraph2])
// const oParagraph4 = Api.CreateParagraph();
// oParagraph4.AddText("Q/FT A001-2020");
// oParagraph4.SetFontSize(28);
// oParagraph4.SetFontFamily("ZTZhongsong");
// oParagraph4.SetJc("right");
// oParagraph4.SetSpacingAfter(3);
// oParagraph4.SetBold(false);
// oParagraph4.SetPosition(1);
// oDocument.InsertContent([oParagraph4]);
const oParagraph4 = Api.CreateParagraph()
const oInlineLvlSdtStandCode = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandCode.SetAlias('foton.standCode')
oInlineLvlSdtStandCode.SetLock('sdtLocked')
const oRunStandCode = Api.CreateRun()
oRunStandCode.AddText(Asc.scope.standCode)
// oInlineLvlSdtStandCode.SetLock("sdtContentLocked");
oInlineLvlSdtStandCode.AddElement(oRunStandCode, 0)
oParagraph4.AddInlineLvlSdt(oInlineLvlSdtStandCode)
oParagraph4.SetJc('right')
oParagraph4.SetSpacingAfter(6)
oParagraph4.SetFontFamily('黑体')
oParagraph4.SetFontSize(28)
oParagraph4.SetPosition(0)
oParagraph4.SetBold(false)
oParagraph4.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oParagraph4])
const oParagraphOne = Api.CreateParagraph()
const oInlineLvlSdtStandCodeOne = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandCodeOne.SetAlias('foton.replaceStandCode')
oInlineLvlSdtStandCodeOne.SetLock('sdtLocked')
const oRunStandCodeOne = Api.CreateRun()
oRunStandCodeOne.AddText('代替 ' + Asc.scope.replaceStandCode)
oInlineLvlSdtStandCodeOne.AddElement(oRunStandCodeOne, 0)
oParagraphOne.AddInlineLvlSdt(oInlineLvlSdtStandCodeOne)
oParagraphOne.SetJc('right')
oParagraphOne.SetFontSize(21)
oParagraphOne.SetFontFamily('黑体')
oParagraphOne.SetSpacingBefore(0)
oParagraphOne.SetSpacingAfter(0)
oParagraphOne.SetBold(false)
oParagraphOne.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oParagraphOne])
const oParagraphLine1 = Api.CreateParagraph()
const oFill1 = Api.CreateSolidFill(Api.CreateRGBColor(0, 0, 0))
const oStroke1 = Api.CreateStroke(0, Api.CreateNoFill())
const oDrawing1 = Api.CreateShape('rect', 6110900, 18000, oFill1, oStroke1)
oDrawing1.SetWrappingStyle('inline')
oParagraphLine1.AddDrawing(oDrawing1)
oDrawing1.SetDistances(0, 541, 0, 0)
oDocument.InsertContent([oParagraphLine1])
const oNextParagraph1 = Api.CreateParagraph()
oNextParagraph1.SetSpacingBefore(1098)
var oStroke = Api.CreateStroke(0, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)))
var oDrawing = Api.CreateShape('rect', 6110900, 2102400, null, oStroke)
oNextParagraph1.AddDrawing(oDrawing)
oDocument.InsertContent([oNextParagraph1])
const oParagraph5 = Api.CreateParagraph()
const oInlineLvlSdtStandCNName = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandCNName.SetAlias('foton.standCNName')
oInlineLvlSdtStandCNName.SetLock('sdtLocked')
const oRunStandCNName = Api.CreateRun()
oRunStandCNName.AddText(Asc.scope.standCNName)
// oInlineLvlSdtStandCNName.SetLock("sdtContentLocked");
oInlineLvlSdtStandCNName.AddElement(oRunStandCNName, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdtStandCNName)
oParagraph5.SetJc('center')
oParagraph5.SetFontSize(52)
oParagraph5.SetSpacingBefore(10)
oParagraph5.SetPosition(3)
oParagraph5.SetColor(0, 0, 7, false)
oParagraph5.SetFontFamily('黑体')
oParagraph5.SetBold(false)
oParagraph5.SetSpacingLine(240, 'auto')
var oDocContent = oDrawing.GetDocContent()
oDocContent.AddElement(0, oParagraph5)
const oParagraph6 = Api.CreateParagraph()
const oInlineLvlSdtStandENName = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandENName.SetAlias('foton.standENName')
oInlineLvlSdtStandENName.SetLock('sdtLocked')
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText(Asc.scope.standENName)
// oInlineLvlSdtStandENName.SetLock("sdtContentLocked");
oInlineLvlSdtStandENName.AddElement(oRunStandENName, 0)
oParagraph6.AddInlineLvlSdt(oInlineLvlSdtStandENName)
oParagraph6.SetJc('center')
oParagraph6.SetFontSize(21)
oParagraph6.SetColor(0, 0, 7, false)
oParagraph6.SetFontFamily('宋体')
oParagraph6.SetBold(true)
oParagraph6.SetSpacingLine(240, 'auto')
oDocContent.AddElement(1, oParagraph6)
// oDocument.InsertContent([oParagraph6]);
const oNextParagraph2 = Api.CreateParagraph()
oNextParagraph2.SetSpacingBefore(1208)
oNextParagraph2.SetSpacingAfter(1508)
var oStroke = Api.CreateStroke(0, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)))
var oDrawing = Api.CreateShape('rect', 6110900, 2233900, null, oStroke)
oDrawing.SetLockValue('noSelect', true)
oNextParagraph2.AddDrawing(oDrawing)
oDocument.InsertContent([oNextParagraph2])
const oTable7 = Api.CreateTable(2, 1)
oTable7.SetTableLayout('fixed')
oTable7.SetWidth('percent', 100)
oTable7.SetTableBorderTop('single', 10, 0, 255, 255, 255)
oTable7.SetTableBorderBottom('single', 20, 0, 255, 255, 255)
oTable7.SetTableBorderLeft('single', 0, 0, 255, 255, 255)
oTable7.SetTableBorderRight('single', 0, 0, 255, 255, 255)
oTable7.SetTableBorderInsideV('single', 0, 0, 255, 255, 255)
oTable7.SetTableBorderInsideH('single', 0, 0, 255, 255, 255)
const oParagraph7Left = oTable7
.GetCell(0, 0)
.GetContent()
.GetElement(0)
const oParagraph7Right = oTable7
.GetCell(0, 1)
.GetContent()
.GetElement(0)
// oParagraph7Left.AddLineBreak()
// oParagraph7Right.AddLineBreak()
// oParagraph7Left.AddLineBreak()
// oParagraph7Right.AddLineBreak()
// oParagraph7Left.AddLineBreak()
// oParagraph7Right.AddLineBreak()
// oParagraph7Left.AddLineBreak()
// oParagraph7Right.AddLineBreak()
const oInlineLvlSdtIssueDate = Api.CreateInlineLvlSdt()
oInlineLvlSdtIssueDate.SetAlias('foton.issueDate')
const oRunIssueDate = Api.CreateRun()
oRunIssueDate.AddText(Asc.scope.issueDate)
oRunIssueDate.SetFontSize(28)
oRunIssueDate.SetFontFamily('黑体')
// oInlineLvlSdtIssueDate.SetLock("sdtContentLocked");
oInlineLvlSdtIssueDate.AddElement(oRunIssueDate, 0)
oParagraph7Left.AddInlineLvlSdt(oInlineLvlSdtIssueDate)
const oInlineLvlSdtImpDate = Api.CreateInlineLvlSdt()
oInlineLvlSdtImpDate.SetAlias('foton.impDate')
const oRunImpDate = Api.CreateRun()
oRunImpDate.AddText(Asc.scope.impDate)
oRunImpDate.SetFontSize(28)
oRunImpDate.SetFontFamily('黑体')
// oInlineLvlSdtImpDate.SetLock("sdtContentLocked");
oInlineLvlSdtImpDate.AddElement(oRunImpDate, 0)
oParagraph7Right.AddInlineLvlSdt(oInlineLvlSdtImpDate)
const issueCN = Api.CreateRun()
issueCN.SetFontFamily('黑体')
issueCN.AddText(' 发布')
issueCN.SetFontSize(28)
oParagraph7Left.AddElement(issueCN)
oParagraph7Left.SetSpacingAfter(10)
oParagraph7Left.SetSpacingAfter(10)
oParagraph7Left.SetJc('left')
oParagraph7Left.SetSpacingLine(240, 'auto')
const impCN = Api.CreateRun()
impCN.SetFontFamily('黑体')
impCN.AddText(' 实施')
impCN.SetFontSize(28)
oParagraph7Right.AddElement(impCN)
oParagraph7Right.SetJc('right')
oParagraph7Right.SetSpacingAfter(10)
oParagraph7Right.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oTable7])
const oParagraphLine2 = Api.CreateParagraph()
const oFill2 = Api.CreateSolidFill(Api.CreateRGBColor(0, 0, 0))
const oStroke2 = Api.CreateStroke(0, Api.CreateNoFill())
const oDrawing2 = Api.CreateShape('rect', 6110900, 18000, oFill2, oStroke2)
oDrawing2.SetWrappingStyle('inline')
oParagraphLine2.AddDrawing(oDrawing2)
oParagraphLine2.AddLineBreak()
oDocument.InsertContent([oParagraphLine2])
const oParagraph10 = Api.CreateParagraph()
oParagraph10.AddText('中国重型汽车集团有限公司 发布')
oParagraph10.SetFontSize(44)
oParagraph10.SetSpacing(1.4)
oParagraph10.SetFontFamily('黑体')
oParagraph10.SetJc('center')
oParagraph10.SetBold(false)
oParagraph10.SetPosition(0)
oParagraph10.SetSpacingLine(240, 'auto')
oDocument.InsertContent([oParagraph10])
oParagraph10.Search('发布')[0].SetSpacing(3)
oParagraph10.Search('发')[0].SetFontSize(14)
oParagraph10.Search('发')[0].SetPosition(1)
oParagraph10.Search('布')[0].SetFontSize(14)
oParagraph10.Search('布')[0].SetPosition(1)
// 开新页
oParagraph10.AddPageBreak()
const oParagraph11 = Api.CreateParagraph()
oDocument.InsertContent([oParagraph11])
oDocument.CreateSection(oParagraph11)
let oSection1 = oDocument.GetSections()[0]
oSection1.SetTitlePage(true)
oSection1.SetHeaderDistance(0)
oSection1.SetPageMargins(1415, 566, 849, 1132)
let oNextSection = oDocument.GetSections()[1]
oNextSection.SetPageMargins(1415, 1415, 849, 1132)
// oNextSection.SetHeaderDistance(2615)
oNextSection.SetType('oddPage')
let oHeader = oNextSection.GetHeader('even', true)
const oParagraph = oHeader.GetElement(0)
oParagraph.AddText(Asc.scope.standCode)
oParagraph.SetPosition(-4)
oParagraph.SetJc('left')
oParagraph.SetFontFamily('黑体')
let oHeader1 = oNextSection.GetHeader('default', true)
const oParagraph20 = oHeader1.GetElement(0)
oParagraph20.AddText(Asc.scope.standCode)
oParagraph20.SetPosition(-4)
oParagraph20.SetJc('right')
oParagraph20.SetFontFamily('黑体')
let oFooter = oNextSection.GetFooter('even', true)
const oParagraphFooter = oFooter.GetElement(0)
// oParagraphFooter.AddText(Asc.scope.standCode);
oParagraphFooter.AddPageNumber()
oParagraphFooter.SetPosition(3)
oParagraphFooter.SetJc('left')
let oFooter1 = oNextSection.GetFooter('default', true)
const oParagraph20Footer = oFooter1.GetElement(0)
// oParagraph20Footer.AddText(Asc.scope.standCode);
oParagraph20Footer.AddPageNumber()
oParagraph20Footer.SetPosition(3)
oParagraph20Footer.SetJc('right')
// oParagraph20Footer.AddPageNumber()
// Api.asc_SetSectionStartPage(1)
const oParagraphTwo = Api.CreateParagraph()
// var oNewDocumentStyle = oDocument.GetStyle("Heading 1");
// oParagraphTwo.SetStyle(oNewDocumentStyle);
oParagraphTwo.AddText('目 次')
oParagraphTwo.SetFontSize(32)
oParagraphTwo.SetSpacing(1.8)
oParagraphTwo.SetSpacingBefore(949)
oParagraphTwo.SetSpacingAfter(597)
oParagraphTwo.SetFontFamily('黑体')
oParagraphTwo.SetColor(0, 0, 0)
oParagraphTwo.SetJc('center')
oParagraphTwo.SetBold(false)
oDocument.InsertContent([oParagraphTwo])
// 目录层级只留两级
oDocument.AddTableOfContents({ 'BuildFrom': { 'OutlineLvls': 2 } })
// Api.asc_AddTableOfContents()
} catch (e) {
console.log(e)
}
})
let timer = setTimeout(() => {
// 初始化前言,只有前言标题的版本
this.initForeword()
clearTimeout(timer)
timer = null
}, 500)
},
equationClick () {
// this.isTrue = !this.isTrue
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const oParagraph = Api.CreateParagraph()
oDocument.InsertContent([oParagraph])
let num = oParagraph.GetPosInParent()
let oNumLvl
let currentNumbering
let table
let SpacingBefore
for (let i = num - 1; i >= 0; i--) {
const element = oDocument.GetElement(i)
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
table = element
break
} else if (element.GetTableDescription() == 'Empty table') {
let number = element.GetCell(0, 1).GetContent().GetElement(0)
const getNumbering = number.GetNumbering()
if (getNumbering !== null) {
currentNumbering = getNumbering
}
}
}
}
const allElement = oDocument.GetElementsCount()
if (table) {
let number = table.GetCell(0, 0).GetContent().GetElement(1)
SpacingBefore = number.GetSpacingBefore()
}
let Previous = oParagraph.GetPrevious()
// Previous.Delete()
if (Previous) {
Previous.SetJc('right')
var oParagraph2 = Previous.Copy()
const oTable = Api.CreateTable(2, 1)
oTable.SetWidth('percent', 100)
oTable.SetTableLayout('fixed')
oTable.SetTableCellMarginRight(0.2 * (1440 / 2.54))
oTable.SetTableCellMarginTop(0.2 * (1440 / 2.54))
oTable.SetTableCellMarginLeft(0.2 * (1440 / 2.54))
oTable.SetTableCellMarginBottom(0.2 * (1440 / 2.54))
oTable.SetTableBorderTop('single', 0, 0, 255, 255, 255)
oTable.SetTableBorderBottom('single', 0, 0, 255, 255, 255)
oTable.SetTableBorderLeft('single', 0, 0, 255, 255, 255)
oTable.SetTableBorderRight('single', 0, 0, 255, 255, 255)
oTable.SetTableBorderInsideV('single', 0, 0, 255, 255, 255)
oTable.SetTableBorderInsideH('single', 0, 0, 255, 255, 255)
oTable.SetTableDescription('Empty table')
oDocument.InsertContent([oTable])
const oCell = oTable.GetRow(0).GetCell(0)
const oCell1 = oTable.GetRow(0).GetCell(1)
const oParagraph1 = Api.CreateParagraph()
if (SpacingBefore) {
for (let i = num + 1; i < allElement; i++) {
const element = oDocument.GetElement(i)
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
break
} else if (element.GetTableDescription() == 'Empty table') {
let number = element.GetCell(0, 1).GetContent().GetElement(0)
const getNumbering = number.GetNumbering()
if (getNumbering !== null) {
currentNumbering = getNumbering
}
}
}
}
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
} else {
let oNumbering = oDocument.CreateNumbering('numbered')
oNumLvl = oNumbering.GetLevel(0)
const sFormatString = '..................(' + Asc.scope.numData[SpacingBefore] + '.%1)'
oNumLvl.SetCustomType('decimal', sFormatString, 'left')
}
} else {
for (let i = num + 1; i < allElement; i++) {
const element = oDocument.GetElement(i)
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
break
} else if (element.GetTableDescription() == 'Empty table') {
let number = element.GetCell(0, 1).GetContent().GetElement(0)
const getNumbering = number.GetNumbering()
if (getNumbering !== null) {
currentNumbering = getNumbering
}
}
}
}
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
} else {
let oNumbering = oDocument.CreateNumbering('numbered')
oNumLvl = oNumbering.GetLevel(0)
const sFormatString = '..................(%1)'
oNumLvl.SetCustomType('decimal', sFormatString, 'left')
}
}
const paraPr = oNumLvl.GetParaPr()
paraPr.SetJc('right')
const textPr = oNumLvl.GetTextPr()
textPr.SetVertAlign('baseline')
textPr.SetSmallCaps(false)
textPr.SetFontSize(21)
textPr.SetFontFamily('黑体')
oParagraph1.SetNumbering(oNumLvl)
oParagraph2.GetParaPr().SetJc('right')
oParagraph2.AddText(' ')
oParagraph2.SetSpacingAfter(10)
oParagraph2.SetSpacingBefore(9)
oCell.AddElement(0, oParagraph2)
oCell1.AddElement(0, oParagraph1)
oCell.GetContent().GetElement(0).GetParaPr().SetJc('right')
oCell.GetContent().GetElement(0).GetParaPr().SetIndRight(800)
oCell.SetWidth('percent', 130)
oCell1.SetWidth('percent', 65)
oCell.SetVerticalAlign('center')
oCell1.SetVerticalAlign('center')
oCell.GetContent().GetElement(1).Delete()
oCell1.GetContent().GetElement(1).Delete()
}
Previous.Delete()
oParagraph.Delete()
} catch (e) {
console.log(e)
}
})
},
//双面排版
doubleSided () {
this.isTrue = !this.isTrue
Asc.scope.isTrue = this.isTrue
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
var oSection = oDocument.GetSections()[1]
var oSectionOne = oDocument.GetSections()[2]
// oSection.SetType('oddPage')
if (!Asc.scope.isTrue) {
// oSection.SetPageMargins(849, 1415, 1415, 1132);
let oHeader = oSection.GetHeader('even', true)
const oParagraph = oHeader.GetElement(0)
oParagraph.SetJc('left')
let oFooter = oSection.GetFooter('even', true)
const oParagraphFooter = oFooter.GetElement(0)
oParagraphFooter.SetJc('left')
let oHeaderOne = oSectionOne.GetHeader('even', true)
const oParagraphOne = oHeaderOne.GetElement(0)
oParagraphOne.SetJc('left')
let oFooterOne = oSectionOne.GetFooter('even', true)
const oParagraphFooterOne = oFooterOne.GetElement(0)
oParagraphFooterOne.SetJc('left')
} else {
// oSection.SetPageMargins(1415, 1415, 849, 1132);
let oHeader = oSection.GetHeader('even', true)
const oParagraph = oHeader.GetElement(0)
oParagraph.SetJc('right')
let oFooter = oSection.GetFooter('even', true)
const oParagraphFooter = oFooter.GetElement(0)
oParagraphFooter.SetJc('right')
let oHeaderOne = oSectionOne.GetHeader('even', true)
const oParagraphOne = oHeaderOne.GetElement(0)
oParagraphOne.SetJc('right')
let oFooterOne = oSectionOne.GetFooter('even', true)
const oParagraphFooterOne = oFooterOne.GetElement(0)
oParagraphFooterOne.SetJc('right')
}
} catch (e) {
console.log(e)
}
})
},
//封面左上角
catalogueClick () {
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
var arrTables = oDocument.GetElement(0)
if (arrTables.GetClassType() == 'table') {
const table = arrTables.GetCell(0, 0).GetContent().GetElement(0)
if (table.GetText() != '') {
return
}
table.AddText('ICS XXXXXXX')
table.SetFontSize(22)
table.SetFontFamily('黑体')
table.SetSpacingAfter(0)
table.SetSpacingLine(200, 'auto')
table.AddLineBreak()
const table1 = arrTables.GetCell(0, 0).GetContent().GetElement(0)
table.AddText('CCS X XX')
table.SetFontSize(22)
table.SetFontFamily('黑体')
table.Search('ICS')[0].SetFontFamily('Times New Roman')
table.Search('ICS')[0].SetBold(true)
table.Search('CCS')[0].SetFontFamily('Times New Roman')
table.Search('CCS')[0].SetBold(true)
}
console.log(arrTables)
} catch (e) {
}
})
},
//终结线
terminationLine () {
this.ctx.callCommand(() => {
try {
// DE.controllers.Toolbar.api.put_LineEndSize()
const oDocument = Api.GetDocument()
const oParagraphLine1 = Api.CreateParagraph()
const oFill1 = Api.CreateSolidFill(Api.CreateRGBColor(0, 0, 0))
const oStroke1 = Api.CreateStroke(0, Api.CreateNoFill())
const oDrawing1 = Api.CreateShape('rect', 1810900, 19000, oFill1, oStroke1)
oParagraphLine1.SetJc('center')
oParagraphLine1.SetSpacingBefore(840)
oParagraphLine1.AddDrawing(oDrawing1)
oDocument.InsertContent([oParagraphLine1])
} catch (e) {
console.log(e)
}
})
},
// 目次
handleInitDirectory () {
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const oParagraph2 = Api.CreateParagraph()
oParagraph2.AddText('目 次')
oParagraph2.SetFontSize(32)
oParagraph2.SetSpacing(1.8)
oParagraph2.SetSpacingBefore(949)
oParagraph2.SetSpacingAfter(597)
oParagraph2.SetFontFamily('黑体')
oParagraph2.SetColor(0, 0, 0)
oParagraph2.SetJc('center')
oParagraph2.SetBold(false)
oDocument.InsertContent([oParagraph2])
// const oParagraph4 = Api.CreateParagraph();
// const oInlineLvlSdtStandCode = Api.CreateInlineLvlSdt();
// oInlineLvlSdtStandCode.SetAlias("目录");
// const oRunStandCode = Api.CreateRun();
// oRunStandCode.AddText("Q/FT A001-2020");
// oInlineLvlSdtStandCode.AddElement(oRunStandCode, 0);
// oParagraph4.AddInlineLvlSdt(oInlineLvlSdtStandCode);
// oParagraph4.SetJc("right");
// oParagraph4.SetSpacingAfter(6);
// oParagraph4.SetFontFamily("黑体");
// oParagraph4.SetFontSize(28);
// oParagraph4.SetPosition(0);
// oParagraph4.SetBold(false);
// oDocument.InsertContent([oParagraph4]);
} catch (e) {
console.log(e)
}
})
},
/**
* 初始化前言,仅包含前言两个字,下面的内容由客户选择创建
*/
initForeword () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const AllContentControls = oDocument.GetAllContentControls()
let flag = false
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'foton.standardName') {
flag = true
break
}
}
if (flag) {
return
}
DE.controllers.Toolbar.api.put_AddPageBreak()
const oParagraph20 = Api.CreateParagraph()
oDocument.InsertContent([oParagraph20])
const oParagraph2 = Api.CreateParagraph()
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
oParagraph2.SetStyle(oNewDocumentStyle)
oParagraph2.AddText('前 言')
oParagraph2.SetFontSize(32)
oParagraph2.SetSpacing(1.8)
oParagraph2.SetSpacingBefore(549)
oParagraph2.SetSpacingAfter(597)
oParagraph2.SetFontFamily('黑体')
oParagraph2.SetColor(0, 0, 0)
oParagraph2.SetJc('center')
oParagraph2.SetBold(false)
oDocument.InsertContent([oParagraph2])
} catch (e) {
console.log(e)
}
})
let timer = setTimeout(() => {
clearTimeout(timer)
timer = null
this.initIntroduction()
}, 500)
},
/**
* 初始化引言
*/
initIntroduction () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const AllContentControls = oDocument.GetAllContentControls()
let flag = false
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'foton.standardName') {
flag = true
break
}
}
if (flag) {
return
}
DE.controllers.Toolbar.api.put_AddPageBreak()
const oParagraph20 = Api.CreateParagraph()
oDocument.InsertContent([oParagraph20])
const oParagraph2 = Api.CreateParagraph()
let oNewDocumentStyle = oDocument.GetStyle('Heading 1')
oParagraph2.SetStyle(oNewDocumentStyle)
oParagraph2.AddText('引 言')
oParagraph2.SetFontSize(32)
oParagraph2.SetSpacing(1.8)
oParagraph2.SetSpacingBefore(549)
oParagraph2.SetSpacingAfter(597)
oParagraph2.SetFontFamily('黑体')
oParagraph2.SetColor(0, 0, 0)
oParagraph2.SetJc('center')
oParagraph2.SetBold(false)
oDocument.InsertContent([oParagraph2])
const text = ' 引言为可选要素。如果需要,则给出标准技术内容的特殊信息或说明,以及编制该标准的原因引言不应包含要求。'
const oParagraph3 = Api.CreateParagraph()
oParagraph3.AddText(text)
oParagraph3.SetFontSize(21)
oParagraph3.SetFontFamily('宋体')
oParagraph3.SetColor(0, 0, 0)
oParagraph3.SetSpacingAfter(0)
oParagraph3.SetBold(false)
oDocument.InsertContent([oParagraph3])
} catch (e) {
console.log(e)
}
})
let timer = setTimeout(() => {
clearTimeout(timer)
timer = null
this.handleInit()
}, 500)
},
// 初始化正文
handleInit () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
Asc.scope.standCNName = this.form.standName
Asc.scope.standCode = this.form.standCode || 'X/XX xxxx-xxxx'
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const AllContentControls = oDocument.GetAllContentControls()
let flag = false
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'foton.standardName') {
flag = true
break
}
}
if (flag) {
return
}
DE.controllers.Toolbar.api.put_AddPageBreak()
// const BORDER_DISABLE = Asc.scope.BORDER_DISABLE;
const oParagraph20 = Api.CreateParagraph()
oDocument.InsertContent([oParagraph20])
oDocument.CreateSection(oParagraph20)
let oSectionNext = oDocument.GetSections()[2]
oSectionNext.SetPageMargins(1415, 1415, 849, 1132)
// oSectionNext.SetHeaderDistance(1315)
let oHeaderText = oSectionNext.GetHeader('even', true)
const oParagraphText = oHeaderText.GetElement(0)
oParagraphText.AddText(Asc.scope.standCode)
oParagraphText.SetPosition(-4)
oParagraphText.SetJc('right')
oParagraphText.SetFontFamily('黑体')
let oHeader2Text = oSectionNext.GetHeader('default', true)
const oParagraph20Text = oHeader2Text.GetElement(0)
oParagraph20Text.AddText(Asc.scope.standCode)
oParagraph20Text.SetPosition(-4)
oParagraph20Text.SetJc('left')
oParagraph20Text.SetFontFamily('黑体')
let oFooterText = oSectionNext.GetFooter('even', true)
const oParagraphFooterText = oFooterText.GetElement(0)
oParagraphFooterText.SetPosition(3)
oParagraphFooterText.SetJc('right')
oParagraphFooterText.AddPageNumber()
let oFooter1Text = oSectionNext.GetFooter('default', true)
const oParagraph20FooterText = oFooter1Text.GetElement(0)
oParagraph20FooterText.SetPosition(3)
oParagraph20FooterText.SetJc('left')
oParagraph20FooterText.AddPageNumber()
const oRunStandENName = Api.CreateRun()
const oParagraph2 = Api.CreateParagraph()
let name = Asc.scope.standCNName || 'xxxx'
oRunStandENName.AddText(name)
const oInlineLvlSdtStandCode = Api.CreateInlineLvlSdt()
oInlineLvlSdtStandCode.SetAlias('foton.standardName')
oInlineLvlSdtStandCode.AddElement(oRunStandENName, 0)
// const oNewDocumentStyleOne = oDocument.GetStyle("Heading 1");
// oParagraph2.SetStyle(oNewDocumentStyleOne);
oParagraph2.AddInlineLvlSdt(oInlineLvlSdtStandCode)
// oParagraph2.AddText(Asc.scope.standCNName);
oParagraph2.SetFontSize(32)
oParagraph2.SetSpacing(1.8)
oParagraph2.SetSpacingBefore(949)
oParagraph2.SetSpacingAfter(597)
oParagraph2.SetFontFamily('黑体')
oParagraph2.SetColor(0, 0, 0)
// oParagraph2.SetPosition(-12);
oParagraph2.SetJc('center')
oParagraph2.SetBold(false)
oDocument.InsertContent([oParagraph2])
let oNumbering = oDocument.CreateNumbering('numbered')
const oNumLvl = oNumbering.GetLevel(0)
const sFormatString = '%1'
oNumLvl.SetCustomType('decimal', sFormatString, 'left')
oNumLvl.SetSuff('space')
var oParaPr = oNumLvl.GetParaPr()
oParaPr.SetIndFirstLine(0)
const oParagraph = Api.CreateParagraph()
var oNewDocumentStyle = oDocument.GetStyle('Heading 1')
oParagraph.SetStyle(oNewDocumentStyle)
oParagraph.AddText(' 范围')
oParagraph.SetNumbering(oNumLvl)
oParagraph.SetFontFamily('黑体')
oParagraph.SetFontSize(21)
oParagraph.SetSpacingAfter(267)
oParagraph.SetJc('left')
oParagraph.SetColor(0, 0, 0)
oParagraph.SetIndLeft(0)
oParagraph.SetBold(false)
oDocument.InsertContent([oParagraph])
const oParagraph1 = Api.CreateParagraph()
oParagraph1.AddText(' 本文件规定了……(标准化对象和所涉及的各个方面) 。')
oParagraph1.SetFontFamily('宋体')
oParagraph1.SetFontSize(21)
oParagraph1.SetJc('left')
oParagraph1.SetSpacingAfter(0)
oParagraph1.SetSpacingBefore(17)
oParagraph1.SetColor(0, 0, 0)
oDocument.InsertContent([oParagraph1])
const oParagraphA = Api.CreateParagraph()
oParagraphA.AddText(' 本文件适用于……(指明标准化或其特定部分的适用界限)。')
oParagraphA.SetFontFamily('宋体')
oParagraphA.SetFontSize(21)
oParagraphA.SetJc('left')
oParagraphA.SetSpacingAfter(0)
oParagraphA.SetSpacingBefore(17)
oParagraphA.SetColor(0, 0, 0)
oDocument.InsertContent([oParagraphA])
const oParagraph4 = Api.CreateParagraph()
oParagraph4.AddText(' 规范性引用文件')
oParagraph4.SetNumbering(oNumLvl)
oParagraph4.SetStyle(oNewDocumentStyle)
oParagraph4.SetBold(false)
oParagraph4.SetFontFamily('黑体')
oParagraph4.SetFontSize(21)
oParagraph4.SetSpacingAfter(267)
oParagraph4.SetSpacingBefore(267)
oParagraph4.SetJc('left')
oParagraph4.SetColor(0, 0, 0)
oParagraph4.SetIndLeft(0)
oDocument.InsertContent([oParagraph4])
const oParagraph5 = Api.CreateParagraph()
oParagraph5.AddText(' 下列文件中的内容通过文中的规范性引用而构成本文件必不可少的条款。其中,注日期的引用文件,仅该日期对应的版本适用于本文件;不注日期的引用文件,其最新版本(包括所有的修改单)适用于本文件。')
oParagraph5.SetFontFamily('宋体')
oParagraph5.SetFontSize(21)
oParagraph5.SetJc('both')
oParagraph5.SetSpacingAfter(0)
oParagraph5.SetSpacingBefore(17)
oParagraph5.SetColor(0, 0, 0)
oDocument.InsertContent([oParagraph5])
// oParagraph6.Search("GB/T 321")[0].SetFontFamily('Times New Roman');
//
const textList = [
'GB XXX-XXXXX',
'GB 3100 国际单位制及其应用 (GB、GB/T统一按标准号从小到大排序,不分开排序)',
'GB 3101 有关量、单位和符号的一般原则',
'GB/T 20000 标准化工作指南 第1部分:标准化和相关活动的通用术语',
'GB/T 38186 商用车辆自动紧急制动系统(AEBS)性能要求及试验方法',
'JT/T 789 道路甩挂运输车辆技术条件 (国标之后是行业标准,按首字母顺序先后分类排序)',
'QC/T 79.1 道路车辆 汽车和挂车之间气制动连接用螺旋管总成 第1部分:尺寸',
'ISO 17361-2017 智能运输系统.道路偏离警告系统.性能要求和试验程序(行业标准之后是地方标准、团体标准、ISO/IEC标准)',
'Q/ZZ 90019 车辆识别代号(VIN)编制规则 (企业标准中,Q/ZZ放在TS/ZZ之前)',
'TS/ZZ 70001 汽车高强度螺纹紧固件技术规范',
'DIN 3017-4 软管环箍 供货技术条件 (其他国际标准放在企业标准之后)'
]
for (let i = 0; i < textList.length; i++) {
const text = ' ' + textList[i]
const oParagraph6 = Api.CreateParagraph()
oParagraph6.AddText(text)
oParagraph6.SetFontFamily('宋体')
oParagraph6.SetFontSize(21)
oParagraph6.SetJc('left')
oParagraph6.SetSpacingAfter(0)
oParagraph6.SetSpacingBefore(17)
oParagraph6.SetColor(0, 0, 0)
oDocument.InsertContent([oParagraph6])
}
const oParagraph8 = Api.CreateParagraph()
oParagraph8.SetStyle(oNewDocumentStyle)
oParagraph8.AddText(' 术语和定义')
oParagraph8.SetBold(false)
oParagraph8.SetNumbering(oNumLvl)
oParagraph8.SetFontFamily('黑体')
oParagraph8.SetFontSize(21)
oParagraph8.SetSpacingAfter(267)
oParagraph8.SetSpacingBefore(267)
oParagraph8.SetJc('left')
oParagraph8.SetColor(0, 0, 0)
oParagraph8.SetIndLeft(0)
oDocument.InsertContent([oParagraph8])
const oParagraph9 = Api.CreateParagraph()
oParagraph9.AddText(' 下列术语和定义适用于本文件')
oParagraph9.SetFontFamily('宋体')
oParagraph9.SetFontSize(21)
oParagraph9.SetJc('left')
oParagraph9.SetSpacingAfter(0)
oParagraph9.SetSpacingBefore(17)
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)
} catch (e) {
console.log(e)
}
})
let timer = setTimeout(() => {
clearTimeout(timer)
timer = null
this.reorderSort()
this.equationOne()
this.replaceData()
this.initReferences()
}, 500)
},
reorderSort () {
this.ctx.callCommand(() => {
try {
console.log('页码操作')
Api.GoToFooter(1)
Api.asc_SetSectionStartPage(1)
Api.GoToFooter(4)
Api.asc_SetSectionStartPage(1)
Api.ExitHeader_Footer(4)
} catch (e) {
}
})
},
replaceData () {
Asc.scope.standCode = this.form.standCode || 'X/XX xxxx-xxxx'
Asc.scope.replaceStandCode = this.form.dtqbbhbuss || 'X/XX xxxx-xxxx'
Asc.scope.standCNName = this.form.standName || 'xx'
Asc.scope.standENName = this.form.standEnName || 'xx'
Asc.scope.issueDate = this.form.issueTime || 'xxxx-xx-xx'
Asc.scope.impDate = this.form.putTime || 'xxxx-xx-xx'
Asc.scope.standardNumberPrefix = this.form.standardNumberPrefix || 'X/XX'
window.Asc.plugin.callCommand(() => {
try {
const oDocument = Api.GetDocument()
// 封面只创建一次
const AllContentControls = oDocument.GetAllContentControls()
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'foton.standCode') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.standCode) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText(Asc.scope.standCode)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
parentParagraph.SetJc('right')
parentParagraph.SetSpacingAfter(6)
parentParagraph.SetFontFamily('黑体')
parentParagraph.SetFontSize(28)
parentParagraph.SetPosition(0)
parentParagraph.SetBold(false)
}
}
if (AllContentControls[i].GetAlias() === 'foton.replaceStandCode') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.replaceStandCode) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText('代替 ' + Asc.scope.replaceStandCode)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
parentParagraph.SetJc('right')
parentParagraph.SetFontSize(21)
parentParagraph.SetFontFamily('宋体')
parentParagraph.SetSpacingBefore(0)
parentParagraph.SetSpacingAfter(0)
parentParagraph.SetBold(false)
}
}
if (AllContentControls[i].GetAlias() === 'foton.standCNName') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.standCNName) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText(Asc.scope.standCNName)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
parentParagraph.SetJc('center')
parentParagraph.SetFontSize(52)
parentParagraph.SetSpacingBefore(10)
parentParagraph.SetPosition(3)
parentParagraph.SetColor(0, 0, 7, false)
parentParagraph.SetFontFamily('黑体')
parentParagraph.SetBold(false)
}
}
if (AllContentControls[i].GetAlias() === 'foton.standENName') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.standENName) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText(Asc.scope.standENName)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
parentParagraph.SetJc('center')
parentParagraph.SetFontSize(28)
parentParagraph.SetColor(0, 0, 7, false)
parentParagraph.SetFontFamily('黑体')
parentParagraph.SetBold(true)
}
}
if (AllContentControls[i].GetAlias() === 'foton.issueDate') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.issueDate) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.SetFontSize(28)
oRunStandENName.SetFontFamily('黑体')
oRunStandENName.AddText(Asc.scope.issueDate)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
}
}
if (AllContentControls[i].GetAlias() === 'foton.impDate') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.impDate) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.SetFontSize(28)
oRunStandENName.SetFontFamily('黑体')
oRunStandENName.AddText(Asc.scope.impDate)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
}
}
if (AllContentControls[i].GetAlias() === 'foton.standardName') {
let parentParagraph = AllContentControls[i].GetParentParagraph()
if (Asc.scope.standCNName) {
const oRunStandENName = Api.CreateRun()
oRunStandENName.AddText(Asc.scope.standCNName)
AllContentControls[i].RemoveElement(0)
AllContentControls[i].AddElement(oRunStandENName, 0)
parentParagraph.SetFontSize(32)
parentParagraph.SetSpacing(1.8)
parentParagraph.SetSpacingBefore(949)
parentParagraph.SetSpacingAfter(597)
parentParagraph.SetFontFamily('黑体')
parentParagraph.SetColor(0, 0, 0)
// oParagraph2.SetPosition(-12);
parentParagraph.SetJc('center')
parentParagraph.SetBold(false)
}
}
}
if (Asc.scope.standCode) {
let oSection = oDocument.GetSections()[1]
let oSectionOne = oDocument.GetSections()[2]
let oHeaderText = oSection.GetHeader('even', true)
const oParagraphText = oHeaderText.GetElement(0)
let oHeader2Text = oSection.GetHeader('default', true)
const oParagraph20Text = oHeader2Text.GetElement(0)
oParagraphText.Delete()
oHeaderText.GetElement(0).AddText(Asc.scope.standCode)
oHeaderText.GetElement(0).SetPosition(-4)
oHeaderText.GetElement(0).SetJc('left')
oParagraph20Text.Delete()
oHeader2Text.GetElement(0).AddText(Asc.scope.standCode)
oHeader2Text.GetElement(0).SetPosition(-4)
oHeader2Text.GetElement(0).SetJc('right')
let oHeaderTextOne = oSectionOne.GetHeader('even', true)
const oParagraphTextOne = oHeaderTextOne.GetElement(0)
let oHeader2TextOne = oSectionOne.GetHeader('default', true)
const oParagraph20TextOne = oHeader2TextOne.GetElement(0)
oParagraphTextOne.Delete()
oHeaderTextOne.GetElement(0).AddText(Asc.scope.standCode)
oHeaderTextOne.GetElement(0).SetPosition(-4)
oHeaderTextOne.GetElement(0).SetJc('left')
oParagraph20TextOne.Delete()
oHeader2TextOne.GetElement(0).AddText(Asc.scope.standCode)
oHeader2TextOne.GetElement(0).SetPosition(-4)
oHeader2TextOne.GetElement(0).SetJc('right')
// oParagraphText.AddText(Asc.scope.standCode);
// oParagraphText.SetPosition(-4)
// oParagraphText.SetJc("left")
}
} catch (e) {
console.log(e)
}
})
// if (this.form.issueTime) {
// this.addSeal()
// }
},
getYearMonth (date) {
date = (date + '').split(/[ ]+/)
let result = []
let reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/
// 用截取出来的年月日进行正则表达式匹配
reg.exec(date[0])
result.push(RegExp.$1) //获取匹配到的第一个子匹配,即‘2020’
result.push(RegExp.$2)
result.push(RegExp.$3)
return result
},
//创建发布认可章
addSeal () {
if (this.form.issueTime) {
let getYearMonth = this.getYearMonth(this.form.issueTime)
Asc.scope.year = getYearMonth[0]
Asc.scope.month = getYearMonth[1]
Asc.scope.day = getYearMonth[2]
} else {
let data = new Date()
Asc.scope.year = data.getFullYear()
Asc.scope.month = data.getMonth() + 1
Asc.scope.day = data.getDate()
}
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const GetAllDrawingObjects = oDocument.GetAllShapes()
let count = oDocument.GetElementsCount()
let element
let num = 0
for (let i = 0; i < count; i++) {
element = oDocument.GetElement(i)
if ('paragraph' === element.GetClassType()) {
if (element.GetSpacingAfter() == 2460) {
element.Delete()
num = i
break
} else if (element.GetSpacingAfter() == 2360) {
num = 1
break
}
}
}
if (num == 0) {
num = 6
} else if (num == 1) {
return
}
var oNextParagraph = Api.CreateParagraph()
oNextParagraph.SetJc('center')
oNextParagraph.SetSpacingBefore(1308)
oNextParagraph.SetSpacingAfter(2360)
var oStrokeOne = Api.CreateStroke(0.75 * 36000, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)))
var oDrawingOne = Api.CreateShape('rect', 2548400, 1562400, null, oStrokeOne)
oDrawingOne.SetLockValue('noSelect', true)
oNextParagraph.AddDrawing(oDrawingOne)
oDocument.AddElement(num, oNextParagraph)
const oNextParagraphOne = Api.CreateParagraph()
var oDrawing20 = Api.CreateImage(imageSvg, 24.11 * 36000, 8.34 * 36000)
oNextParagraphOne.AddDrawing(oDrawing20)
var oDocContentOne = oDrawingOne.GetDocContent()
oDocContentOne.AddElement(0, oNextParagraphOne)
const oNextParagraph11 = Api.CreateParagraph()
oNextParagraph11.AddText('技术标准发布发放专用章')
oNextParagraph11.SetColor(255, 0, 13, false)
oNextParagraph11.SetFontFamily('宋体')
oNextParagraph11.SetBold(true)
oNextParagraph11.SetSpacingAfter(80)
oNextParagraph11.SetFontSize(28)
oNextParagraph11.SetJc('center')
oNextParagraph11.SetSpacing(0.3)
oDocContentOne.AddElement(1, oNextParagraph11)
const oNextParagraph22 = Api.CreateParagraph()
oNextParagraph22.AddText('分 发 有 效')
oNextParagraph22.SetFontFamily('黑体')
oNextParagraph22.SetColor(255, 0, 13, false)
oNextParagraph22.SetFontSize(45)
oNextParagraph22.SetBold(true)
oNextParagraph22.SetSpacingAfter(80)
oNextParagraph22.SetJc('center')
oDocContentOne.AddElement(2, oNextParagraph22)
const oNextParagraph33 = Api.CreateParagraph()
oNextParagraph33.AddText('分发日期:' + Asc.scope.year + '年' + Asc.scope.month + '月' + Asc.scope.day + '日')
oNextParagraph33.SetBold(true)
oNextParagraph33.SetColor(51, 51, 51, false)
oNextParagraph33.SetFontSize(28)
oNextParagraph33.SetBold(false)
oNextParagraph33.SetJc('center')
oNextParagraph33.SetFontFamily('宋体')
oDocContentOne.AddElement(3, oNextParagraph33)
oNextParagraph33.Search('分发日期:')[0].SetColor(255, 0, 13, false)
oNextParagraph33.Search('年')[0].SetColor(255, 0, 13, false)
oNextParagraph33.Search('月')[0].SetColor(255, 0, 13, false)
oNextParagraph33.Search('日')[1].SetColor(255, 0, 13, false)
} catch (e) {
console.log(e)
}
})
},
// 创建空行
handleInsertRow () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
this.ctx.callCommand(() => {
try {
const BORDER_DISABLE = Asc.scope.BORDER_DISABLE
const oDocument = Api.GetDocument()
// const oParagraph = oDocument.Document.GetCurrentParagraph(
// undefined,
// undefined,
// {CheckDocContent: true}
// );
// console.log(oParagraph);
const newParagraph = Api.CreateParagraph()
// newParagraph.SetParagraphWx(oParagraph);
// 获取到父Table
let parentTable = newParagraph.GetParentTable()
let parentTableCell = newParagraph.GetParentTableCell()
if (!parentTable) {
return '当前父元素ClassType不是Table'
}
// 在最后一个单元格之后插入一个新行
const oTableRow = parentTable.AddRow(parentTableCell, false)
// // 获取插入的行共有几列
const oCellsCount = oTableRow.GetCellsCount()
// 清除单元格内容
oTableRow.GetCell(0).GetContent().GetElement(0).Delete()
oTableRow.SetHeight('atLeast', 2880)
oTableRow.GetCell(0).SetCellMarginRight(120)
oTableRow.GetCell(0).SetCellMarginLeft(120)
// 去除父表格Border
if (BORDER_DISABLE) {
oTableRow
.GetCell(0)
.SetCellBorderTop('single', 0, 0, 255, 255, 255)
oTableRow
.GetCell(0)
.SetCellBorderRight('single', 0, 0, 255, 255, 255)
oTableRow
.GetCell(0)
.SetCellBorderBottom('single', 0, 0, 255, 255, 255)
oTableRow
.GetCell(0)
.SetCellBorderLeft('single', 0, 0, 255, 255, 255)
} else {
oTableRow.GetCell(0).SetCellBorderTop('single', 0, 0, 255, 255, 255)
oTableRow.GetCell(0).SetCellBorderRight('single', 0, 0, 255, 255, 255)
oTableRow.GetCell(0).SetCellBorderBottom('single', 0, 0, 255, 255, 255)
oTableRow.GetCell(0).SetCellBorderLeft('single', 0, 0, 255, 255, 255)
}
// 如果列数大于1 默认合并
if (oCellsCount !== 1) {
oTableRow.MergeCells()
}
} catch (e) {
console.log(e)
}
})
},
// 创建内容控件
handleInsertControl (control) {
Asc.scope.alias = control.key
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
// 创建前言
if (
Asc.scope.alias === 'forewordCN' ||
Asc.scope.alias === 'forewordEN'
) {
const oInlineLvlSdt1 = Api.CreateInlineLvlSdt()
const oRun1 = Api.CreateRun()
oRun1.AddText('为规范')
oInlineLvlSdt1.SetLock('sdtContentLocked')
oInlineLvlSdt1.AddElement(oRun1, 0)
const oParagraph1 = Api.CreateParagraph()
oParagraph1.AddInlineLvlSdt(oInlineLvlSdt1)
oParagraph1.SetIndLeft(360)
oParagraph1.AddText('XXXXXXXXXXXXXXXXXXXX,')
oDocument.InsertContent([oParagraph1])
const oInlineLvlSdt2 = Api.CreateInlineLvlSdt()
oInlineLvlSdt2.SetLock('sdtContentLocked')
const oRun2 = Api.CreateRun()
oRun2.AddText('特制定此标准。')
oInlineLvlSdt2.AddElement(oRun2, 0)
const oParagraph2 = Api.CreateParagraph()
oParagraph2.AddInlineLvlSdt(oInlineLvlSdt2)
oParagraph2.AddLineBreak()
oDocument.InsertContent([oParagraph2])
const oInlineLvlSdt3 = Api.CreateInlineLvlSdt()
oInlineLvlSdt3.SetLock('sdtContentLocked')
const oRun3 = Api.CreateRun()
oRun3.AddText('本标准是对')
oInlineLvlSdt3.AddElement(oRun3, 0)
const oParagraph3 = Api.CreateParagraph()
oParagraph3.AddInlineLvlSdt(oInlineLvlSdt3)
oParagraph3.SetIndLeft(360)
const oInlineLvlSdt4 = Api.CreateInlineLvlSdt()
oInlineLvlSdt4.SetAlias('foton.standCode')
const oRun4 = Api.CreateRun()
oRun4.AddText('SMTC XXXX.X—XXXXVX')
oInlineLvlSdt4.AddElement(oRun4, 0)
oParagraph3.AddInlineLvlSdt(oInlineLvlSdt4)
oParagraph3.AddLineBreak()
oDocument.InsertContent([oParagraph3])
const oInlineLvlSdt5 = Api.CreateInlineLvlSdt()
oInlineLvlSdt5.SetLock('sdtContentLocked')
const oRun5 = Api.CreateRun()
oRun5.AddText('《')
oInlineLvlSdt5.AddElement(oRun5, 0)
const oParagraph5 = Api.CreateParagraph()
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt5)
const oInlineLvlSdt6 = Api.CreateInlineLvlSdt()
oInlineLvlSdt6.SetAlias('foton.standName')
const oRun6 = Api.CreateRun()
oRun6.AddText('XXXXXXXXXXXXX XXXXXX')
oInlineLvlSdt6.AddElement(oRun6, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt6)
const oInlineLvlSdt7 = Api.CreateInlineLvlSdt()
oInlineLvlSdt7.SetLock('sdtContentLocked')
const oRun7 = Api.CreateRun()
oRun7.AddText('》')
oInlineLvlSdt7.AddElement(oRun7, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt7)
const oInlineLvlSdt8 = Api.CreateInlineLvlSdt()
oInlineLvlSdt8.SetLock('sdtContentLocked')
const oRun8 = Api.CreateRun()
oRun8.AddText('的修订,自本标准实施之日起废除')
oInlineLvlSdt8.AddElement(oRun8, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt8)
const oInlineLvlSdt9 = Api.CreateInlineLvlSdt()
oInlineLvlSdt9.SetAlias('foton.standCode')
const oRun9 = Api.CreateRun()
oRun9.AddText('SMTC XXXX.X—XXXXVX')
oInlineLvlSdt9.AddElement(oRun9, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt9)
const oInlineLvlSdt10 = Api.CreateInlineLvlSdt()
const oRun10 = Api.CreateRun()
oRun10.AddText('。')
oInlineLvlSdt10.AddElement(oRun10, 0)
oParagraph5.AddInlineLvlSdt(oInlineLvlSdt10)
oDocument.InsertContent([oParagraph5])
} else {
const oInlineLvlSdtCN = Api.CreateInlineLvlSdt()
const oRun1 = Api.CreateRun()
oRun1.SetFontSize(21)
if (Asc.scope.alias !== 'fixed') {
oInlineLvlSdtCN.SetAlias(`${Asc.scope.alias}`)
switch (Asc.scope.alias) {
case 'standCode':
oRun1.AddText('XXXX.X—XXXXVX')
oRun1.SetFontFamily('黑体')
break
case 'standCNName':
oRun1.AddText('XXXXXXXXXXXXXXX XXXXXX')
oRun1.SetFontFamily('黑体')
break
case 'standENName':
oRun1.AddText('XXXXXXXXXXXXXXX XXXXXX')
oRun1.SetFontFamily('Airal')
break
case 'primaryDrafter':
oRun1.AddText('XXX、XX、XX、XX、XX')
oRun1.SetFontFamily('宋体')
break
case 'issueDate':
oRun1.AddText('XXXX年XX月XX日')
oRun1.SetFontFamily('宋体')
break
case 'impDate':
oRun1.AddText('XXXX年XX月XX日')
oRun1.SetFontFamily('宋体')
break
case 'replaceStandCode':
oRun1.AddText(
'SMTC XXXX.X—XXXXVX)、SMTC XXXX.X—XXXXVX'
)
oRun1.SetFontFamily('宋体')
break
}
} else {
oRun1.SetFontSize(21)
oRun1.SetFontFamily('Airal')
// oInlineLvlSdtCN.SetLock("sdtContentLocked");
}
oInlineLvlSdtCN.AddElement(oRun1, 0)
const CNParagraph = Api.CreateParagraph()
CNParagraph.AddInlineLvlSdt(oInlineLvlSdtCN)
oDocument.InsertContent([CNParagraph])
}
} catch (e) {
console.log(e)
}
})
},
/**
* 数据替换
*/
handleReplace () {
this.initModalVisible = true
},
equationOne: debounce(function () {
let that = this
that.ctx.callCommand(() => {
try {
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])
}
}
}
Api.asc_UpdateTableOfContents()
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 list = ContentsPr.GetAllParagraphs()
if (list && list.length > 0) {
for (let i = 0; i < list.length; i++) {
list[i].SetFontFamily('宋体')
console.log('更新目录样式')
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)
var aSearch = list[i].Search('前 言')
aSearch[0].AddText('前言')
var aSearch1 = list[i].Search('前 言')
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)
var aSearch = list[i].Search('引 言')
aSearch[0].AddText('引言')
var aSearch1 = list[i].Search('引 言')
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)
}
}
}
}
} catch (e) {
console.log(e)
}
})
}, 500),
/**
* 添加新制定标准化文件格式前言
*/
addNewForeword () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
this.ctx.callCommand(() => {
try {
// 获取文档对象
const oDocument = Api.GetDocument()
// 内容
const newForewordContent = {
default_one: [
'本文件按照GB/T 1.1-2020《标准化工作导则 第1部分:准化文件的结构和起草规则》的规定起草。',
'本文件为首次制定。',
'本文件附录A为规范性附录,附录B为资料性附录。(如有附录,则需在前言中提及)',
'本文件由中国重型汽车集团有限公司提出。',
'本文件由中国重型汽车集团有限公司汽车研究总院归口。',
'本文件起草单位:中国重型汽车集团有限公司汽车研究总院。',
'本文件主要起草人:xx、XX。'
]
}
/**
* 添加普通段落格式的前言
*/
const addDefaultForewordText = (text) => {
text = ' ' + text
const oParagraph3 = Api.CreateParagraph()
oParagraph3.AddText(text)
oParagraph3.SetFontSize(21)
oParagraph3.SetFontFamily('宋体')
oParagraph3.SetColor(0, 0, 0)
oParagraph3.SetSpacingAfter(0)
oParagraph3.SetBold(false)
oDocument.InsertContent([oParagraph3])
}
/**
* 添加列表式段落格式前言
*/
const addNumberedForewordText = (text) => {
}
const keys = Object.keys(newForewordContent)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const type = key.substring(0, key.indexOf('_'))
let dealFunc
const contentArr = newForewordContent[key] || []
switch (type) {
case 'default':
dealFunc = addDefaultForewordText
break
case 'numbered':
dealFunc = addNumberedForewordText
break
default:
break
}
if (dealFunc) {
for (let j = 0; j < contentArr.length; j++) {
const text = contentArr[j]
dealFunc(text)
}
}
}
} catch (e) {
console.log(e)
}
})
},
/**
* 添加修订标准化文件格式前言
*/
addReviseForeword () {
window.Asc.scope.BORDER_DISABLE = BORDER_DISABLE
this.ctx.callCommand(() => {
try {
// 获取文档对象
const oDocument = Api.GetDocument()
// 修订标准化文件格式前言内容
const content = {
default_one: [
'本文件按照GB/T 1.1-2020《标准化工作导则 第1部分:标准化文件的结构和起草规则》的规定起草。',
'本文件代替Q/zz xxxx-XX《标准名称》,本文件与上一版本相比,主要变化如下:'
],
numbered_one: [
'增加了xx内容;',
'删除了xx内容;',
'修改了xx内容。'
],
default_two: [
'本文件为第x次修订。',
'本文件由中国重型汽车集团有限公司提出',
'本文件由中国重型汽车集团有限公司汽车研究总院归口。',
'本文件起草单位:中国重型汽车集团有限公司汽车研究总院。',
'本文件主要起草人:xxx、xX。',
'本文件及其所代替文件的历次版本发布情况为:'
],
numbered_two: [
'Q/zzXXXXX-2001(主要起草人:XX、XX)',
'Q/zzXXXXX-2009(主要起草人:XX、XX)',
'Q/ZZXXXXX-2018(主要起草人:XX、XX)。'
]
}
/**
* 添加普通段落格式的前言
*/
const addDefaultForewordText = (text) => {
text = ' ' + text
const oParagraph3 = Api.CreateParagraph()
oParagraph3.AddText(text)
oParagraph3.SetFontSize(21)
oParagraph3.SetFontFamily('宋体')
oParagraph3.SetColor(0, 0, 0)
oParagraph3.SetSpacingAfter(0)
oParagraph3.SetBold(false)
oDocument.InsertContent([oParagraph3])
}
/**
* 添加列表式段落格式前言
*/
const addNumberedForewordText = (text) => {
let oNumbering = oDocument.CreateNumbering('numbered')
const oNumLvl = oNumbering.GetLevel(0)
oNumLvl.SetCustomType('decimalZero', '——', 'right')
oNumLvl.SetSuff('tab')
var oParaPr = oNumLvl.GetParaPr()
oParaPr.SetSpacingLine(280, 'auto')
oParaPr.SetIndFirstLine(0)
const oParagraph3 = Api.CreateParagraph()
oParagraph3.AddText(text)
oParagraph3.SetNumbering(oNumLvl)
oParagraph3.SetFontSize(21)
oParagraph3.SetIndLeft(840)
oParagraph3.SetFontFamily('宋体')
oParagraph3.SetColor(0, 0, 0)
oParagraph3.SetSpacingAfter(0)
oParagraph3.SetBold(false)
oDocument.InsertContent([oParagraph3])
}
const keys = Object.keys(content)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const type = key.substring(0, key.indexOf('_'))
let dealFunc
const contentArr = content[key] || []
switch (type) {
case 'default':
dealFunc = addDefaultForewordText
break
case 'numbered':
dealFunc = addNumberedForewordText
break
default:
break
}
if (dealFunc) {
for (let j = 0; j < contentArr.length; j++) {
const text = contentArr[j]
dealFunc(text)
}
}
}
} catch (e) {
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++) {
// 避免重复创建参考文献
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)
}
})
},
/**
* 添加发布章
*/
addPublicationChapter () {
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
const GetAllDrawingObjects = oDocument.GetAllShapes()
// 获取在封面预留的添加发布章的区域
let oDocContentOne
for (let i = 0; i < GetAllDrawingObjects.length; i++) {
if (GetAllDrawingObjects[i].GetLockValue('noSelect')) {
oDocContentOne = GetAllDrawingObjects[i].GetDocContent()
break
}
}
oDocContentOne.RemoveAllElements()
const paragraph = Api.CreateParagraph()
paragraph.AddText('受 控')
paragraph.SetFontSize(48)
paragraph.SetColor(255, 0, 13, false)
paragraph.SetJc('center')
paragraph.SetBold(true)
paragraph.SetSpacingAfter(100)
// 创建图形
const rectParagraph = Api.CreateParagraph()
const stroke = Api.CreateStroke(24000, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)))
const oDrawing = Api.CreateShape('rect', 1518483, 708475, null, stroke)
rectParagraph.AddDrawing(oDrawing)
rectParagraph.SetJc('center')
const rectDocContent = oDrawing.GetContent()
const rectTextParagh = rectDocContent.GetElement(0)
rectTextParagh.AddText('正 本')
rectTextParagh.SetFontSize(68)
rectTextParagh.SetColor(255, 0, 13, false)
rectTextParagh.SetBold(true)
rectTextParagh.SetSpacingBefore(0)
rectTextParagh.SetSpacingAfter(0)
oDocContentOne.AddElement(paragraph)
oDocContentOne.Push(paragraph)
oDocContentOne.AddElement(rectParagraph)
oDocContentOne.Push(rectParagraph)
} catch (e) {
console.log(e)
}
})
},
/**
* 插入签审信息
*/
async insertSignatureInfo () {
Asc.scope.signatureInfo = await this.getSignatureInfo()
Asc.scope.standCode = this.form.standCode
Asc.scope.standCNName = this.form.standName
Asc.scope.downloadUrl = window._CONFIG.downloadUrl
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
// 签审信息只创建一次
const AllContentControls = oDocument.GetAllContentControls()
let flag = false
for (let i = 0; i < AllContentControls.length; i++) {
if (AllContentControls[i].GetAlias() === 'sinotruk.signatureInfo') {
flag = true
break
}
}
if (flag) {
return
}
const count = oDocument.GetElementsCount()
let coverEndParagraph, paragraphIndex
for (let i = 0; i < count; i++) {
const element = oDocument.GetElement(i)
if ('paragraph' === element.GetClassType() && element.GetText().indexOf('中国重型汽车集团有限公司') !== -1 && element.GetText().indexOf('发布') !== -1) {
paragraphIndex = i + 1
coverEndParagraph = element
}
}
if (!coverEndParagraph) {
return
}
const emptyParagraph = Api.CreateParagraph()
oDocument.AddElement(paragraphIndex, emptyParagraph)
// 最上面的黑体标题
const oRunSubTitle = Api.CreateRun()
const oParagraphSubTitle = Api.CreateParagraph()
oRunSubTitle.AddText('中国重型汽车集团有限公司企业标准')
const oInlineLvlSdtSubTitle = Api.CreateInlineLvlSdt()
oInlineLvlSdtSubTitle.SetAlias('sinotruk.signatureInfo')
oInlineLvlSdtSubTitle.AddElement(oRunSubTitle, 0)
oParagraphSubTitle.AddInlineLvlSdt(oInlineLvlSdtSubTitle)
// oParagraphSubTitle.AddText(Asc.scope.standCNName);
oParagraphSubTitle.SetFontSize(32)
oParagraphSubTitle.SetSpacingBefore(300)
oParagraphSubTitle.SetSpacingAfter(300)
oParagraphSubTitle.SetFontFamily('黑体')
oParagraphSubTitle.SetColor(0, 0, 0)
oParagraphSubTitle.SetJc('center')
oParagraphSubTitle.SetBold(false)
emptyParagraph.InsertParagraph(oParagraphSubTitle, 'after')
// 责任签署的大标题
const oParagraphLargeTitle = Api.CreateParagraph()
oParagraphLargeTitle.AddText('责任签署')
oParagraphLargeTitle.SetFontSize(96)
oParagraphLargeTitle.SetSpacing(6)
oParagraphLargeTitle.SetSpacingAfter(300)
oParagraphLargeTitle.SetFontFamily('宋体')
oParagraphLargeTitle.SetColor(0, 0, 0)
oParagraphLargeTitle.SetJc('center')
oParagraphSubTitle.InsertParagraph(oParagraphLargeTitle, 'after')
// 计划编号
const oParagraphPlanNum = Api.CreateParagraph()
oParagraphPlanNum.AddText('计划编号:')
oParagraphPlanNum.SetFontFamily('宋体')
oParagraphPlanNum.SetFontSize(21)
oParagraphPlanNum.SetJc('left')
oParagraphPlanNum.SetSpacingAfter(0)
oParagraphPlanNum.SetSpacingBefore(0)
oParagraphPlanNum.SetColor(0, 0, 0)
oParagraphPlanNum.SetSpacingLine(1.5 * 240, 'auto')
oParagraphLargeTitle.InsertParagraph(oParagraphPlanNum, 'after')
// 标准名称
const oParagraphStandardName = Api.CreateParagraph()
oParagraphStandardName.AddText('标准名称:' + Asc.scope.standCode + ' ' + Asc.scope.standCNName)
oParagraphStandardName.SetFontFamily('宋体')
oParagraphStandardName.SetFontSize(21)
oParagraphStandardName.SetJc('left')
oParagraphStandardName.SetSpacingAfter(0)
oParagraphStandardName.SetSpacingBefore(0)
oParagraphStandardName.SetColor(0, 0, 0)
oParagraphStandardName.SetSpacingLine(1.5 * 240, 'auto')
oParagraphPlanNum.InsertParagraph(oParagraphStandardName, 'after')
// 横线
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', 6110900, 9000, oFill, oStroke)
oDrawing.SetWrappingStyle('inline')
oParagraphLine.AddDrawing(oDrawing)
oDrawing.SetDistances(0, 541, 0, 0)
oParagraphStandardName.InsertParagraph(oParagraphLine, 'after')
// 签章信息部分
const oParagraphBox = Api.CreateParagraph()
oParagraphBox.SetSpacingBefore(400)
const oStrokeBox = Api.CreateStroke(0, Api.CreateSolidFill(Api.CreateRGBColor(255, 0, 13)))
const oDrawingBox = Api.CreateShape('rect', 6110900, 6120900, null, oStrokeBox)
oDrawingBox.SetVerticalTextAlign('top')
oParagraphBox.AddDrawing(oDrawingBox)
oParagraphLine.InsertParagraph(oParagraphBox, 'after')
const signatureInfo = Asc.scope.signatureInfo
if (signatureInfo) {
// 内部的信息及手写章等内容
const oDocContent = oDrawingBox.GetDocContent()
const labelList = Object.keys(signatureInfo)
for (const key of labelList) {
const oParagraphLineOne = Api.CreateParagraph()
const oRunLabel = Api.CreateRun()
oRunLabel.AddText(key)
oRunLabel.SetPosition(48)
if (key.length === 4) {
oRunLabel.SetSpacing(80)
} else {
oRunLabel.SetSpacing(20)
}
oParagraphLineOne.AddElement(oRunLabel)
const oRunSymbol = Api.CreateRun()
oRunSymbol.AddText('')
oRunSymbol.SetPosition(48)
oParagraphLineOne.AddElement(oRunSymbol)
const userList = signatureInfo[key] || []
for (let i = 0; i < userList.length; i++) {
const user = userList[i]
// 姓名工号
const oRunUserName = Api.CreateRun()
oRunUserName.AddText(user.userName + ' ')
oRunUserName.SetPosition(48)
// 手写章图片
const oRunImage = Api.CreateRun()
const url = `${Asc.scope.downloadUrl}/laws-sinotruk/sys/common/downloadWithoutToken/${user.avatarFileId}`
const oDrawingImg = Api.CreateImage(url, 53 * 36000, 18.4 * 36000)
oRunImage.AddDrawing(oDrawingImg)
// 签署日期
const oRunTime = Api.CreateRun()
oRunTime.AddText(' 签署日期:' + user.signTime)
oRunTime.SetPosition(48)
if (i === 0) {
oParagraphLineOne.AddElement(oRunUserName)
oParagraphLineOne.AddElement(oRunImage)
oParagraphLineOne.AddElement(oRunTime)
oParagraphLineOne.GetElement(0)
oDocContent.AddElement(oParagraphLineOne)
oDocContent.Push(oParagraphLineOne)
} else {
const oParagraphLine = Api.CreateParagraph()
oParagraphLine.AddElement(oRunUserName)
oParagraphLine.AddElement(oRunImage)
oParagraphLine.AddElement(oRunTime)
oParagraphLine.SetIndLeft(1388)
oDocContent.AddElement(oParagraphLine)
oDocContent.Push(oParagraphLine)
}
}
}
}
// 中国重型汽车集团有限公司
const oParagraphPageEnd = Api.CreateParagraph()
oParagraphPageEnd.AddText('中国重型汽车集团有限公司')
oParagraphPageEnd.SetFontSize(48)
oParagraphPageEnd.SetSpacingBefore(300)
oParagraphPageEnd.SetSpacingAfter(0)
oParagraphPageEnd.SetFontFamily('宋体')
oParagraphPageEnd.SetColor(0, 0, 0)
oParagraphPageEnd.SetJc('center')
oParagraphPageEnd.SetBold(false)
oParagraphPageEnd.SetSpacing(1.8)
oParagraphBox.InsertParagraph(oParagraphPageEnd, 'after')
} catch (e) {
console.log(e)
}
})
},
getSignatureInfo () {
return new Promise(resolve => {
let result = false
const params = {
processInstanceId: this.form.processId
}
_axios({
url: '/laws-sinotruk/process/es/revision/getSignInfo',
method: 'get',
params: params
}).then(res => {
if (res.success) {
result = res.result
}
}).finally(() => {
resolve(result)
})
})
}
},
created () {
// 获取企标详情
// this.$axios
// .get("/static/json/detail.json")
// .then((res) => {
// console.log(res);
// const form = res;
// this.form = form;
// console.log(this.form);
// })
// .catch((e) => {
// console.log(e);
// });
// this.initModalVisible = true;
},
mounted () {
function param2Obj (url) {
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
if (!search) {
return {}
}
const obj = {}
const searchArr = search.split('&')
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
let val = v.substring(index + 1, v.length)
if (val === 'undefined' || !val) {
val = ''
}
obj[name] = val
}
})
return obj
}
let timer = setTimeout(() => {
clearTimeout(timer)
timer = null
let documentCallbackUrl = window.Asc.plugin.info.documentCallbackUrl
console.log(documentCallbackUrl)
let query = param2Obj(documentCallbackUrl)
const businessInfo = JSON.parse(query.business)
this.form = Object.assign(query, businessInfo)
console.log(this.form)
this.handleCreateCover()
}, 1000)
}
}
</script>
<style lang="less" scoped>
::v-deep {
.el-date-editor {
width: 100% !important;
.el-input__inner {
height: 32px;
line-height: 32px;
}
}
}
.ant-drawer {
width: 210px;
height: 40px;
text-align: center;
line-height: 40px;
background: #000;
color: #fff;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 6px;
}
.ant-drawer-text {
width: 10px;
display: inline-block;
color: #ffff00;
}
</style>