Commit c3131aef by channing

fix_poster

1 parent 4a7ba866
...@@ -15,6 +15,7 @@ export function getList(params) { ...@@ -15,6 +15,7 @@ export function getList(params) {
* @param {*} params * @param {*} params
*/ */
export function updatePoster(data) { export function updatePoster(data) {
console.log('poster change:', JSON.stringify(data))
return request({ url: serviceCategory + '/update', method: 'put', data }) return request({ url: serviceCategory + '/update', method: 'put', data })
} }
...@@ -23,7 +24,7 @@ export function updatePoster(data) { ...@@ -23,7 +24,7 @@ export function updatePoster(data) {
* @param {*} data * @param {*} data
*/ */
export function addPoster(data) { export function addPoster(data) {
console.log(JSON.stringify(data)) console.log('poster add:', JSON.stringify(data))
return request({ url: serviceCategory + '/insert', method: 'post', data }) return request({ url: serviceCategory + '/insert', method: 'post', data })
} }
......
...@@ -171,6 +171,8 @@ export default { ...@@ -171,6 +171,8 @@ export default {
edit(data, type) { edit(data, type) {
switch (type) { switch (type) {
case 5: case 5:
// 清除编辑的数据
this.$parent.posterSubassemblyList = [];
this.$parent.posterEdit.step = 0 this.$parent.posterEdit.step = 0
this.$parent.dialog.edit = true this.$parent.dialog.edit = true
break break
......
...@@ -97,8 +97,8 @@ export default { ...@@ -97,8 +97,8 @@ export default {
this.editorInstance. this.editorInstance.
addText('', { addText('', {
position: { position: {
x: 0, x: -100,
y: 0 y: -100
}, },
}) })
.then(function (objectProps) { .then(function (objectProps) {
...@@ -124,13 +124,26 @@ export default { ...@@ -124,13 +124,26 @@ export default {
} }
i ++; i ++;
} }
// fixme 有个bug,暂时在添加空的文本重制下状态
this.editorInstance.
addText('', {
position: {
x: -100,
y: -100
},
})
// 清楚状态
this.activateImageMode();
}, },
// 1 固定文本 2 固定图片 3 二维码图片 // 1 固定文本 2 固定图片 3 二维码图片
createReShowDisplay(data) { createReShowDisplay(data) {
return new Promise((resolve)=>{ return new Promise((resolve)=>{
switch (data.type) { switch (data.type) {
case 1: case 1:
this.showSubMenu('text');
this.activateTextMode(); this.activateTextMode();
this.editorInstance. this.editorInstance.
addText(data.content, { addText(data.content, {
position: { position: {
...@@ -139,38 +152,60 @@ export default { ...@@ -139,38 +152,60 @@ export default {
}, },
}) })
.then(function (objectProps) { .then(function (objectProps) {
console.log(objectProps); this.activeObjectId = objectProps.id;
objectProps.left = data.left;
objectProps.top = data.top;
objectProps.fontSize = data.fontSize;
objectProps.fill = data.fontColor;
objectProps.textAlign = data.textAlign;
this.getRecord(objectProps);
// 重置 TextStyle // 重置 TextStyle
this.editorInstance.changeTextStyle(objectProps.id, { this.editorInstance.changeTextStyle(objectProps.id, {
fontSize: data.fontSize, fontSize: data.fontSize,
fill: data.fontColor, fill: data.fontColor,
textAlign: data.fontTextAlign === 1 ? 'left' : textAlign: data.fontTextAlign === 1 ? 'left' :
data.fontTextAlign === 2 ? 'center' : 'right' data.fontTextAlign === 2 ? 'center' : 'right'
}); }).then(()=>{
resolve(); resolve();
}); })
}.bind(this));
break; break;
case 2: case 2:
case 3: case 3:
this.activateImageMode() this.activateImageMode();
this.editorInstance.addImageObject( this.editorInstance.addImageObject(
data.type === 2 ? data.imgPath : data.type === 2 ? data.imgPath :
data.imgPath === this.qrCodeUrl ? qrCodeImage : data.imgPath data.imgPath === this.qrCodeUrl ? qrCodeImage : data.imgPath
).then(objectProps => { ).then(objectProps => {
console.log(objectProps.id); console.log(objectProps.id);
this.activeObjectId = objectProps.id;
let target = {} let target = {}
target.url = data.imgPath; data.displayId = objectProps.id;
target.randomId = objectProps.id; target.url = data.imgPath;
target.objType = data.type; target.randomId = objectProps.id;
target.objType = data.type;
this.editorInstance.setObjectProperties(objectProps.id, { this.editorInstance.setObjectProperties(objectProps.id, {
left: data.left, left: data.left + data.width / 2,
top: data.top top: data.top + data.height / 2
}).then(()=>{
let obj = {
left: data.left + data.width / 2,
top: data.top + data.height / 2,
width: data.width,
height: data.height,
angle: data.rotate,
id: data.displayId
}
this.getRecord(obj);
resolve()
}) })
// 将图片数据传给父组件保存 // 将图片数据传给父组件保存
this.$emit('getImageData', target);console.log(objectProps); this.$emit('getImageData', target);
resolve() console.log(objectProps);
}); });
break; break;
} }
...@@ -310,23 +345,24 @@ export default { ...@@ -310,23 +345,24 @@ export default {
}) })
.then(function (objectProps) { .then(function (objectProps) {
console.log(objectProps); console.log(objectProps);
this.records(objectProps); this.getRecord(objectProps);
}.bind(this)); }.bind(this));
}, },
// 文本改变事件 // 文本改变事件
textEditing (e) { textEditing (e) {
console.log('dsds', e) console.log('textEditing', e)
}, },
//移动 //移动
onObjectMoved(obj) { onObjectMoved(obj) {
console.log('onObjectMoved'); console.log('onObjectMoved', JSON.stringify(obj));
this.getRecord(obj); this.getRecord(obj);
}, },
//新增/选中 //新增/选中
objectActivated(obj) { objectActivated(obj) {
console.log('objectActivated'); console.log('objectActivated');
// 第一次选中tui-image传过来的位置有问题,这里处理一下,如果之前有数据不使用选中的数据
this.activeObjectId = obj.id; this.activeObjectId = obj.id;
this.getRecord(obj); this.getRecord(obj, true);
if (obj.type === 'text' || obj.type === 'i-text') { if (obj.type === 'text' || obj.type === 'i-text') {
this.showSubMenu('text'); this.showSubMenu('text');
this.setTextToolbar(obj); this.setTextToolbar(obj);
...@@ -341,7 +377,12 @@ export default { ...@@ -341,7 +377,12 @@ export default {
console.log('onObjectScaled') console.log('onObjectScaled')
this.getRecord(obj); this.getRecord(obj);
if (obj.type === 'text' || obj.type === 'i-text') { if (obj.type === 'text' || obj.type === 'i-text') {
this.inputFontSizeRange.setAttribute('value',obj.fontSize); let size = obj.fontSize;
size = size > 100 ? 100 : size < 10 ? 10 : size;
// this.editorInstance.changeTextStyle(this.activeObjectId, {
// fontSize: size
// });
this.inputFontSizeRange.value = size;
} }
}, },
onRedoStackChanged(length) { onRedoStackChanged(length) {
...@@ -452,7 +493,7 @@ export default { ...@@ -452,7 +493,7 @@ export default {
let fontSize = obj.fontSize; let fontSize = obj.fontSize;
let fontColor = obj.fill; let fontColor = obj.fill;
this.inputFontSizeRange.setAttribute('value', fontSize); this.inputFontSizeRange.value = fontSize;
this.textColorpicker.setColor(fontColor); this.textColorpicker.setColor(fontColor);
}, },
showSubMenu (type) { showSubMenu (type) {
...@@ -470,9 +511,11 @@ export default { ...@@ -470,9 +511,11 @@ export default {
this.displayingSubMenu = submenu; this.displayingSubMenu = submenu;
}, },
inputFontSizeRangeChange () { inputFontSizeRangeChange () {
let value = this.inputFontSizeRange.getAttribute('value'); console.log('inputFontSizeRangeChange')
let value = this.inputFontSizeRange.value;
if (this.activeObjectId) { if (this.activeObjectId) {
let size = parseInt(value, 10); let size = parseInt(value, 10);
size = size > 100 ? 100 : size < 10 ? 10 : size;
this.editorInstance.changeTextStyle(this.activeObjectId, { this.editorInstance.changeTextStyle(this.activeObjectId, {
fontSize: size fontSize: size
}); });
...@@ -570,8 +613,7 @@ export default { ...@@ -570,8 +613,7 @@ export default {
}); });
}, },
activateImageMode () { activateImageMode () {
let imageEditor = this.editorInstance; this.editorInstance.stopDrawingMode();
imageEditor.stopDrawingMode();
}, },
resizeEditor () { resizeEditor () {
let editor = document.getElementsByClassName('tui-image-editor')[0]; let editor = document.getElementsByClassName('tui-image-editor')[0];
...@@ -579,9 +621,13 @@ export default { ...@@ -579,9 +621,13 @@ export default {
editor.style.height = window.getComputedStyle(container).maxHeight; editor.style.height = window.getComputedStyle(container).maxHeight;
}, },
getRecord(obj){ getRecord(obj, isSelect){
if (!this.records) this.records = {}; if (!this.records) this.records = {};
let vo = this.records[obj.id]; let vo = this.records[obj.id];
// 如果之前有数据且是选中传过来的数据,不接收
if (vo && isSelect) return;
if (vo) { if (vo) {
vo.left = obj.left; vo.left = obj.left;
vo.top = obj.top; vo.top = obj.top;
...@@ -591,6 +637,8 @@ export default { ...@@ -591,6 +637,8 @@ export default {
if (obj.type === 'text' || obj.type === 'i-text') { if (obj.type === 'text' || obj.type === 'i-text') {
vo.text = obj.text; vo.text = obj.text;
vo.fontSize = obj.fontSize; vo.fontSize = obj.fontSize;
vo.fill = obj.fontColor,
vo.textAlign = obj.textAlign
} }
this.records[obj.id] = vo; this.records[obj.id] = vo;
} else { } else {
......
...@@ -166,6 +166,7 @@ export default { ...@@ -166,6 +166,7 @@ export default {
this.dialog.preview = true this.dialog.preview = true
}, },
async edit (item) { async edit (item) {
console.log('edit!!!!!!!')
try { try {
const res = await getPosterInfo(item.id) const res = await getPosterInfo(item.id)
const data = res.data || {} const data = res.data || {}
...@@ -177,6 +178,7 @@ export default { ...@@ -177,6 +178,7 @@ export default {
type: data.type, type: data.type,
delFlag: data.delFlag, delFlag: data.delFlag,
} }
this.posterSubassemblyList = [];
this.posterSubassemblyList = data.posterSubassemblyList || []; this.posterSubassemblyList = data.posterSubassemblyList || [];
this.materialSelected = data.backgroundImgPath this.materialSelected = data.backgroundImgPath
this.posterEdit.step = 0 this.posterEdit.step = 0
...@@ -311,7 +313,7 @@ export default { ...@@ -311,7 +313,7 @@ export default {
}) })
}, },
inputFontSizeRangeChange (e) { inputFontSizeRangeChange (e) {
this.$refs.tuiImageEditor.inputFontSizeRangeChange(e); this.$refs.tuiImageEditor.inputFontSizeRangeChange();
}, },
// getRecord(res){ // getRecord(res){
// var flag = false; // var flag = false;
...@@ -397,9 +399,9 @@ export default { ...@@ -397,9 +399,9 @@ export default {
while (i < len) { while (i < len) {
vo = list[i]; vo = list[i];
if (this.imgList[vo.id]) { if (this.imgList[vo.id]) {
vo.objType = this.imgList[vo.id].objType; vo.objType = this.imgList[vo.id].objType;
vo.url = this.imgList[vo.id].url; vo.url = this.imgList[vo.id].url;
vo.randomId = this.imgList[vo.id].randomId vo.randomId = this.imgList[vo.id].randomId
} }
let type = vo.type; let type = vo.type;
...@@ -408,36 +410,40 @@ export default { ...@@ -408,36 +410,40 @@ export default {
// 如果是文本需要对文字内容进行特殊处理 // 如果是文本需要对文字内容进行特殊处理
isText = true; isText = true;
let targetData = this.getLastSelectData(vo.id, historys); let targetData = this.getLastSelectData(vo.id, historys);
if (targetData) { vo.text = targetData && targetData.text || vo.text || '';
vo.text = targetData.text;
// 如果文本没有数据则移除
if (!vo.text.length) {
i++;
continue;
} }
} }
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; || 1;
let posData = { let posData = {
id: vo.randomId || i, id: null, // 修改的时候后端默认没增删,沟通后让先传null
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: null,// TODO 后端让传NULL isText ? i : null, // 字体ID 与imgPath互斥 fontId: null, // TODO 后端让传NULL isText ? i : null, // 字体ID 与imgPath互斥
fontSize: vo.fontSize, fontSize: parseInt(vo.fontSize),
fontTextAlign: align, // 1 2 3 left center right fontTextAlign: align, // 1 2 3 left center right
left: parseInt(vo.left), left: parseInt(vo.left) - (isText ? 0 : vo.width >> 1), // FIXME:显示偏移了
top: parseInt(vo.top), top: parseInt(vo.top) - (isText ? 0 : vo.height >> 1),
width: vo.width, width: Math.ceil(vo.width + vo.fontSize / 2),
height: vo.height, height: parseInt(vo.height),
imgPath: vo.url || '', imgPath: vo.url || '',
posterId: null, posterId: null,
type: isText ? 1 : vo.objType, // 1 固定文本 2 固定图片 3 二维码图片 type: isText ? 1 : vo.objType, // 1 固定文本 2 固定图片 3 二维码图片
// alpha: vo.opacity, // 页面没有设置透明度,可不传 // alpha: vo.opacity, // 后端暂时不支持
fontStyle: (vo.italic && vo.bold) ? 3 : vo.italic ? 2 : vo.bold ? 1 : 0, // 0 通常 1 粗体 2 斜体 3 粗 + 斜 fontStyle: (vo.italic && vo.bold) ? 3 : vo.italic ? 2 : vo.bold ? 1 : 0, // 0 通常 1 粗体 2 斜体 3 粗 + 斜
rotate: vo.angle, rotate: vo.angle,
order: i, // 层级 order: i, // 层级
// categoryId: 0, // 分类ID (不需要传了) // categoryId: 0, // 分类ID (不需要传了)
verticalType: 2 // 居中方式 写死2 verticalType: 2 // 居中方式后端让写死2
}; };
posterSubList.push(posData); posterSubList.push(posData);
i++; i++;
...@@ -677,7 +683,7 @@ export default { ...@@ -677,7 +683,7 @@ export default {
</li> </li>
<li class="menu-item"> <li class="menu-item">
<label class="no-pointer"> <label class="no-pointer">
<input id="input-font-size-range" @change="inputFontSizeRangeChange($event)" type="range" min="10" max="100" value="10" /> <input id="input-font-size-range" @change="inputFontSizeRangeChange($event)" type="range" min="10" max="100" value="40" />
</label> </label>
</li> </li>
<li class="menu-item"> <li class="menu-item">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!