vue中alert toast confirm loading 公用


import Vue from 'vue'
import { ToastPlugin, AlertPlugin, ConfirmPlugin, LoadingPlugin } from 'vux'
/*import { Promise } from 'es6-promise';*/
 
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(LoadingPlugin)
 
const Message = {};
Message.install = () => {
     const msg = {
         $toast: config => {
             let def = {
                 type: 'text' ,
                 text: ''
             }
             if(typeof  config  === 'string' || typeof  config  === 'number' ){
                 Vue.$vux.toast.show({type: 'text' ,text:config})
             } else {
                 Vue.$vux.toast.show(Object.assign(def,config))
             }
 
         },
         $alert: config => {
             let def = {
                 title: '提示' ,
                 content: '系統異常,請重新登錄后再試!' ,
                 buttonText: '確定'
             }
             if(typeof  config  === 'string' || typeof  config  === 'number' ){
                 Vue.$vux.alert.show(Object.assign(def,{content:config}));
             } else {
                 Vue.$vux.alert.show(Object.assign(def,config));
             }
         },
         $confirm: config => {
             let isConfirm = false ;
             let def = {
                 title: '提示' ,
                 content: '系統異常,請重新登錄后再試!' ,
                 confirmText: '確定' ,
                 cancelText: '取消' ,
                 onConfirm:() =>{
                     isConfirm = true ;
                 }
             }
             if(typeof  config  === 'string' || typeof  config  === 'number' ){
                 Vue.$vux.confirm.show(Object.assign(def,{content:config}));
             } else {
                 Vue.$vux.confirm.show(Object.assign(def,config));
             }
             /*return new Promise((resolve,reject) => {
                 if(isConfirm){
                     resolve();
                 }
             })*/
         },
         $showLoading: config => {
             let def = {
                 text: '加載中...'
             }
             if(typeof  config  === 'string' || typeof  config  === 'number' ){
                 Vue.$vux.loading.show(Object.assign(def,{text:config}));
             } else {
                 Vue.$vux.loading.show(Object.assign(def,config));
             }
         }
 
     }
     Object.entries(msg).forEach(([method,fn]) => {
         Vue.prototype[method] = fn;
     })
}
Vue.use(Message)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM