atr-components 0.2.242 → 0.2.243

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -173,6 +173,77 @@ var UserAction;
173
173
  UserAction[UserAction["SUPPERADD"] = 4] = "SUPPERADD";
174
174
  })(UserAction || (UserAction = {}));
175
175
 
176
+ class SessionStorageUtil {
177
+ static getStorageKey(key) {
178
+ return atr_static_datas.STORAGE_PRE + key;
179
+ }
180
+ static putDictGroup(dictGroup) {
181
+ let str = sessionStorage.getItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
182
+ let dicts = {};
183
+ // console.log("fff");
184
+ if (str) {
185
+ dicts = JSON.parse(str);
186
+ }
187
+ dicts[dictGroup.groupCode] = dictGroup;
188
+ if (dicts) {
189
+ sessionStorage.setItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode(), JSON.stringify(dicts));
190
+ }
191
+ }
192
+ static getDictGroupByCode(code) {
193
+ // console.log("jjj")
194
+ let str = sessionStorage.getItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
195
+ let dicts = null;
196
+ if (str) {
197
+ dicts = JSON.parse(str);
198
+ }
199
+ if (dicts && dicts.hasOwnProperty(code))
200
+ return dicts[code];
201
+ else
202
+ return null;
203
+ }
204
+ static setImg(url, dataUrl) {
205
+ let str = sessionStorage.getItem(this.getStorageKey('IMG_CACH'));
206
+ let map = null;
207
+ if (str) {
208
+ map = JSON.parse(str);
209
+ }
210
+ if (!map) {
211
+ map = {};
212
+ }
213
+ if (url.indexOf("?") > 0) {
214
+ url = url.substring(0, url.indexOf("?"));
215
+ }
216
+ map[url] = dataUrl;
217
+ sessionStorage.setItem(this.getStorageKey('IMG_CACH'), JSON.stringify(map));
218
+ }
219
+ static getImg(url) {
220
+ // console.log("jjj")
221
+ let str = sessionStorage.getItem(this.getStorageKey('IMG_CACH'));
222
+ let map = null;
223
+ if (str) {
224
+ if (url.indexOf("?") > 0) {
225
+ url = url.substring(0, url.indexOf("?"));
226
+ }
227
+ map = JSON.parse(str)[url];
228
+ }
229
+ return map;
230
+ }
231
+ static resetDict() {
232
+ sessionStorage.removeItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
233
+ }
234
+ static put(key, value) {
235
+ sessionStorage.setItem(this.getStorageKey(key), JSON.stringify(value));
236
+ }
237
+ static get(key) {
238
+ let str = sessionStorage.getItem(this.getStorageKey(key));
239
+ let value = null;
240
+ if (str) {
241
+ value = JSON.parse(str);
242
+ }
243
+ return value;
244
+ }
245
+ }
246
+
176
247
  class ToolsUtil {
177
248
  static isBase64(string) {
178
249
  let reg = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)\s*$/i;
@@ -495,6 +566,37 @@ class ToolsUtil {
495
566
  // a.download = "3321.xls";
496
567
  a.click();
497
568
  }
569
+ static getImg(url, param = {
570
+ imgW: 0, imgH: 0,
571
+ needTime: false, isFullUrl: false
572
+ }) {
573
+ return new Promise((resolve, reject) => {
574
+ let dataUrl = SessionStorageUtil.getImg(url);
575
+ let img = new Image();
576
+ img.setAttribute('crossOrigin', 'anonymous');
577
+ if (!dataUrl) {
578
+ img.src = param.isFullUrl ? url : ToolsUtil.getOssUrl(url, param.needTime);
579
+ }
580
+ else {
581
+ let index = dataUrl.indexOf("}") + 1;
582
+ img.src = dataUrl.slice(0, 50) + dataUrl.slice(index);
583
+ }
584
+ img.onload = () => {
585
+ let c = document.createElement('canvas');
586
+ let context2 = c.getContext("2d");
587
+ c.width = param.imgW || img.width;
588
+ c.height = param.imgH || img.height;
589
+ context2.drawImage(img, 0, 0, c.width, c.height);
590
+ let dataUrl = c.toDataURL();
591
+ let str = c.width + "," + c.height + "}";
592
+ dataUrl = dataUrl.slice(0, 50) + str + dataUrl.slice(50);
593
+ console.log('getImg', dataUrl);
594
+ //不保存
595
+ // SessionStorageUtil.setImg(url, dataUrl)
596
+ resolve(img);
597
+ };
598
+ });
599
+ }
498
600
  static pixelToNum(width) {
499
601
  const re = /px/gi;
500
602
  let widthStr = width.replace(re, "");
@@ -1571,50 +1673,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1571
1673
  }]
1572
1674
  }] });
1573
1675
 
1574
- class SessionStorageUtil {
1575
- static getStorageKey(key) {
1576
- return atr_static_datas.STORAGE_PRE + key;
1577
- }
1578
- static putDictGroup(dictGroup) {
1579
- let str = sessionStorage.getItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
1580
- let dicts = {};
1581
- // console.log("fff");
1582
- if (str) {
1583
- dicts = JSON.parse(str);
1584
- }
1585
- dicts[dictGroup.groupCode] = dictGroup;
1586
- if (dicts) {
1587
- sessionStorage.setItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode(), JSON.stringify(dicts));
1588
- }
1589
- }
1590
- static getDictGroupByCode(code) {
1591
- // console.log("jjj")
1592
- let str = sessionStorage.getItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
1593
- let dicts = null;
1594
- if (str) {
1595
- dicts = JSON.parse(str);
1596
- }
1597
- if (dicts && dicts.hasOwnProperty(code))
1598
- return dicts[code];
1599
- else
1600
- return null;
1601
- }
1602
- static resetDict() {
1603
- sessionStorage.removeItem(this.getStorageKey('USER_INFO_') + ToolsUtil.getOrgCode());
1604
- }
1605
- static put(key, value) {
1606
- sessionStorage.setItem(this.getStorageKey(key), JSON.stringify(value));
1607
- }
1608
- static get(key) {
1609
- let str = sessionStorage.getItem(this.getStorageKey(key));
1610
- let value = null;
1611
- if (str) {
1612
- value = JSON.parse(str);
1613
- }
1614
- return value;
1615
- }
1616
- }
1617
-
1618
1676
  class DictService {
1619
1677
  constructor(httpService) {
1620
1678
  this.httpService = httpService;
@@ -4836,28 +4894,19 @@ class ImgCanvasComponent {
4836
4894
  return;
4837
4895
  //获得 2d 上下文对象
4838
4896
  let context1 = this.canvasDom.getContext('2d');
4839
- let image = this.imgUrl;
4840
- this.img = new Image(); //创建img元素
4841
- this.img.setAttribute('crossOrigin', 'anonymous');
4842
- this.img.src = this.imgUrl; //设置图片源地址
4843
- // this.img.src = ToolsUtil.getOssUrl(this.imgUrl);//设置图片源地址
4844
- this.img.onload = () => {
4845
- this.initBase(context1);
4897
+ ToolsUtil.getImg(this.imgUrl, { isFullUrl: true }).then(img => {
4898
+ this.img = img;
4899
+ const { imgW, imgH } = this.getCanvasFull();
4900
+ this.canvasDom.width = this.width;
4901
+ this.canvasDom.height = this.height;
4902
+ if (this.clipArr && this.clipArr.length > 0) {
4903
+ this.goClip(context1);
4904
+ }
4905
+ // 参数 1:要绘制的 img 参数 2、3:绘制的 img 在 canvas 中的坐标 参数4,5是width,height
4906
+ console.log("图片加载完毕 typeof", typeof this.img, Object.prototype.toString.call(this.img));
4907
+ context1.drawImage(this.img, 0, 0, this.width, this.height);
4846
4908
  this.loadOver.emit({ code: 'loadOver' });
4847
- };
4848
- }
4849
- initBase(context1) {
4850
- console.log("图片加载完毕", this.img.height);
4851
- console.log("图片加载完毕", this.img.width);
4852
- const { imgW, imgH } = this.getCanvasFull();
4853
- this.canvasDom.width = this.width;
4854
- this.canvasDom.height = this.height;
4855
- if (this.clipArr && this.clipArr.length > 0) {
4856
- this.goClip(context1);
4857
- }
4858
- // 参数 1:要绘制的 img 参数 2、3:绘制的 img 在 canvas 中的坐标 参数4,5是width,height
4859
- context1.drawImage(this.img, 0, 0, this.width, this.height);
4860
- console.log("图片加载完毕", this.canvasDom.width + "," + this.canvasDom.height);
4909
+ });
4861
4910
  }
4862
4911
  goClip(context) {
4863
4912
  context.beginPath();