emacroh5lib 1.0.2 → 1.0.5

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.
@@ -0,0 +1,16 @@
1
+ .app-container {
2
+ height: 100%;
3
+ width: 100%;
4
+ margin: 0;
5
+ padding: 0;
6
+ background-color: aqua;
7
+ }
8
+
9
+
10
+ .click-button {
11
+ padding: 10px;
12
+ font-size: 16px;
13
+ color: white;
14
+ border-radius: 15px;
15
+ background-color: blue;
16
+ }
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div class="app-container">
3
+
4
+
5
+
6
+ </div>
7
+ </template>
8
+
9
+ <script lang="ts">
10
+
11
+
12
+
13
+ import { Component, Prop, Vue } from "vue-property-decorator";
14
+
15
+ import $ from "jquery";
16
+
17
+ import { saveAs } from 'file-saver';
18
+ import XLSX from "xlsx-style";
19
+
20
+ import * as echarts from "echarts";
21
+
22
+
23
+ @Component({
24
+ components: {}
25
+ })
26
+ @Component({ name: 'FileViewer' })
27
+ export default class ExcelExporter extends Vue {
28
+ @Prop(Number) readonly msg!: number | undefined;
29
+ @Prop() private name!: string;
30
+
31
+ public static entryName = 'FileViewer';
32
+ private currentTime = "";
33
+
34
+ public data_0 = {
35
+ page_index: 0,
36
+ page_size: 3,
37
+ data: [
38
+ { a: "面料类", b: "16500", c: "12063", d: "45.5%" },
39
+ { a: "面料类", b: "26500", c: "12063", d: "45.5%" },
40
+ { a: "面料类", b: "36500", c: "12063", d: "45.5%" },
41
+ { a: "面料类", b: "46500", c: "12063", d: "45.5%" },
42
+ { a: "面料类", b: "56500", c: "12063", d: "45.5%" },
43
+ ],
44
+ };
45
+
46
+ // 计算属性
47
+ private get reversedMessage(): string {
48
+ return this.currentTime;
49
+ }
50
+
51
+ public test1(): void {
52
+ // EMacro.File.readLocalExcel((file, workbook) => {
53
+ // console.log("file", file);
54
+ // console.log("workbook", workbook);
55
+ // console.log("数据", workbook.Sheets["工作表1"]["G32"].h);
56
+ // });
57
+ }
58
+
59
+ // 生命周期
60
+ private created(): void { }
61
+ private mounted(): void {
62
+ this.$nextTick(() => {
63
+ // console.log("调用", EMacro);
64
+ });
65
+ }
66
+ private updated(): void { }
67
+ private destroyed(): void { }
68
+
69
+ }
70
+ </script>
71
+
72
+ <style lang="less" scoped>
73
+ @import "index.less";
74
+ </style>
@@ -0,0 +1,505 @@
1
+ <template>
2
+ <div class="duo-viewer" v-if="show" ref="duoViewer" @click="clickAgent">
3
+ <div class="duo-viewer-mask">
4
+ <img ref="duoViewerImage" :src="realSrc" alt="image" class="duo-viewer-mask__image" />
5
+ </div>
6
+ <div class="duo-viewer-footer">
7
+ <div class="duo-viewer-footer__title">{{ realSrc }}</div>
8
+ <div class="duo-viewer-footer__toolbar">
9
+ <ul>
10
+ <li class="duo-viewer-footer__zoom-in" data-viewer-action="zoom-in"></li>
11
+ <li class="duo-viewer-footer__zoom-out" data-viewer-action="zoom-out"></li>
12
+ <li class="duo-viewer-footer__one-to-one" data-viewer-action="one-to-one"></li>
13
+ <li class="duo-viewer-footer__prev" data-viewer-action="prev"></li>
14
+
15
+ <li class="duo-viewer-footer__play" data-viewer-action="play"></li>
16
+
17
+ <li class="duo-viewer-footer__next" data-viewer-action="next"></li>
18
+ <li class="duo-viewer-footer__reset" data-viewer-action="reset"></li>
19
+ <li class="duo-viewer-footer__rotate-left" data-viewer-action="rotate-left"></li>
20
+ <li class="duo-viewer-footer__rotate-right" data-viewer-action="rotate-right"></li>
21
+ </ul>
22
+ </div>
23
+ <div class="duo-viewer-footer__navbar">
24
+ <div class="duo-viewer-footer__navbar-thumbnail-wrap">
25
+ <div ref="duoViewerImageThumbnailList" class="duo-viewer-footer__navbar-thumbnail-list"
26
+ :style="{ width: `${listLength * 34}px` }">
27
+ <div :key="item + i" v-for="(item, i) in list" :class="
28
+ i === index
29
+ ? 'duo-viewer-footer__navbar-thumbnail-item viewer-current'
30
+ : 'duo-viewer-footer__navbar-thumbnail-item'
31
+ ">
32
+ <img data-viewer-action="select" :data-viewer-action-index="i" :src="item" alt="image"
33
+ class="duo-viewer-footer__navbar-thumbnail-image" />
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ <div class="duo-viewer-close" @click="handleClose">
40
+ <div class="duo-viewer-close__off"></div>
41
+ </div>
42
+ </div>
43
+ </template>
44
+
45
+ <script>
46
+ import "./style/css/index.css";
47
+
48
+ export default {
49
+ name: "ImageViewer",
50
+ data() {
51
+ return {
52
+ viewerSrc: "",
53
+ image: null,
54
+ listDataCache: [],
55
+ index: 0,
56
+ };
57
+ },
58
+ props: {
59
+ // Image src list
60
+ list: {
61
+ type: Array,
62
+ default: [],
63
+ },
64
+ // Control is show of viewer
65
+ show: {
66
+ type: Boolean,
67
+ default: false,
68
+ },
69
+ // Default index
70
+ currentIndex: {
71
+ type: Number,
72
+ default: 0,
73
+ },
74
+ },
75
+ computed: {
76
+ listLength() {
77
+ return this.list.length;
78
+ },
79
+ realSrc() {
80
+ return this.list[this.index];
81
+ },
82
+ currentData() {
83
+ return this.listDataCache[this.index];
84
+ },
85
+ },
86
+ watch: {
87
+ show(val) {
88
+ if (val) {
89
+ this.$emit("open");
90
+ this.index = this.currentIndex;
91
+ this.init();
92
+ } else {
93
+ this.$emit("close");
94
+ }
95
+ },
96
+ },
97
+ methods: {
98
+ // Global init
99
+ init() {
100
+ this.initMouseWheel();
101
+ this.keydown();
102
+ this.initListDataCache();
103
+ },
104
+ // Init listDataCache
105
+ initListDataCache(index = 0) {
106
+ const promises = [];
107
+ let $this = this;
108
+
109
+ this.list.forEach((item, i) => {
110
+ const imageObject = new Image();
111
+ promises.push(
112
+ new Promise((resolve) => {
113
+ imageObject.onload = function () {
114
+ $this.listDataCache[i] = {
115
+ transform: {
116
+ scaleX: "1",
117
+ skewY: "0",
118
+ translateX: "-50%",
119
+ translateY: "-50%",
120
+ rotate: "0deg",
121
+ },
122
+ left: "50%",
123
+ top: "50%",
124
+ width: `${imageObject.width}px`,
125
+ height: `${imageObject.height}px`,
126
+ };
127
+
128
+ resolve("");
129
+ imageObject.onload = null
130
+ };
131
+ imageObject.src = item;
132
+ })
133
+ );
134
+ });
135
+
136
+ Promise.all(promises).then((data) => {
137
+ this.image = this.$refs["duoViewerImage"];
138
+ this.initDrag();
139
+ const { width, height } = $this.listDataCache[index];
140
+
141
+ $this.setStyleByName($this.image, "width", width);
142
+ $this.setStyleByName($this.image, "height", height);
143
+ });
144
+ },
145
+ // Reset position
146
+ resetPosition() {
147
+ let image = this.image,
148
+ oldTransform = this.getCurrentTransform(image);
149
+
150
+ this.setStyleByName(image, "top", "50%");
151
+ this.setStyleByName(image, "left", "50%");
152
+
153
+ oldTransform.translateX = "-50%";
154
+ oldTransform.translateY = "-50%";
155
+
156
+ this.setTransform(image, oldTransform);
157
+ },
158
+
159
+ // Reset Rotate
160
+ resetRotate() {
161
+ let image = this.image,
162
+ oldTransform = this.getCurrentTransform(image);
163
+
164
+ oldTransform.rotate = `0deg`;
165
+
166
+ this.setTransform(image, oldTransform);
167
+ },
168
+
169
+ // Reset zoom action
170
+ resetZoom() {
171
+ let image = this.image;
172
+ const imageObject = new Image();
173
+
174
+ imageObject.src = this.list[this.index];
175
+
176
+ const { width, height } = imageObject;
177
+
178
+ this.setStyleByName(image, "width", `${width}px`);
179
+ this.setStyleByName(image, "height", `${height}px`);
180
+
181
+ this.listDataCache[this.index].width = `${width}px`;
182
+ this.listDataCache[this.index].height = `${height}px`;
183
+ },
184
+
185
+ // Reset all action
186
+ resetAll() {
187
+ this.resetZoom();
188
+ this.resetRotate();
189
+ this.resetPosition();
190
+ this.initListDataCache(this.index);
191
+ },
192
+
193
+ // Rotate action
194
+ rotate(type) {
195
+ let image = this.image,
196
+ oldTransform = this.getCurrentTransform(image),
197
+ oldRotate = Math.round(
198
+ Math.atan2(+oldTransform.skewY, +oldTransform.scaleX) *
199
+ (180 / Math.PI)
200
+ ),
201
+ changeValue = type === "left" ? -90 : 90,
202
+ rotateValue = oldRotate + changeValue;
203
+
204
+ oldTransform.rotate = `${rotateValue}deg`;
205
+
206
+ oldTransform.translateX = `${oldTransform.translateX}px`;
207
+ oldTransform.translateY = `${oldTransform.translateY}px`;
208
+ this.currentData.transform = oldTransform;
209
+ this.setTransform(image, oldTransform);
210
+ },
211
+
212
+ // Get style by name
213
+ getStyleByName(obj, type) {
214
+ return window.getComputedStyle(obj, null)[type];
215
+ },
216
+
217
+ // Set style by name
218
+ setStyleByName(obj, key, value) {
219
+ obj && (obj.style[key] = value);
220
+ },
221
+
222
+ // Get element current transform
223
+ getCurrentTransform(obj) {
224
+ let value,
225
+ transform = this.getStyleByName(obj, "transform");
226
+
227
+ if (transform === "none") return;
228
+
229
+ value = transform.split("(")[1].split(")")[0].split(",");
230
+
231
+ return {
232
+ scaleX: value[0].trim(),
233
+ skewY: value[1].trim(),
234
+ // skewX: value[2].trim(),
235
+ // scaleY: value[3].trim(),
236
+ translateX: value[4].trim(),
237
+ translateY: value[5].trim(),
238
+ };
239
+ },
240
+ // Next or prev action
241
+ switchAction(a) {
242
+ let lastIndex = this.index;
243
+ switch (a) {
244
+ case "prev":
245
+ // prev action
246
+ this.index += this.index <= 0 ? 0 : -1;
247
+ break;
248
+ case "next":
249
+ // next action
250
+ let srcListLength = this.listLength - 1;
251
+
252
+ this.index +=
253
+ this.index >= srcListLength ? srcListLength - this.index : 1;
254
+ break;
255
+ default:
256
+ this.index = +a;
257
+ break;
258
+ }
259
+ this.judgeThumbnailListMove(lastIndex, this.index);
260
+
261
+ this.setStyleByName(this.image, "width", this.currentData.width);
262
+ this.setStyleByName(this.image, "height", this.currentData.height);
263
+ this.setStyleByName(this.image, "left", this.currentData.left);
264
+ this.setStyleByName(this.image, "top", this.currentData.top);
265
+ this.setTransform(this.image, this.currentData.transform);
266
+ },
267
+ // To judge thumbnail list move
268
+ judgeThumbnailListMove(lastIndex, index) {
269
+ if (lastIndex == index) return;
270
+
271
+ let translateX = 0,
272
+ lastTransform = 0,
273
+ step = index - lastIndex,
274
+ move = step * 34,
275
+ length = this.listLength,
276
+ target = this.$refs["duoViewerImageThumbnailList"];
277
+
278
+ if (!target) return;
279
+
280
+ lastTransform = this.getCurrentTransform(target);
281
+
282
+ if (lastTransform) {
283
+ translateX = Math.abs(+lastTransform.translateX);
284
+ }
285
+
286
+ this.setTransform(target, {
287
+ scaleX: "1",
288
+ skewY: "0",
289
+ translateX: `-${translateX + move}px`,
290
+ translateY: "0%",
291
+ rotate: "0deg",
292
+ });
293
+ },
294
+ // Set element Transform
295
+ setTransform(obj, transformValue) {
296
+ let str = "";
297
+
298
+ str += `translateX(${transformValue["translateX"]}) `;
299
+ str += `translateY(${transformValue["translateY"]}) `;
300
+ transformValue["rotate"] &&
301
+ (str += `rotate(${transformValue["rotate"]}) `);
302
+
303
+ this.setStyleByName(obj, "transform", str);
304
+ },
305
+
306
+ // Zoom action
307
+ zoom(type) {
308
+ let image = this.image,
309
+ w = +this.getStyleByName(image, "width").split("px")[0],
310
+ h = +this.getStyleByName(image, "height").split("px")[0];
311
+
312
+ if (h <= 20 && type === "out") return;
313
+
314
+ if (type === "out") {
315
+ this.setStyleByName(image, "width", `${w * 0.45}px`);
316
+ this.setStyleByName(image, "height", `${h * 0.45}px`);
317
+ } else {
318
+ this.setStyleByName(image, "width", `${w * (1 + 0.35)}px`);
319
+ this.setStyleByName(image, "height", `${h * (1 + 0.35)}px`);
320
+ }
321
+
322
+ this.currentData.width = this.getStyleByName(this.image, "width");
323
+ this.currentData.height = this.getStyleByName(this.image, "height");
324
+ },
325
+
326
+ // FullScreen action
327
+ requestFullScreen() {
328
+ let element = this.$refs["duoViewer"],
329
+ requestMethod =
330
+ element.requestFullScreen ||
331
+ element.webkitRequestFullScreen ||
332
+ element.mozRequestFullScreen ||
333
+ element.msRequestFullScreen;
334
+
335
+ if (requestMethod) {
336
+ requestMethod.call(element);
337
+ } else if (typeof window.ActiveXObject !== "undefined") {
338
+ // ie
339
+ let wscript = new ActiveXObject("WScript.Shell");
340
+ wscript !== null && wscript.SendKeys("{F11}");
341
+ }
342
+ },
343
+
344
+ // Keydown action
345
+ keydown() {
346
+ window.addEventListener("keydown", (e) => {
347
+ e = event || window.event || arguments.callee.caller.arguments[0];
348
+
349
+ if (e && e.keyCode == 40) {
350
+ // down
351
+ this.zoom("out");
352
+ }
353
+ if (e && e.keyCode == 37) {
354
+ // left
355
+ this.switchAction("prev");
356
+ }
357
+ if (e && e.keyCode == 39) {
358
+ // right
359
+ this.switchAction("next");
360
+ }
361
+ if (e && e.keyCode == 38) {
362
+ // up
363
+ this.zoom("in");
364
+ }
365
+ });
366
+ },
367
+
368
+ // Init element drag
369
+ initDrag() {
370
+ let x,
371
+ y,
372
+ boxX,
373
+ boxY,
374
+ pageX,
375
+ pageY,
376
+ scrollLeft,
377
+ scrollTop,
378
+ drop = this.image;
379
+
380
+ if (!drop) {
381
+ console.error("初始化图片拖拽失败");
382
+ return;
383
+ }
384
+
385
+ const getScroll = () => {
386
+ (scrollLeft =
387
+ document.body.scrollLeft || document.documentElement.scrollLeft),
388
+ (scrollTop =
389
+ document.body.scrollTop || document.documentElement.scrollTop);
390
+ return {
391
+ scrollLeft,
392
+ scrollTop,
393
+ };
394
+ };
395
+
396
+ // Get the location of the mouse on the page, handle browser compatibility
397
+ const getPage = (e) => {
398
+ (pageX = e.pageX || e.clientX + getScroll().scrollLeft),
399
+ (pageY = e.pageY || e.clientY + getScroll().scrollTop);
400
+ return {
401
+ pageX,
402
+ pageY,
403
+ };
404
+ };
405
+
406
+ drop.onmousedown = (e) => {
407
+ // Compatible processing
408
+ e = e || window.event;
409
+ // When the mouse is pressed, get the location of the mouse in the box
410
+ // Mouse position in box = mouse position on page - box position on page
411
+ (x = getPage(e).pageX - drop.offsetLeft),
412
+ (y = getPage(e).pageY - drop.offsetTop);
413
+
414
+ // When the mouse starts to move
415
+ document.onmousemove = (e) => {
416
+ // Compatible processing
417
+ e = e || window.event;
418
+ // When the mouse moves, get the location of the box on the page
419
+ // Box on page = mouse on page - mouse in box
420
+ (boxX = getPage(e).pageX - x), (boxY = getPage(e).pageY - y);
421
+ drop.style.left = `${boxX}px`;
422
+ drop.style.top = `${boxY}px`;
423
+ };
424
+ return false;
425
+ };
426
+ // Stop dragging when the mouse pops up
427
+ document.onmouseup = () => {
428
+ document.onmousemove = null;
429
+ this.listDataCache[this.index].left = `${boxX}px`;
430
+ this.listDataCache[this.index].top = `${boxY}px`;
431
+ };
432
+ },
433
+ // Init mouse wheel event
434
+ initMouseWheel() {
435
+ const scrollFn = (e) => {
436
+ e = e || window.event;
437
+ if (e.wheelDelta) {
438
+ // for IE/Google
439
+ if (e.wheelDelta > 0) {
440
+ this.zoom("out");
441
+ }
442
+ if (e.wheelDelta < 0) {
443
+ this.zoom("in");
444
+ }
445
+ } else if (e.detail) {
446
+ // for Firefox
447
+ if (e.detail > 0) {
448
+ this.zoom("out");
449
+ }
450
+ if (e.detail < 0) {
451
+ this.zoom("in");
452
+ }
453
+ }
454
+ };
455
+
456
+ document.addEventListener &&
457
+ document.addEventListener("DOMMouseScroll", scrollFn, false);
458
+ window.onmousewheel = document.onmousewheel = scrollFn;
459
+ },
460
+
461
+ // Agent
462
+ clickAgent(e) {
463
+ switch (e.target.getAttribute("data-viewer-action")) {
464
+ case "zoom-in":
465
+ this.zoom("in");
466
+ break;
467
+ case "zoom-out":
468
+ this.zoom("out");
469
+ break;
470
+ case "one-to-one":
471
+ this.resetZoom();
472
+ break;
473
+ case "prev":
474
+ this.switchAction("prev");
475
+ break;
476
+ case "play":
477
+ this.requestFullScreen();
478
+ break;
479
+ case "next":
480
+ this.switchAction("next");
481
+ break;
482
+ case "reset":
483
+ this.resetAll();
484
+ break;
485
+ case "select":
486
+ this.switchAction(e.target.getAttribute("data-viewer-action-index"));
487
+ break;
488
+ case "rotate-left":
489
+ this.rotate("left");
490
+ break;
491
+ case "rotate-right":
492
+ this.rotate("right");
493
+ break;
494
+ }
495
+ },
496
+ // On close
497
+ handleClose() {
498
+ this.$emit("update:show", false);
499
+ },
500
+ },
501
+ };
502
+ </script>
503
+
504
+ <style>
505
+ </style>