This commit is contained in:
syuilo 2020-09-20 11:07:52 +09:00
parent 208343a3da
commit c50342a19e
4 changed files with 15 additions and 15 deletions

View File

@ -93,11 +93,6 @@ export default defineComponent({
required: true, required: true,
}, },
complete: {
type: Function,
required: true,
},
close: { close: {
type: Function, type: Function,
required: true, required: true,
@ -114,6 +109,8 @@ export default defineComponent({
}, },
}, },
emits: ['done', 'closed'],
data() { data() {
return { return {
getStaticImageUrl, getStaticImageUrl,
@ -200,6 +197,11 @@ export default defineComponent({
}, },
methods: { methods: {
complete(type, value) {
this.$emit('done', { type, value });
this.$emit('closed');
},
setPosition() { setPosition() {
if (this.x + this.$el.offsetWidth > window.innerWidth) { if (this.x + this.$el.offsetWidth > window.innerWidth) {
this.$el.style.left = (window.innerWidth - this.$el.offsetWidth) + 'px'; this.$el.style.left = (window.innerWidth - this.$el.offsetWidth) + 'px';

View File

@ -54,20 +54,15 @@ export function popup(component: Component, props: Record<string, any>, events =
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);
const close = (...args) => {
resolve(...args);
showing.value = false;
};
const modal = { const modal = {
type: 'popup', type: 'popup',
component, component,
props, props,
showing, showing,
events, events,
done: close,
bgClick: () => close(),
closed: () => { closed: () => {
store.commit('removePopup', id); store.commit('removePopup', id);
resolve();
}, },
id, id,
}; };
@ -75,7 +70,7 @@ export function popup(component: Component, props: Record<string, any>, events =
onCancel.shouldReject = false; onCancel.shouldReject = false;
onCancel(() => { onCancel(() => {
close(); showing.value = false;
}); });
}); });
} }

View File

@ -6,7 +6,7 @@
<component :is="modal.component" v-bind="modal.props" v-on="modal.events" @done="modal.done"/> <component :is="modal.component" v-bind="modal.props" v-on="modal.events" @done="modal.done"/>
</XModal> </XModal>
<component v-for="popup in $store.state.popups.filter(x => x.type === 'popup')" :key="popup.id" :is="popup.component" v-bind="popup.props" v-on="popup.events" @done="popup.done" @closed="popup.closed"/> <component v-for="popup in $store.state.popups.filter(x => x.type === 'popup')" :key="popup.id" :is="popup.component" v-bind="popup.props" :showing="popup.showing" v-on="popup.events" @closed="popup.closed"/>
<div id="wait" v-if="$store.state.pendingApiRequestsCount > 0"></div> <div id="wait" v-if="$store.state.pendingApiRequestsCount > 0"></div>
</template> </template>

View File

@ -154,12 +154,15 @@ export class Autocomplete {
const promise = popup(MkAutocomplete, { const promise = popup(MkAutocomplete, {
textarea: this.textarea, textarea: this.textarea,
complete: this.complete,
close: this.close, close: this.close,
type: type, type: type,
q: _q, q: _q,
x: _x, x: _x,
y: _y, y: _y,
}, {
done: (res) => {
this.complete(res);
}
}); });
this.suggestion = { this.suggestion = {
@ -188,7 +191,7 @@ export class Autocomplete {
/** /**
* *
*/ */
private complete(type, value) { private complete({ type, value }) {
this.close(); this.close();
const caret = this.textarea.selectionStart; const caret = this.textarea.selectionStart;