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

View File

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