index.js
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const $polysoft="$polysoft"
/**
* @name 获取location
*/
export let locationFormat=()=>{
let _search = location.search.length>location.hash.length? location.search:location.hash;
_search = _search.substr(_search.indexOf("?")+1,_search.length-1);
let str = `'${decodeURIComponent(_search).replace(/^(?!\?|#)/ig,"").replace(/&/ig,"','").replace(/\=/ig,"':'")}'`.split(",").map(d=>(d.includes(":")? d:d+":''" ));
str=`{${str}}`;
console.log(str, 111);
return new Function("return "+str)();
}
/**
* @name 本地存储
*/
export let storeSet=(key, val, time)=>{
if (!val) {
return key
}
let name = key.includes($polysoft) ? key : $polysoft + key
let opt = {
key: name,
val,
type: isType(val),
createTime: Date.now(),
time
}
sessionStorage.setItem(name, JSON.stringify(opt))
}
export let storeGet=(key)=>{
let name = key.includes($polysoft) ? key : $polysoft + key
let date = Date.now()
let data = sessionStorage.getItem(name)
if (data) {
let da = JSON.parse(data)
if (da.time && da.time >= date) {
storeDel(name)
}
return da.val
} else {
return null
}
}
export let storeDel=(key)=>{
if (key && isType(key) == 'String') {
let name = $polysoft + key
key.includes($polysoft)
? sessionStorage.removeItem(key)
: sessionStorage.removeItem(name)
}
}
export let storeAll=()=>{
let item = sessionStorage,
list = []
for (let i = 0; i < item.length; i++) {
let keys = sessionStorage.key(i)
if (keys.includes($polysoft)) {
list.push(getItem(keys))
}
}
return list
}
//常用呢类型判断
export let isType=(obj)=>{
if (obj) {
return /\[object(.*?)\]/gi
.exec(Object.prototype.toString.call(obj))[1]
.trim()
}
return 'undefined'
}
/**
* @name 拼图
* @param {data} Array 只包含src的数组
* @param {width} Int 单个图片宽度
* @param {height} Int 单个图片高度
* @param {col} Int 列数
* @param {row} Int 行数
*/
export const jigsaw=({data=[],width=15,height=15,col=3,row=3})=>{
const canvas = document.createElement("canvas");
const d2 = canvas.getContext("2d");
let j = 2; //间隙宽度
let x ,y ; //每次
x =y = 0;
let _width = width*col+(j*(col-1))+j;
let _height = height*row+(j*(row-1))+j;
Object.assign(canvas,{width:_width,height:_height})
d2.fillStyle="rgba(0,0,0,0.1)";
d2.fillRect(0,0,_width,_height);
let primise = data.map((d,index)=>{
return new Promise((resolve,reject)=>{
let img = new Image();
//img.src = 'http://10.10.80.99:808/nas/images/app/20190412180056f96b2939-ac07-4502-ab0e-6fbd327ed80d.jpg';
img.src='image/HeadPortrait2.png?d='+Date.now();
img.crossOrigin = "";
img.addEventListener("load",(ev)=>{
resolve(img)
},false)
})
})
return Promise.all(primise)
.then(data=>{
data.forEach((el,ind)=>{
x=(ind%col);
d2.drawImage(el,x*width+(x+j),y*height+(y+j),width,height);
if((ind+1)%col==0){y+=1}
})
return canvas.toDataURL("image/png");
})
}