|
|
@ -25,6 +25,7 @@ |
|
|
|
import 'tui-image-editor/dist/tui-image-editor.css' |
|
|
|
import 'tui-color-picker/dist/tui-color-picker.css' |
|
|
|
import ImageEditor from 'tui-image-editor' |
|
|
|
import { fabric } from 'fabric' |
|
|
|
// 汉化 |
|
|
|
const locale_zh = { |
|
|
|
// override default English locale to your custom |
|
|
@ -199,27 +200,11 @@ export default { |
|
|
|
instance: null, |
|
|
|
textOne: '', |
|
|
|
textTwo: '', |
|
|
|
textThree: '' |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// ImageEditor |
|
|
|
|
|
|
|
}, |
|
|
|
methods: { |
|
|
|
init(textOne, textTwo, textThree) { |
|
|
|
textOne ? this.textOne = textOne : '' |
|
|
|
textTwo ? this.textTwo = textTwo : '' |
|
|
|
textThree ? this.textThree = textThree : '' |
|
|
|
this.visible = true |
|
|
|
this.$nextTick(() => { |
|
|
|
// console.log(this.imgUrl) |
|
|
|
this.instance = new ImageEditor( |
|
|
|
document.querySelector('#tui-image-editor'), |
|
|
|
{ |
|
|
|
textThree: '', |
|
|
|
editorOptions: { |
|
|
|
includeUI: { |
|
|
|
loadImage: { |
|
|
|
path: this.imgUrl, |
|
|
|
path: '', |
|
|
|
name: 'image' |
|
|
|
}, |
|
|
|
// menu: ['crop', 'rotate', 'draw', 'shape', 'icon', 'text', 'filter'], // 底部菜单按钮列表 隐藏镜像flip和遮罩mask |
|
|
@ -231,10 +216,48 @@ export default { |
|
|
|
menuBarPosition: 'bottom', |
|
|
|
locale: locale_zh, // 本地化语言为中文 |
|
|
|
theme: customTheme // 自定义主题 |
|
|
|
}, |
|
|
|
fabricConfig: { |
|
|
|
// 添加背景颜色 |
|
|
|
backgroundColor: 'rgba(255, 255, 255, 1)', |
|
|
|
// 禁用缩放 |
|
|
|
scalable: false, |
|
|
|
// 添加自定义图形 |
|
|
|
customShapes: [ |
|
|
|
{ |
|
|
|
name: 'triangle', |
|
|
|
icon: 'path://M0,0 L50,50 L100,0 Z', |
|
|
|
points: [25, 0, 50, 50, 0, 50], |
|
|
|
offset: 25 |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// const ref = this.$refs.can |
|
|
|
// const canvas = new fabric.Canvas(ref) |
|
|
|
// const rect = new fabric.Rect({ |
|
|
|
// fill: 'red', |
|
|
|
// width: 20, |
|
|
|
// height: 20 |
|
|
|
// }) |
|
|
|
// canvas.add(rect) |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
init(textOne, textTwo, textThree) { |
|
|
|
textOne ? this.textOne = textOne : '' |
|
|
|
textTwo ? this.textTwo = textTwo : '' |
|
|
|
textThree ? this.textThree = textThree : '' |
|
|
|
this.visible = true |
|
|
|
this.$nextTick(() => { |
|
|
|
this.editorOptions.includeUI.loadImage.path = this.imgUrl |
|
|
|
this.instance = new ImageEditor( |
|
|
|
'#tui-image-editor', |
|
|
|
this.editorOptions |
|
|
|
) |
|
|
|
// document.querySelector('.tie-btn-resize').style.display = 'none' // 隐藏顶部重置按钮 |
|
|
|
this.instance.setBrush({ width: 20, color: 'red' }) |
|
|
|
document.querySelector('.tie-btn-mask').style.display = 'none' // 隐藏遮罩按钮 |
|
|
|
}) |
|
|
|
}, |
|
|
@ -257,11 +280,9 @@ export default { |
|
|
|
// 替换图片 |
|
|
|
replaceHandle(e) { |
|
|
|
var file = e.target.files[0] |
|
|
|
console.log(file) |
|
|
|
var reader = new FileReader() |
|
|
|
var that = this |
|
|
|
reader.readAsDataURL(file) |
|
|
|
console.log(reader) |
|
|
|
reader.onload = function(e) { |
|
|
|
that.imgUrl = reader.result |
|
|
|
that.init() |
|
|
|