enhance(client): ウィンドウを最大化できるように
This commit is contained in:
parent
01d7403dc4
commit
e9a97b4717
|
@ -9,6 +9,15 @@
|
||||||
You should also include the user name that made the change.
|
You should also include the user name that made the change.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
## 12.x.x (unreleased)
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
- Client: ウィンドウを最大化できるように @syuilo
|
||||||
|
- Client: UIのブラッシュアップ @syuilo
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
-
|
||||||
|
|
||||||
## 12.116.1 (2022/07/17)
|
## 12.116.1 (2022/07/17)
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<transition :name="$store.state.animation ? 'window' : ''" appear @after-leave="$emit('closed')">
|
<transition :name="$store.state.animation ? 'window' : ''" appear @after-leave="$emit('closed')">
|
||||||
<div v-if="showing" class="ebkgocck">
|
<div v-if="showing" ref="rootEl" class="ebkgocck">
|
||||||
<div class="body _shadow _narrow_" @mousedown="onBodyMousedown" @keydown="onKeydown">
|
<div class="body _shadow _narrow_" @mousedown="onBodyMousedown" @keydown="onKeydown">
|
||||||
<div class="header" :class="{ mini }" @contextmenu.prevent.stop="onContextmenu">
|
<div class="header" :class="{ mini }" @contextmenu.prevent.stop="onContextmenu">
|
||||||
<span class="left">
|
<span class="left">
|
||||||
|
@ -11,6 +11,8 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="right">
|
<span class="right">
|
||||||
<button v-for="button in buttonsRight" v-tooltip="button.title" class="button _button" :class="{ highlighted: button.highlighted }" @click="button.onClick"><i :class="button.icon"></i></button>
|
<button v-for="button in buttonsRight" v-tooltip="button.title" class="button _button" :class="{ highlighted: button.highlighted }" @click="button.onClick"><i :class="button.icon"></i></button>
|
||||||
|
<button v-if="canResize && maximized" class="button _button" @click="unMaximize()"><i class="fas fa-window-restore"></i></button>
|
||||||
|
<button v-else-if="canResize && !maximized" class="button _button" @click="maximize()"><i class="fas fa-window-maximize"></i></button>
|
||||||
<button v-if="closeButton" class="button _button" @click="close()"><i class="fas fa-times"></i></button>
|
<button v-if="closeButton" class="button _button" @click="close()"><i class="fas fa-times"></i></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,15 +34,16 @@
|
||||||
</transition>
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { onBeforeUnmount, onMounted, provide } from 'vue';
|
||||||
import contains from '@/scripts/contains';
|
import contains from '@/scripts/contains';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
|
import { MenuItem } from '@/types/menu';
|
||||||
|
|
||||||
const minHeight = 50;
|
const minHeight = 50;
|
||||||
const minWidth = 250;
|
const minWidth = 250;
|
||||||
|
|
||||||
function dragListen(fn) {
|
function dragListen(fn: (ev: MouseEvent) => void) {
|
||||||
window.addEventListener('mousemove', fn);
|
window.addEventListener('mousemove', fn);
|
||||||
window.addEventListener('touchmove', fn);
|
window.addEventListener('touchmove', fn);
|
||||||
window.addEventListener('mouseleave', dragClear.bind(null, fn));
|
window.addEventListener('mouseleave', dragClear.bind(null, fn));
|
||||||
|
@ -56,117 +59,115 @@ function dragClear(fn) {
|
||||||
window.removeEventListener('touchend', dragClear);
|
window.removeEventListener('touchend', dragClear);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
const props = withDefaults(defineProps<{
|
||||||
provide: {
|
initialWidth?: number;
|
||||||
inWindow: true,
|
initialHeight?: number | null;
|
||||||
},
|
canResize?: boolean;
|
||||||
|
closeButton?: boolean;
|
||||||
|
mini?: boolean;
|
||||||
|
front?: boolean;
|
||||||
|
contextmenu?: MenuItem[] | null;
|
||||||
|
buttonsLeft?: any[];
|
||||||
|
buttonsRight?: any[];
|
||||||
|
}>(), {
|
||||||
|
initialWidth: 400,
|
||||||
|
initialHeight: null,
|
||||||
|
canResize: false,
|
||||||
|
closeButton: true,
|
||||||
|
mini: false,
|
||||||
|
front: true,
|
||||||
|
contextmenu: null,
|
||||||
|
buttonsLeft: () => [],
|
||||||
|
buttonsRight: () => [],
|
||||||
|
});
|
||||||
|
|
||||||
props: {
|
const emit = defineEmits<{
|
||||||
initialWidth: {
|
(ev: 'closed'): void;
|
||||||
type: Number,
|
}>();
|
||||||
required: false,
|
|
||||||
default: 400,
|
|
||||||
},
|
|
||||||
initialHeight: {
|
|
||||||
type: Number,
|
|
||||||
required: false,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
canResize: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
closeButton: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
mini: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
front: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
contextmenu: {
|
|
||||||
type: Array,
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
buttonsLeft: {
|
|
||||||
type: Array,
|
|
||||||
required: false,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
buttonsRight: {
|
|
||||||
type: Array,
|
|
||||||
required: false,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['closed'],
|
provide('inWindow', true);
|
||||||
|
|
||||||
data() {
|
let rootEl = $ref<HTMLElement>();
|
||||||
return {
|
let showing = $ref(true);
|
||||||
showing: true,
|
let beforeClickedAt = 0;
|
||||||
id: Math.random().toString(), // TODO: UUIDとかにする
|
let maximized = $ref(false);
|
||||||
};
|
let unMaximizedTop = '';
|
||||||
},
|
let unMaximizedLeft = '';
|
||||||
|
let unMaximizedWidth = '';
|
||||||
|
let unMaximizedHeight = '';
|
||||||
|
|
||||||
mounted() {
|
function close() {
|
||||||
if (this.initialWidth) this.applyTransformWidth(this.initialWidth);
|
showing = false;
|
||||||
if (this.initialHeight) this.applyTransformHeight(this.initialHeight);
|
}
|
||||||
|
|
||||||
this.applyTransformTop((window.innerHeight / 2) - (this.$el.offsetHeight / 2));
|
function onKeydown(evt) {
|
||||||
this.applyTransformLeft((window.innerWidth / 2) - (this.$el.offsetWidth / 2));
|
|
||||||
|
|
||||||
// 他のウィンドウ内のボタンなどを押してこのウィンドウが開かれた場合、親が最前面になろうとするのでそれに隠されないようにする
|
|
||||||
this.top();
|
|
||||||
|
|
||||||
window.addEventListener('resize', this.onBrowserResize);
|
|
||||||
},
|
|
||||||
|
|
||||||
unmounted() {
|
|
||||||
window.removeEventListener('resize', this.onBrowserResize);
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
close() {
|
|
||||||
this.showing = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
onKeydown(evt) {
|
|
||||||
if (evt.which === 27) { // Esc
|
if (evt.which === 27) { // Esc
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
this.close();
|
close();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
onContextmenu(ev: MouseEvent) {
|
function onContextmenu(ev: MouseEvent) {
|
||||||
if (this.contextmenu) {
|
if (props.contextmenu) {
|
||||||
os.contextMenu(this.contextmenu, ev);
|
os.contextMenu(props.contextmenu, ev);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// 最前面へ移動
|
// 最前面へ移動
|
||||||
top() {
|
function top() {
|
||||||
(this.$el as any).style.zIndex = os.claimZIndex(this.front ? 'middle' : 'low');
|
rootEl.style.zIndex = os.claimZIndex(props.front ? 'middle' : 'low');
|
||||||
},
|
}
|
||||||
|
|
||||||
onBodyMousedown() {
|
function maximize() {
|
||||||
this.top();
|
maximized = true;
|
||||||
},
|
unMaximizedTop = rootEl.style.top;
|
||||||
|
unMaximizedLeft = rootEl.style.left;
|
||||||
|
unMaximizedWidth = rootEl.style.width;
|
||||||
|
unMaximizedHeight = rootEl.style.height;
|
||||||
|
rootEl.style.top = '0';
|
||||||
|
rootEl.style.left = '0';
|
||||||
|
rootEl.style.width = '100%';
|
||||||
|
rootEl.style.height = '100%';
|
||||||
|
}
|
||||||
|
|
||||||
onHeaderMousedown(evt: MouseEvent) {
|
function unMaximize() {
|
||||||
|
maximized = false;
|
||||||
|
rootEl.style.top = unMaximizedTop;
|
||||||
|
rootEl.style.left = unMaximizedLeft;
|
||||||
|
rootEl.style.width = unMaximizedWidth;
|
||||||
|
rootEl.style.height = unMaximizedHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBodyMousedown() {
|
||||||
|
top();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDblClick() {
|
||||||
|
maximize();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onHeaderMousedown(evt: MouseEvent) {
|
||||||
// 右クリックはコンテキストメニューを開こうとした可能性が高いため無視
|
// 右クリックはコンテキストメニューを開こうとした可能性が高いため無視
|
||||||
if (evt.button === 2) return;
|
if (evt.button === 2) return;
|
||||||
|
|
||||||
const main = this.$el as any;
|
let beforeMaximized = false;
|
||||||
|
|
||||||
|
if (maximized) {
|
||||||
|
beforeMaximized = true;
|
||||||
|
unMaximize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ダブルクリック判定
|
||||||
|
if (Date.now() - beforeClickedAt < 300) {
|
||||||
|
beforeClickedAt = Date.now();
|
||||||
|
onDblClick();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeClickedAt = Date.now();
|
||||||
|
|
||||||
|
const main = rootEl;
|
||||||
|
|
||||||
if (!contains(main, document.activeElement)) main.focus();
|
if (!contains(main, document.activeElement)) main.focus();
|
||||||
|
|
||||||
|
@ -174,18 +175,14 @@ export default defineComponent({
|
||||||
|
|
||||||
const clickX = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientX : evt.clientX;
|
const clickX = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientX : evt.clientX;
|
||||||
const clickY = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientY : evt.clientY;
|
const clickY = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientY : evt.clientY;
|
||||||
const moveBaseX = clickX - position.left;
|
const moveBaseX = beforeMaximized ? parseInt(unMaximizedWidth, 10) / 2 : clickX - position.left; // TODO: parseIntやめる
|
||||||
const moveBaseY = clickY - position.top;
|
const moveBaseY = beforeMaximized ? 20 : clickY - position.top;
|
||||||
const browserWidth = window.innerWidth;
|
const browserWidth = window.innerWidth;
|
||||||
const browserHeight = window.innerHeight;
|
const browserHeight = window.innerHeight;
|
||||||
const windowWidth = main.offsetWidth;
|
const windowWidth = main.offsetWidth;
|
||||||
const windowHeight = main.offsetHeight;
|
const windowHeight = main.offsetHeight;
|
||||||
|
|
||||||
// 動かした時
|
function move(x: number, y: number) {
|
||||||
dragListen(me => {
|
|
||||||
const x = me.touches && me.touches.length > 0 ? me.touches[0].clientX : me.clientX;
|
|
||||||
const y = me.touches && me.touches.length > 0 ? me.touches[0].clientY : me.clientY;
|
|
||||||
|
|
||||||
let moveLeft = x - moveBaseX;
|
let moveLeft = x - moveBaseX;
|
||||||
let moveTop = y - moveBaseY;
|
let moveTop = y - moveBaseY;
|
||||||
|
|
||||||
|
@ -201,14 +198,26 @@ export default defineComponent({
|
||||||
// 右はみ出し
|
// 右はみ出し
|
||||||
if (moveLeft + windowWidth > browserWidth) moveLeft = browserWidth - windowWidth;
|
if (moveLeft + windowWidth > browserWidth) moveLeft = browserWidth - windowWidth;
|
||||||
|
|
||||||
this.$el.style.left = moveLeft + 'px';
|
rootEl.style.left = moveLeft + 'px';
|
||||||
this.$el.style.top = moveTop + 'px';
|
rootEl.style.top = moveTop + 'px';
|
||||||
});
|
}
|
||||||
},
|
|
||||||
|
|
||||||
// 上ハンドル掴み時
|
if (beforeMaximized) {
|
||||||
onTopHandleMousedown(evt) {
|
move(clickX, clickY);
|
||||||
const main = this.$el as any;
|
}
|
||||||
|
|
||||||
|
// 動かした時
|
||||||
|
dragListen(me => {
|
||||||
|
const x = me.touches && me.touches.length > 0 ? me.touches[0].clientX : me.clientX;
|
||||||
|
const y = me.touches && me.touches.length > 0 ? me.touches[0].clientY : me.clientY;
|
||||||
|
|
||||||
|
move(x, y);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上ハンドル掴み時
|
||||||
|
function onTopHandleMousedown(evt) {
|
||||||
|
const main = rootEl;
|
||||||
|
|
||||||
const base = evt.clientY;
|
const base = evt.clientY;
|
||||||
const height = parseInt(getComputedStyle(main, '').height, 10);
|
const height = parseInt(getComputedStyle(main, '').height, 10);
|
||||||
|
@ -219,22 +228,22 @@ export default defineComponent({
|
||||||
const move = me.clientY - base;
|
const move = me.clientY - base;
|
||||||
if (top + move > 0) {
|
if (top + move > 0) {
|
||||||
if (height + -move > minHeight) {
|
if (height + -move > minHeight) {
|
||||||
this.applyTransformHeight(height + -move);
|
applyTransformHeight(height + -move);
|
||||||
this.applyTransformTop(top + move);
|
applyTransformTop(top + move);
|
||||||
} else { // 最小の高さより小さくなろうとした時
|
} else { // 最小の高さより小さくなろうとした時
|
||||||
this.applyTransformHeight(minHeight);
|
applyTransformHeight(minHeight);
|
||||||
this.applyTransformTop(top + (height - minHeight));
|
applyTransformTop(top + (height - minHeight));
|
||||||
}
|
}
|
||||||
} else { // 上のはみ出し時
|
} else { // 上のはみ出し時
|
||||||
this.applyTransformHeight(top + height);
|
applyTransformHeight(top + height);
|
||||||
this.applyTransformTop(0);
|
applyTransformTop(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
// 右ハンドル掴み時
|
// 右ハンドル掴み時
|
||||||
onRightHandleMousedown(evt) {
|
function onRightHandleMousedown(evt) {
|
||||||
const main = this.$el as any;
|
const main = rootEl;
|
||||||
|
|
||||||
const base = evt.clientX;
|
const base = evt.clientX;
|
||||||
const width = parseInt(getComputedStyle(main, '').width, 10);
|
const width = parseInt(getComputedStyle(main, '').width, 10);
|
||||||
|
@ -246,19 +255,19 @@ export default defineComponent({
|
||||||
const move = me.clientX - base;
|
const move = me.clientX - base;
|
||||||
if (left + width + move < browserWidth) {
|
if (left + width + move < browserWidth) {
|
||||||
if (width + move > minWidth) {
|
if (width + move > minWidth) {
|
||||||
this.applyTransformWidth(width + move);
|
applyTransformWidth(width + move);
|
||||||
} else { // 最小の幅より小さくなろうとした時
|
} else { // 最小の幅より小さくなろうとした時
|
||||||
this.applyTransformWidth(minWidth);
|
applyTransformWidth(minWidth);
|
||||||
}
|
}
|
||||||
} else { // 右のはみ出し時
|
} else { // 右のはみ出し時
|
||||||
this.applyTransformWidth(browserWidth - left);
|
applyTransformWidth(browserWidth - left);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
// 下ハンドル掴み時
|
// 下ハンドル掴み時
|
||||||
onBottomHandleMousedown(evt) {
|
function onBottomHandleMousedown(evt) {
|
||||||
const main = this.$el as any;
|
const main = rootEl;
|
||||||
|
|
||||||
const base = evt.clientY;
|
const base = evt.clientY;
|
||||||
const height = parseInt(getComputedStyle(main, '').height, 10);
|
const height = parseInt(getComputedStyle(main, '').height, 10);
|
||||||
|
@ -270,19 +279,19 @@ export default defineComponent({
|
||||||
const move = me.clientY - base;
|
const move = me.clientY - base;
|
||||||
if (top + height + move < browserHeight) {
|
if (top + height + move < browserHeight) {
|
||||||
if (height + move > minHeight) {
|
if (height + move > minHeight) {
|
||||||
this.applyTransformHeight(height + move);
|
applyTransformHeight(height + move);
|
||||||
} else { // 最小の高さより小さくなろうとした時
|
} else { // 最小の高さより小さくなろうとした時
|
||||||
this.applyTransformHeight(minHeight);
|
applyTransformHeight(minHeight);
|
||||||
}
|
}
|
||||||
} else { // 下のはみ出し時
|
} else { // 下のはみ出し時
|
||||||
this.applyTransformHeight(browserHeight - top);
|
applyTransformHeight(browserHeight - top);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
// 左ハンドル掴み時
|
// 左ハンドル掴み時
|
||||||
onLeftHandleMousedown(evt) {
|
function onLeftHandleMousedown(evt) {
|
||||||
const main = this.$el as any;
|
const main = rootEl;
|
||||||
|
|
||||||
const base = evt.clientX;
|
const base = evt.clientX;
|
||||||
const width = parseInt(getComputedStyle(main, '').width, 10);
|
const width = parseInt(getComputedStyle(main, '').width, 10);
|
||||||
|
@ -293,78 +302,97 @@ export default defineComponent({
|
||||||
const move = me.clientX - base;
|
const move = me.clientX - base;
|
||||||
if (left + move > 0) {
|
if (left + move > 0) {
|
||||||
if (width + -move > minWidth) {
|
if (width + -move > minWidth) {
|
||||||
this.applyTransformWidth(width + -move);
|
applyTransformWidth(width + -move);
|
||||||
this.applyTransformLeft(left + move);
|
applyTransformLeft(left + move);
|
||||||
} else { // 最小の幅より小さくなろうとした時
|
} else { // 最小の幅より小さくなろうとした時
|
||||||
this.applyTransformWidth(minWidth);
|
applyTransformWidth(minWidth);
|
||||||
this.applyTransformLeft(left + (width - minWidth));
|
applyTransformLeft(left + (width - minWidth));
|
||||||
}
|
}
|
||||||
} else { // 左のはみ出し時
|
} else { // 左のはみ出し時
|
||||||
this.applyTransformWidth(left + width);
|
applyTransformWidth(left + width);
|
||||||
this.applyTransformLeft(0);
|
applyTransformLeft(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
// 左上ハンドル掴み時
|
// 左上ハンドル掴み時
|
||||||
onTopLeftHandleMousedown(evt) {
|
function onTopLeftHandleMousedown(evt) {
|
||||||
this.onTopHandleMousedown(evt);
|
onTopHandleMousedown(evt);
|
||||||
this.onLeftHandleMousedown(evt);
|
onLeftHandleMousedown(evt);
|
||||||
},
|
}
|
||||||
|
|
||||||
// 右上ハンドル掴み時
|
// 右上ハンドル掴み時
|
||||||
onTopRightHandleMousedown(evt) {
|
function onTopRightHandleMousedown(evt) {
|
||||||
this.onTopHandleMousedown(evt);
|
onTopHandleMousedown(evt);
|
||||||
this.onRightHandleMousedown(evt);
|
onRightHandleMousedown(evt);
|
||||||
},
|
}
|
||||||
|
|
||||||
// 右下ハンドル掴み時
|
// 右下ハンドル掴み時
|
||||||
onBottomRightHandleMousedown(evt) {
|
function onBottomRightHandleMousedown(evt) {
|
||||||
this.onBottomHandleMousedown(evt);
|
onBottomHandleMousedown(evt);
|
||||||
this.onRightHandleMousedown(evt);
|
onRightHandleMousedown(evt);
|
||||||
},
|
}
|
||||||
|
|
||||||
// 左下ハンドル掴み時
|
// 左下ハンドル掴み時
|
||||||
onBottomLeftHandleMousedown(evt) {
|
function onBottomLeftHandleMousedown(evt) {
|
||||||
this.onBottomHandleMousedown(evt);
|
onBottomHandleMousedown(evt);
|
||||||
this.onLeftHandleMousedown(evt);
|
onLeftHandleMousedown(evt);
|
||||||
},
|
}
|
||||||
|
|
||||||
// 高さを適用
|
// 高さを適用
|
||||||
applyTransformHeight(height) {
|
function applyTransformHeight(height) {
|
||||||
if (height > window.innerHeight) height = window.innerHeight;
|
if (height > window.innerHeight) height = window.innerHeight;
|
||||||
(this.$el as any).style.height = height + 'px';
|
rootEl.style.height = height + 'px';
|
||||||
},
|
}
|
||||||
|
|
||||||
// 幅を適用
|
// 幅を適用
|
||||||
applyTransformWidth(width) {
|
function applyTransformWidth(width) {
|
||||||
if (width > window.innerWidth) width = window.innerWidth;
|
if (width > window.innerWidth) width = window.innerWidth;
|
||||||
(this.$el as any).style.width = width + 'px';
|
rootEl.style.width = width + 'px';
|
||||||
},
|
}
|
||||||
|
|
||||||
// Y座標を適用
|
// Y座標を適用
|
||||||
applyTransformTop(top) {
|
function applyTransformTop(top) {
|
||||||
(this.$el as any).style.top = top + 'px';
|
rootEl.style.top = top + 'px';
|
||||||
},
|
}
|
||||||
|
|
||||||
// X座標を適用
|
// X座標を適用
|
||||||
applyTransformLeft(left) {
|
function applyTransformLeft(left) {
|
||||||
(this.$el as any).style.left = left + 'px';
|
rootEl.style.left = left + 'px';
|
||||||
},
|
}
|
||||||
|
|
||||||
onBrowserResize() {
|
function onBrowserResize() {
|
||||||
const main = this.$el as any;
|
const main = rootEl;
|
||||||
const position = main.getBoundingClientRect();
|
const position = main.getBoundingClientRect();
|
||||||
const browserWidth = window.innerWidth;
|
const browserWidth = window.innerWidth;
|
||||||
const browserHeight = window.innerHeight;
|
const browserHeight = window.innerHeight;
|
||||||
const windowWidth = main.offsetWidth;
|
const windowWidth = main.offsetWidth;
|
||||||
const windowHeight = main.offsetHeight;
|
const windowHeight = main.offsetHeight;
|
||||||
if (position.left < 0) main.style.left = 0; // 左はみ出し
|
if (position.left < 0) main.style.left = '0'; // 左はみ出し
|
||||||
if (position.top + windowHeight > browserHeight) main.style.top = browserHeight - windowHeight + 'px'; // 下はみ出し
|
if (position.top + windowHeight > browserHeight) main.style.top = browserHeight - windowHeight + 'px'; // 下はみ出し
|
||||||
if (position.left + windowWidth > browserWidth) main.style.left = browserWidth - windowWidth + 'px'; // 右はみ出し
|
if (position.left + windowWidth > browserWidth) main.style.left = browserWidth - windowWidth + 'px'; // 右はみ出し
|
||||||
if (position.top < 0) main.style.top = 0; // 上はみ出し
|
if (position.top < 0) main.style.top = '0'; // 上はみ出し
|
||||||
},
|
}
|
||||||
},
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.initialWidth) applyTransformWidth(props.initialWidth);
|
||||||
|
if (props.initialHeight) applyTransformHeight(props.initialHeight);
|
||||||
|
|
||||||
|
applyTransformTop((window.innerHeight / 2) - (rootEl.offsetHeight / 2));
|
||||||
|
applyTransformLeft((window.innerWidth / 2) - (rootEl.offsetWidth / 2));
|
||||||
|
|
||||||
|
// 他のウィンドウ内のボタンなどを押してこのウィンドウが開かれた場合、親が最前面になろうとするのでそれに隠されないようにする
|
||||||
|
top();
|
||||||
|
|
||||||
|
window.addEventListener('resize', onBrowserResize);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('resize', onBrowserResize);
|
||||||
|
});
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
close,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue