emacroh5lib 1.0.44 → 1.0.45

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emacroh5lib",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
@@ -54,7 +54,7 @@
54
54
  viewerSrc: "",
55
55
  image: null,
56
56
  listDataCache: [],
57
- index: 0,
57
+ index: 0
58
58
  };
59
59
  },
60
60
  props: {
@@ -123,6 +123,8 @@
123
123
  }
124
124
  },
125
125
  },
126
+ mounted() {
127
+ },
126
128
  methods: {
127
129
  // Global init
128
130
  init() {
@@ -133,7 +135,8 @@
133
135
  // Init listDataCache
134
136
  initListDataCache(index = 0) {
135
137
  const promises = [];
136
- let $this = this;
138
+
139
+ const $this = null
137
140
 
138
141
  this.list.forEach((item, i) => {
139
142
  const imageObject = new Image();
@@ -176,24 +179,24 @@
176
179
  // $this.setStyleByName($this.image, "width", width);
177
180
  // $this.setStyleByName($this.image, "height", height);
178
181
 
179
- $this.image = $this.$refs["duoViewerImage"];
180
- $this.initDrag();
181
- $this.$emit("loadComplete");
182
- const { width, height } = $this.listDataCache[index];
183
- $this.setStyleByName($this.image, "width", width);
184
- $this.setStyleByName($this.image, "height", height);
182
+ this.image = this.$refs["duoViewerImage"];
183
+ this.initDrag();
184
+ this.$emit("loadComplete");
185
+ const { width, height } = this.listDataCache[index];
186
+ this.setStyleByName(this.image, "width", width);
187
+ this.setStyleByName(this.image, "height", height);
185
188
  })
186
189
 
187
190
  Promise.race(promises).then((data) => {
188
- $this.image = $this.$refs["duoViewerImage"];
189
- $this.initDrag();
191
+ this.image = this.$refs["duoViewerImage"];
192
+ this.initDrag();
190
193
  this.$emit("loadComplete");
191
- const { width, height } = $this.listDataCache[index];
192
- $this.setStyleByName($this.image, "width", width);
193
- $this.setStyleByName($this.image, "height", height);
194
+ const { width, height } = this.listDataCache[index];
195
+ this.setStyleByName(this.image, "width", width);
196
+ this.setStyleByName(this.image, "height", height);
194
197
 
195
198
  setTimeout(() => {
196
- $this.resetZoom();
199
+ this.resetZoom();
197
200
  }, 100);
198
201
  })
199
202
 
@@ -225,30 +228,35 @@
225
228
  // Reset zoom action
226
229
  resetZoom(adaptive = true) {
227
230
  let image = this.image;
231
+
232
+ console.log("图片宽高1", image);
233
+ console.log("图片宽高2", image.width);
234
+
228
235
  const imageObject = new Image();
229
236
 
230
237
  imageObject.src = this.list[this.index];
231
238
 
232
- let { width, height } = imageObject;
239
+ const $this = this
240
+ imageObject.onload = () => {
233
241
 
234
- if (adaptive) {
235
- let rate = 1
236
- if (width > height) {
237
- rate = width / document.body.clientWidth
238
- }
239
- else {
240
- rate = height / document.body.clientHeight
242
+ let { width, height } = imageObject;
243
+ if (adaptive) {
244
+ let rate = 1
245
+ if (width > height) {
246
+ rate = width / document.body.clientWidth
247
+ } else {
248
+ rate = height / document.body.clientHeight
249
+ }
250
+ width = width / rate
251
+ height = height / rate
241
252
  }
242
253
 
243
- width = width / rate
244
- height = height / rate
245
- }
246
-
247
- this.setStyleByName(image, "width", `${width}px`);
248
- this.setStyleByName(image, "height", `${height}px`);
254
+ $this.setStyleByName(image, "width", `${width}px`);
255
+ $this.setStyleByName(image, "height", `${height}px`);
249
256
 
250
- this.listDataCache[this.index].width = `${width}px`;
251
- this.listDataCache[this.index].height = `${height}px`;
257
+ $this.listDataCache[this.index].width = `${width}px`;
258
+ $this.listDataCache[this.index].height = `${height}px`;
259
+ }
252
260
  },
253
261
 
254
262
  // Reset all action
@@ -286,7 +294,6 @@
286
294
  // Set style by name
287
295
  setStyleByName(obj, key, value) {
288
296
  obj && (obj.style[key] = value);
289
-
290
297
  },
291
298
 
292
299
  // Get element current transform