diff --git a/cToast/cToast.js b/cToast/cToast.js new file mode 100644 index 0000000..5d5e6ad --- /dev/null +++ b/cToast/cToast.js @@ -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 + } +} \ No newline at end of file diff --git a/cToast/cToast.vue b/cToast/cToast.vue index 8e1d5de..2d76ec8 100644 --- a/cToast/cToast.vue +++ b/cToast/cToast.vue @@ -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{ setTimeout(()=>{ for(let i=0;i{ 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) + }) } } } diff --git a/index.js b/index.js index a7f4a97..b2b8fcb 100644 --- a/index.js +++ b/index.js @@ -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') } \ No newline at end of file diff --git a/unisocket/unisocket.js b/unisocket/unisocket.js index 2c45eba..e021fb0 100644 --- a/unisocket/unisocket.js +++ b/unisocket/unisocket.js @@ -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)=>{