智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/9e/9e9ef5e43f94bd581d72fc0e5ba...

49 lines
1.5 KiB

export default {
data () {
return {
showToast: {
visible: false
}
}
},
created () {
let showType = ''
const createOnShow = (type) => {
return (args) => {
showType = type
setTimeout(() => { // 延迟一下 show 可解决窗口打开前调用 showToast 在 onHidePopup 之后触发
this.showToast = args
}, 10)
}
}
UniServiceJSBridge.on('onShowToast', createOnShow('onShowToast'))
UniServiceJSBridge.on('onShowLoading', createOnShow('onShowLoading'))
const createOnHide = (type) => {
return () => {
if (!showType) {
return
}
let warnMsg = ''
if (type === 'onHideToast' && showType !== 'onShowToast') {
warnMsg = '请注意 showToast 与 hideToast 必须配对使用'
} else if (type === 'onHideLoading' && showType !== 'onShowLoading') {
warnMsg = '请注意 showLoading 与 hideLoading 必须配对使用'
}
if (warnMsg) {
return console.warn(warnMsg)
}
showType = ''
setTimeout(() => { // 与 show 对应延迟10ms,避免快速调用 show,hide 导致无法关闭
this.showToast.visible = false
}, 10)
}
}
UniServiceJSBridge.on('onHidePopup', createOnHide('onHidePopup'))
UniServiceJSBridge.on('onHideToast', createOnHide('onHideToast'))
UniServiceJSBridge.on('onHideLoading', createOnHide('onHideLoading'))
}
}