Skip to content

Commit

Permalink
fix: channel log
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Dec 5, 2022
1 parent 858619c commit 7ed4772
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 166 deletions.
16 changes: 16 additions & 0 deletions src/api/Dlink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ export async function postTopic(Topic = '$dg/user/router/') {
Vue.prototype.$mqttInfo = mqttInfo
return submessage
}

export async function nopostTopic(Topic = '$dg/user/router/') {
const mqttInfo = {
href: location.href,
topic: Topic,
topicKey:
typeof Topic == 'string'
? Vue.prototype.$dgiotBus.getTopicKeyBypage(Topic.split('/')[2])
: Topic,
splitTopicKey: typeof Topic == 'string' ? Topic.split('/')[2] : Topic,
}
// MqttSubscribe
window.mqttInfo = window.dgiot.mqttInfo = mqttInfo
Vue.prototype.$mqttInfo = mqttInfo
return mqttInfo
}
2 changes: 2 additions & 0 deletions src/utils/utilwen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
deleteTopic as unSubscribe,
getTopic,
postTopic as subscribe,
nopostTopic,
} from '@/api/Dlink/index'
// https://www.jianshu.com/p/abdee4e7875a
/**
Expand Down Expand Up @@ -567,6 +568,7 @@ export default {
// 订阅方法挂载到全局变量上 2022年5月27日
Vue.prototype.$getTopic = getTopic
Vue.prototype.$subscribe = subscribe
Vue.prototype.$nopostsubscribe = nopostTopic
Vue.prototype.$unSubscribe = unSubscribe
// 全局配置环境变量
Vue.prototype.$dgiot = window.dgiot
Expand Down
89 changes: 6 additions & 83 deletions src/views/CloudFunction/engine/channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,6 @@
>
{{ $translateTitle('developer.delete') }}
</el-button>
<!-- <el-button-->
<!-- type="goon"-->
<!-- size="mini"-->
<!-- @click="productinformation(row.objectId)"-->
<!-- >-->
<!-- &lt;!&ndash; 订阅日志 &ndash;&gt;-->
<!-- {{ $translateTitle('product.productinformation') }}-->
<!-- </el-button>-->
</template>
</el-table-column>
</el-table>
Expand Down Expand Up @@ -549,6 +541,7 @@
</span>
</el-dialog>
<a-drawer
v-if="subdialog"
:append-to-body="true"
placement="right"
:title="channelname + '日志'"
Expand All @@ -560,7 +553,6 @@
:channel-id="channelname"
:list="msgList"
:msg="submessage"
:product="channelInfo"
:refresh-key="refreshFlag"
/>
</a-drawer>
Expand All @@ -581,64 +573,6 @@
</el-button>
</dgiot-query-form-left-panel>
</dgiot-query-form>

<el-table
:data="channelInfo"
height="60vh"
stripe
style="width: 100%"
@selection-change="handleSelectionChange"
>
<el-table-column align="center" type="index" />
<el-table-column type="selection" width="50" />
<el-table-column
align="center"
:label="$translateTitle('developer.channelname')"
prop="name"
show-overflow-tooltip
sortable
/>
<el-table-column
align="center"
:label="$translateTitle('developer.servicetype')"
prop="devType"
show-overflow-tooltip
sortable
/>
<el-table-column
align="center"
:label="$translateTitle('developer.describe')"
prop="desc"
show-overflow-tooltip
sortable
/>
<el-table-column
align="center"
:label="$translateTitle('developer.operation')"
prop="objectId"
show-overflow-tooltip
sortable
>
<template #default="{ row }">
<el-button
size="mini"
type="danger"
@click="deleteRelation(channelInfo, row.objectId)"
>
{{ $translateTitle('developer.remove') }}
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="pagination.currentPage"
:layout="pagination.layout"
:page-size="pagination.size"
:page-sizes="pagination.sizes"
:total="pagination.total"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
/>
</el-dialog>
</div>
</template>
Expand Down Expand Up @@ -701,7 +635,7 @@
topotopic: '',
refreshFlag: '99',
msgList: [],
submessage: '',
submessage: 'Starting the log' + `\n`,
subtopic: '',
pubtopic: '',
channeindex: 0,
Expand Down Expand Up @@ -1524,32 +1458,21 @@
})
this.refreshFlag = moment().format('x')
this.submessage += Msg + `\n`
// subdialog.setValue(this.submessage)
// subdialog.gotoLine(subdialog.session.getLength())
},
async subProTopic(row) {
this.productinformation(row.objectId)
this.subdialog = true
this.subdialogid = row.objectId
this.channelid = row.objectId
this.channelname = row.objectId
this.subtopic = '$dg/user/channel/' + row.objectId + '/#'
this.msgList = []
this.submessage = ''
this.msgList = []
let subInfo = {
router: this.router,
topic: this.subtopic,
qos: 2,
ttl: 1000 * 60 * 60 * 3,
}
await this.$subscribe(this.subtopic)
await this.$nopostsubscribe(this.subtopic)
console.log(this.$mqttInfo)
subupadte(row.objectId, 'start_logger')
this.msgList = []
this.submessage = ''
this.submessage = 'Starting the log' + `\n`
this.$dgiotBus.$off(this.$mqttInfo.topicKey)
this.$dgiotBus.$on(this.$mqttInfo.topicKey, (res) => {
console.log(res)
const { payloadString } = res
// 过滤登录时候,首页mqtt乱码的情况
this.mqttMsg(payloadString)
Expand All @@ -1559,7 +1482,7 @@
async handleCloseSubdialog() {
this.$dgiotBus.$off(this.$mqttInfo.topicKey)
this.msgList = []
this.submessage = ''
this.submessage = 'Starting the log' + `\n`
subupadte(this.channelid, 'stop_logger')
// this.$dgiotBus.$emit('MqttUnbscribe', this.topicKey, this.subtopic)
await this.$unSubscribe(this.subtopic)
Expand Down
104 changes: 46 additions & 58 deletions src/views/CloudFunction/engine/components/mqttLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
/>
</a-tab-pane>

<a-tab-pane key="device" :disabled="!product.length">
<a-tab-pane key="device">
<span slot="tab">
<dgiot-icon icon="traffic-light-line" />
{{ $translateTitle('system.Accurate log') }}
Expand Down Expand Up @@ -171,6 +171,8 @@
</template>
<script>
import { queryDevice } from '@/api/Device/index'
import { subupadte } from '@/api/System'
import { queryProduct } from '@/api/Product'
export default {
name: 'MqttLog',
Expand All @@ -183,19 +185,14 @@
},
msg: {
type: String,
default: '',
default: 'Starting the log' + `\n`,
required: false,
},
list: {
type: Array,
default: () => [],
required: false,
},
product: {
type: Array,
default: () => [],
required: false,
},
refreshFlag: {
type: String,
default: '',
Expand All @@ -204,6 +201,7 @@
},
data() {
return {
product: [],
router: '',
pubtopic: '',
topicKey: '',
Expand Down Expand Up @@ -235,58 +233,41 @@
this.queryDevice()
}
},
// topicKey: {
// handler: function (newVal, oldval) {
// console.log('newVal topicKey', newVal)
// console.log('oldval topicKey', oldval)
// let _this = this
// if (newVal) {
// this.$dgiotBus.$off(newVal)
// this.$dgiotBus.$on(newVal, (res) => {
// console.error(res)
// const { payloadString } = res
// this.mqttMsg(payload)
// })
// }
// if (oldval) {
// // 取消订阅
// _this.submessage = ''
// _this.msgList = []
// _this.logKey = '99'
// }
// },
// deep: true,
// limit: true,
// },
},
mounted() {},
async beforeDestroy() {
// this.$dgiotBus.$emit('MqttUnbscribe', this.topicKey, this.subtopic)
await this.$unSubscribe(this.subtopic)
},
methods: {
stopchannel(val) {
async stopchannel(val) {
if (val == 'device') {
this.productinformation(this.channelId)
this.$dgiotBus.$emit(
'MqttUnbscribe',
this.$dgiotBus.router(this.$route.fullPath),
'$dg/user/' + this.channelId + '/#'
)
} else if (val == 'editor') {
subupadte(this.channelId, 'start_logger')
let subtopic = '$dg/user/channel/' + this.channelId + '/#'
await this.$nopostsubscribe(subtopic)
_this = this
_this.msg = 'Starting the log' + `\n`
this.$dgiotBus.$off(this.$mqttInfo.topicKey)
this.$dgiotBus.$on(this.$mqttInfo.topicKey, (res) => {
const { payloadString } = res
this.mqttMsg(payloadString)
})
}
},
mqttMsg(Msg) {
// this.msgList.push({
// timestamp: moment().format('x'),
// msg: Msg,
// })
this.editorKey = moment().format('x')
this.deviceLog += Msg + `\n`
// subdialog.setValue(this.submessage)
// subdialog.gotoLine(subdialog.session.getLength())
},
async subscriptionlog(devaddr) {
this.editorKey = moment().format('x')
this.deviceLog = 'Log is true' + `\n`
this.deviceLog = 'Starting the log' + `\n`
this.pubtopic =
'channel/' +
this.channelId +
Expand All @@ -299,32 +280,39 @@
console.log(this.$mqttInfo)
this.$dgiotBus.$off(this.$mqttInfo.topicKey)
this.$dgiotBus.$on(this.$mqttInfo.topicKey, (res) => {
console.log(res)
const { payloadString } = res
// 过滤登录时候,首页mqtt乱码的情况
this.mqttMsg(payloadString)
})
// this.router = this.$dgiotBus.router(location.href)
// this.topicKey = this.$dgiotBus.topicKey(this.router, this.subtopic)
// let subInfo = {
// router: this.router,
// topic: this.subtopic,
// qos: 2,
// ttl: 1000 * 60 * 60 * 3,
// }
// this.$dgiotBus.$emit('MqttSubscribe', subInfo)
// setTimeout(() => {
// this.$dgiotBus.$emit(
// `MqttPublish`,
// this.pubtopic,
// JSON.parse(JSON.stringify({ action: 'start_logger' })),
// 0,
// false
// )
// this.editorKey = this.subtopic.split('log')[1]
// }, 500)
this.dialogVisible = !this.dialogVisible
},
async productinformation(ChannelId) {
try {
const params = {
order: '-createdAt',
skip: 0,
where: {
$relatedTo: {
object: {
__type: 'Pointer',
className: 'Channel',
objectId: ChannelId,
},
key: 'product',
},
},
}
const { results = [], count: total = 0 } = await queryProduct(params)
this.product = results
} catch (error) {
this.$baseMessage(
this.$translateTitle('alert.Data request error') + `${error}`,
'error',
'dgiot-hey-message-error'
)
}
},
async queryDevice() {
try {
const loading = this.$baseColorfullLoading()
Expand Down
2 changes: 1 addition & 1 deletion src/views/CloudFunction/topo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@
// console.error('this.topicKey', this.$mqttInfo.topicKey)
// console.log('是否是pc端', this.$ispc())
if (this.$route.query.type == 'device') {
await this.$subscribe(this.subtopic)
await this.$nopostsubscribe(this.subtopic)
}
this.$dgiotBus.$off('$dg/user/konva')
this.$dgiotBus.$on('$dg/user/konva', (Msg) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/CloudFunction/topo/preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
_this.subtopic = `$dg/user/konva/${
_this?.$route?.query?.deviceid || 'test'
}/report`
await _this.$subscribe(_this.subtopic)
await _this.$nopostsubscribe(_this.subtopic)
_this.handleMqttMsg()
},
handleMqttMsg() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/CloudFunction/topo/topo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
_this.subtopic = `$dg/user/konva/${
_this?.$route?.query?.deviceid || 'test'
}/report`
await _this.$subscribe(_this.subtopic)
await _this.$nopostsubscribe(_this.subtopic)
_this.handleMqttMsg()
// 处理消息
},
Expand Down
Loading

0 comments on commit 7ed4772

Please sign in to comment.