index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Component({
  2. properties: {
  3. defaultImage: String,
  4. imgType: {
  5. type: Number,
  6. value: 2
  7. },
  8. loadImage: {
  9. type: String,
  10. observer: function (t) {
  11. if (t) {
  12. var e = Math.ceil(wx.getSystemInfoSync().pixelRatio), i = t + "?imageView2/" + this.data.imgType + "/w/" + this.getPx(this.data.width) * e + "/h/" + this.getPx(this.data.height) * e + "/ignore-error/1";
  13. this.setData({
  14. img: i,
  15. w: this.getPx(this.data.width),
  16. h: this.getPx(this.data.height)
  17. });
  18. }
  19. }
  20. },
  21. width: String,
  22. height: String,
  23. canPreview: {
  24. type: Boolean,
  25. value: false
  26. },
  27. isLazy: {
  28. type: Boolean,
  29. value: false
  30. },
  31. isCircle: {
  32. type: Boolean,
  33. value: false
  34. }
  35. },
  36. data: {
  37. isLoad: false,
  38. img: "",
  39. systemInfo: {},
  40. w: 0,
  41. h: 0
  42. },
  43. methods: {
  44. imageLoad: function () {
  45. this.setData({
  46. isLoad: true
  47. });
  48. },
  49. getPx: function (t) {
  50. var e = wx.getSystemInfoSync();
  51. return Math.round(e.windowWidth / 375 * t);
  52. },
  53. preview: function () {
  54. this.data.canPreview && wx.previewImage({
  55. urls: [this.data.loadImage],
  56. fail: function (t) {
  57. wx.showToast({
  58. title: "预览图片失败,请重试",
  59. icon: "none"
  60. }), console.log(t);
  61. }
  62. });
  63. }
  64. }
  65. });