fix 插入图片

This commit is contained in:
赵霄
2023-09-17 18:46:49 +08:00
parent 18bea574ca
commit 50e199c43c
5 changed files with 558 additions and 566 deletions
+2 -2
View File
@@ -13,14 +13,14 @@
<% if (process.env.NODE_ENV === 'development' ) { %>
<script>
window._CONFIG = {
'interfaceUrl': 'http://10.10.10.46:4202',
'interfaceUrl': 'http://139.9.235.66:8184',
};
</script>
<% } %>
<% if (process.env.NODE_ENV === 'production' ) { %>
<script>
window._CONFIG = {
'interfaceUrl': 'https://srms.foton.com.cn',
'interfaceUrl': 'http://laws-sinotruk-server-kmc2c.yf-grp:8080',
};
</script>
<% } %>
+3 -3
View File
@@ -3,12 +3,12 @@
* @author: chenxiaoxi
* @date: 2021-08-18 17:47:46
*/
const interfaceUrl = window._CONFIG.interfaceUrl + '/api/' //本地
const interfaceUrl = window._CONFIG.interfaceUrl + '/laws-sinotruk/' //本地
// const interfaceUrl = 'https://srms.foton.com.cn/api/' //线上
const uploadFilePath = 'api/att/attFile/uploadNew'
const uploadFilePath = '/laws-sinotruk/onlyoffice/upload'
const staticFilePath = window._CONFIG.interfaceUrl + '/api/att/attFile/downloadFileForSarNew' //本地
const staticFilePath = window._CONFIG.interfaceUrl + '/laws-sinotruk/onlyoffice/downLoadFile' //本地
// const staticFilePath = 'https://srms.foton.com.cn/api/att/attFile/downloadFile' //线上
module.exports = {
interfaceUrl,
+128 -127
View File
@@ -18,12 +18,12 @@
v-bind="formItemLayout"
@submit="handleSubmit"
>
<!-- <a-form-item label="标题">-->
<!-- <a-input-->
<!-- v-model="form.title"-->
<!-- placeholder="请输入标题"-->
<!-- />-->
<!-- </a-form-item>-->
<!-- <a-form-item label="标题">-->
<!-- <a-input-->
<!-- v-model="form.title"-->
<!-- placeholder="请输入标题"-->
<!-- />-->
<!-- </a-form-item>-->
<a-form-item label="图片">
<a-upload
ref="upload"
@@ -31,7 +31,7 @@
list-type="picture-card"
class="avatar-uploader"
:show-upload-list="false"
action="api/att/attFile/upload"
action="/laws-sinotruk/onlyoffice/upload"
:before-upload="beforeUpload"
:customRequest="uploadFile"
@change="handleChange"
@@ -47,9 +47,9 @@
},
]"
>
<img ref="myImg" v-if="imageUrl" :src="imageUrl" style="width: 300px; height: 300px;"/>
<img ref="myImg" v-if="imageUrl" :src="imageUrl" style="width: 300px; height: 300px;" />
<div v-else>
<a-icon :type="loading ? 'loading' : 'plus'"/>
<a-icon :type="loading ? 'loading' : 'plus'" />
<div class="ant-upload-text">
Upload
</div>
@@ -57,7 +57,7 @@
</a-upload>
</a-form-item>
<a-form-item label="图片大小">
<a-radio-group :options="plainOptions" v-model="form.size"/>
<a-radio-group :options="plainOptions" v-model="form.size" />
</a-form-item>
</a-form-model>
</a-modal>
@@ -65,24 +65,24 @@
</template>
<script>
import _axios from '@/plugins/axios2'
import pxConversionMm from '../common/unitConversion'
import _axios from '@/plugins/axios2'
import pxConversionMm from '../common/unitConversion'
function getBase64(img, callback) {
console.log(img);
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result));
reader.readAsDataURL(img);
}
function getBase64 (img, callback) {
console.log(img)
const reader = new FileReader()
reader.addEventListener('load', () => callback(reader.result))
reader.readAsDataURL(img)
}
const plainOptions = ['原图', '小', '中', '大'];
export default {
data() {
const plainOptions = ['原图', '小', '中', '大']
export default {
data () {
return {
visible: false,
formItemLayout: {
labelCol: {span: 6},
wrapperCol: {span: 14},
labelCol: { span: 6 },
wrapperCol: { span: 14 }
},
loading: false,
imageUrl: '',
@@ -122,7 +122,7 @@
}
},
methods: {
handleClick() {
handleClick () {
// console.log(window.Asc.plugin.info)
window.Asc.scope.guid = window.Asc.plugin.info.guid
this.ctx.callCommand(() => {
@@ -173,7 +173,7 @@
// contentWindow.postMessage({ m: 'Wx Success' }, '*')
}, false)
},
handleCaptionClick() {
handleCaptionClick () {
// console.log(window.Asc.plugin.info)
window.Asc.scope.guid = window.Asc.plugin.info.guid
this.ctx.callCommand(() => {
@@ -217,7 +217,7 @@
// contentWindow.postMessage({ m: 'Wx Success' }, '*')
}, false)
},
handleCaptionClick2() {
handleCaptionClick2 () {
// _api.init(oWordControl);
// this.ctx.callCommand(function () {
// try {
@@ -259,10 +259,10 @@
}, false)
},
openImageDialog() {
openImageDialog () {
this.visible = true
},
openImageNoteFou() {
openImageNoteFou () {
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument()
@@ -281,36 +281,36 @@
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
} else {
let oNumbering = oDocument.CreateNumbering("numbered");
oNumLvl = oNumbering.GetLevel(0);
let oNumbering = oDocument.CreateNumbering('numbered')
oNumLvl = oNumbering.GetLevel(0)
}
const sFormatString = "%1";
oNumLvl.SetCustomType("lowerLetter", sFormatString, "left");
oNumLvl.SetSuff("space");
const sFormatString = '%1'
oNumLvl.SetCustomType('lowerLetter', sFormatString, 'left')
oNumLvl.SetSuff('space')
const textPr = oNumLvl.GetTextPr()
textPr.SetFontSize(18);
textPr.SetFontSize(18)
textPr.SetFontFamily('黑体')
textPr.SetSmallCaps(true);
textPr.SetVertAlign("superscript");
textPr.SetSmallCaps(true)
textPr.SetVertAlign('superscript')
const paraPr = oNumLvl.GetParaPr()
paraPr.SetSpacingBefore(0);
paraPr.SetJc("left");
paraPr.SetIndFirstLine(-150);
paraPr.SetSpacingBefore(0)
paraPr.SetJc('left')
paraPr.SetIndFirstLine(-150)
const oParagraph1 = Api.CreateParagraph()
oParagraph1.SetIndLeft(574);
oParagraph1.SetIndLeft(574)
oParagraph1.SetNumbering(oNumLvl)
oParagraph1.SetSpacingAfter(32)
oParagraph1.SetFontSize(18)
oDocument.InsertContent([oParagraph1])
let GetNext = oParagraph1.GetNext()
GetNext.Delete()
oParagraph.Delete();
oParagraph.Delete()
} catch (error) {
console.error(error)
}
}, false)
},
openImageName(){
openImageName () {
Asc.scope.numData = this.numData
this.ctx.callCommand(() => {
try {
@@ -324,12 +324,12 @@
let SpacingBefore
for (let i = num - 1; i >= 0; i--) {
const element = oDocument.GetElement(i)
if ("table" === element.GetClassType()) {
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
table = element
break
}
} else if ("paragraph" === element.GetClassType()) {
} else if ('paragraph' === element.GetClassType()) {
const getNumbering = element.GetNumbering()
const text = element.GetSpacingAfter()
if (getNumbering !== null) {
@@ -341,21 +341,21 @@
}
}
const allElement = oDocument.GetElementsCount()
if (table){
let number = table.GetCell(0, 0).GetContent().GetElement(1);
SpacingBefore = number.GetSpacingBefore();
if (table) {
let number = table.GetCell(0, 0).GetContent().GetElement(1)
SpacingBefore = number.GetSpacingBefore()
}
if (SpacingBefore){
if (currentNumbering){
if (SpacingBefore) {
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
}else{
} else {
for (let i = num + 1; i < allElement; i++) {
const element = oDocument.GetElement(i)
if ("table" === element.GetClassType()) {
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
break
}
} else if ("paragraph" === element.GetClassType()) {
} else if ('paragraph' === element.GetClassType()) {
const getNumbering = element.GetNumbering()
const text = element.GetSpacingAfter()
if (getNumbering !== null) {
@@ -366,26 +366,26 @@
}
}
}
if (currentNumbering){
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, "center");
} else {
let oNumbering = oDocument.CreateNumbering('numbered')
oNumLvl = oNumbering.GetLevel(0)
const sFormatString = '图' + Asc.scope.numData[SpacingBefore] + '.%1'
oNumLvl.SetCustomType('decimal', sFormatString, 'center')
}
}
}else{
if (currentNumbering){
} else {
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
}else{
} else {
for (let i = num + 1; i < allElement; i++) {
const element = oDocument.GetElement(i)
if ("table" === element.GetClassType()) {
if ('table' === element.GetClassType()) {
if (element.GetTableDescription() == 'appendix') {
break
}
} else if ("paragraph" === element.GetClassType()) {
} else if ('paragraph' === element.GetClassType()) {
const getNumbering = element.GetNumbering()
const text = element.GetSpacingAfter()
if (getNumbering !== null) {
@@ -396,30 +396,30 @@
}
}
}
if (currentNumbering){
if (currentNumbering) {
oNumLvl = currentNumbering.GetNumbering().GetLevel(0)
}else{
let oNumbering = oDocument.CreateNumbering("numbered");
oNumLvl = oNumbering.GetLevel(0);
const sFormatString = "图 %1";
oNumLvl.SetCustomType("decimal", sFormatString, "center");
} else {
let oNumbering = oDocument.CreateNumbering('numbered')
oNumLvl = oNumbering.GetLevel(0)
const sFormatString = '图 %1'
oNumLvl.SetCustomType('decimal', sFormatString, 'center')
}
}
}
const oNewDocumentStyle = oDocument.GetStyle("List Paragraph");
const oTextPr3 = oNewDocumentStyle.GetTextPr();
oTextPr3.SetFontFamily("黑体");
const textPr = oNumLvl.GetTextPr();
textPr.SetFontFamily("黑体");
const oNewDocumentStyle = oDocument.GetStyle('List Paragraph')
const oTextPr3 = oNewDocumentStyle.GetTextPr()
oTextPr3.SetFontFamily('黑体')
const textPr = oNumLvl.GetTextPr()
textPr.SetFontFamily('黑体')
textPr.SetFontSize(21)
// const CNParagraph = Api.CreateParagraph();
oParagraph.SetJc("center");
oParagraph.SetJc('center')
// oParagraph.AddText("图片");
oParagraph.SetFontSize(21);
oParagraph.SetStyle(oNewDocumentStyle);
oParagraph.SetFontFamily("黑体");
oParagraph.SetSpacingAfter(34,false)
oParagraph.SetNumbering(oNumLvl);
oParagraph.SetFontSize(21)
oParagraph.SetStyle(oNewDocumentStyle)
oParagraph.SetFontFamily('黑体')
oParagraph.SetSpacingAfter(34, false)
oParagraph.SetNumbering(oNumLvl)
oDocument.InsertContent([oParagraph])
let GetNext = oParagraph.GetNext()
GetNext.Delete()
@@ -429,7 +429,8 @@
}
}, false)
},
handleOk() {
handleOk () {
console.log('图片上传和了')
this.visible = false
window.Asc.scope.imageUrl = this.imageUrl
window.Asc.scope.title = this.form.title
@@ -442,7 +443,7 @@
}
this.ctx.callCommand(() => {
try {
const oDocument = Api.GetDocument();
const oDocument = Api.GetDocument()
const imgOParagraph = Api.CreateParagraph()
let imgSize = {
width: 0,
@@ -466,8 +467,8 @@
imgSize.height = 89.3
break
}
const oDrawing = Api.CreateImage(Asc.scope.imageUrl, imgSize.width * 36000, imgSize.height * 36000);
imgOParagraph.AddDrawing(oDrawing);
const oDrawing = Api.CreateImage(Asc.scope.imageUrl, imgSize.width * 36000, imgSize.height * 36000)
imgOParagraph.AddDrawing(oDrawing)
// const allElement = oDocument.GetElementsCount()
// let numbering = null
// let currentNumbering = null
@@ -507,11 +508,11 @@
// imgText.SetJc("center");
// imgText.SetSpacingBefore(10)
// imgText.SetSmallCaps(true);
imgOParagraph.SetJc("center");
imgOParagraph.SetSmallCaps(true);
imgOParagraph.SetJc('center')
imgOParagraph.SetSmallCaps(true)
const breakLine = Api.CreateParagraph()
breakLine.SetJc('left')
oDocument.InsertContent([imgOParagraph]);
oDocument.InsertContent([imgOParagraph])
// oDocument.InsertContent([imgText]);
// 创建表格 包裹文字和列项
@@ -527,37 +528,37 @@
},
handleChange(info) {
handleChange (info) {
if (info.file.status === 'uploading') {
this.loading = true;
return;
this.loading = true
return
}
if (info.file.status === 'done') {
// Get this url from response in real world.
getBase64(info.file.originFileObj, imageUrl => {
console.log(imageUrl);
this.imageUrl = imageUrl;
this.loading = false;
});
console.log(imageUrl)
this.imageUrl = imageUrl
this.loading = false
})
}
},
beforeUpload(file) {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
beforeUpload (file) {
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
if (!isJpgOrPng) {
this.$message.error('You can only upload JPG file!');
this.$message.error('You can only upload JPG file!')
}
const isLt2M = file.size / 1024 / 1024 < 2;
const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) {
this.$message.error('Image must smaller than 2MB!');
this.$message.error('Image must smaller than 2MB!')
}
return isJpgOrPng && isLt2M;
return isJpgOrPng && isLt2M
},
uploadFile(fileObj) {
let {file} = fileObj
uploadFile (fileObj) {
let { file } = fileObj
const _data = new FormData()
var renameReportFile = new File([file], '新名称.jpg', {type: file.type});
var renameReportFile = new File([file], '新名称.jpg', { type: file.type })
_data.append('file', renameReportFile)
_axios({
url: this.uploadFilePath,
@@ -565,10 +566,10 @@
data: _data
}).then(res => {
this.loading = false
console.log(res);
this.imageUrl = this.staticFilePath + '?fileId=' + res.data.id
console.log(res)
this.imageUrl = this.staticFilePath + '?path=' + res.result.url
const img = new Image()
img.src = this.staticFilePath + '?fileId=' + res.data.id
img.src = this.staticFilePath + '?path=' + res.result.url
if (img.complete) {
this.imgOrigin = {
width: img.width,
@@ -576,12 +577,12 @@
}
} else {
img.onload = () => {
console.log(12);
console.log(12)
this.imgOrigin = {
width: img.width,
height: img.height
}
console.log(this.imgOrigin);
console.log(this.imgOrigin)
}
}
}).catch(e => {
@@ -589,25 +590,25 @@
})
},
handleSubmit() {
handleSubmit () {
this.visible = false
},
handleTest() {
handleTest () {
this.ctx.callCommand(() => {
try {
window.imgNumOParagraph = window.imgNumOParagraph || null
var oNumbering, oNumLvl
oDocument = Api.GetDocument();
oDocument = Api.GetDocument()
// 未创建图片列项
if (window.imgNumOParagraph) {
oNumbering = window.imgNumOParagraph
} else {
// 图片
oNumbering = oDocument.CreateNumbering("numbered");
oNumbering = oDocument.CreateNumbering('numbered')
window.imgNumOParagraph = oNumbering
}
oNumLvl = oNumbering.GetLevel(oNumbering.GetLevel(0).GetLevelIndex());
oNumLvl = oNumbering.GetLevel(oNumbering.GetLevel(0).GetLevelIndex())
// console.log('this', this)
var num = oNumLvl.GetNumbering()
// console.log(oDocument.GetNumbering())
@@ -616,36 +617,36 @@
oNumLvl.SetRestart(false)
// title = '图' + oNumLvl.GetNumbering()
// oNumLvl.SetCustomType('lowerRoman', oNumLvl.GetNumbering(), 'left')
oParagraph = Api.CreateParagraph();
oParagraph.SetNumbering(oNumLvl);
oParagraph.AddText("测试段落");
oParagraph.SetContextualSpacing(true);
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph()
oParagraph.SetNumbering(oNumLvl)
oParagraph.AddText('测试段落')
oParagraph.SetContextualSpacing(true)
oDocument.Push(oParagraph)
} catch (e) {
console.log(e)
}
})
},
}
},
computed: {},
mounted() {
}
mounted () {
}
}
</script>
<style>
.avatar-uploader > .ant-upload {
.avatar-uploader > .ant-upload {
width: 128px;
height: 128px;
}
}
.ant-upload-select-picture-card i {
.ant-upload-select-picture-card i {
font-size: 32px;
color: #999;
}
}
.ant-upload-select-picture-card .ant-upload-text {
.ant-upload-select-picture-card .ant-upload-text {
margin-top: 8px;
color: #666;
}
}
</style>
+1 -3
View File
@@ -8,7 +8,7 @@ import axios from 'axios'
const config = {
// baseURL: '/'
baseURL: window._CONFIG.interfaceUrl,//本地
baseURL: window._CONFIG.interfaceUrl//本地
// baseURL: 'https://srms.foton.com.cn',//线上
// timeout: 60 * 1000, // Timeout
// withCredentials: true, // Check cross-site Access-Control
@@ -23,7 +23,6 @@ _axios.interceptors.request.use(
(error) =>
// Do something with request error
Promise.reject(error)
)
// Add a response interceptor
@@ -34,7 +33,6 @@ _axios.interceptors.response.use(
(error) =>
// Do something with response error
Promise.reject(error)
)
export default _axios
+7 -14
View File
@@ -7,8 +7,9 @@ const pageMethod = require('./utils/getPages.js')
const pages = pageMethod.pages()
const configs = pageMethod.configs()
// const { interfaceUrl } = require('./src/config')
function resolve(dir) {
function resolve (dir) {
return path.join(__dirname, dir)
}
@@ -40,22 +41,14 @@ module.exports = {
port: 8081,
headers: { 'Access-Control-Allow-Origin': '*' },
proxy: {
'/api': {
target: 'localhost:8080/',
'/laws-sinotruk': {
target: 'http://139.9.235.66:8184',
ws: false,
changeOrigin: true,
pathRewrite: {
'^/api': ''
// '/laws-sinotruk': '' // 默认所有请求都加了jero-boot前缀,需要去掉
}
}
},
// '/api': {
// // target: 'https://qcwss.cloud.tencent.com/domain/ajax',
// target: interfaceUrl,
// ws: true,
// changeOrigin: true,
// pathRewrite: {
// '^/api': '', // rewrite path
// },
// }
}
}
}