Skip to content

Commit

Permalink
feat: Konva gif Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaobo1010 committed Aug 12, 2022
1 parent dabb61a commit 43da241
Show file tree
Hide file tree
Showing 8 changed files with 901 additions and 53 deletions.
73 changes: 72 additions & 1 deletion src/store/modules/topo.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,23 @@ const mutations = {
// `#${}`
// )
if (handler == 'remove') {
let contextmenu = ''
console.log('当前节点', canvas.contextmenu)
if (
canvas.contextmenu.attrs.name == 'evidence' ||
canvas.contextmenu.attrs.name == 'konvaimage' ||
canvas.contextmenu.attrs.name == 'sprite'
) {
contextmenu = canvas.contextmenu
} else {
contextmenu = canvas.contextmenu.getParent()
}
addNodeEvent({
type: 'contextMenu',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
contextmenu: canvas.contextmenu.getParent(), //canvas.contextmenu,
contextmenu, //canvas.contextmenu,
handler,
})
} else {
Expand Down Expand Up @@ -273,6 +284,66 @@ const mutations = {
y,
})
},
createBasicThing(state, thing, x, y) {
console.log('thing内容', thing, x, y)
if (thing.type == 'knovaimage' || thing.type == 'gifimage') {
console.log('konvaimage', thing)
// state.createdEvidence = Evidence
// var imageObj = new Image()
// imageObj.src = thing.image
let simpleImage = ''
if (thing.type == 'knovaimage') {
simpleImage = addNodeEvent(
_.merge(canvas.handlerArgs, {
type: 'createImage',
image: thing.image,
productid: thing.productid,
})
)
} else if (thing.type == 'gifimage') {
simpleImage = addNodeEvent(
_.merge(canvas.handlerArgs, {
type: 'gifImage',
image: thing.image,
animations: thing.animations,
productid: thing.productid,
})
)
simpleImage.start()
}
console.log('simpleEvidence\n', simpleImage)
canvas.layer.add(simpleImage)
canvas.layer.batchDraw()
canvas.stage.batchDraw()
addNodeEvent({
type: 'handleChildren',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
})
return
}
const simpleText = addNodeEvent({
type: 'createStatic',
thing,
saleInfo: {
scaleX: 100 * 0.01,
scaleY: 100 * 0.01,
},
randomXy,
})
canvas.layer.add(simpleText)
// canvas.layer.batchDraw()
// canvas.stage.batchDraw()
addNodeEvent({
type: 'handleChildren',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
x,
y,
})
},
createHistory(state, thing, x, y) {
const simpleText = addNodeEvent({
type: 'createHistory',
Expand Down
31 changes: 29 additions & 2 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/**
* @description 登录、获取用户信息、退出登录、清除token逻辑,不建议修改
*/

const isPC = () => {
var userAgentInfo = navigator.userAgent
var Agents = new Array(
'Android',
'iPhone',
'SymbianOS',
'Windows Phone',
'iPad',
'iPod'
)
var flag = true
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false
break
}
}
return flag
}
const getLocalStorage = (key) => {
const value = localStorage.getItem(key)
if (isJson(value)) {
Expand Down Expand Up @@ -409,7 +427,16 @@ const actions = {
},
_userInfo
)
const { sessionToken = '', roles = [] } = data
console.log('查看数据', data)
const { sessionToken = '', roles = [], objectId = '' } = data
console.log('不是pc端', isPC())
if (!isPC()) {
window.jstoken?.setJsToken(
window.location.hostname,
objectId,
sessionToken
)
}
if (sessionToken) {
await queryAllMsg(commit, dispatch, data, 'ajax')
await departmentToken(roles[0].name)
Expand Down
22 changes: 22 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,28 @@ export function parseQueryString(url) {
this[`${name}`] = value
}
}
//
// 原文链接:https://blog.csdn.net/weixin_42539678/article/details/124509254
export function imgUrlToFile(url) {
return new Promise((resolve, reject) => {
var blob = null
let imgFile = null
var xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('Accept', 'image/gif')
xhr.responseType = 'blob'
xhr.onload = () => {
blob = xhr.response
imgFile = new File([blob], 'imageName', { type: 'image/gif' })
resolve(imgFile)
}

xhr.onerror = (e) => {
reject(e)
}
xhr.send()
})
}

// api
// findInfo https://konvajs.org/docs/selectors/Select_by_id.html
Expand Down
13 changes: 13 additions & 0 deletions src/utils/konva/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import topoLable from './core/topoLable'
import topoBasic from './core/topoBasic'
import amis from './core/amis'
import device from './core/device'
import topoVideo from './core/topoVideo'
Expand All @@ -11,6 +12,9 @@ import topoPath from '@/utils/konva/core/topoPath'
function createThing(thing, saleInfo, randomXy, args) {
return topoLable.create(thing, saleInfo, randomXy, args)
}
function createBasic(thing, saleInfo, randomXy, args) {
return topoBasic.create(thing, saleInfo, randomXy, args)
}

function createHistory(thing, saleInfo, randomXy, args) {
return device.create(thing, saleInfo, randomXy, args)
Expand Down Expand Up @@ -91,6 +95,15 @@ function addNodeEvent(args) {
case 'createThing': // 创建物模型
return createThing(thing, saleInfo, randomXy, args)
break
case 'createStatic':
return createBasic(thing, saleInfo, randomXy, args)
break
case 'createImage':
return topoBasic.createImage(args)
break
case 'gifImage':
return topoBasic.createGifImage(args)
break
case 'createHistory': // 历史数据按钮
return createHistory(thing, saleInfo, randomXy, args)
break
Expand Down
Loading

0 comments on commit 43da241

Please sign in to comment.