onlineTest.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <a-row>
  3. <a-col :span="13">
  4. <a-card title="调试输出" style="background-color: #eef0f5;">
  5. <template #extra >
  6. <a-button type="primary" @click="clearLog" >清空日志</a-button>
  7. </template>
  8. <a-row>
  9. <a-col :span="6" class="app-imitate" >应用模拟器</a-col>
  10. <a-col :span="3" class="app-to-platform" >
  11. <div class="equipment-platform" >
  12. <div class="border-dot-top">命令下发</div>
  13. <div class="border-dot-bottom">数据上报</div>
  14. </div>
  15. </a-col>
  16. <a-col :span="6" class="IOT" @click="state.msgTrackVisible = !state.msgTrackVisible" >
  17. IOT平台 <span v-if="state.eventList.length " >(输出数:{{state.eventList.length }})</span>
  18. </a-col>
  19. <a-col :span="3" class="app-to-platform" >
  20. <div class="equipment-platform" >
  21. <div class="border-dot-top">命令下发</div>
  22. <div class="border-dot-bottom">数据上报</div>
  23. </div>
  24. </a-col>
  25. <a-col :span="6" class="device-imitate" >真实设备</a-col>
  26. </a-row>
  27. <a-row style="height: 505px;width: 100%" justify="space-between" >
  28. <a-col :span="11" style="height: 100%;background-color: #fff;position: relative;overflow: hidden;overflow-y: auto;" >
  29. <a-empty v-if="state.eventList.length == 0" style="position: absolute;top: 50%;left:50%; transform: translate(-50%, -50%);" ></a-empty>
  30. <span v-else >
  31. <div v-for="(item, index) in state.eventList"
  32. class="log-item"
  33. :key="index"
  34. >
  35. <div><api-two-tone style="margin-right: 10px;" />{{item.ts}}</div>
  36. <a-row
  37. v-for="(_, i) in item.json"
  38. :key="_.id"
  39. :gutter="[8, 8]"
  40. >
  41. <span v-if="_.eventType !== 'TRANSPORT_TO_PLATFORM'" >
  42. <a-col span="24" >事件名称:{{_.eventName}}</a-col>
  43. <a-col span="24" >事件类型:{{EventController.eventTypeMap.get(_.eventType)?.name}}</a-col>
  44. <a-col span="24" >事件参数:{{_.eventPayload}}</a-col>
  45. <a-divider v-if="index !== state.eventList.length && i === 1" style="height: 1px; background-color: #8a8e99; margin: 8px 0px;" dashed />
  46. </span>
  47. </a-row>
  48. </div>
  49. </span>
  50. </a-col>
  51. <a-col :span="11" style='background-color: #fff;height: 100%;overflow: hidden;overflow-y: auto;' >
  52. <a-empty v-if="state.eventList.length == 0" style="position: absolute;top: 50%;left:50%; transform: translate(-50%, -50%);" ></a-empty>
  53. <div v-for="(item, index) in state.eventList"
  54. class="log-item"
  55. :key="index"
  56. >
  57. <div><api-two-tone style="margin-right: 10px;" /> {{item.ts}}</div>
  58. <a-row
  59. v-for="(_, i) in item.json"
  60. :key="_.id"
  61. :gutter="[8, 8]"
  62. >
  63. <span v-if="_.eventType === 'TRANSPORT_TO_PLATFORM'">
  64. <a-col span="24" >事件名称:{{_.eventName}}</a-col>
  65. <a-col span="24" >事件类型:{{EventController.eventTypeMap.get(_.eventType)?.name}}</a-col>
  66. <a-col span="24" >事件参数:{{_.eventPayload}}</a-col>
  67. <a-divider v-if="index != state.eventList.length - 1" style="height: 1px; background-color: #8a8e99; margin: 8px 0px;" dashed />
  68. </span>
  69. </a-row>
  70. </div>
  71. </a-col>
  72. <a-col class="msg-track" :span="11" >
  73. <a-drawer
  74. title="消息追踪"
  75. :mask="false"
  76. placement="left"
  77. :open="state.msgTrackVisible"
  78. :get-container="false"
  79. :style="{ position: 'absolute' }"
  80. headerStyle="{text-align: center;}"
  81. @close="state.msgTrackVisible = false"
  82. >
  83. <a-row>
  84. <a-col>
  85. <div v-for="(item, index) in state.eventList"
  86. class="log-item"
  87. :key="index"
  88. >
  89. <div><api-two-tone style="margin-right: 10px;" />{{item.ts}}</div>
  90. <a-row
  91. v-for="(_, i) in item.json"
  92. :key="_.id"
  93. :gutter="[8, 8]"
  94. >
  95. <span>
  96. <a-col span="24" >事件名称:{{_.eventName}}</a-col>
  97. <a-col span="24" >事件类型:{{EventController.eventTypeMap.get(_.eventType)?.name}}</a-col>
  98. <a-col span="24" >事件参数:{{_.eventPayload}}</a-col>
  99. <a-divider style="height: 1px; background-color: #8a8e99; margin: 8px 0px;" dashed />
  100. </span>
  101. </a-row>
  102. </div>
  103. </a-col>
  104. </a-row>
  105. </a-drawer>
  106. </a-col>
  107. </a-row>
  108. </a-card>
  109. </a-col>
  110. <a-col :span="9">
  111. <a-row justify='end' >
  112. <a-col>
  113. <a-button type="link" >{{state.device.deviceLabel ? state.device.deviceLabel : "尚未选择设备"}}</a-button>
  114. <a-button type="primary" @click="state.drawerVisible = true" >选择设备</a-button>
  115. </a-col>
  116. </a-row>
  117. <!-- :tab-list="tabListNoTitle"
  118. :active-tab-key="state.activeKey"
  119. @tabChange="onTabChange" -->
  120. <a-card
  121. title="应用模拟器"
  122. style="width: 100%;height: 632px;margin-top: 10px;position: relative;"
  123. >
  124. <a-row :gutter="[8, 8]">
  125. <a-col span="24" ><a-tag color="blue" style="scale: 1.2;" >命令下发</a-tag></a-col>
  126. <a-col class="subtitle" span="24" >
  127. 应用模拟器可根据产品定义向设备下发命令。<br/>
  128. 若您使用了图形化开发的编解码插件,为获得正确的编码结果,下发命令时,请携带所有在插件中定义的字段,且每个命令的长度需小于512个字节
  129. </a-col>
  130. <a-col span="24" v-if="false" >
  131. <a-form
  132. :labelCol="{span: 2}"
  133. :wrapperCol="{span: 14}"
  134. >
  135. <a-form-item label="产品" >
  136. <a-select allowClear v-model:value="state.modelId" >
  137. <a-select-option
  138. v-for="item in state.modelSouce"
  139. :key="item.id"
  140. :value="item.id"
  141. >
  142. {{item.modelLabel}}
  143. </a-select-option>
  144. </a-select>
  145. </a-form-item>
  146. <a-form-item label="命令" >
  147. <a-select allowClear v-model:value="state.cmdId" >
  148. <a-select-option
  149. v-for="item in state.modelCmdList"
  150. :key="item.id"
  151. :value="item.id"
  152. >
  153. {{item.cmdLabel}}
  154. </a-select-option>
  155. </a-select>
  156. </a-form-item>
  157. <span v-if="cmdDetail?.cmdParams.length" >
  158. <a-form-item :label="item.paramLabel" v-for="(item, index) in cmdDetail?.cmdParams" :key="item.id" >
  159. <a-input allowClear v-model:value="item.dataUnit" ></a-input>
  160. </a-form-item>
  161. </span>
  162. </a-form>
  163. </a-col>
  164. </a-row>
  165. <template #extra >
  166. <a-button type="primary" @click="openCmdModal">命令下发</a-button>
  167. </template>
  168. </a-card>
  169. </a-col>
  170. </a-row>
  171. <a-drawer
  172. v-model:open="state.drawerVisible"
  173. size="large"
  174. class="custom-class"
  175. title="选择设备2233"
  176. placement="right"
  177. >
  178. <SelectDevice ref="selectDeviceRef" />
  179. <template #footer >
  180. <a-row justify="end" >
  181. <a-col>
  182. <a-space>
  183. <a-button @click="state.drawerVisible = false">取消</a-button>
  184. <a-button type="primary" @click="handleSelectDevice">确定</a-button>
  185. </a-space>
  186. </a-col>
  187. </a-row>
  188. </template>
  189. </a-drawer>
  190. <cmd-push
  191. :visible="cmdState.visible"
  192. :device-id="state.device.id"
  193. :model-id="state.device.modelId"
  194. @cancel="cmdState.visible = false"
  195. @ok="cmdState.visible = false"
  196. />
  197. </template>
  198. <script lang='ts' setup >
  199. import { computed, onMounted, reactive, ref, watch } from 'vue'
  200. import SelectDevice from '@/pages/iot/rule/components/selectDevice.vue'
  201. import { message } from 'ant-design-vue'
  202. import { DeviceContriller, EventController, ModelCmdController, ModelController } from '@/controller'
  203. import { useRoute } from 'vue-router'
  204. import dayjs from 'dayjs'
  205. import { FieldTimeOutlined, ApiTwoTone } from '@ant-design/icons-vue'
  206. import CmdPush from '@/pages/iot/device/modal/cmdPush.vue'
  207. import { useScheduler } from '@/hooks'
  208. const route = useRoute()
  209. const selectDeviceRef = ref()
  210. const cmdState = reactive({
  211. visible: false
  212. })
  213. const state = reactive<{
  214. activeKey: 'app',
  215. drawerVisible: boolean,
  216. modelSouce: IOT.API.MODEL.Model[],
  217. modelId: string,
  218. cmdId: string,
  219. modelCmdList: IOT.API.CMD.Cmd[],
  220. eventList: any,
  221. startTime: number,
  222. lastId: string
  223. msgTrackVisible: boolean
  224. device: {
  225. id: string
  226. deviceLabel: string
  227. modelId: string
  228. }
  229. }>({
  230. activeKey: 'app',
  231. drawerVisible: false,
  232. msgTrackVisible: false,
  233. modelSouce: [],
  234. modelId: '',
  235. cmdId: '',
  236. modelCmdList: [],
  237. eventList: [],
  238. startTime: 0,
  239. lastId: '',
  240. device: {
  241. id: '',
  242. deviceLabel: '',
  243. modelId: ''
  244. }
  245. })
  246. watch(() => state.modelId, () => getModelCmdList())
  247. watch(
  248. () => state.device.id,
  249. () => {
  250. addEventList()
  251. },
  252. {
  253. deep: true
  254. }
  255. )
  256. const cmdDetail = computed(() => state.modelCmdList.find(item => item.id === state.cmdId))
  257. const clearLog = () => {
  258. state.eventList = []
  259. message.success('清除成功')
  260. }
  261. const openCmdModal = () => {
  262. if (!state.device.id) {
  263. message.error('请先选择设备')
  264. return
  265. }
  266. cmdState.visible = true
  267. }
  268. const handleSelectDevice = () => {
  269. console.log('我不处罚')
  270. const _device = selectDeviceRef.value.getSelectDevice()
  271. console.log('_device:', _device)
  272. if (_device) {
  273. state.device = _device
  274. console.log('state.device:', state.device)
  275. state.drawerVisible = false
  276. } else {
  277. message.warn('请选择产品')
  278. }
  279. }
  280. const getModelCmdList = async () => {
  281. const { data } = await ModelCmdController.list({ modelId: state.modelId })
  282. state.modelCmdList = data
  283. }
  284. const getEventList = async () => {
  285. const { data, sum } = await EventController.list({ deviceId: state.device.id, startTime: state.startTime, lastId: state.lastId })
  286. if (data) {
  287. state.eventList.unshift ({
  288. json: data,
  289. ts: dayjs(new Date().getTime()).format('YYYY/MM/DD HH:mm:ss')
  290. })
  291. } else {
  292. state.eventList = []
  293. }
  294. }
  295. const { start, stop } = useScheduler(getEventList, 2000)
  296. const getEventTraceList = async () => {
  297. await EventController.listTrace({ deviceId: state.device.id }) as unknown as Number
  298. start()
  299. }
  300. const addEventList = async () => {
  301. stop()
  302. await EventController.addTrace({ deviceId: state.device.id })
  303. getEventTraceList()
  304. }
  305. const getDeviceById = async () => {
  306. const data = await DeviceContriller.byId(state.device.id)
  307. state.device = data
  308. }
  309. onMounted(() => {
  310. const deviceId = route.query.id as string
  311. if (deviceId) {
  312. state.device.id = deviceId
  313. getDeviceById()
  314. }
  315. })
  316. </script>
  317. <style lang='less' scoped >
  318. @import "~@/styles/theme.less";
  319. .subtitle {
  320. font-size: 12px;
  321. color: @label-color;
  322. }
  323. .app-imitate {
  324. width: 250px;
  325. height: 80px;
  326. background-color: #fff;
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. font-size: 20px;
  331. }
  332. .IOT {
  333. width: 250px;
  334. height: 64px;
  335. background-color: #fff;
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. font-size: 20px;
  340. cursor: pointer;
  341. span {
  342. color: @sublabel-color;
  343. font-size: 16px;
  344. }
  345. }
  346. .app-to-platform {
  347. height: 100%;
  348. // width: 12.5%;
  349. // float: left;
  350. // height: 100%;
  351. }
  352. .device-imitate {
  353. width: 250px;
  354. height: 80px;
  355. background-color: #fff;
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. font-size: 20px;
  360. }
  361. .equipment-platform {
  362. position: absolute;
  363. display: inline-block;
  364. vertical-align: middle;
  365. width: 100%;
  366. line-height: 1;
  367. color: #4d4d4d;
  368. text-align: center;
  369. font-size: 12px;
  370. .border-dot-top {
  371. position: relative;
  372. padding-bottom: 0.6rem;
  373. margin-bottom: 1rem;
  374. border-bottom: 2px #999 solid;
  375. }
  376. .border-dot-top::before {
  377. left: 0;
  378. top: 100%;
  379. margin-top: -0.15rem;
  380. content: "";
  381. display: block;
  382. width: 0.4rem;
  383. height: 0.4rem;
  384. border-radius: 0.2rem;
  385. border: 2px #999 solid;
  386. background-color: #ebedf0;
  387. position: absolute;
  388. }
  389. .border-dot-top::after {
  390. content: "";
  391. display: block;
  392. border: 4px #999 solid;
  393. width: 0;
  394. height: 0;
  395. transform: rotate(45deg);
  396. position: absolute;
  397. right: 0;
  398. top: 97%;
  399. margin-top: -0.15rem;
  400. border-color: #999 #999 transparent transparent;
  401. }
  402. .border-dot-bottom {
  403. border-color: #ccc;
  404. position: relative;
  405. padding-top: 0.6rem;
  406. border-top: 2px #999 dashed;
  407. }
  408. .border-dot-bottom::before {
  409. content: "";
  410. display: block;
  411. border: 4px #999 solid;
  412. width: 0;
  413. height: 0;
  414. transform: rotate(-135deg);
  415. position: absolute;
  416. top: -11%;
  417. margin-top: -0.15rem;
  418. border-color: #999 #999 transparent transparent;
  419. }
  420. .border-dot-bottom::after {
  421. right: 0;
  422. top: -1px;
  423. margin-top: -0.15rem;
  424. content: "";
  425. display: block;
  426. width: 0.4rem;
  427. height: 0.4rem;
  428. border-radius: 0.2rem;
  429. border: 2px #999 solid;
  430. background-color: #ebedf0;
  431. position: absolute;
  432. }
  433. }
  434. .log-item {
  435. width: 100%;
  436. table-layout: fixed;
  437. word-wrap: break-all;
  438. word-break: normal;
  439. word-wrap: break-word;
  440. white-space: pre-wrap;
  441. padding: 0px 10px;
  442. box-sizing: border-box;
  443. margin-top: 10px;
  444. }
  445. .msg-track {
  446. width: 100%;
  447. height: 300px;
  448. position: absolute;
  449. bottom: 24px;
  450. left: 24px;
  451. box-shadow: #000;
  452. overflow: hidden;
  453. overflow-y: auto;
  454. .title {
  455. font-size: 20px;
  456. width: 100%;
  457. display: flex;
  458. justify-content: center;
  459. align-items: center;
  460. margin-bottom: 10px;
  461. }
  462. }
  463. </style>