Update os.ts

This commit is contained in:
syuilo 2020-09-08 10:49:58 +09:00
parent cd79314f69
commit 354c7fcaf6
1 changed files with 10 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { Component, defineAsyncComponent, markRaw, ref } from 'vue';
import Stream from '@/scripts/stream'; import Stream from '@/scripts/stream';
import { store } from '@/store'; import { store } from '@/store';
import { apiUrl } from '@/config'; import { apiUrl } from '@/config';
import * as EventEmitter from 'eventemitter3';
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
export const isMobile = /mobile|iphone|ipad|android/.test(ua); export const isMobile = /mobile|iphone|ipad|android/.test(ua);
@ -70,6 +71,8 @@ export function popup(component: Component, props: Record<string, any>, callback
} }
export function modal(component: Component, props: Record<string, any>, callback?: Function, option?) { export function modal(component: Component, props: Record<string, any>, callback?: Function, option?) {
//const controller = new EventEmitter();
//markRaw(controller);
markRaw(component); markRaw(component);
const id = Math.random().toString(); // TODO: uuidとか使う const id = Math.random().toString(); // TODO: uuidとか使う
const showing = ref(true); const showing = ref(true);
@ -84,7 +87,10 @@ export function modal(component: Component, props: Record<string, any>, callback
showing, showing,
source: option?.source, source: option?.source,
done: close, done: close,
bgClick: () => close(), bgClick: () => {
if (option?.cancelableByBgClick === false) return;
close();
},
closed: () => { closed: () => {
store.commit('removePopup', id); store.commit('removePopup', id);
}, },
@ -95,6 +101,7 @@ export function modal(component: Component, props: Record<string, any>, callback
} }
export function dialog(props: Record<string, any>) { export function dialog(props: Record<string, any>) {
const cancelableByBgClick = props.cancelableByBgClick;
return new Promise((res, rej) => { return new Promise((res, rej) => {
modal(defineAsyncComponent(() => import('@/components/dialog.vue')), props, result => { modal(defineAsyncComponent(() => import('@/components/dialog.vue')), props, result => {
if (result) { if (result) {
@ -102,6 +109,8 @@ export function dialog(props: Record<string, any>) {
} else { } else {
res({ canceled: true }); res({ canceled: true });
} }
}, {
cancelableByBgClick
}); });
}); });
} }