Commit 43b79b3d by liuchuanming

posterpage

1 parent 622e4f01
tag-version-prefix=""
registry=https://registry.npm.taobao.org
\ No newline at end of file \ No newline at end of file
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
"axios": "0.18.1", "axios": "0.18.1",
"clipboard": "2.0.4", "clipboard": "2.0.4",
"core-js": "3.6.5", "core-js": "3.6.5",
"fabric": "^3.5.1",
"tui-image-editor": "^3.7.1",
"echarts": "4.2.1", "echarts": "4.2.1",
"element-ui": "2.13.2", "element-ui": "2.13.2",
"file-saver": "2.0.1", "file-saver": "2.0.1",
......
No preview for this file type
...@@ -103,6 +103,7 @@ export default { ...@@ -103,6 +103,7 @@ export default {
}, },
// 获取素材列表 // 获取素材列表
getList(page) { getList(page) {
console.log('getList', page, JSON.stringify(this.query))
page && (this.query.pageNum = page) page && (this.query.pageNum = page)
this.loading = true this.loading = true
getList(this.query) getList(this.query)
...@@ -161,14 +162,22 @@ export default { ...@@ -161,14 +162,22 @@ export default {
}, },
// 素材添加/编辑 // 素材添加/编辑
edit(data, type) { edit(data, type) {
this.form = Object.assign( switch (type) {
{}, case 5:
data || { categoryId: this.query.categoryId } this.$parent.posterEdit.step = 0
) this.$parent.dialog.edit = true
this.dialogVisible = true break
this.$nextTick(() => { default:
this.$refs['form'].clearValidate() this.form = Object.assign(
}) {},
data || { categoryId: this.query.categoryId }
)
this.dialogVisible = true
this.$nextTick(() => {
this.$refs['form'].clearValidate()
})
break;
}
// type || !data ? (this.disabled = false) : (this.disabled = true) // type || !data ? (this.disabled = false) : (this.disabled = true)
}, },
// 素材提交 // 素材提交
...@@ -323,7 +332,7 @@ export default { ...@@ -323,7 +332,7 @@ export default {
<el-button <el-button
v-hasPermi="['material:add']" v-hasPermi="['material:add']"
type="primary" type="primary"
@click="edit(1)" @click="edit(1, ~~type)"
>添加{{ typeTitle[type] }}</el-button >添加{{ typeTitle[type] }}</el-button
> >
</div> </div>
......
<template>
<div ref="tuiImageEditor" style="width: 100%;height: 100%;"></div>
</template>
<script>
import ImageEditor from 'tui-image-editor';
import { setTimeout } from 'timers';
const includeUIOptions = {
includeUI: {
initMenu: 'filter',
}
};
const editorDefaultOptions = {
cssMaxWidth: 640,
cssMaxHeight: 1136
};
export default {
name: 'PosterPage',
props: {
includeUi: {
type: Boolean,
default: true
},
options: {
type: Object,
default() {
return editorDefaultOptions;
}
}
},
mounted() {
let options = editorDefaultOptions;
if (this.includeUi) {
options = Object.assign(includeUIOptions, this.options);
}
this.editorInstance = new ImageEditor(this.$refs.tuiImageEditor, options);
setTimeout(()=>{
if(window.localStorage.getItem('record')){
var list = JSON.parse(window.localStorage.getItem('record'));
list.forEach(element => {
setTimeout(()=>{
this.editorInstance.addIcon(element.type, element).then(objectProps=>{
console.log(objectProps)
}).catch((res)=>{console.log(res)})
},500)
});
}
this.editorInstance.addImageObject('https://pics7.baidu.com/feed/3801213fb80e7bec2314d2a77c58683f9a506b2c.jpeg?token=ff070cf4be817f18bbe26476f682d614&s=BD84CB14520A434F063CA4C30300E0B5')
},2000)
this.addEventListener();
},
destroyed() {
Object.keys(this.$listeners).forEach(eventName => {
this.editorInstance.off(eventName);
});
this.editorInstance.destroy();
this.editorInstance = null;
},
methods: {
addEventListener() {
Object.keys(this.$listeners).forEach(eventName => {
this.editorInstance.on(eventName, (...args) => this.$emit(eventName, ...args));
});
},
getRootElement() {
return this.$refs.tuiImageEditor;
},
invoke(methodName, ...args) {
console.log('invoke', methodName)
console.log('invoke', ...args)
let result = null;
if (this.editorInstance[methodName]) {
result = this.editorInstance[methodName](...args);
} else if (methodName.indexOf('.') > -1) {
const func = this.getMethod(this.editorInstance, methodName);
if (typeof func === 'function') {
result = func(...args);
}
}
return result;
},
getMethod(instance, methodName) {
const {first, rest} = this.parseDotMethodName(methodName);
const isInstance = (instance.constructor.name !== 'Object');
const type = typeof instance[first];
let obj;
if (isInstance && type === 'function') {
obj = instance[first].bind(instance);
} else {
obj = instance[first];
}
if (rest.length > 0) {
return this.getMethod(obj, rest);
}
return obj;
},
parseDotMethodName(methodName) {
console.log('parseDotMethodName', methodName)
const firstDotIdx = methodName.indexOf('.');
let firstMethodName = methodName;
let restMethodName = '';
if (firstDotIdx > -1) {
firstMethodName = methodName.substring(0, firstDotIdx);
restMethodName = methodName.substring(firstDotIdx + 1, methodName.length);
}
return {
first: firstMethodName,
rest: restMethodName
};
}
}
};
</script>
<script> <script>
import VueUeditorWrap from 'vue-ueditor-wrap'
import MaPage from '@/views/material/components/MaPage' import MaPage from '@/views/material/components/MaPage'
import "tui-image-editor/dist/svg/icon-a.svg";
import "tui-image-editor/dist/svg/icon-b.svg";
import "tui-image-editor/dist/svg/icon-c.svg";
import "tui-image-editor/dist/svg/icon-d.svg";
// Load Style Code
import "tui-image-editor/dist/tui-image-editor.css";
import "tui-color-picker/dist/tui-color-picker.css";
// import $ from "jquery";
import PosterPage from "./components/PosterPage.vue";
import bgpng from "@/assets/poster/img/bg.png";
import iconA from "@/assets/poster/icon-a.svg";
import iconB from "@/assets/poster/icon-b.svg";
import iconC from "@/assets/poster/icon-c.svg";
import iconD from "@/assets/poster/icon-d.svg";
var locale_ru_RU = {
"Text": "文本",
"Mask": "遮罩",
"Delete-all": "全部清空"
};
export default { export default {
name: 'Poster', name: 'Poster',
components: { MaPage, VueUeditorWrap }, components: {
MaPage,
"tui-image-editor": PosterPage
},
data () { data () {
return { return {
dialog: { dialog: {
...@@ -28,10 +53,110 @@ export default { ...@@ -28,10 +53,110 @@ export default {
srcList: [], srcList: [],
ids: [], // 选中数组 ids: [], // 选中数组
previewImg: '', // 预览图片地址 previewImg: '', // 预览图片地址
useDefaultUI: true,
options: {
includeUI: {
initMenu: "Text",
locale: locale_ru_RU,
loadImage: {
path: 'https://pics1.baidu.com/feed/b151f8198618367a934321a0a7275bd3b21ce565.jpeg?token=2e8af569910896950d7bb7f518460a94&s=592087194F2170054E4055DA030010B4',
name: "posterImage"
},
usageStatistics: false,
menuBarPosition: "top",
menu: ["text", "mask"],
theme: {
"common.bi.image": "",
"common.bisize.width": "251px",
"common.bisize.height": "21px",
"common.backgroundImage": bgpng,
"common.backgroundColor": "#fff",
"common.border": "1px solid #c1c1c1",
// header
"header.backgroundImage": "none",
"header.backgroundColor": "transparent",
"header.border": "0px",
// load button
"loadButton.backgroundColor": "#fff",
"loadButton.border": "1px solid #ddd",
"loadButton.color": "#222",
"loadButton.fontFamily": "'Noto Sans', sans-serif",
"loadButton.fontSize": "12px",
// download button
"downloadButton.backgroundColor": "#fdba3b",
"downloadButton.border": "1px solid #fdba3b",
"downloadButton.color": "#fff",
"downloadButton.fontFamily": "'Noto Sans', sans-serif",
"downloadButton.fontSize": "12px",
// main icons
"menu.normalIcon.path": iconD,
"menu.normalIcon.name": "icon-d",
"menu.activeIcon.path": iconB,
"menu.activeIcon.name": "icon-b",
"menu.disabledIcon.path": iconA,
"menu.disabledIcon.name": "icon-a",
"menu.hoverIcon.path": iconC,
"menu.hoverIcon.name": "icon-c",
"menu.iconSize.width": "24px",
"menu.iconSize.height": "24px",
// submenu primary color
"submenu.backgroundColor": "transparent",
"submenu.partition.color": "#e5e5e5",
// submenu icons
"submenu.normalIcon.path": iconD,
"submenu.normalIcon.name": "icon-d",
"submenu.activeIcon.path": iconB,
"submenu.activeIcon.name": "icon-b",
"submenu.iconSize.width": "32px",
"submenu.iconSize.height": "32px",
// submenu labels
"submenu.normalLabel.color": "#858585",
"submenu.normalLabel.fontWeight": "normal",
"submenu.activeLabel.color": "#000",
"submenu.activeLabel.fontWeight": "normal",
// checkbox style
"checkbox.border": "1px solid #ccc",
"checkbox.backgroundColor": "#fff",
// rango style
"range.pointer.color": "#333",
"range.bar.color": "#ccc",
"range.subbar.color": "#606060",
"range.disabledPointer.color": "#d3d3d3",
"range.disabledBar.color": "rgba(85,85,85,0.06)",
"range.disabledSubbar.color": "rgba(51,51,51,0.2)",
"range.value.color": "#000",
"range.value.fontWeight": "normal",
"range.value.fontSize": "11px",
"range.value.border": "0",
"range.value.backgroundColor": "#f5f5f5",
"range.title.color": "#000",
"range.title.fontWeight": "lighter",
// colorpicker style
"colorpicker.button.border": "0px",
"colorpicker.title.color": "#000"
}
},
cssMaxWidth: 640,
cssMaxHeight: 1136
}
} }
}, },
watch: {}, watch: {},
created () { }, created () {
console.log('created')
},
methods: { methods: {
listChange (data) { listChange (data) {
console.log('listChange', JSON.stringify(data)) console.log('listChange', JSON.stringify(data))
...@@ -49,6 +174,96 @@ export default { ...@@ -49,6 +174,96 @@ export default {
}, },
ready () { ready () {
console.log('ready') console.log('ready')
},
onAddText(res) {
console.log("RES : ", res);
},
//移动
onObjectMoved(res) {
console.log('onObjectMoved')
this.getRecord(res)
},
//新增/选中
objectActivated(res) {
console.log('objectActivated')
this.getRecord(res)
},
//缩放
onObjectScaled(res) {
console.log('onObjectScaled')
this.getRecord(res)
},
//重做
onRedoStackChanged(res) {
console.log("RES : ", res);
},
onUndoStackChanged(res) {
if(res == 0){
this.records = []
}
},
getRecord(res){
var flag = false;
for (let index = 0; index < this.records.length; index++) {
const element ={
fill: this.records[index].fill,
height: this.records[index].height,
id: this.records[index].id,
left: this.records[index].left,
opacity: this.records[index].opacity,
stroke: this.records[index].stroke,
strokeWidth: this.records[index].strokeWidth,
top: this.records[index].top,
type: this.records[index].type,
width: this.records[index].width,
};
if(element.id == res.id){
// console.log(element)
this.records[index] = res;
flag = true;
}
}
if(!flag){
this.records.push(res)
}
},
//
save() {
let res = {};
var list =[];
this.$refs.tuiImageEditor.editorInstance._invoker._undoStack.forEach(element => {
this.records.forEach(item => {
if(element.name =='addIcon' && element.undoData.object.__fe_id && item.id == element.undoData.object.__fe_id){
item.type = element.args[1]
}
});
});
var deleteId = [];
this.$refs.tuiImageEditor.editorInstance._invoker._undoStack.forEach(element => {
if(element.name == "removeObject"){
deleteId.push(element.args[1])
}
})
this.records.forEach(item => {
if(deleteId.indexOf((item.id).toString())>=0){
console.log(" ")
}else{
list.push(item)
}
});
//全清除
this.$refs.tuiImageEditor.editorInstance._invoker._undoStack.forEach(element => {
if(element.name == "loadImage" || element.name == "clearObjects"){
list = []
}
})
const image = this.$refs.tuiImageEditor.editorInstance.toDataURL();
res.url = image;
res.records = list;
console.log("最后结果:")
console.log(res)
window.localStorage.setItem('record',JSON.stringify(list))
} }
}, },
} }
...@@ -190,7 +405,21 @@ export default { ...@@ -190,7 +405,21 @@ export default {
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<div v-else></div> <div v-else>
<div class="imageEditorApp">
<tui-image-editor
ref="tuiImageEditor"
:include-ui="useDefaultUI"
:options="options"
@addText="onAddText"
@objectMoved="onObjectMoved"
@objectScaled="onObjectScaled"
@redoStackChanged="onRedoStackChanged"
@undoStackChanged="onUndoStackChanged"
@objectActivated="objectActivated"
></tui-image-editor>
</div>
</div>
</div> </div>
</el-dialog> </el-dialog>
</MaPage> </MaPage>
...@@ -236,4 +465,15 @@ export default { ...@@ -236,4 +465,15 @@ export default {
.preview-img { .preview-img {
width: 100%; width: 100%;
} }
.imageEditorApp {
width: 1000px;
height: 800px;
}
.tui-image-editor-header-logo {
display: none !important;
border: 1px solid red;
}
.tui-image-editor-download-btn {
display: none !important;
}
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!