224 lines
8.4 KiB
Vue
224 lines
8.4 KiB
Vue
<template>
|
||
<div class="note">
|
||
<a-button-group style="margin-bottom: 10px;">
|
||
<a-button @click="handleInsertNoteOne('CN')">注</a-button>
|
||
<a-button @click="handleInsertMultNotTwo('CN')">注X</a-button>
|
||
<a-button @click="handleInsertMultNoteThe('CN')">首注</a-button>
|
||
</a-button-group>
|
||
<!-- <a-button-group>-->
|
||
<!-- <a-button @click="handleInsertNote('EN')">插入单个注(English)</a-button>-->
|
||
<!-- <a-button @click="handleInsertMultNote('EN')">插入多个注(English)</a-button>-->
|
||
<!-- </a-button-group>-->
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
methods: {
|
||
// 插入单个注释
|
||
handleInsertNote(lang) {
|
||
window.Asc.scope.lang = lang
|
||
this.ctx.callCommand(() => {
|
||
try {
|
||
const oDocument = Api.GetDocument();
|
||
const newParagraph = Api.CreateParagraph();
|
||
const oTableCell = newParagraph.GetParentTableCell();
|
||
const elementsCount = oTableCell.GetContent().GetElementsCount();
|
||
let noteNumLevel = null;
|
||
for (let i = 0; i < elementsCount; i++) {
|
||
if (noteNumLevel) { break; }
|
||
const ele = oTableCell.GetContent().GetElement(i);
|
||
if (ele && ele.GetClassType() === 'paragraph' && ele.GetNumbering()) {
|
||
const contentControls = ele.GetAllContentControls();
|
||
for (let j = 0; j < contentControls.length; j++) {
|
||
if (contentControls[j] && contentControls[j].GetAlias() === 'smtc.note') {
|
||
noteNumLevel = ele.GetNumbering();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (noteNumLevel) {
|
||
const sFormatString = Asc.scope.lang === 'CN' ? '注%1:' : 'Note%1:'
|
||
noteNumLevel.SetCustomType('decimal', sFormatString, 'left')
|
||
} else {
|
||
const oNumbering = oDocument.CreateNumbering('numbered')
|
||
noteNumLevel = oNumbering.GetLevel(0)
|
||
const sFormatString = Asc.scope.lang === 'CN' ? '注:' : 'Note:'
|
||
noteNumLevel.SetCustomType('decimal', sFormatString, 'left')
|
||
noteNumLevel.SetSuff('space')
|
||
}
|
||
|
||
const oParagraphNote = Api.CreateParagraph();
|
||
const oInlineLvlSdtNote = Api.CreateInlineLvlSdt();
|
||
oInlineLvlSdtNote.SetAlias("smtc.note");
|
||
oParagraphNote.AddInlineLvlSdt(oInlineLvlSdtNote);
|
||
oParagraphNote.AddText('XXX');
|
||
oParagraphNote.SetNumbering(noteNumLevel);
|
||
oParagraphNote.SetContextualSpacing(true);
|
||
oParagraphNote.SetFontSize(18);
|
||
if (Asc.scope.lang === 'CN') {
|
||
oParagraphNote.SetFontFamily('Arial');
|
||
} else {
|
||
oParagraphNote.SetFontFamily('SimSun');
|
||
}
|
||
oParagraphNote.SetSpacingAfter(60);
|
||
oTableCell.AddElement(oTableCell.GetContent().GetElementsCount() - 1, oParagraphNote);
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}, false)
|
||
},
|
||
|
||
// 插入多个注释
|
||
handleInsertMultNote(lang) {
|
||
window.Asc.scope.lang = lang
|
||
this.ctx.callCommand(() => {
|
||
try {
|
||
const oDocument = Api.GetDocument()
|
||
let oNumbering = oDocument.CreateNumbering('numbered')
|
||
const oNumLvl = oNumbering.GetLevel(0)
|
||
const sFormatString = Asc.scope.lang === 'CN' ? '注%1:' : 'Note%1:'
|
||
oNumLvl.SetCustomType('decimal', sFormatString, 'left')
|
||
oNumLvl.SetSuff('space')
|
||
for (let nLvl = 1; nLvl < 4; nLvl++) {
|
||
const oParagraphNote = Api.CreateParagraph()
|
||
const oInlineLvlSdt = Api.CreateInlineLvlSdt();
|
||
oInlineLvlSdt.SetAlias("smtc.note");
|
||
oParagraphNote.AddInlineLvlSdt(oInlineLvlSdt);
|
||
if (Asc.scope.lang === 'CN') {
|
||
oParagraphNote.AddText('XXXXXX')
|
||
} else {
|
||
oParagraphNote.AddText('XXXXXX.')
|
||
}
|
||
oParagraphNote.SetNumbering(oNumLvl)
|
||
oParagraphNote.SetContextualSpacing(true)
|
||
oParagraphNote.SetFontSize(18);
|
||
if (Asc.scope.lang === 'CN') {
|
||
oParagraphNote.SetFontFamily('Arial');
|
||
} else {
|
||
oParagraphNote.SetFontFamily('SimSun');
|
||
}
|
||
oParagraphNote.SetSpacingAfter(60);
|
||
oDocument.InsertContent([oParagraphNote]);
|
||
}
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}, false)
|
||
},
|
||
|
||
handleInsertNoteOne(){
|
||
window.Asc.scope.guid = window.Asc.plugin.info.guid
|
||
window.Asc.scope.suffType = ''
|
||
this.ctx.callCommand(() => {
|
||
try {
|
||
const oDocument = Api.GetDocument()
|
||
let oNumbering = oDocument.CreateNumbering('numbered')
|
||
const oNumLvl = oNumbering.GetLevel(0)
|
||
oNumLvl.SetCustomType('decimalZero', "注:", "left")
|
||
oNumLvl.SetSuff("space");
|
||
var oParaPr = oNumLvl.GetParaPr();
|
||
oParaPr.SetSpacingLine(280, "auto");
|
||
oParaPr.SetJc("both");
|
||
oParaPr.SetIndFirstLine(0);
|
||
const oParagraph = Api.CreateParagraph()
|
||
oParagraph.SetNumbering(oNumLvl)
|
||
oParagraph.SetContextualSpacing(true)
|
||
oParagraph.SetFontFamily('宋体')
|
||
oParagraph.SetFontSize(21)
|
||
oParagraph.SetHighlight(255, 255, 0);
|
||
oDocument.InsertContent([oParagraph])
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}, false)
|
||
},
|
||
handleInsertMultNotTwo(){
|
||
window.Asc.scope.guid = window.Asc.plugin.info.guid
|
||
window.Asc.scope.suffType = ''
|
||
this.ctx.callCommand(() => {
|
||
try {
|
||
const oDocument = Api.GetDocument()
|
||
const allElement = oDocument.GetElementsCount()
|
||
let numbering = null
|
||
let currentNumbering = null
|
||
for (let index = 0; index < allElement; index++) {
|
||
const element = oDocument.GetElement(index)
|
||
if ("paragraph" === element.GetClassType()) {
|
||
const getNumbering = element.GetNumbering()
|
||
const text = element.GetSpacingBefore()
|
||
if (getNumbering !== null) {
|
||
if (text == 50) {
|
||
currentNumbering = getNumbering
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!numbering) {
|
||
if (currentNumbering) {
|
||
numbering = currentNumbering.GetNumbering().GetLevel(0)
|
||
} else {
|
||
let oNumbering = oDocument.CreateNumbering('numbered')
|
||
numbering = oNumbering.GetLevel(0)
|
||
const sFormatString = '注 %1:';
|
||
numbering.SetCustomType("decimal", sFormatString, "left");
|
||
}
|
||
}
|
||
const oParagraph = Api.CreateParagraph()
|
||
// oParagraph.SetSpacingLine(400, "auto");
|
||
var oParaPr = numbering.GetParaPr();
|
||
oParaPr.SetSpacingLine(280, "auto");
|
||
oParaPr.SetJc("both");
|
||
oParaPr.SetIndFirstLine(0);
|
||
oParagraph.SetNumbering(numbering)
|
||
oParagraph.SetFontFamily('宋体')
|
||
oParagraph.SetSpacingBefore(50)
|
||
oParagraph.SetSpacingAfter(50)
|
||
oParagraph.SetFontSize(21)
|
||
oParagraph.SetBold(false);
|
||
oParagraph.SetJc("left");
|
||
oParagraph.SetHighlight(255, 255, 0);
|
||
oDocument.InsertContent([oParagraph])
|
||
// oNumbering = oParagraph.GetNumbering().GetNumbering()
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}, false)
|
||
},
|
||
handleInsertMultNoteThe(){
|
||
window.Asc.scope.guid = window.Asc.plugin.info.guid
|
||
window.Asc.scope.suffType = ''
|
||
this.ctx.callCommand(() => {
|
||
try {
|
||
const oDocument = Api.GetDocument()
|
||
let oNumbering = oDocument.CreateNumbering('numbered')
|
||
const oNumLvl = oNumbering.GetLevel(0)
|
||
oNumLvl.SetCustomType('decimal', "注 %1:", "left")
|
||
oNumLvl.SetSuff("space");
|
||
var oParaPr = oNumLvl.GetParaPr();
|
||
oParaPr.SetSpacingLine(280, "auto");
|
||
oParaPr.SetJc("both");
|
||
oParaPr.SetIndFirstLine(0);
|
||
const oParagraph = Api.CreateParagraph()
|
||
oParagraph.SetNumbering(oNumLvl)
|
||
oParagraph.SetFontFamily('宋体')
|
||
oParagraph.SetSpacingBefore(50)
|
||
oParagraph.SetSpacingAfter(50)
|
||
oParagraph.SetBold(false);
|
||
oParagraph.SetFontSize(21)
|
||
oParagraph.SetHighlight(255, 255, 0);
|
||
oDocument.InsertContent([oParagraph])
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}, false)
|
||
},
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
|
||
</style>
|