让unisocket通用化;把showToast(...)集成在 cToast库里

This commit is contained in:
陆柯 2020-05-22 17:04:53 +08:00
parent 1ec8c2c600
commit 73bd6564c6
4 changed files with 43 additions and 25 deletions

17
cToast/cToast.js Normal file
View File

@ -0,0 +1,17 @@
module.exports = function showToast({type, icon, image, title, duration}){
if (this.$refs && this.$refs.toast) {
this.$refs.toast.open({type, content:title, duration})
}else {
// #ifndef APP-PLUS
if (!image){
image = `../static/Common.${type}.png`
}
uni.showToast({icon, image, title, duration})
// #endif
// #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform==='android') {
uni.showToast({icon:'none', title, duration})
}
// #endif
}
}

View File

@ -33,10 +33,10 @@ based on
methods:{ methods:{
open:function(toast){ open:function(toast){
//uuid //uuid
let uuid=this.guid(); let uuid=this.guid()
toast.uuid=uuid; toast.uuid=uuid
// //
toast.animator='fade_Down'; toast.animator='fade_Down'
toast.clickable = toast.clickable || false /// toast.clickable = toast.clickable || false ///
toast.duration = toast.duration || 1500 toast.duration = toast.duration || 1500
@ -44,13 +44,13 @@ based on
toast.type = toast.type || 'info' toast.type = toast.type || 'info'
// //
this.popup_list.push(toast); this.popup_list.push(toast)
if(!toast.clickable){ if(!toast.clickable){
this.disappear(toast.uuid,toast.duration); this.disappear(toast.uuid,toast.duration)
}// }//
else{ else{
this.$emit('uuidCallback',toast.uuid); this.$emit('uuidCallback',toast.uuid)
} }
}, },
@ -62,23 +62,23 @@ based on
for(let i=0;i<this.popup_list.length;i++){ for(let i=0;i<this.popup_list.length;i++){
if(this.popup_list[i].uuid==res){ if(this.popup_list[i].uuid==res){
// //
this.popup_list.splice(i,1); this.popup_list.splice(i,1)
this.$forceUpdate() this.$forceUpdate()
} }
} }
},250) },250)
}); })
}, },
fade_out_animator:function(uuid,duration){ fade_out_animator:function(uuid,duration){
//duration退 //duration退
if(!duration||typeof(duration)!='number'){duration=1500;} if(!duration||typeof(duration)!='number'){duration=1500}
return new Promise(res=>{ return new Promise(res=>{
setTimeout(()=>{ setTimeout(()=>{
for(let i=0;i<this.popup_list.length;i++){ for(let i=0;i<this.popup_list.length;i++){
if(this.popup_list[i].uuid==uuid){ if(this.popup_list[i].uuid==uuid){
//退 //退
this.popup_list[i].animator='fade_Top'; this.popup_list[i].animator='fade_Top'
res(uuid); res(uuid)
} }
} }
},duration) },duration)
@ -94,8 +94,8 @@ based on
for(let i=0;i<this.popup_list.length;i++){ for(let i=0;i<this.popup_list.length;i++){
if(this.popup_list[i].uuid==res){ if(this.popup_list[i].uuid==res){
// //
this.popup_list.splice(i,1); this.popup_list.splice(i,1)
this.$emit('closeCallback',uuid); this.$emit('closeCallback',uuid)
this.$forceUpdate() this.$forceUpdate()
} }
} }
@ -107,9 +107,9 @@ based on
return new Promise(res=>{ return new Promise(res=>{
for (var i = 0; i < this.popup_list.length; i++) { for (var i = 0; i < this.popup_list.length; i++) {
if(this.popup_list[i].uuid==uuid){ if(this.popup_list[i].uuid==uuid){
this.popup_list[i].animator='fade_Top'; this.popup_list[i].animator='fade_Top'
res(uuid) res(uuid)
break; break
} }
} }
}) })
@ -120,18 +120,18 @@ based on
for (var i = 0; i < this.popup_list.length; i++) { for (var i = 0; i < this.popup_list.length; i++) {
if(this.popup_list[i].uuid==update_list.uuid){ if(this.popup_list[i].uuid==update_list.uuid){
this.popup_list[i].type=update_list.type; this.popup_list[i].type=update_list.type;
this.init(this.popup_list[i]); this.init(this.popup_list[i])
this.popup_list[i].content=update_list.content; this.popup_list[i].content=update_list.content
break; break
} }
} }
}, },
//uuid //uuid
guid:function() { guid:function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8)
return v.toString(16); return v.toString(16)
}); })
} }
} }
} }

View File

@ -1,5 +1,6 @@
module.exports={ module.exports={
cColorText: require('./cColorText/cColorText.vue'), cColorText: require('./cColorText/cColorText.vue'),
cPager: require('./cPager/cPager.vue'), cPager: require('./cPager/cPager.vue'),
cQrcode: require('./cQrcode/cQrcode.vue') cQrcode: require('./cQrcode/cQrcode.vue'),
cToast: require('./cToast/cToast.vue')
} }

View File

@ -5,11 +5,11 @@ const my = {
} }
module.exports={ module.exports={
initSocket(){ initSocket(url){
if (!my.socket || my.socket.readyState!==my.socket.OPEN && getApp()._SS.nodeHost) { if (!my.socket || my.socket.readyState!==my.socket.OPEN && typeof(url)==='string') {
console.log('WebSocket connecting...') console.log('WebSocket connecting...')
my.socket = uni.connectSocket({ my.socket = uni.connectSocket({
url: getApp()._SS.nodeHost.replace(/^http/, 'ws'), url: url.replace(/^http/, 'ws'),
complete: ()=>{} complete: ()=>{}
}) })
my.socket.onOpen((res)=>{ my.socket.onOpen((res)=>{