Commit 8c944576 by xinla Committed by Gitee

!18 海报分支合并前端分支

Merge pull request !18 from xinla/dev_poster
2 parents edf8a52f 2d47c381
...@@ -23,6 +23,7 @@ export function updatePoster(data) { ...@@ -23,6 +23,7 @@ export function updatePoster(data) {
* @param {*} data * @param {*} data
*/ */
export function addPoster(data) { export function addPoster(data) {
console.log(JSON.stringify(data))
return request({ url: serviceCategory + '/insert', method: 'post', data }) return request({ url: serviceCategory + '/insert', method: 'post', data })
} }
......
...@@ -39,6 +39,7 @@ export default { ...@@ -39,6 +39,7 @@ export default {
}, },
data() { data() {
return { return {
qrCodeUrl: 'http://www.linkwechat.cn/static/img/qrCodeImage.a6d01316.png',
visible: false visible: false
} }
}, },
...@@ -47,6 +48,9 @@ export default { ...@@ -47,6 +48,9 @@ export default {
if (this.includeUi) { if (this.includeUi) {
options = Object.assign(includeUIOptions, this.options); options = Object.assign(includeUIOptions, this.options);
} }
if (this.editorInstance) {
console.log('this.editorInstance')
}
this.editorInstance = new ImageEditor(this.$refs.tuiImageEditor, options); this.editorInstance = new ImageEditor(this.$refs.tuiImageEditor, options);
document.getElementsByClassName('tui-image-editor-header')[0].innerHTML = ''; document.getElementsByClassName('tui-image-editor-header')[0].innerHTML = '';
...@@ -67,6 +71,8 @@ export default { ...@@ -67,6 +71,8 @@ export default {
this.editorInstance.ui._actions.text.modeChange = function () {} this.editorInstance.ui._actions.text.modeChange = function () {}
document.getElementsByClassName('tui-image-editor-submenu')[0].style.display = 'none'; document.getElementsByClassName('tui-image-editor-submenu')[0].style.display = 'none';
document.getElementsByClassName('tie-btn-text')[0].style.display = 'none'; document.getElementsByClassName('tie-btn-text')[0].style.display = 'none';
document.getElementsByClassName('tui-image-editor-main')[0].style.top = '0';
document.getElementsByClassName('tui-image-editor-align-wrap')[0].style.verticalAlign = 'top';
this.initBtn(); this.initBtn();
this.addEventListener(); this.addEventListener();
...@@ -75,16 +81,99 @@ export default { ...@@ -75,16 +81,99 @@ export default {
// Object.keys(this.$listeners).forEach(eventName => { // Object.keys(this.$listeners).forEach(eventName => {
// this.editorInstance.off(eventName); // this.editorInstance.off(eventName);
// }); // });
console.log('deatory poster')
this.editorInstance.destroy(); this.editorInstance.destroy();
this.editorInstance = null; this.editorInstance = null;
}, },
methods: { methods: {
getBackgroundUrl(bacUrl) { // 设置背景图片
getBackgroundUrl(bacUrl, posterSubassemblyList) {
this.editorInstance.loadImageFromURL(bacUrl, 'imagePoster').then(async result => { this.editorInstance.loadImageFromURL(bacUrl, 'imagePoster').then(async result => {
console.log('old : ' + result.oldWidth + ', ' + result.oldHeight); console.log('old : ' + result.oldWidth + ', ' + result.oldHeight);
console.log('new : ' + result.newWidth + ', ' + result.newHeight); console.log('new : ' + result.newWidth + ', ' + result.newHeight);
// await this.addImage('https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2980445260,41238050&fm=26&gp=0.jpg')
// await this.addText('aloha'); // 由于篡改了tuiimage,第一次使用addText会报错,错误不影响流程,但是会导致promise中断,提前触发报错。
try {
this.editorInstance.
addText('', {
position: {
x: 0,
y: 0
},
})
.then(function (objectProps) {
console.log('dd');
}).catch(()=>{});
} catch (e) {
console.log('addText 内部状态错误')
}
// FIXME 暂时延迟回显
setTimeout(()=>{
posterSubassemblyList.length && this.reShowDisplay(posterSubassemblyList);
}, 500);
});
},
// 设置修改回显
async reShowDisplay (reShowDisplays) {
let i = 0,len = reShowDisplays.length;
let _data = null;
while (i < len) {
_data = reShowDisplays[i];
if (_data) {
await this.createReShowDisplay(_data);
}
i ++;
}
},
// 1 固定文本 2 固定图片 3 二维码图片
createReShowDisplay(data) {
return new Promise((resolve)=>{
switch (data.type) {
case 1:
this.activateTextMode();
this.editorInstance.
addText(data.content, {
position: {
x: data.left,
y: data.top
},
})
.then(function (objectProps) {
console.log(objectProps);
// 重置 TextStyle
this.editorInstance.changeTextStyle(objectProps.id, {
fontSize: data.fontSize,
fill: data.fontColor,
textAlign: data.fontTextAlign === 1 ? 'left' :
data.fontTextAlign === 2 ? 'center' : 'right'
});
resolve();
});
break;
case 2:
case 3:
this.activateImageMode()
this.editorInstance.addImageObject(
data.type === 2 ? data.imgPath :
data.imgPath === this.qrCodeUrl ? qrCodeImage : data.imgPath
).then(objectProps => {
console.log(objectProps.id);
let target = {}
target.url = data.imgPath;
target.randomId = objectProps.id;
target.objType = data.type;
this.editorInstance.setObjectProperties(objectProps.id, {
left: data.left,
top: data.top
})
// 将图片数据传给父组件保存
this.$emit('getImageData', target);console.log(objectProps);
resolve()
});
break;
}
}); });
}, },
initBtn () { initBtn () {
...@@ -178,6 +267,7 @@ export default { ...@@ -178,6 +267,7 @@ export default {
redoStackChanged: this.onRedoStackChanged.bind(this), redoStackChanged: this.onRedoStackChanged.bind(this),
objectScaled: this.onObjectScaled.bind(this), objectScaled: this.onObjectScaled.bind(this),
addText: this.onAddText.bind(this), addText: this.onAddText.bind(this),
textEditing: this.textEditing.bind(this),
objectActivated: this.objectActivated.bind(this), objectActivated: this.objectActivated.bind(this),
objectMoved: this.onObjectMoved.bind(this) objectMoved: this.onObjectMoved.bind(this)
}); });
...@@ -220,12 +310,13 @@ export default { ...@@ -220,12 +310,13 @@ export default {
}) })
.then(function (objectProps) { .then(function (objectProps) {
console.log(objectProps); console.log(objectProps);
this.records(objectProps) this.records(objectProps);
let id = this.GenNonDuplicateID() + '_' + objectProps.id;
let target = this.$parent.records[objectProps.id];
target && (target.randomId = id);
}.bind(this)); }.bind(this));
}, },
// 文本改变事件
textEditing (e) {
console.log('dsds', e)
},
//移动 //移动
onObjectMoved(obj) { onObjectMoved(obj) {
console.log('onObjectMoved'); console.log('onObjectMoved');
...@@ -306,6 +397,7 @@ export default { ...@@ -306,6 +397,7 @@ export default {
qrCodeHandler () { qrCodeHandler () {
// let codeUrl = 'https://images.gitee.com/uploads/images/2020/1231/234016_20fdd151_1480777.png'; // let codeUrl = 'https://images.gitee.com/uploads/images/2020/1231/234016_20fdd151_1480777.png';
this.activateImageMode(); this.activateImageMode();
// 暂时写死二维码
this.addImage(qrCodeImage, 3); this.addImage(qrCodeImage, 3);
}, },
clearObjects () { clearObjects () {
...@@ -446,12 +538,9 @@ export default { ...@@ -446,12 +538,9 @@ export default {
}, },
getImages () { getImages () {
this.visible = true; // 显示图片列表dialog this.visible = true; // 显示图片列表dialog
// this.activateImageMode();
// this.addImage('https://images.gitee.com/uploads/images/2020/1231/234016_20fdd151_1480777.png',2);
}, },
// 提交选择的图片 // 提交选择的图片
getMaterial(text, image, file) { getMaterial(text, image, file) {
// console.log(image.materialUrl)
this.activateImageMode(); this.activateImageMode();
this.addImage(image.materialUrl, 2); this.addImage(image.materialUrl, 2);
this.visible = false; this.visible = false;
...@@ -461,50 +550,23 @@ export default { ...@@ -461,50 +550,23 @@ export default {
throw Error("imgPath can't null") throw Error("imgPath can't null")
} }
this.editorInstance.addImageObject(imgPath).then(objectProps => { this.editorInstance.addImageObject(imgPath).then(objectProps => {
let id = this.GenNonDuplicateID() + '_' + objectProps.id;
// this.$parent.imgList[id] = imgPath; // FIXME
// console.log(objectProps)
// console.log(this.$parent.records)
// let target = this.$parent.records[objectProps.id];
let target = {} let target = {}
// if (target) { // 二维码是占位符,所以可以写死
target.url = imgPath; target.url = type === 3 ? this.qrCodeUrl : imgPath;
target.randomId = objectProps.id; target.randomId = objectProps.id;
target.objType = type; target.objType = type;
// } // 将图片数据传给父组件保存
this.$emit('getImageData', target); // 将图片数据传给父组件保存 this.$emit('getImageData', target);
}); });
}, },
addText (text, style = null, position = null) { addText (text, style = null, position = null) {
// return new Promise(function(resolve, reject) {
// !style && (style = {
// fill: '#000',
// fontSize: 20,
// fontWeight: 'bold'
// })
// !position && (position = {
// x: 10,
// y: 10
// })
// this.activateTextMode();
// this.editorInstance.addText( text, {
// style: style,
// position: position
// }).then(objectProps => {
// console.log(objectProps.id);
// resolve(objectProps);
// });
// }.bind(this));
this.editorInstance this.editorInstance
.addText(text || '双击输入文字', { .addText(text || '双击输入文字', {
position: position, position: position,
}) })
.then(function (objectProps) { .then(function (objectProps) {
console.log(objectProps); console.log(objectProps);
let id = this.GenNonDuplicateID() + '_' + objectProps.id;
let target = this.$parent.records[objectProps.id];
target && (target.randomId = id);
}); });
}, },
activateImageMode () { activateImageMode () {
...@@ -535,10 +597,10 @@ export default { ...@@ -535,10 +597,10 @@ export default {
this.records[obj.id] = obj; this.records[obj.id] = obj;
} }
},
GenNonDuplicateID(randomLength){
return parseFloat(Math.random().toString().substr(3,randomLength) + Date.now()).toString(36)
} }
// GenNonDuplicateID(randomLength){
// return parseFloat(Math.random().toString().substr(3,randomLength) + Date.now()).toString(36)
// }
} }
}; };
</script> </script>
<script> <script>
import { import {
getList,
getPosterInfo, getPosterInfo,
addPoster, addPoster,
updatePoster, updatePoster,
...@@ -32,7 +31,7 @@ export default { ...@@ -32,7 +31,7 @@ export default {
data () { data () {
return { return {
imgList: {}, imgList: {},
imgData: [], posterSubassemblyList: [],
dialogVisibleSelectMaterial: false, dialogVisibleSelectMaterial: false,
dialog: { dialog: {
preview: false, // 预览弹出显示隐藏 preview: false, // 预览弹出显示隐藏
...@@ -178,6 +177,7 @@ export default { ...@@ -178,6 +177,7 @@ export default {
type: data.type, type: data.type,
delFlag: data.delFlag, delFlag: data.delFlag,
} }
this.posterSubassemblyList = data.posterSubassemblyList || [];
this.materialSelected = data.backgroundImgPath this.materialSelected = data.backgroundImgPath
this.posterEdit.step = 0 this.posterEdit.step = 0
this.dialog.edit = true this.dialog.edit = true
...@@ -216,8 +216,6 @@ export default { ...@@ -216,8 +216,6 @@ export default {
//缩放 //缩放
onObjectScaled(obj) { onObjectScaled(obj) {
console.log('onObjectScaled') console.log('onObjectScaled')
// this.getRecord(res);
// this.checkState();
if (obj.type === 'text') { if (obj.type === 'text') {
this.$refs.tuiImageEditor.inputFontSizeRange.setAttribute('value',obj.fontSize); this.$refs.tuiImageEditor.inputFontSizeRange.setAttribute('value',obj.fontSize);
} }
...@@ -277,10 +275,16 @@ export default { ...@@ -277,10 +275,16 @@ export default {
} else { } else {
this.rangeErrorMsg = '' this.rangeErrorMsg = ''
} }
if (this.$refs.tuiImageEditor && this.$refs.tuiImageEditor.editorInstance) {
this.$refs.tuiImageEditor.editorInstance._invoker._redoStack = [];
this.$refs.tuiImageEditor.editorInstance._invoker._undoStack = [];
this.$refs.tuiImageEditor.records = {}
this.imgList = {};
}
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
this.posterEdit.step = 1 this.posterEdit.step = 1
this.$refs.tuiImageEditor.getBackgroundUrl(this.materialSelected) this.$refs.tuiImageEditor.getBackgroundUrl(this.materialSelected, this.posterSubassemblyList);
} else { } else {
return false; return false;
} }
...@@ -309,76 +313,38 @@ export default { ...@@ -309,76 +313,38 @@ export default {
inputFontSizeRangeChange (e) { inputFontSizeRangeChange (e) {
this.$refs.tuiImageEditor.inputFontSizeRangeChange(e); this.$refs.tuiImageEditor.inputFontSizeRangeChange(e);
}, },
getRecord(res){ // getRecord(res){
var flag = false; // var flag = false;
if (this.records && this.records.length) { // if (this.records && this.records.length) {
for (let index = 0; index < this.records.length; index++) { // for (let index = 0; index < this.records.length; index++) {
const element ={ // const element ={
fill: this.records[index].fill, // fill: this.records[index].fill,
height: this.records[index].height, // height: this.records[index].height,
id: this.records[index].id, // id: this.records[index].id,
left: this.records[index].left, // left: this.records[index].left,
opacity: this.records[index].opacity, // opacity: this.records[index].opacity,
stroke: this.records[index].stroke, // stroke: this.records[index].stroke,
strokeWidth: this.records[index].strokeWidth, // strokeWidth: this.records[index].strokeWidth,
top: this.records[index].top, // top: this.records[index].top,
type: this.records[index].type, // type: this.records[index].type,
width: this.records[index].width, // width: this.records[index].width,
}; // };
if(element.id == res.id){ // if(element.id == res.id){
// console.log(element) // // console.log(element)
this.records[index] = res; // this.records[index] = res;
flag = true; // flag = true;
} // }
} // }
} else { // } else {
this.records = []; // this.records = [];
} // }
if(!flag){ // if(!flag){
this.records.push(res) // this.records.push(res)
} // }
}, // },
// FIXME 没写完
async reShow (list) {
list = JSON.parse('[{"id":2,"type":"i-text","left":55.26947693665858,"top":180.32266601562497,"width":200,"height":45.199999999999996,"fill":"#000000","stroke":null,"strokeWidth":1,"opacity":1,"angle":0,"text":"请输入文字","fontFamily":"Times New Roman","fontSize":40,"fontStyle":"normal","textAlign":"left","fontWeight":"normal"},{"id":3,"type":"image","left":195.71660545226203,"top":506.3232314730081,"width":500,"height":500,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"opacity":1,"angle":0},{"id":4,"type":"image","left":373.102002853498,"top":190.44302690999768,"width":792,"height":792,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"opacity":1,"angle":0}]');
let i = 0, len = list && list.length || 0
for ( ; i<len; i++) {
await this.loadRes(list[i]);
}
},
async loadRes (obj) {
return new Promise((resolve) => {
let imageEditor = this.$refs.tuiImageEditor.editorInstance;
switch (obj.type) {
case 'i-text':
case 'text':
imageEditor.
addText(obj.text, {
position: {
x: obj.left,
y: obj.right
},
})
.then(function (objectProps) {
console.log(objectProps);
});
break;
case 'image':
this.editorInstance.addImageObject(imgPath).then(objectProps => {
console.log(objectProps.id);
}).then(function (objectProps) {
console.log(objectProps);
});
break;
}
});
},
// 获取子组件传来的数据 // 获取子组件传来的数据
getImgData(data) { getImgData(data) {
this.imgList.id = data.imgUrl this.imgList[data.randomId] = data
// console.log(data)
this.imgData.push(data)
// console.log(this.imgData)
}, },
// 选择素材确认按钮 // 选择素材确认按钮
submitSelectMaterial(text, image, file) { submitSelectMaterial(text, image, file) {
...@@ -393,14 +359,22 @@ export default { ...@@ -393,14 +359,22 @@ export default {
// //
async save() { async save() {
let list =[]; let list =[];
let historys = [];
try { try {
let imageEditor = this.$refs.tuiImageEditor; let imageEditor = this.$refs.tuiImageEditor;
let deleteId = []; let deleteId = [];
imageEditor.editorInstance._invoker._undoStack.forEach(element => { imageEditor.editorInstance._invoker._undoStack.forEach(element => {
if(element.name == "removeObject"){ if(element.name == "removeObject"){
deleteId.push(element.args[1]) deleteId.push(element.args[1])
} }
else
{
if (element.args[1] instanceof Array) {
historys.push(element.args[1][0])
} else {
historys.push(element.args[1])
}
}
}) })
Object.values(imageEditor.records).forEach(item => { Object.values(imageEditor.records).forEach(item => {
if(deleteId.indexOf((item.id).toString())>=0){ if(deleteId.indexOf((item.id).toString())>=0){
...@@ -418,33 +392,41 @@ export default { ...@@ -418,33 +392,41 @@ export default {
// TODO 塞新建海报的数据 // TODO 塞新建海报的数据
let posterSubList = []; let posterSubList = [];
let vo = null;
let i = 0, len = list.length; let i = 0, len = list.length;
while (i < len) { while (i < len) {
let vo = list[i]; vo = list[i];
if (!this.imgData[i]) { if (this.imgList[vo.id]) {
console.log('this.imgData[i] is null') vo.objType = this.imgList[vo.id].objType;
i++; vo.url = this.imgList[vo.id].url;
continue; vo.randomId = this.imgList[vo.id].randomId
}
let type = vo.type;
let isText = false;
if (type === 'i-text' || type === 'text') {
// 如果是文本需要对文字内容进行特殊处理
isText = true;
let targetData = this.getLastSelectData(vo.id, historys);
if (targetData) {
vo.text = targetData.text;
}
} }
vo.objType = this.imgData[i].objType;
vo.url = this.imgData[i].url;
vo.randomId = this.imgData[i].randomId;
// console.log(vo)
let type = list[i].type;
let align = vo.textAlign && let align = vo.textAlign &&
(vo.textAlign === 'left' ? 1 : vo.textAlign === 'center' ? 2 : 3) (vo.textAlign === 'left' ? 1 : vo.textAlign === 'center' ? 2 : 3)
|| null; || null;
let isText = type === 'i-text' || type === 'text';
let posData = { let posData = {
id: vo.randomId || i, id: vo.randomId || i,
content: vo.text || '', // 文本内容 content: vo.text || '', // 文本内容
delFlag: 0, // 1 启动 0 删除 FIXME 暂时写死 delFlag: 0, // 1 启动 0 删除 FIXME 暂时写死
fontColor: vo.fill || '#000000', // fontColor: vo.fill || '#000000', //
fontId: isText ? i : null, // 字体ID 与imgPath互斥 fontId: null,// TODO 后端让传NULL isText ? i : null, // 字体ID 与imgPath互斥
fontSize: vo.fontSize, fontSize: vo.fontSize,
fontTextAlign: align, // 1 2 3 left center right fontTextAlign: align, // 1 2 3 left center right
left: vo.left, left: parseInt(vo.left),
top: vo.top, top: parseInt(vo.top),
width: vo.width, width: vo.width,
height: vo.height, height: vo.height,
imgPath: vo.url || '', imgPath: vo.url || '',
...@@ -474,7 +456,6 @@ export default { ...@@ -474,7 +456,6 @@ export default {
} else { } else {
// 新建海报 // 新建海报
res = await addPoster(Object.assign({}, { res = await addPoster(Object.assign({}, {
// backgroundImgPath: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2980445260,41238050&fm=26&gp=0.jpg',
backgroundImgPath: this.materialSelected, backgroundImgPath: this.materialSelected,
posterSubassemblyList: posterSubList posterSubassemblyList: posterSubList
}, this.posterForm)) }, this.posterForm))
...@@ -484,8 +465,26 @@ export default { ...@@ -484,8 +465,26 @@ export default {
this.$refs.page.getList(1) this.$refs.page.getList(1)
this.beforeCloseDialog() this.beforeCloseDialog()
} }
}
}, },
getLastSelectData (id, arr) {
let index = arr.length - 1, len = 0;
let selectData = null;
try {
while (index >= len) {
// 类型转换对比
if (arr[index].id == id) {
selectData = arr[index];
break;
}
index --;
}
}catch (e) {
console.log('getLastSelectData 循环出错')
}
return selectData;
}
}
} }
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!