index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <platform-page
  9. class="l-flex__fill"
  10. @change="onTenantChanged"
  11. >
  12. <schema-table
  13. ref="table"
  14. :schema="schema"
  15. />
  16. </platform-page>
  17. <confirm-dialog
  18. ref="editDialog"
  19. title="日志抓取配置"
  20. @confirm="onConfirm"
  21. >
  22. <div class="c-sibling-item--v c-grid-form u-align-self--center">
  23. <div class="c-grid-form__row u-font-size--xs u-bold">
  24. <button
  25. class="o-button"
  26. @click="showDocument"
  27. >
  28. 抓取说明
  29. </button>
  30. </div>
  31. <div class="c-grid-form__row u-font-size--xs u-bold">
  32. 当前状态:{{ logSetting.activate ? '已下发配置' : '未下发配置' }}
  33. </div>
  34. <span class="c-grid-form__label u-required">
  35. 抓取时长
  36. </span>
  37. <div class="l-flex--row">
  38. <el-input-number
  39. v-model="logSetting.duration"
  40. controls-position="right"
  41. :min="60"
  42. :max="86400"
  43. step-strictly
  44. />&nbsp;秒
  45. </div>
  46. <span class="c-grid-form__label u-required">
  47. 抓取指令
  48. </span>
  49. <div
  50. class="has-info"
  51. data-info="多条指令以分号分隔"
  52. >
  53. <el-input
  54. v-model="logSetting.commands"
  55. type="textarea"
  56. :rows="5"
  57. />
  58. </div>
  59. <span class="c-grid-form__label u-required">
  60. 是否重启
  61. </span>
  62. <el-switch
  63. v-model="logSetting.reboot"
  64. class="c-grid-form__option"
  65. active-color="#13ce66"
  66. inactive-color="#ff4949"
  67. />
  68. </div>
  69. <template #footer="{ confirm, cancel }">
  70. <button
  71. class="c-sibling-item o-button"
  72. @click="confirm"
  73. >
  74. 开启抓取
  75. </button>
  76. <button
  77. class="c-sibling-item o-button o-button--info"
  78. @click="cancel"
  79. >
  80. 取消
  81. </button>
  82. </template>
  83. </confirm-dialog>
  84. <table-dialog
  85. ref="resultDialog"
  86. size="lg"
  87. title="抓取结果"
  88. :schema="resultSchema"
  89. />
  90. <table-dialog
  91. ref="heartbeatDialog"
  92. size="lg fixed"
  93. :title="title"
  94. :schema="heartbeatSchema"
  95. />
  96. </wrapper>
  97. </template>
  98. <script>
  99. import { parseTime } from '@/utils'
  100. import { getAssetUrl } from '@/api/asset'
  101. import { getDevicesByTenant } from '@/api/device'
  102. import {
  103. getRemoteLogConfig,
  104. startRemoteLog,
  105. stopRemoteLog,
  106. getRemoteLogs,
  107. getHeartbeats
  108. } from './api'
  109. const defaultLogSettingForm = {
  110. activate: false,
  111. duration: 60,
  112. commands: 'logcat -vtime | grep -i -E "MqttClient|PushCallback|MqttService"',
  113. reboot: false
  114. }
  115. export default {
  116. name: 'DeviceLog',
  117. data () {
  118. return {
  119. logSetting: {},
  120. schema: {
  121. autoRefreshEachPage: true,
  122. props: {
  123. size: 'small'
  124. },
  125. list: this.getDevicesByTenant,
  126. buttons: [
  127. { label: '未入库设备心跳记录', on: this.onHeartbeats }
  128. ],
  129. filters: [
  130. { key: 'serialNumber', type: 'search', placeholder: '序列号' },
  131. { key: 'mac', type: 'search', placeholder: 'MAC' },
  132. { key: 'name', type: 'search', placeholder: '名称' },
  133. { type: 'refresh' }
  134. ],
  135. cols: [
  136. { prop: 'name', label: '名称', 'min-width': 120 },
  137. { prop: 'serialNumber', label: '序列号', 'min-width': 80 },
  138. { prop: 'mac', label: 'MAC', 'min-width': 80 },
  139. { prop: 'remark', label: '型号', width: 100 },
  140. { type: 'tag', render: ({ activate, onlineStatus }) => activate
  141. ? onlineStatus === 0
  142. ? { type: 'primary', label: '待接入' }
  143. : onlineStatus === 1
  144. ? { type: 'success', label: '在线' }
  145. : { type: 'danger', label: '离线' }
  146. : { type: 'warning', label: '未激活' }, 'size': 'sm', width: 80 },
  147. { type: 'invoke', render: [
  148. { label: '开始抓取', on: this.onStart },
  149. { label: '停止抓取', on: this.onStop },
  150. { label: '抓取结果', on: this.onResult },
  151. { label: '心跳记录', on: this.onHeartbeat }
  152. ], width: 300 }
  153. ]
  154. },
  155. curDeviceId: null,
  156. currDeviceTenant: null,
  157. title: '',
  158. sn: ''
  159. }
  160. },
  161. computed: {
  162. heartbeatSchema () {
  163. return {
  164. nonPagination: true,
  165. autoRefresh: true,
  166. list: this.getheartbeatData,
  167. condition: { sn: this.sn },
  168. filters: this.sn
  169. ? null
  170. : [
  171. { key: 'sn', type: 'search', placeholder: '序列号' },
  172. { type: 'refresh' }
  173. ],
  174. cols: this.sn
  175. ? [
  176. { prop: 'sn', label: '序列号' },
  177. { prop: 'mac', label: 'MAC', width: 160 },
  178. { prop: 'ip', label: 'ip', width: 140 },
  179. { prop: 'settingId', label: '当前事件' },
  180. { label: '上报时间', render: ({ timestamp }) => parseTime(timestamp), width: 180 }
  181. ]
  182. : [
  183. { prop: 'sn', label: '序列号' },
  184. { prop: 'mac', label: 'MAC', width: 200 },
  185. { prop: 'ip', label: 'ip', width: 180 },
  186. { label: '上报时间', render: ({ timestamp }) => parseTime(timestamp), width: 180 }
  187. ]
  188. }
  189. },
  190. resultSchema () {
  191. return {
  192. list: getRemoteLogs,
  193. autoRefresh: true,
  194. condition: { tenant: this.currDeviceTenant, deviceId: this.curDeviceId },
  195. cols: [
  196. { prop: 'settingId', label: '事件' },
  197. { label: '执行状态', type: 'tag', render: ({ status }) => {
  198. return {
  199. type: ['warning', 'success', 'danger', 'primary'][status],
  200. label: ['抓取中', '成功', '失败', '取消'][status]
  201. }
  202. } },
  203. { prop: 'message', label: '备注' },
  204. { prop: 'createTime', label: '抓取开始时间', width: 180, align: 'center' },
  205. { prop: 'commandArrayString', label: '抓取命令数组' },
  206. { prop: 'duration', label: '抓取时长(s)', width: 100, align: 'center' },
  207. { type: 'invoke', render: [
  208. { label: '下载日志', allow: ({ status }) => status === 1, on: this.onDownload }
  209. ] }
  210. ]
  211. }
  212. }
  213. },
  214. methods: {
  215. onTenantChanged (tenant) {
  216. this.$tenant = tenant
  217. this.$refs.table?.pageTo(1)
  218. },
  219. getDevicesByTenant (params) {
  220. if (!this.$tenant) {
  221. return Promise.resolve({ data: [] })
  222. }
  223. return getDevicesByTenant(this.$tenant.path, params)
  224. },
  225. getheartbeatData (params) {
  226. if (this.sn) {
  227. return getHeartbeats(params, this.sn).then(({ data }) => {
  228. if (data.length && data[0].timestamp !== this.$heartbeats[0]?.timestamp) {
  229. this.$heartbeats.unshift(data[0])
  230. }
  231. return { data: this.$heartbeats }
  232. })
  233. }
  234. return getHeartbeats(params)
  235. },
  236. onHeartbeats () {
  237. this.title = '未入库设备心跳记录'
  238. this.sn = ''
  239. this.$refs.heartbeatDialog.show()
  240. },
  241. onHeartbeat ({ name, serialNumber }) {
  242. this.title = `${name}心跳记录`
  243. this.sn = serialNumber
  244. this.$heartbeats = []
  245. this.$refs.heartbeatDialog.show()
  246. },
  247. onStop ({ tenant, id }) {
  248. stopRemoteLog({
  249. tenant,
  250. deviceId: id,
  251. duration: 60,
  252. activate: false
  253. })
  254. },
  255. onStart (device) {
  256. getRemoteLogConfig(device.id).then(({ data }) => {
  257. if (data) {
  258. const { activate, duration, commands, reboot } = data
  259. this.logSetting = {
  260. activate,
  261. duration,
  262. commands: commands ? commands.join(';') : [],
  263. reboot
  264. }
  265. } else {
  266. this.logSetting = { ...defaultLogSettingForm }
  267. }
  268. this.currDeviceTenant = device.tenant
  269. this.curDeviceId = device.id
  270. this.$refs.editDialog.show()
  271. })
  272. },
  273. async onConfirm (done) {
  274. const { duration, commands, reboot } = this.logSetting
  275. if (~commands.indexOf(';')) {
  276. this.$message({
  277. type: 'warning',
  278. message: '请使用英文输入下的【;】符号'
  279. })
  280. return
  281. }
  282. await startRemoteLog({
  283. tenant: this.currDeviceTenant,
  284. deviceId: this.curDeviceId,
  285. duration,
  286. activate: true,
  287. commands: commands.split(';'),
  288. reboot
  289. })
  290. done()
  291. },
  292. onResult (device) {
  293. this.$deviceName = device.name
  294. this.currDeviceTenant = device.tenant
  295. this.curDeviceId = device.id
  296. this.$refs.resultDialog.show()
  297. },
  298. showDocument () {
  299. window.open('https://inspur-rd.feishu.cn/docx/M4oIdhmU1oFyvAxErn3cYv6Cnuf', '_blank')
  300. },
  301. onDownload ({ fileName, createTime, duration }) {
  302. const a = document.createElement('a')
  303. a.style.display = 'none'
  304. a.setAttribute('target', '_blank')
  305. a.setAttribute('download', `${this.$deviceName}-${createTime}-${duration}s日志.zip`)
  306. a.href = getAssetUrl(fileName)
  307. document.body.appendChild(a)
  308. a.click()
  309. document.body.removeChild(a)
  310. }
  311. }
  312. }
  313. </script>