atr-components 0.2.237 → 0.2.238

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.
@@ -387,12 +387,31 @@ class ToolsUtil {
387
387
  }
388
388
  return date.getFullYear() + "-" + month + "-" + strDate + " " + hours + ":" + seconds;
389
389
  }
390
+ static getFormatDateHour(date) {
391
+ let month = date.getMonth() + 1;
392
+ let strDate = date.getDate();
393
+ let hours = date.getHours();
394
+ let seconds = date.getMinutes();
395
+ if (month <= 9) {
396
+ month = "0" + month;
397
+ }
398
+ if (strDate <= 9) {
399
+ strDate = "0" + strDate;
400
+ }
401
+ if (hours <= 9) {
402
+ hours = "0" + hours;
403
+ }
404
+ if (seconds <= 9) {
405
+ seconds = "0" + seconds;
406
+ }
407
+ return date.getFullYear() + "" + month + strDate + hours;
408
+ }
390
409
  static getOssUrl(url, needTime = false) {
391
410
  if (!url) {
392
411
  return "";
393
412
  }
394
413
  if (needTime) {
395
- url = url + "?v=" + new Date().getTime();
414
+ url = url + "?v=" + ToolsUtil.getFormatDateHour(new Date());
396
415
  }
397
416
  if (url.startsWith("http")) {
398
417
  return url;
@@ -1817,8 +1836,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1817
1836
  class OssImgPipe {
1818
1837
  constructor() {
1819
1838
  }
1820
- transform(value, isVideoCover = false) {
1821
- return isVideoCover ? ToolsUtil.getVideoCover(value) : ToolsUtil.getOssUrl(value);
1839
+ transform(value, isVideoCover = false, needTime = false) {
1840
+ return isVideoCover ? ToolsUtil.getVideoCover(value) : ToolsUtil.getOssUrl(value, needTime);
1822
1841
  }
1823
1842
  }
1824
1843
  OssImgPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: OssImgPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
@@ -4749,6 +4768,12 @@ class ImgCanvasComponent {
4749
4768
  this.clipArr = [];
4750
4769
  }
4751
4770
  set url(url) {
4771
+ if (url && url.indexOf('?v=') < 0) {
4772
+ if (url.indexOf("?") < 0) {
4773
+ url += "?";
4774
+ }
4775
+ url += "v=" + new Date().getTime();
4776
+ }
4752
4777
  this.imgUrl = url;
4753
4778
  }
4754
4779
  ngOnInit() {
@@ -4790,7 +4815,8 @@ class ImgCanvasComponent {
4790
4815
  imgH: imgH
4791
4816
  };
4792
4817
  }
4793
- initImg() {
4818
+ initImg(needSession = true) {
4819
+ let obj = SessionStorageUtil.get('appImg');
4794
4820
  this.canvasDom = this.canvas1.nativeElement;
4795
4821
  // this.canvasDom = document.getElementById(this.canvasId);
4796
4822
  //检测支持性
@@ -4798,24 +4824,39 @@ class ImgCanvasComponent {
4798
4824
  return;
4799
4825
  //获得 2d 上下文对象
4800
4826
  let context1 = this.canvasDom.getContext('2d');
4827
+ let image = this.imgUrl;
4828
+ // if (obj && needSession && obj[image]) {
4829
+ // //图片缓存在session中
4830
+ // this.img = obj[image]
4831
+ // this.initBase(context1)
4832
+ // return;
4833
+ // }
4834
+ if (!obj) {
4835
+ obj = {};
4836
+ }
4801
4837
  this.img = new Image(); //创建img元素
4802
4838
  this.img.setAttribute('crossOrigin', 'anonymous');
4803
4839
  this.img.src = this.imgUrl; //设置图片源地址
4804
4840
  // this.img.src = ToolsUtil.getOssUrl(this.imgUrl);//设置图片源地址
4805
4841
  this.img.onload = () => {
4806
- console.log("图片加载完毕", this.img.height);
4807
- console.log("图片加载完毕", this.img.width);
4808
- const { imgW, imgH } = this.getCanvasFull();
4809
- this.canvasDom.width = this.width;
4810
- this.canvasDom.height = this.height;
4811
- if (this.clipArr && this.clipArr.length > 0) {
4812
- this.goClip(context1);
4813
- }
4814
- // 参数 1:要绘制的 img 参数 2、3:绘制的 img 在 canvas 中的坐标 参数4,5是width,height
4815
- context1.drawImage(this.img, 0, 0, this.width, this.height);
4816
- console.log("图片加载完毕", this.canvasDom.width + "," + this.canvasDom.height);
4842
+ obj[image] = this.img;
4843
+ SessionStorageUtil.put('appImg', obj);
4844
+ this.initBase(context1);
4817
4845
  };
4818
4846
  }
4847
+ initBase(context1) {
4848
+ console.log("图片加载完毕", this.img.height);
4849
+ console.log("图片加载完毕", this.img.width);
4850
+ const { imgW, imgH } = this.getCanvasFull();
4851
+ this.canvasDom.width = this.width;
4852
+ this.canvasDom.height = this.height;
4853
+ if (this.clipArr && this.clipArr.length > 0) {
4854
+ this.goClip(context1);
4855
+ }
4856
+ // 参数 1:要绘制的 img 参数 2、3:绘制的 img 在 canvas 中的坐标 参数4,5是width,height
4857
+ context1.drawImage(this.img, 0, 0, this.width, this.height);
4858
+ console.log("图片加载完毕", this.canvasDom.width + "," + this.canvasDom.height);
4859
+ }
4819
4860
  goClip(context) {
4820
4861
  context.beginPath();
4821
4862
  context.moveTo(this.clipArr[0].x1, this.clipArr[0].y1);