Window.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div ref="main" class="main xyfit absolute" @click="close" @mouseup="onMouseUp" @mousemove="onMouseMove">
  3. <div ref="windowBox" class="xyfit absolute flex no-wrap" @click.stop>
  4. <div ref="window" class="window flexfit column no-wrap">
  5. <div
  6. ref="header"
  7. class="header row justify-end"
  8. @mousedown.prevent.stop="onMouseDown"
  9. @touchstart.stop="onTouchStart"
  10. @touchend.stop="onTouchEnd"
  11. @touchmove.stop="onTouchMove"
  12. >
  13. <span class="header-text col"><slot name="header"></slot></span>
  14. <slot name="buttons"></slot>
  15. <span class="close-button row justify-center items-center" @mousedown.stop @click="close"><q-icon name="la la-times" size="16px" /></span>
  16. </div>
  17. <slot></slot>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. //-----------------------------------------------------------------------------
  24. import vueComponent from '../vueComponent.js';
  25. class Window {
  26. _props = {
  27. height: { type: String, default: '100%' },
  28. width: { type: String, default: '100%' },
  29. maxWidth: { type: String, default: '' },
  30. topShift: { type: Number, default: 0 },
  31. margin: '',
  32. };
  33. init() {
  34. this.$nextTick(() => {
  35. this.$refs.main.style.top = 0;
  36. this.$refs.main.style.left = 0;
  37. this.$refs.windowBox.style.height = this.height;
  38. this.$refs.windowBox.style.width = this.width;
  39. if (this.maxWidth)
  40. this.$refs.windowBox.style.maxWidth = this.maxWidth;
  41. const left = (this.$refs.main.offsetWidth - this.$refs.windowBox.offsetWidth)/2;
  42. const top = (this.$refs.main.offsetHeight - this.$refs.windowBox.offsetHeight)/2 + this.topShift;
  43. this.$refs.windowBox.style.left = (left > 0 ? left : 0) + 'px';
  44. this.$refs.windowBox.style.top = (top > 0 ? top : 0) + 'px';
  45. if (this.margin)
  46. this.$refs.window.style.margin = this.margin;
  47. });
  48. }
  49. onMouseDown(event) {
  50. if (this.$root.isMobileDevice)
  51. return;
  52. if (event.button == 0) {
  53. this.$refs.header.style.cursor = 'move';
  54. this.startX = event.screenX;
  55. this.startY = event.screenY;
  56. this.moving = true;
  57. }
  58. }
  59. onMouseUp(event) {
  60. if (event.button == 0) {
  61. this.$refs.header.style.cursor = 'default';
  62. this.moving = false;
  63. }
  64. }
  65. onMouseMove(event) {
  66. if (this.moving) {
  67. const deltaX = event.screenX - this.startX;
  68. const deltaY = event.screenY - this.startY;
  69. this.startX = event.screenX;
  70. this.startY = event.screenY;
  71. this.$refs.windowBox.style.left = (this.$refs.windowBox.offsetLeft + deltaX) + 'px';
  72. this.$refs.windowBox.style.top = (this.$refs.windowBox.offsetTop + deltaY) + 'px';
  73. }
  74. }
  75. onTouchStart(event) {
  76. if (!this.$root.isMobileDevice)
  77. return;
  78. if (event.touches.length == 1) {
  79. const touch = event.touches[0];
  80. this.$refs.header.style.cursor = 'move';
  81. this.startX = touch.screenX;
  82. this.startY = touch.screenY;
  83. this.moving = true;
  84. }
  85. }
  86. onTouchMove(event) {
  87. if (!this.$root.isMobileDevice)
  88. return;
  89. if (event.touches.length == 1 && this.moving) {
  90. const touch = event.touches[0];
  91. const deltaX = touch.screenX - this.startX;
  92. const deltaY = touch.screenY - this.startY;
  93. this.startX = touch.screenX;
  94. this.startY = touch.screenY;
  95. this.$refs.windowBox.style.left = (this.$refs.windowBox.offsetLeft + deltaX) + 'px';
  96. this.$refs.windowBox.style.top = (this.$refs.windowBox.offsetTop + deltaY) + 'px';
  97. }
  98. }
  99. onTouchEnd() {
  100. if (!this.$root.isMobileDevice)
  101. return;
  102. this.$refs.header.style.cursor = 'default';
  103. this.moving = false;
  104. }
  105. close() {
  106. if (!this.moving)
  107. this.$emit('close');
  108. }
  109. }
  110. export default vueComponent(Window);
  111. //-----------------------------------------------------------------------------
  112. </script>
  113. <style scoped>
  114. .main {
  115. background-color: transparent !important;
  116. z-index: 50;
  117. }
  118. .xyfit {
  119. height: 100%;
  120. width: 100%;
  121. }
  122. .flexfit {
  123. flex: 1;
  124. }
  125. .window {
  126. margin: 10px;
  127. background-color: #ffffff;
  128. border: 3px double black;
  129. border-radius: 4px;
  130. box-shadow: 3px 3px 5px black;
  131. }
  132. .header {
  133. background: linear-gradient(to bottom right, #007000, #59B04F);
  134. align-items: center;
  135. height: 30px;
  136. }
  137. .header-text {
  138. margin-left: 10px;
  139. margin-right: 10px;
  140. color: #FFFFA0;
  141. text-shadow: 2px 2px 5px #005000, 2px 1px 5px #005000;
  142. overflow: hidden;
  143. white-space: nowrap;
  144. }
  145. .close-button {
  146. width: 30px;
  147. height: 30px;
  148. cursor: pointer;
  149. }
  150. .close-button:hover {
  151. color: white;
  152. background-color: #FF3030;
  153. }
  154. </style>