mirror of
https://github.com/aelve/guide.git
synced 2024-12-24 05:13:50 +03:00
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import Vue from 'vue'
|
|
import { Mixin } from 'vue-mixin-decorator'
|
|
import ConfirmDialog from 'client/components/ConfirmDialog.vue'
|
|
import DeferredPromise from 'utils/DeferredPromise'
|
|
|
|
const ComponentClass = Vue.extend(ConfirmDialog)
|
|
|
|
interface IConfirmDialogProps {
|
|
fullText?: string
|
|
text?: string
|
|
confirmBtnText?: string
|
|
cancelBtnText?: string,
|
|
confirmBtnProps?: object,
|
|
cancelBtnProps?: object
|
|
}
|
|
|
|
@Mixin
|
|
export default class ConfirmDialogMixin extends Vue {
|
|
async _confirm ({
|
|
text,
|
|
fullText,
|
|
confirmBtnText,
|
|
cancelBtnText,
|
|
confirmBtnProps,
|
|
cancelBtnProps
|
|
}: IConfirmDialogProps): Promise<boolean> {
|
|
const instance = new ComponentClass({
|
|
propsData: {
|
|
value: true,
|
|
text,
|
|
fullText,
|
|
confirmBtnText,
|
|
cancelBtnText,
|
|
confirmBtnProps,
|
|
cancelBtnProps
|
|
}
|
|
})
|
|
instance.$mount()
|
|
const deferredPromise = new DeferredPromise()
|
|
this.$el.appendChild(instance.$el)
|
|
instance.$on('confirmed', () => {
|
|
instance.$destroy()
|
|
deferredPromise.resolve(true)
|
|
})
|
|
instance.$on('canceled', () => {
|
|
instance.$destroy()
|
|
deferredPromise.resolve(false)
|
|
})
|
|
return deferredPromise
|
|
}
|
|
}
|