| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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
- }
- }
- }
- }
|