1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <template> <div v-show="component" id="EnlargeWrapperArea"> <div id="EnlargeWrapperAreaMask" @click="close"></div> <div id="EnlargeWrapper" :style="{ width: finalWidth + 'px', height: finalHeight + 'px' }"> <component :is="component" v-bind="props" style="transform-origin: top left" :style="{ width: initialWidth + 'px', height: initialHeight + 'px', transform: `scale(${scale})`, }" enlarged ></component> </div> </div> </template> <script> export default { data() { return { component: null, props: {}, initialWidth: 0, initialHeight: 0, finalWidth: 0, finalHeight: 0, scale: 1, }; }, methods: { handler(component, initialWidth, initialHeight, props = {}) { if (!component || !initialWidth || !initialHeight) { return; } this.initialWidth = initialWidth; this.initialHeight = initialHeight; const maxWidth = 2400, maxHeight = 1200; const maxWidthScale = maxWidth / this.initialWidth, maxHeightScale = maxHeight / this.initialHeight; this.scale = Math.min(maxWidthScale, maxHeightScale); this.finalWidth = this.initialWidth * this.scale; this.finalHeight = this.initialHeight * this.scale; this.component = component; this.props = props; }, close() { this.component = null; this.props = {}; } } } </script> <style scoped> #EnlargeWrapperArea { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 9999; } #EnlargeWrapperAreaMask { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.5); } #EnlargeWrapper { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: #061d33; margin: auto; } </style>
|