index.js 1.4 KB

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