|
|
@@ -1,88 +1,83 @@
|
|
|
import { toastController, loadingController } from '@ionic/vue'
|
|
|
import { checkmarkOutline, closeOutline } from 'ionicons/icons'
|
|
|
-const q = []
|
|
|
-export default {
|
|
|
- async showToast(msg) {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
+let toastInstance = null
|
|
|
+let loadingInstance = null
|
|
|
+const Toast = async function (options) {
|
|
|
+ options = options || {}
|
|
|
+ if (typeof options === 'string') {
|
|
|
+ options = {
|
|
|
+ message: options
|
|
|
}
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
- }
|
|
|
- const toast = await toastController.create({
|
|
|
- message: msg,
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- this.toastInstance = toast
|
|
|
- toast.present()
|
|
|
- },
|
|
|
- async info(msg) {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
- }
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
- }
|
|
|
- const toast = await toastController.create({
|
|
|
- message: msg,
|
|
|
- duration: 1500
|
|
|
- })
|
|
|
- this.toastInstance = toast
|
|
|
- toast.present()
|
|
|
- },
|
|
|
- async success(msg) {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
- }
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
- }
|
|
|
- const toast = await toastController.create({
|
|
|
- message: msg,
|
|
|
- duration: 1500,
|
|
|
- cssClass: 'success-toast',
|
|
|
- icon: checkmarkOutline
|
|
|
- })
|
|
|
- this.toastInstance = toast
|
|
|
- toast.present()
|
|
|
- },
|
|
|
- async error(msg) {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
- }
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
- }
|
|
|
- const toast = await toastController.create({
|
|
|
- message: msg,
|
|
|
- duration: 1500,
|
|
|
- cssClass: 'error-toast',
|
|
|
- icon: closeOutline
|
|
|
- })
|
|
|
- this.toastInstance = toast
|
|
|
- toast.present()
|
|
|
- },
|
|
|
- async loading(msg) {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
- }
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
- }
|
|
|
- const loading = await loadingController.create({
|
|
|
- message: msg,
|
|
|
- duration: 0,
|
|
|
- cssClass: 'custom-loading'
|
|
|
- })
|
|
|
- this.loadingInstance = loading
|
|
|
- loading.present()
|
|
|
- },
|
|
|
- async dismiss() {
|
|
|
- if (this.toastInstance) {
|
|
|
- this.toastInstance.dismiss()
|
|
|
+ }
|
|
|
+ options.type = options.type || 'info'
|
|
|
+ if (toastInstance) {
|
|
|
+ toastInstance.dismiss()
|
|
|
+ }
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.dismiss()
|
|
|
+ }
|
|
|
+ let toastOps = {
|
|
|
+ message: options.message,
|
|
|
+ duration: 1500
|
|
|
+ }
|
|
|
+ switch (options.type) {
|
|
|
+ case 'info':
|
|
|
+ break
|
|
|
+ case 'success':
|
|
|
+ toastOps.cssClass = 'success-toast'
|
|
|
+ toastOps.icon = checkmarkOutline
|
|
|
+ break
|
|
|
+ case 'error':
|
|
|
+ toastOps.cssClass = 'error-toast'
|
|
|
+ toastOps.icon = closeOutline
|
|
|
+ break
|
|
|
+ }
|
|
|
+ const toast = await toastController.create(toastOps)
|
|
|
+ toastInstance = toast
|
|
|
+ toast.present()
|
|
|
+}
|
|
|
+;['success', 'info', 'error'].forEach(type => {
|
|
|
+ Toast[type] = async options => {
|
|
|
+ options = options || {}
|
|
|
+ if (typeof options === 'string') {
|
|
|
+ options = {
|
|
|
+ message: options
|
|
|
+ }
|
|
|
}
|
|
|
- if (this.loadingInstance) {
|
|
|
- this.loadingInstance.dismiss()
|
|
|
+ options.type = type
|
|
|
+ return await Toast(options)
|
|
|
+ }
|
|
|
+})
|
|
|
+Toast.loading = async function (options) {
|
|
|
+ if (toastInstance) {
|
|
|
+ toastInstance.dismiss()
|
|
|
+ }
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.dismiss()
|
|
|
+ }
|
|
|
+ options = options || {}
|
|
|
+ if (typeof options === 'string') {
|
|
|
+ options = {
|
|
|
+ message: options
|
|
|
}
|
|
|
}
|
|
|
+ const loading = await loadingController.create({
|
|
|
+ message: options.message,
|
|
|
+ duration: options.duration || 0,
|
|
|
+ cssClass: 'custom-loading'
|
|
|
+ })
|
|
|
+ loadingInstance = loading
|
|
|
+ loading.present()
|
|
|
+}
|
|
|
+Toast.dismiss = async () => {
|
|
|
+ if (toastInstance) {
|
|
|
+ toastInstance.dismiss()
|
|
|
+ }
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.dismiss()
|
|
|
+ }
|
|
|
+}
|
|
|
+Toast.install = (app, options) => {
|
|
|
+ app.config.globalProperties.$toast = Toast
|
|
|
}
|
|
|
+export default Toast
|