让unisocket通用化;把showToast(...)集成在 cToast库里
This commit is contained in:
parent
1ec8c2c600
commit
73bd6564c6
17
cToast/cToast.js
Normal file
17
cToast/cToast.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
index.js
3
index.js
@ -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')
|
||||||
}
|
}
|
@ -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)=>{
|
||||||
|
Loading…
Reference in New Issue
Block a user