Commit 2f568fa1 by xinla

海报问题修改

1 parent eae30a22
...@@ -163,10 +163,7 @@ export default { ...@@ -163,10 +163,7 @@ export default {
edit(data, type) { edit(data, type) {
switch (type) { switch (type) {
case 5: case 5:
// 清除编辑的数据 this.$parent.edit()
this.$parent.posterSubassemblyList = []
this.$parent.dialog.edit = true
this.$parent.initPoster()
break break
default: default:
this.form = Object.assign({}, data || { categoryId: this.query.categoryId }) this.form = Object.assign({}, data || { categoryId: this.query.categoryId })
......
...@@ -69,31 +69,34 @@ export default { ...@@ -69,31 +69,34 @@ export default {
mounted() {}, mounted() {},
methods: { methods: {
listChange(data) { listChange(data) {
console.log('listChange', JSON.stringify(data))
this.srcList = data.map((item) => item.materialUrl) this.srcList = data.map((item) => item.materialUrl)
}, },
preview(url) { preview(url) {
console.log(url)
console.log('preview', url)
this.previewImg = url || '' this.previewImg = url || ''
this.dialog.preview = true this.dialog.preview = true
}, },
async edit(item) { async edit(item) {
try { try {
const res = await getPosterInfo(item.id) if (item) {
const data = res.data || {} // 编辑
console.log('getPosterInfo', data) const res = await getPosterInfo(item.id)
this.form = { const data = res.data || {}
id: data.id, // console.log('getPosterInfo', data)
title: data.title, this.form = {
categoryId: data.categoryId, id: data.id,
type: data.type, title: data.title,
delFlag: data.delFlag, categoryId: data.categoryId,
posterJSON: JSON.parse(data.otherField) type: data.type,
delFlag: data.delFlag,
posterJSON: JSON.parse(data.otherField)
}
this.posterSubassemblyList = data.posterSubassemblyList || []
this.materialSelected = data.backgroundImgPath
} else {
// 新增,清除编辑的数据
this.form = {}
this.posterSubassemblyList = []
} }
this.posterSubassemblyList = []
this.posterSubassemblyList = data.posterSubassemblyList || []
this.materialSelected = data.backgroundImgPath
this.dialog.edit = true this.dialog.edit = true
this.initPoster() this.initPoster()
} catch (error) { } catch (error) {
...@@ -105,8 +108,34 @@ export default { ...@@ -105,8 +108,34 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
let canvas = (this.canvas = new fabric.Canvas('canvas')) let canvas = (this.canvas = new fabric.Canvas('canvas'))
if (this.form.posterJSON) {
// 加载画布信息
this.setPosterBackgroundImage()
canvas.loadFromJSON(this.form.posterJSON, () => {
canvas.renderAll()
})
} else {
this.setPosterBackgroundImage()
}
// 删除某个图层
var deleteBtn = document.getElementById('deleteBtn')
function addDeleteBtn(x, y) {
deleteBtn.style.display = 'none'
deleteBtn.style.left = x - 10 + 'px'
deleteBtn.style.top = y - 30 + 'px'
deleteBtn.style.display = 'block'
}
canvas.on('selection:created', function(e) {
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y)
})
canvas.on('selection:updated', function(e) {
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y)
})
//通用事件另外写法
canvas.on({ canvas.on({
//通用事件
'mouse:down': function(e) { 'mouse:down': function(e) {
if (e.target != undefined) { if (e.target != undefined) {
var ob = canvas.getActiveObject() var ob = canvas.getActiveObject()
...@@ -134,37 +163,34 @@ export default { ...@@ -134,37 +163,34 @@ export default {
} }
}) })
if (this.form.posterJSON) { //是否拖动
// 加载画布信息 // let panning = false
canvas.loadFromJSON(this.form.posterJSON, () => { // canvas.on('mouse:down', (e) => {
canvas.renderAll() // this.activeObject = canvas.getActiveObject()
}) // if (!this.activeObject) {
} else { // deleteBtn.style.display = 'none'
this.setPosterBackgroundImage() // }
} // //按住alt键可拖动画布
// if (e.e.altKey) {
// panning = true
// canvas.selection = false
// }
// })
// 删除某个图层 // //鼠标抬起
var deleteBtn = document.getElementById('deleteBtn') // canvas.on('mouse:up', function(e) {
function addDeleteBtn(x, y) { // panning = false
deleteBtn.style.display = 'none' // canvas.selection = true
deleteBtn.style.left = x - 10 + 'px' // })
deleteBtn.style.top = y - 30 + 'px'
deleteBtn.style.display = 'block'
}
canvas.on('selection:created', function(e) { // //鼠标移动
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y) // canvas.on('mouse:move', function(e) {
}) // if (panning && e && e.e) {
canvas.on('selection:updated', function(e) { // let delta = new fabric.Point(e.e.movementX, e.e.movementY)
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y) // canvas.relativePan(delta)
}) // console.log(e)
canvas.on('mouse:down', (e) => { // }
console.log(canvas.getActiveObject()) // })
this.activeObject = canvas.getActiveObject()
if (!this.activeObject) {
deleteBtn.style.display = 'none'
}
})
canvas.on('object:modified', function(e) { canvas.on('object:modified', function(e) {
addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y) addDeleteBtn(e.target.lineCoords.tr.x, e.target.lineCoords.tr.y)
...@@ -181,6 +207,21 @@ export default { ...@@ -181,6 +207,21 @@ export default {
canvas.on('mouse:wheel', function(e) { canvas.on('mouse:wheel', function(e) {
deleteBtn.style.display = 'none' deleteBtn.style.display = 'none'
}) })
// alt键缩放
document.getElementById('canvas-wrap').addEventListener('wheel', (e) => {
// e.stopPropagation()
if (e.altKey) {
e.preventDefault()
console.log(e)
let zoom = (e.deltaY > 0 ? 0.1 : -0.1) + canvas.getZoom()
zoom = Math.max(0.1, zoom) //最小为原来的1/10
zoom = Math.min(5, zoom) //最大是原来的5倍
let zoomPoint = new fabric.Point(e.offsetX, e.offsetY)
canvas.zoomToPoint(zoomPoint, zoom)
}
})
deleteBtn.addEventListener('click', () => { deleteBtn.addEventListener('click', () => {
let activeObject = canvas.getActiveObject() let activeObject = canvas.getActiveObject()
if (activeObject) { if (activeObject) {
...@@ -202,11 +243,13 @@ export default { ...@@ -202,11 +243,13 @@ export default {
} }
let canvas = this.canvas let canvas = this.canvas
new fabric.Image.fromURL(this.materialSelected, (img) => { new fabric.Image.fromURL(this.materialSelected, (img) => {
img.set({ // img.set({
// 通过scale来设置图片大小,这里设置和画布一样大 // // 通过scale来设置图片大小,这里设置和画布一样大
scaleX: canvas.width / img.width, // // scaleX: canvas.width / img.width,
scaleY: canvas.height / img.height // // scaleY: canvas.height / img.height
}) // })
canvas.setWidth(img.width)
canvas.setHeight(img.height)
canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas)) canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas))
canvas.renderAll() canvas.renderAll()
}) })
...@@ -254,6 +297,7 @@ export default { ...@@ -254,6 +297,7 @@ export default {
beforeCloseDialog() { beforeCloseDialog() {
this.$refs.form.resetFields() this.$refs.form.resetFields()
this.form.id = undefined this.form.id = undefined
this.form.posterJSON = undefined
this.dialog.edit = false this.dialog.edit = false
}, },
remove(id) { remove(id) {
...@@ -288,6 +332,7 @@ export default { ...@@ -288,6 +332,7 @@ export default {
} }
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
let laoding = this.$loading()
const form = this.form const form = this.form
form.posterJSON = this.canvas.toJSON(['customType']) form.posterJSON = this.canvas.toJSON(['customType'])
let list = form.posterJSON.objects let list = form.posterJSON.objects
...@@ -312,8 +357,8 @@ export default { ...@@ -312,8 +357,8 @@ export default {
fontId: null, // TODO 后端让传NULL isText ? i : null, // 字体ID 与imgPath互斥 fontId: null, // TODO 后端让传NULL isText ? i : null, // 字体ID 与imgPath互斥
fontSize: parseInt(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) - (isText ? 0 : vo.width >> 1), // FIXME:显示偏移了 left: parseInt(vo.left), // - (isText ? 0 : vo.width >> 1), // 显示偏移了
top: parseInt(vo.top) - (isText ? 0 : vo.height >> 1), top: parseInt(vo.top), // - (isText ? 0 : vo.height >> 1),
width: parseInt(vo.width + (isText ? vo.fontSize / 2 : 0)), width: parseInt(vo.width + (isText ? vo.fontSize / 2 : 0)),
height: parseInt(vo.height), height: parseInt(vo.height),
imgPath: vo.src || '', imgPath: vo.src || '',
...@@ -339,13 +384,18 @@ export default { ...@@ -339,13 +384,18 @@ export default {
}, },
form form
) )
).then((res) => { )
this.msgSuccess(res.msg) .then((res) => {
if (isBack) { laoding.close()
this.$refs.page.getList(1) this.msgSuccess(res.msg)
this.beforeCloseDialog() if (isBack) {
} this.$refs.page.getList(1)
}) this.beforeCloseDialog()
}
})
.catch(() => {
laoding.close()
})
} }
}) })
} }
...@@ -378,7 +428,7 @@ export default { ...@@ -378,7 +428,7 @@ export default {
</el-col> </el-col>
</el-row> </el-row>
<el-dialog title="海报预览" width="30%" :visible.sync="dialog.preview"> <el-dialog title="海报预览" width="50%" :visible.sync="dialog.preview">
<img class="preview-img" :src="previewImg" /> <img class="preview-img" :src="previewImg" />
</el-dialog> </el-dialog>
<el-dialog <el-dialog
...@@ -471,14 +521,14 @@ export default { ...@@ -471,14 +521,14 @@ export default {
</el-form-item> </el-form-item>
<el-form-item label=""> <el-form-item label="">
<el-button type="success" @click="save()">保存</el-button> <el-button type="success" @click="save()">保存</el-button>
<el-button type="success" @click="save(1)">保存并返回</el-button> <el-button type="success" @click="save(1)">保存并关闭</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<div style=""> <div style="">
<div class="canvas-wrap"> <div id="canvas-wrap">
<i class="el-icon-error" id="deleteBtn"></i> <i class="el-icon-error" id="deleteBtn"></i>
<canvas id="canvas" width="375" height="700" style="border: 1px solid #ddd;"> </canvas> <canvas id="canvas" width="300" height="500" style="border: 1px solid #ddd;"> </canvas>
</div> </div>
<div id="tbody-containerui-image-editor-controls"> <div id="tbody-containerui-image-editor-controls">
<ul class="menu"> <ul class="menu">
...@@ -569,11 +619,14 @@ export default { ...@@ -569,11 +619,14 @@ export default {
.preview-img { .preview-img {
width: 100%; width: 100%;
} }
.canvas-wrap { #canvas-wrap {
margin-right: 20px; margin-right: 20px;
display: inline-block; display: inline-block;
position: relative; position: relative;
vertical-align: top; vertical-align: top;
overflow: auto;
max-width: 500px;
max-height: 700px;
} }
#tbody-containerui-image-editor-controls { #tbody-containerui-image-editor-controls {
display: inline-block; display: inline-block;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!