Skip to content

Commit

Permalink
feat: add Konva Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaobo1010 committed Aug 5, 2022
1 parent 24a9690 commit 49883e0
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
/.vscode
*.zip
*.rar
release
Expand Down
3 changes: 2 additions & 1 deletion src/dgiot/components/DgiotIcon/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
props: {
icon: {
type: String,
required: true,
default: '',
// required: true,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ export default {
background: '背景底图',
evidence: '取证',
'evidence control': '取证控件',
'basic element': '基本元件',
'Add text content': '添加文本',
text: '文本',
'text button': '文本按钮',
Expand Down
42 changes: 35 additions & 7 deletions src/store/modules/topo.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,38 @@ const mutations = {
canvas.konva = attr
},
contextMenu(state, handler) {
addNodeEvent({
type: 'contextMenu',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
contextmenu: canvas.contextmenu,
// node.findAncestors('.mygroup'); Node.prototype.parentNode
let id = canvas.contextmenu.attrs.id
console.log(
'handler',
handler,
})
canvas.contextmenu,
canvas.contextmenu.getParent()
)
id = id.slice(0, id.length - 5)
console.log('寻找', canvas.stage.find(`#${id}`))
// canvas.contextmenu.findAncestors(
// `#${}`
// )
if (handler == 'remove') {
addNodeEvent({
type: 'contextMenu',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
contextmenu: canvas.contextmenu.getParent(), //canvas.contextmenu,
handler,
})
} else {
addNodeEvent({
type: 'contextMenu',
stage: canvas.stage,
layer: canvas.layer,
args: canvas.handlerArgs,
contextmenu: canvas.contextmenu,
handler,
})
}
},
createdEvidence(state, Evidence) {
state.createdEvidence = Evidence
Expand Down Expand Up @@ -227,6 +251,7 @@ const mutations = {
addNodeEvent(args)
},
createThing(state, thing, x, y) {
console.log('thing内容', thing, x, y)
const simpleText = addNodeEvent({
type: 'createThing',
thing,
Expand Down Expand Up @@ -347,6 +372,9 @@ const actions = {
createThing({ commit }, args) {
commit('createThing', args)
},
createBasicThing({ commit }, args) {
commit('createBasicThing', args)
},
createAmis({ commit }, args) {
commit('createAmis', args)
},
Expand Down
12 changes: 7 additions & 5 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ export function isBase64(str) {
return false
}
try {
return btoa(atob(str)) == str
return window.btoa(window.atob(str)) == str
} catch (err) {
return false
}
Expand Down Expand Up @@ -932,11 +932,13 @@ class konvaUtils {
this.nodeTag = []
}
// bo
putNode(node, nodeid, params, type) {
if (type == 'change') {
var change = node.find(nodeid)[0].setAttrs(params)
putNode(node, nodeid, text, type) {
console.log('组态修改', node, nodeid, text, type)
if (type != 'undefined') {
let params = {}
params[type] = text
var change = node.find(`#${nodeid}`)[0].setAttrs(params)
}
console.log(node, nodeid, params, change)
// in nodeid find node
// in node.name event
// if thing put text
Expand Down
38 changes: 36 additions & 2 deletions src/utils/konva/core/topoStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let info = {
evidence: [],
badge: [],
}
let dbclickflag = false
let timer = ''
canvas.info = info
/**
* @description 组态Stage公共函数
Expand Down Expand Up @@ -118,9 +120,41 @@ const topoStage = {
canvas.clickItem = e.target
console.log('contextmenu', e.target)
})
// circle.on('touchend', function() {
// writeMessage('Touchend circle');
// })
node.on('touchend', (e) => {
if (node.getAttr('bind_amis') && node.getAttr('amis_id').length > 0)
dgiotBus.$emit('nodeInfo', node)
})
/** */
node.on('click', (e) => {
canvas.contextmenu = {}
canvas.clickItem = e.target
console.log('点击弹出编辑框', e.evt.button, dbclickflag)
//判断是否点击鼠标左键和在编辑状态
if (dbclickflag) {
// clearTimeout(timer)
setTimeout(() => {
dbclickflag = false
}, 500)
}
if (!dbclickflag) {
dbclickflag = true
timer = setTimeout(() => {
if (
e.evt.button == 0 &&
window.location.hash.indexOf('type=device') < 0
) {
dbclickflag = false
console.log('打开编辑框')
dgiotBus.$emit('nodeEdit', node)
}
}, 500)
}

if (node.getAttr('bind_amis') && node.getAttr('amis_id').length > 0)
dgiotBus.$emit('nodeInfo', node)
// canvas.contextmenu = {}
// canvas.clickItem = e.target
// console.log('click', e.target.attrs)
// 单击时,这里根据node bind 的控件类型,去展示对应的控件信息
})
Expand Down
21 changes: 21 additions & 0 deletions src/utils/utilwen.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ function dateFormat(fmt, date) {
}
return fmt
}
function 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
}

function timestampToTime(timestamp, full) {
if (!timestamp) {
Expand Down Expand Up @@ -543,6 +562,8 @@ export default {
Vue.prototype.$FileServe = Cookies.get('fileServer')
Vue.prototype.$dgiotlog = dgiotlog
Vue.prototype.$dgiotConsole = dgiotConsole
//判断当前是否为pc端
Vue.prototype.$ispc = isPC
// 订阅方法挂载到全局变量上 2022年5月27日
Vue.prototype.$getTopic = getTopic
Vue.prototype.$subscribe = subscribe
Expand Down
9 changes: 5 additions & 4 deletions src/views/CloudFunction/topo/components/TopoBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@
fnHandler: 'moveToTop',
btnName: '置顶',
},
{
fnHandler: 'moveToBottom',
btnName: '置底',
},
// {
// fnHandler: 'moveToBottom',
// btnName: '置底',
// },
// {
// fnHandler: 'copy',
// icoName: 'fa fa-minus-square-o fa-fw',
Expand Down
18 changes: 18 additions & 0 deletions src/views/CloudFunction/topo/components/TopoTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@
<!-- </el-button>-->
<Evidence />
</a-collapse-panel>
<!-- <a-collapse-panel key="4" :header="$translateTitle('topo.basic element')">
<el-button
draggable="true"
size="mini"
type="primary"
@click.native="
createBasicThing({
productid: $route.query.productid,
type: 'static',
hidden: false,
})
"
>
静态框
</el-button>
<el-divider />
</a-collapse-panel> -->
<!-- <a-collapse-panel key="4" :header="$translateTitle('topo.image')">-->
<!-- <div>-->
<!-- <el-collapse v-model="activeNames" accordion>-->
Expand Down Expand Up @@ -276,6 +293,7 @@
setFlag: 'konva/setFlag',
setDrawParams: 'konva/setDrawParams',
createThing: 'topo/createThing',
createBasicThing: 'topo/createBasicThing',
createAmis: 'topo/createAmis',
createHistory: 'topo/createHistory',
setKonvaBg: 'topo/setKonvaBg',
Expand Down
6 changes: 3 additions & 3 deletions src/views/CloudFunction/topo/evidence/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,11 @@
</el-col>
<el-col :lg="16" :md="13" :sm="11" :xl="18" :xs="10">
<el-link
v-if="$route.query.message && Number($route.query.step) != 5"
type="warning"
v-if="$route.query.message && Number($route.query.step) == 4"
type="success"
:underline="false"
>
{{ $translateTitle('cloudTest.The reason is not reviewed') }}:
{{ $translateTitle('cloudTest.report audit opinion') }}:
{{ $route.query.message }}
</el-link>
<el-link
Expand Down

0 comments on commit 49883e0

Please sign in to comment.