import { send } from '../../../monitor' export default { props: { device: { type: Object, required: true } }, data () { return { topic: '/function/invoke' } }, created () { this.$asyncTimer = -1 }, beforeDestroy () { this.closeAsyncLoading() }, methods: { sendTopic (invoke, inputs, aysncFailMessage, delay = 5000) { console.log('invoke', invoke, inputs) this.closeAsyncLoading() const timestamp = `${Date.now()}` const messageId = `${timestamp}` return send( this.topic, { messageId, timestamp, 'function': invoke, inputs: inputs || [] } ).then( () => { if (aysncFailMessage) { this.$messageId = messageId if (aysncFailMessage === true) { return } this.$asyncloadingDialog = this.$showLoading() this.$asyncTimer = setTimeout(() => { this.closeAsyncLoading() this.$message({ type: 'warning', message: aysncFailMessage }) }, delay) } else { this.$message({ type: 'success', message: '执行成功' }) } }, () => { this.$message({ type: 'warning', message: '正在连接,请稍后再试' }) return Promise.reject() } ) }, closeAsyncLoading () { this.$messageId = null if (this.$asyncloadingDialog) { clearTimeout(this.$asyncTimer) this.$closeLoading(this.$asyncloadingDialog) this.$asyncloadingDialog = null } } } }