Window.vue 5.2 KB

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