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
@@ -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
|
-
|
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
|
-
|
180
|
-
|
181
|
-
|
182
|
-
const { width, height } =
|
183
|
-
|
184
|
-
|
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
|
-
|
189
|
-
|
191
|
+
this.image = this.$refs["duoViewerImage"];
|
192
|
+
this.initDrag();
|
190
193
|
this.$emit("loadComplete");
|
191
|
-
const { width, height } =
|
192
|
-
|
193
|
-
|
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
|
-
|
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
|
-
|
239
|
+
const $this = this
|
240
|
+
imageObject.onload = () => {
|
233
241
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
244
|
-
height
|
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
|
-
|
251
|
-
|
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
|