You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.3 KiB

import Konva from "konva";
const workers=function (width,height,persons) {
8 months ago
const _width=width*0.2,_height=height*0.737
const container=function (){
8 months ago
const x=20,y=262
const group=new Konva.Group({
x:0,
y:0,
width:_width,
height:_height,
8 months ago
draggable:true,
dragBoundFunc:function (pos){
return {
x:x,
y:pos.y
}
},
})
8 months ago
const bgGroup=new Konva.Group({
x:x,
y:y,
width:_width,
height:_height,
})
bgGroup.clipFunc(function(ctx) {
ctx.rect(0, 6, _width, _height-11);
});
bgGroup.add(group)
const imageObj = new Image();
imageObj.src = require('@/assets/sliao/personbg.png');
imageObj.onload = function () {
const shape = new Konva.Image({
x: 0,
y: 0,
width: _width,
height:_height,
image: this,
});
bgGroup.add(shape)
shape.zIndex(0)
}
for (let i = 0; i < persons.length; i++) {
const item=persons[i]
const _group=person(i,item)
group.add(_group)
}
8 months ago
return bgGroup
}
let currentWork=null;
8 months ago
let selectedShape=null;
const getCurrentWorker=function (){
return currentWork
}
const person=function (index,item){
const alignSize=2
8 months ago
const width=((_width-30)/alignSize),height=135
const x=index%alignSize*width+(index%alignSize+1)*10,y=height*(Math.floor(index/alignSize))+(Math.floor(index/alignSize)+1)*10
const group=new Konva.Group({
x:x,
y:y,
width:width,
height:height
})
8 months ago
const selectObj = new Image();
selectObj.src = require('@/assets/sliao/selected.png');
let selectShape=null
const setSelectShape=function (shape){
selectShape=shape
}
selectObj.onload = function () {
const shape = new Konva.Image({
x: 83,
y: 0,
width: 39,
height:39,
image: this,
visible:false
});
group.add(shape)
shape.zIndex(0)
setSelectShape(shape)
}
group.on('click touchstart',function (){
currentWork=item
8 months ago
if (selectedShape){
selectedShape.hide()
if (selectedShape===selectShape){
selectedShape=null
8 months ago
return
}
}
selectedShape=selectShape
selectedShape.show()
})
8 months ago
const bgObj = new Image();
bgObj.src = require('@/assets/sliao/personbg1.png');
bgObj.onload = function () {
const shape = new Konva.Image({
x: 0,
y: 0,
offsetX:4,
width: 137*0.95,
height:155*0.80,
image: this,
});
group.add(shape)
shape.zIndex(0)
}
8 months ago
const imageObj = new Image();
imageObj.src = require('@/assets/sliao/headImage.png');
imageObj.onload = function () {
const shape = new Konva.Image({
x: 0,
y: 0,
offsetX:-4,
offsetY:-10,
width: 126*0.9,
height:134*0.80,
image: this,
});
group.add(shape)
shape.zIndex(0)
}
const text=new Konva.Text({
x:0,
8 months ago
y:70,
width: width,
height: height,
fill:'black',
text:item.userName,
align:'center',
verticalAlign:'middle',
fontSize:20
})
group.add(text)
return group
}
return {
container,getCurrentWorker
}
}
export default workers