device-edit.vue 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. <template>
  2. <div class="device-edit">
  3. <el-card class="top-card" :body-style="{ padding: '26px 20px' }">
  4. <div class="title-wrap">
  5. <el-button class="top-button" type="info" size="small" @click="goBack()">
  6. <i class="el-icon-arrow-left"></i>
  7. {{ $t('product.product-edit.473153-44') }}
  8. </el-button>
  9. <span class="info-item">{{ $t('device.device-edit.148398-1') }}:{{ form.deviceName }}</span>
  10. <span class="info-item">{{ $t('device.device-edit.148398-7') }}:{{ form.serialNumber }}</span>
  11. <span class="info-item" v-if="!!form.status">
  12. {{ $t('device.device-edit.148398-83') }}:
  13. <span class="status" :style="{ color: statusColor }">
  14. <span class="dot" :style="{ backgroundColor: statusColor }"></span>
  15. <span v-if="form.status == 1">{{ $t('home.notActive') }}</span>
  16. <span v-if="form.status == 2">{{ $t('home.disabled') }}</span>
  17. <span v-if="form.status == 3">{{ $t('home.onLine') }}</span>
  18. <span v-if="form.status == 4">{{ $t('home.offline') }}</span>
  19. </span>
  20. </span>
  21. <span class="info-item">{{ $t('device.device-edit.148398-4') }}:{{ form.productName }}</span>
  22. </div>
  23. </el-card>
  24. <el-card style="padding-bottom: 100px">
  25. <el-tabs id="deviceDetailTab" class="custom-tabs" v-model="activeName" tab-position="top" @tab-click="tabChange" style="min-height: 400px" lazy>
  26. <el-tab-pane name="basic">
  27. <span slot="label">{{ $t('device.device-edit.148398-0') }}</span>
  28. <el-form class="basic-span" ref="form" :model="form" :rules="rules" label-width="100px">
  29. <el-row :gutter="100">
  30. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8">
  31. <el-form-item :label="$t('device.device-edit.148398-1')" prop="deviceName">
  32. <el-input v-model="form.deviceName" :placeholder="$t('device.device-edit.148398-2')">
  33. <el-button slot="append" @click="openSummaryDialog" v-if="form.deviceId != 0">{{ $t('device.device-edit.148398-3') }}</el-button>
  34. </el-input>
  35. </el-form-item>
  36. <el-form-item :label="$t('device.device-edit.148398-4')" prop="productName">
  37. <el-input readonly v-model="form.productName" :placeholder="$t('device.device-edit.148398-5')" :disabled="form.status != 1">
  38. <el-button slot="append" @click="selectProduct()" :disabled="form.status != 1">{{ $t('device.device-edit.148398-6') }}</el-button>
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item :label="$t('device.device-edit.148398-7')" prop="serialNumber">
  42. <el-input v-model="form.serialNumber" :placeholder="$t('device.device-edit.148398-8')" maxlength="32" :disabled="form.status != 1" :readonly="form.deviceType === 3">
  43. <el-button v-if="form.deviceType !== 3" slot="append" @click="generateNum" :loading="genDisabled" :disabled="form.status != 1" v-hasPermi="['iot:device:add']">
  44. {{ $t('device.device-edit.148398-9') }}
  45. </el-button>
  46. <el-button v-if="form.deviceType === 3" slot="append" @click="genSipID()" :disabled="form.status != 1" v-hasPermi="['iot:device:add']">
  47. {{ $t('device.device-edit.148398-9') }}
  48. </el-button>
  49. </el-input>
  50. <el-alert v-if="openServerTip" class="alert-wrap" type="info" show-icon :description="$t('device.device-edit.148398-10')"></el-alert>
  51. </el-form-item>
  52. <el-form-item :label="$t('device.device-edit.148398-12')" prop="firmwareVersion">
  53. <el-input v-model="form.firmwareVersion" :placeholder="$t('device.device-edit.148398-13')" type="number" step="0.1" :readonly="form.status != 1 || form.deviceType === 3">
  54. <template slot="prepend">Version</template>
  55. <template slot="append">{{ form.firmwareType === 1 ? $t('firmware.index.222541-52') : $t('firmware.index.222541-53') }}</template>
  56. </el-input>
  57. </el-form-item>
  58. <!-- 设备影子 -->
  59. <el-form-item v-if="form.deviceType !== 3" :label="$t('device.device-edit.148398-15')" prop="isShadow">
  60. <el-radio-group v-model="form.isShadow">
  61. <el-radio :label="1">{{ $t('device.device-edit.148398-85') }}</el-radio>
  62. <el-radio :label="0">{{ $t('device.device-edit.148398-86') }}</el-radio>
  63. </el-radio-group>
  64. </el-form-item>
  65. <el-form-item :label="$t('device.device-edit.148398-32')" prop="rssi">
  66. <el-input v-model="form.rssi" :placeholder="$t('device.device-edit.148398-33')" readonly />
  67. </el-form-item>
  68. <el-form-item :label="$t('device.device-edit.148398-17')" prop="remark">
  69. <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }" :placeholder="$t('device.device-edit.148398-18')" />
  70. </el-form-item>
  71. </el-col>
  72. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8">
  73. <el-form-item :label="$t('device.device-edit.148398-19')" prop="locationWay">
  74. <el-select v-model="form.locationWay" :placeholder="$t('device.device-edit.148398-20')" clearable style="width: 100%">
  75. <el-option v-for="dict in dict.type.iot_location_way" :key="dict.value" :label="dict.label" :value="Number(dict.value)" />
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item :label="$t('device.device-edit.148398-21')" prop="longitude">
  79. <el-input v-model="form.longitude" :placeholder="$t('device.device-edit.148398-22')" type="number" :disabled="form.locationWay !== 3">
  80. <el-link slot="append" :underline="false" href="https://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank" :disabled="form.locationWay != 3">
  81. {{ $t('device.device-edit.148398-23') }}
  82. </el-link>
  83. </el-input>
  84. </el-form-item>
  85. <el-form-item :label="$t('device.device-edit.148398-24')" prop="latitude">
  86. <el-input v-model="form.latitude" :placeholder="$t('device.device-edit.148398-25')" type="number" :disabled="form.locationWay !== 3">
  87. <el-link slot="append" :underline="false" href="https://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank" :disabled="form.locationWay != 3">
  88. {{ $t('device.device-edit.148398-23') }}
  89. </el-link>
  90. </el-input>
  91. </el-form-item>
  92. <el-form-item :label="$t('device.device-edit.148398-26')" prop="networkAddress">
  93. <el-input v-model="form.networkAddress" :placeholder="$t('device.device-edit.148398-27')" :disabled="form.locationWay !== 3" />
  94. </el-form-item>
  95. <el-form-item :label="$t('device.device-edit.148398-28')" prop="networkIp">
  96. <el-input v-model="form.networkIp" :placeholder="$t('device.device-edit.148398-29')" readonly />
  97. </el-form-item>
  98. <el-form-item :label="$t('device.device-edit.148398-30')" prop="activeTime">
  99. <el-date-picker v-model="form.activeTime" type="date" value-format="yyyy-MM-dd" :placeholder="$t('device.device-edit.148398-31')" readonly style="width: 100%"></el-date-picker>
  100. </el-form-item>
  101. <el-form-item v-if="form.transport === 'MQTT'" :label="$t('device.device-edit.148398-16')" prop="deviceStatus">
  102. <el-switch v-model="deviceStatus" active-text="" inactive-text="" :disabled="form.status === 1" :active-value="1" :inactive-value="0"></el-switch>
  103. </el-form-item>
  104. <el-form-item :label="$t('device.device-edit.148398-34')" prop="remark" v-if="form.deviceId != 0">
  105. <el-button
  106. size="mini"
  107. @click="handleViewMqtt()"
  108. :disabled="this.form.transport !== 'MQTT' && this.form.transport !== 'TCP' && this.form.transport !== 'HTTP' && this.form.transport !== 'GB28181'"
  109. >
  110. {{ $t('device.device-edit.148398-35') }}
  111. </el-button>
  112. <!-- <el-button size="mini" @click="openCodeDialog()">{{ $t('device.device-edit.148398-36') }}</el-button>-->
  113. </el-form-item>
  114. </el-col>
  115. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="8" v-if="form.deviceId != 0">
  116. <div style="border: 1px solid #dfe4ed; border-radius: 5px; padding: 5px; margin-left: 20px">
  117. <div id="map" style="height: 435px; width: 100%">{{ $t('device.device-edit.148398-37') }}</div>
  118. </div>
  119. </el-col>
  120. </el-row>
  121. </el-form>
  122. <el-form label-width="100px" style="margin-top: 70px">
  123. <el-form-item style="text-align: center; margin-left: -100px; margin-top: 10px">
  124. <el-button type="primary" @click="submitForm" v-hasPermi="['iot:device:edit']" v-show="form.deviceId != 0">
  125. {{ $t('update') }}
  126. </el-button>
  127. <el-button type="primary" @click="submitForm" v-hasPermi="['iot:device:add']" v-show="form.deviceId == 0">
  128. {{ $t('add') }}
  129. </el-button>
  130. </el-form-item>
  131. </el-form>
  132. <!-- 选择产品 -->
  133. <product-list ref="productList" :productId="form.productId" @productEvent="getProductData($event)" />
  134. <sipid ref="sipidGen" :product="form" @addGenEvent="getSipIDData($event)" />
  135. </el-tab-pane>
  136. <el-tab-pane name="runningStatus" v-if="form.deviceType !== 3">
  137. <span slot="label">{{ $t('device.device-edit.148398-42') }}</span>
  138. <!-- <real-time-status ref="realTimeStatus" :device="form" @statusEvent="getDeviceStatusData($event)" /> -->
  139. <running-status ref="runningStatus" :device="form" @statusEvent="getDeviceStatusData($event)" />
  140. </el-tab-pane>
  141. <!-- 数据采集-->
  142. <el-tab-pane name="variable" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>
  143. <span slot="label">{{ $t('device.device-edit.148398-74') }}</span>
  144. <device-variable ref="deviceVariable" :device="form" />
  145. </el-tab-pane>
  146. <!-- 数据调试-->
  147. <!-- <el-tab-pane name="instructionParsing" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>-->
  148. <!-- <span slot="label">{{ $t('device.device-edit.148398-76') }}</span>-->
  149. <!-- <instruction-parsing ref="instructionParsing" :device="form" />-->
  150. <!-- </el-tab-pane>-->
  151. <el-tab-pane
  152. name="deviceSub"
  153. :disabled="form.deviceId == 0"
  154. v-if="form.deviceType == 2 && (form.protocolCode == 'MODBUS-RTU' || form.protocolCode == 'MODBUS-TCP' || form.protocolCode == 'MODBUS-JSON-HP' || form.protocolCode == 'MODBUS-JSON-ZQWL')"
  155. lazy
  156. >
  157. <span slot="label">{{ $t('device.device-edit.148398-43') }}</span>
  158. <device-sub ref="deviceSub" :device="form" />
  159. </el-tab-pane>
  160. <!-- 轮询任务 -->
  161. <el-tab-pane name="deviceModbusTask" :disabled="form.deviceId == 0" v-if="form.canConfigPoll === true" lazy>
  162. <span slot="label">{{ $t('device.device-edit.148398-77') }}</span>
  163. <device-modbus-task ref="deviceModbusTask" :device="form" />
  164. </el-tab-pane>
  165. <!--组态应用-->
  166. <!-- <el-tab-pane name="scada" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3 && isShowScada == true" lazy>-->
  167. <!-- <span slot="label">{{ $t('device.device-edit.148398-73') }}</span>-->
  168. <!-- <device-scada ref="deviceScada" :device="form" />-->
  169. <!-- </el-tab-pane>-->
  170. <!--实时监测-->
  171. <!-- <el-tab-pane name="deviceMonitor" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3">-->
  172. <!-- <span slot="label">{{ $t('device.device-edit.148398-51') }}</span>-->
  173. <!-- <device-monitor ref="deviceMonitor" :device="form" />-->
  174. <!-- </el-tab-pane>-->
  175. <!--监测统计-->
  176. <el-tab-pane name="deviceStastic" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3">
  177. <span slot="label">{{ $t('device.device-edit.148398-52') }}</span>
  178. <device-statistic ref="deviceStatistic" :device="form" />
  179. </el-tab-pane>
  180. <!-- 设备通道-->
  181. <el-tab-pane name="sipChannel" :disabled="form.deviceId == 0" v-if="form.deviceType === 3" lazy>
  182. <span slot="label">{{ $t('device.device-edit.148398-44') }}</span>
  183. <channel ref="Channel" :device="form" @playerEvent="getPlayerData($event)" />
  184. </el-tab-pane>
  185. <!-- 设备管理-->
  186. <el-tab-pane name="sipPlayer" :disabled="form.deviceId == 0" v-if="form.deviceType === 3" lazy>
  187. <span slot="label">{{ $t('device.device-edit.148398-45') }}</span>
  188. <device-live-stream ref="deviceLiveStream" :device="form" />
  189. </el-tab-pane>
  190. <!-- 设备录像-->
  191. <el-tab-pane name="sipVideo" :disabled="form.deviceId == 0" v-if="form.deviceType === 3" lazy>
  192. <span slot="label">{{ $t('device.device-edit.148398-46') }}</span>
  193. <deviceVideo ref="deviceVideo" :device="form" />
  194. </el-tab-pane>
  195. <!-- 云端录像-->
  196. <el-tab-pane name="ossRecord" :disabled="form.deviceId == 0" v-if="form.deviceType === 3" lazy>
  197. <span slot="label">{{ $t('device.device-edit.148398-79') }}</span>
  198. <oss-record-list ref="OssRecord" :device="form"></oss-record-list>
  199. </el-tab-pane>
  200. <!-- 语音对讲-->
  201. <el-tab-pane name="sipTalk" :disabled="form.deviceId == 0" v-if="form.deviceType === 3">
  202. <span slot="label">{{ $t('device.device-edit.148398-82') }}</span>
  203. <siptalk ref="siptalk" :device="form" />
  204. </el-tab-pane>
  205. <!-- 设备定时-->
  206. <el-tab-pane name="deviceTimer" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>
  207. <span slot="label">{{ $t('device.device-edit.148398-47') }}</span>
  208. <device-timer ref="deviceTimer" :device="form" />
  209. </el-tab-pane>
  210. <!-- 事件日支 -->
  211. <el-tab-pane name="deviceLog" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>
  212. <span slot="label">{{ $t('device.device-edit.148398-49') }}</span>
  213. <device-log ref="deviceLog" :device="form" />
  214. </el-tab-pane>
  215. <!-- 指令日支-->
  216. <el-tab-pane name="deviceFuncLog" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>
  217. <span slot="label">{{ $t('device.device-edit.148398-50') }}</span>
  218. <device-func ref="deviceFuncLog" :device="form" />
  219. </el-tab-pane>
  220. <!-- 告警用户-->
  221. <el-tab-pane name="alertUser" v-hasPermi="['iot:device:alert:user:list']" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3">
  222. <span slot="label">{{ $t('device.device-edit.148398-80') }}</span>
  223. <alert-user ref="alertUser" :device="form" />
  224. </el-tab-pane>
  225. <!-- 视频监控-->
  226. <!-- <el-tab-pane name="inlineVideo" :disabled="form.deviceId == 0" v-if="form.deviceType !== 3" lazy>-->
  227. <!-- <span slot="label">{{ $t('device.device-edit.148398-75') }}</span>-->
  228. <!-- <device-inline-video ref="deviceInlineVideo" :sipRelationList="form.sipRelationVOList" />-->
  229. <!-- </el-tab-pane>-->
  230. <el-tab-pane name="deviceAlert" v-hasPermi="['iot:alertLog:list']" :disabled="form.deviceId == 0" lazy>
  231. <span slot="label">{{ $t('device.device-edit.148398-81') }}</span>
  232. <device-alert ref="deviceAlert" :device="form" />
  233. </el-tab-pane>
  234. <!-- 设备分享-->
  235. <!-- <el-tab-pane name="deviceUser" :disabled="form.deviceId == 0" lazy>-->
  236. <!-- <span slot="label">{{ $t('device.device-edit.148398-48') }}</span>-->
  237. <!-- <device-user ref="deviceUser" :device="form" @userEvent="getUserData($event)" />-->
  238. <!-- </el-tab-pane>-->
  239. <!-- <el-tab-pane name="device04" v-if="form.deviceType !== 3" disabled>
  240. <span slot="label">
  241. <el-tooltip class="item" effect="dark" content="用于查看发送的指令,设备是否已经响应" placement="right-start">
  242. <el-button type="warning" size="mini" @click="deviceSynchronization()" :disabled="form.deviceId == 0">数据同步</el-button>
  243. </el-tooltip>
  244. </span>
  245. </el-tab-pane> -->
  246. </el-tabs>
  247. <!-- 设备配置JSON -->
  248. <el-dialog :title="$t('device.device-edit.148398-54')" :visible.sync="openSummary" width="700px" append-to-body>
  249. <el-row :gutter="20">
  250. <el-col :span="14">
  251. <div style="border: 1px solid #ccc; height: 234px; width: 360px; overflow: scroll">
  252. <json-viewer :value="summary" :expand-depth="10" copyable style="margin-top: 5px; cursor: pointer">
  253. <template v-slot:copy>{{ $t('device.device-edit.148398-55') }}</template>
  254. </json-viewer>
  255. </div>
  256. </el-col>
  257. <el-col :span="10">
  258. <div style="border: 1px solid #ccc; width: 220px; text-align: center; margin-left: 20px">
  259. <vue-qr :text="qrText" :size="200"></vue-qr>
  260. <div style="padding-bottom: 10px">{{ $t('device.device-edit.148398-56') }}</div>
  261. </div>
  262. </el-col>
  263. </el-row>
  264. <div slot="footer" class="dialog-footer">
  265. <el-button @click="closeSummaryDialog">{{ $t('device.device-edit.148398-57') }}</el-button>
  266. </div>
  267. </el-dialog>
  268. <el-dialog :visible.sync="openCode" width="300px" append-to-body>
  269. <div style="border: 1px solid #ccc; width: 220px; text-align: center; margin: 0 auto; margin-top: -15px">
  270. <vue-qr :text="qrText" :size="200"></vue-qr>
  271. <div style="padding-bottom: 10px">{{ $t('device.device-edit.148398-56') }}</div>
  272. </div>
  273. </el-dialog>
  274. <el-dialog :title="$t('device.device-edit.148398-58')" :visible.sync="openViewMqtt" width="600px" append-to-body>
  275. <el-form ref="listQuery" :model="listQuery" :rules="rules" label-width="120px" v-if="this.form.transport == 'MQTT'">
  276. <el-form-item label="clientId" prop="clientId">
  277. <el-input v-model="listQuery.clientId" disabled style="width: 400px" />
  278. </el-form-item>
  279. <el-form-item label="username" prop="username">
  280. <el-input v-model="listQuery.username" disabled style="width: 400px" />
  281. </el-form-item>
  282. <el-form-item label="passwd" prop="passwd">
  283. <el-input clearable v-model="listQuery.passwd" disabled style="width: 400px"></el-input>
  284. </el-form-item>
  285. <el-form-item label="subscribeTopic" prop="subscribeTopic">
  286. <el-input clearable v-model="listQuery.subscribeTopic" disabled style="width: 400px"></el-input>
  287. </el-form-item>
  288. <el-form-item label="reportTopic" prop="reportTopic">
  289. <el-input clearable v-model="listQuery.reportTopic" disabled style="width: 400px"></el-input>
  290. </el-form-item>
  291. <el-form-item label="port" prop="port">
  292. <el-input clearable v-model="listQuery.port" disabled style="width: 400px"></el-input>
  293. </el-form-item>
  294. </el-form>
  295. <el-form ref="listQuery" :model="listQuery" :rules="rules" label-width="120px" v-if="this.form.transport == 'TCP'">
  296. <!-- 注册包 -->
  297. <el-form-item label="enrollPackage" prop="enrollPackage">
  298. <el-input clearable v-model="listQuery.enrollPackage" disabled style="width: 400px"></el-input>
  299. </el-form-item>
  300. <el-form-item label="port" prop="port">
  301. <el-input clearable v-model="listQuery.port" disabled style="width: 400px"></el-input>
  302. </el-form-item>
  303. </el-form>
  304. <el-form ref="httpForm" :model="httpForm" :rules="rules" label-width="120px" v-if="this.form.transport == 'HTTP'">
  305. <!-- 认证类型 -->
  306. <el-form-item :label="$t('device.device-edit.148398-91')">
  307. <el-input clearable v-model="httpForm.type" disabled style="width: 400px"></el-input>
  308. </el-form-item>
  309. <el-form-item :label="$t('device.device-edit.148398-92')">
  310. <el-input clearable v-model="httpForm.username" disabled style="width: 400px"></el-input>
  311. </el-form-item>
  312. <el-form-item :label="$t('device.device-edit.148398-93')">
  313. <el-input clearable v-model="httpForm.password" disabled style="width: 400px"></el-input>
  314. </el-form-item>
  315. </el-form>
  316. <el-form ref="GBform" :model="GBform" :rules="rules" label-width="120px" v-if="this.form.transport == 'GB28181'">
  317. <!-- 服务器域 -->
  318. <el-form-item :label="$t('device.device-edit.148398-87')">
  319. <el-input clearable v-model="GBform.domainAlias" disabled style="width: 400px"></el-input>
  320. </el-form-item>
  321. <!-- 服务器sipid" -->
  322. <el-form-item :label="$t('device.device-edit.148398-88')">
  323. <el-input clearable v-model="GBform.serverSipid" disabled style="width: 400px"></el-input>
  324. </el-form-item>
  325. <!-- 认证密码-->
  326. <el-form-item :label="$t('device.device-edit.148398-89')">
  327. <el-input clearable v-model="GBform.password" disabled style="width: 400px"></el-input>
  328. </el-form-item>
  329. <!-- 接入端口号 -->
  330. <el-form-item :label="$t('device.device-edit.148398-90')">
  331. <el-input clearable v-model="GBform.port" disabled style="width: 400px"></el-input>
  332. </el-form-item>
  333. </el-form>
  334. <div slot="footer" class="dialog-footer">
  335. <el-button class="btns" type="primary" @click="doCopy(2)">{{ $t('device.device-edit.148398-59') }}</el-button>
  336. <el-button @click="closeSummaryDialog">{{ $t('device.device-edit.148398-57') }}</el-button>
  337. </div>
  338. </el-dialog>
  339. </el-card>
  340. </div>
  341. </template>
  342. <script>
  343. import 'vue-json-viewer/style.css';
  344. import JsonViewer from 'vue-json-viewer';
  345. import productList from './product-list';
  346. import deviceLog from './device-log';
  347. import deviceAlert from './device-alert';
  348. import alertUser from './alert-user';
  349. import deviceUser from './device-user';
  350. import runningStatus from './running-status';
  351. import deviceMonitor from './device-monitor';
  352. import deviceStatistic from './device-statistic';
  353. import instructionParsing from './instruction-parsing';
  354. import deviceModbusTask from './device-modbus-task';
  355. import deviceTimer from './device-timer';
  356. import channel from '../sip/channel';
  357. import player from '@/views/components/player/player.vue';
  358. import deviceVideo from '@/views/components/player/deviceVideo.vue';
  359. import siptalk from '@/views/components/player/webrtc.vue';
  360. import OssRecordList from './oss-record-list.vue';
  361. import deviceLiveStream from '@/views/components/player/deviceLiveStream';
  362. import sipid from '../sip/sipidGen.vue';
  363. import deviceScada from './device-scada';
  364. import deviceVariable from './device-variable-card';
  365. import deviceInlineVideo from './device-inline-video';
  366. import deviceFuncLog from './device-functionlog';
  367. import deviceSub from './device-sub';
  368. import vueQr from 'vue-qr';
  369. import { loadBMap } from '@/utils/map.js';
  370. import { deviceSynchronization, getDevice, addDevice, updateDevice, generatorDeviceNum, getMqttConnect, getSipConfig, getHttpConfig } from '@/api/iot/device';
  371. import { getDeviceRunningStatus } from '@/api/iot/device';
  372. import { cacheJsonThingsModel } from '@/api/iot/model';
  373. import DeviceFunc from '@/views/iot/device/device-functionlog';
  374. import RealTimeStatus from '@/views/iot/device/realTime-status';
  375. import { clientOut } from '@/api/iot/netty';
  376. import defaultSettings from '@/settings';
  377. export default {
  378. name: 'DeviceEdit',
  379. dicts: ['iot_device_status', 'iot_location_way'],
  380. components: {
  381. RealTimeStatus,
  382. DeviceFunc,
  383. deviceLog,
  384. deviceAlert,
  385. deviceUser,
  386. alertUser,
  387. deviceMonitor,
  388. deviceStatistic,
  389. runningStatus,
  390. productList,
  391. deviceTimer,
  392. deviceFuncLog,
  393. deviceVideo,
  394. siptalk,
  395. OssRecordList,
  396. player,
  397. deviceLiveStream,
  398. deviceSub,
  399. JsonViewer,
  400. vueQr,
  401. channel,
  402. sipid,
  403. deviceScada,
  404. deviceVariable,
  405. instructionParsing,
  406. deviceModbusTask,
  407. deviceInlineVideo,
  408. },
  409. watch: {
  410. activeName(val) {
  411. if (val == 'deviceStastic') {
  412. this.$nextTick(() => {
  413. // TODO 重置统计表格的尺寸
  414. });
  415. }
  416. },
  417. },
  418. computed: {
  419. deviceStatus: {
  420. set(val) {
  421. if (val == 1) {
  422. // 1-未激活,2-禁用,3-在线,4-离线
  423. this.form.status = 2;
  424. } else {
  425. this.form.status = this.oldDeviceStatus;
  426. }
  427. },
  428. get() {
  429. if (this.form.status == 2) {
  430. return 1;
  431. }
  432. return 0;
  433. },
  434. },
  435. statusColor() {
  436. switch (this.form.status) {
  437. case 1:
  438. return '#ffba00';
  439. case 2:
  440. return '#f56c6c';
  441. case 3:
  442. return '#67c23a';
  443. case 4:
  444. return '#909399';
  445. default:
  446. return '#f56c6c';
  447. }
  448. },
  449. },
  450. data() {
  451. return {
  452. // 二维码内容
  453. qrText: 'fastbee',
  454. // 打开设备配置对话框
  455. openSummary: false,
  456. //二维码
  457. openCode: false,
  458. openViewMqtt: false,
  459. // 生成设备编码是否禁用
  460. genDisabled: false,
  461. // 选中选项卡
  462. activeName: 'basic',
  463. //查看mqtt参数
  464. mqttList: [],
  465. // 遮罩层
  466. loading: true,
  467. // 设备开始状态
  468. oldDeviceStatus: null,
  469. deviceId: '',
  470. channelId: '',
  471. // 表单参数
  472. form: {
  473. productId: 0,
  474. status: 1,
  475. locationWay: 1,
  476. firmwareType: 1,
  477. firmwareVersion: 1,
  478. serialNumber: '',
  479. deviceType: 1,
  480. isSimulate: 0,
  481. },
  482. //mqtt参数查看
  483. listQuery: {
  484. clientId: 0,
  485. username: '',
  486. passwd: '',
  487. port: '',
  488. },
  489. GBform: {
  490. domainAlias: '',
  491. serverSipid: '',
  492. password: '',
  493. port: '',
  494. },
  495. httpForm: {
  496. type: '',
  497. username: '',
  498. password: '',
  499. },
  500. openServerTip: false,
  501. serverType: 1,
  502. // 设备摘要
  503. summary: [],
  504. // 地址
  505. baseUrl: process.env.VUE_APP_BASE_API,
  506. // 地图相关
  507. map: null,
  508. mk: null,
  509. latitude: '',
  510. longitude: '',
  511. //组态相关按钮是否显示,true显示,false不显示
  512. isShowScada: defaultSettings.isShowScada,
  513. // 表单校验
  514. rules: {
  515. deviceName: [
  516. {
  517. required: true,
  518. message: this.$t('device.device-edit.148398-60'),
  519. trigger: 'blur',
  520. },
  521. {
  522. min: 2,
  523. max: 32,
  524. message: this.$t('device.device-edit.148398-61'),
  525. trigger: 'blur',
  526. },
  527. ],
  528. productName: [
  529. {
  530. required: true,
  531. message: this.$t('device.device-edit.148398-67'),
  532. trigger: 'blur',
  533. },
  534. ],
  535. serialNumber: [
  536. {
  537. required: true,
  538. message: this.$t('device.device-edit.148398-65'),
  539. trigger: 'blur',
  540. },
  541. ],
  542. firmwareVersion: [
  543. {
  544. required: true,
  545. message: this.$t('device.device-edit.148398-62'),
  546. trigger: 'blur',
  547. },
  548. ],
  549. },
  550. isMediaDevice: false,
  551. };
  552. },
  553. created() {
  554. let activeName = this.$route.query.activeName;
  555. if (activeName != null && activeName != '') {
  556. this.activeName = activeName;
  557. }
  558. // 获取设备信息
  559. this.form.deviceId = this.$route.query && this.$route.query.deviceId;
  560. if (this.form.deviceId != 0) {
  561. // this.connectMqtt();
  562. this.getDevice(this.form.deviceId);
  563. }
  564. },
  565. activated() {
  566. // 跳转选项卡
  567. let activeName = this.$route.query.activeName;
  568. if (activeName != null && activeName != '') {
  569. this.activeName = activeName;
  570. }
  571. },
  572. destroyed() {
  573. // 取消订阅主题
  574. this.mqttUnSubscribe(this.form);
  575. },
  576. methods: {
  577. /* 连接Mqtt消息服务器 */
  578. async connectMqtt() {
  579. if (this.$mqttTool.client == null) {
  580. await this.$mqttTool.connect(this.vuex_token);
  581. }
  582. // 删除所有message事件监听器
  583. // this.$mqttTool.client.removeAllListeners('message');
  584. // 添加message事件监听器
  585. this.mqttCallback();
  586. },
  587. /* Mqtt回调处理 */
  588. mqttCallback() {
  589. this.$mqttTool.client.on('message', (topic, message, buffer) => {
  590. let topics = topic.split('/');
  591. let productId = topics[1];
  592. let deviceNum = topics[2];
  593. if (message instanceof Uint8Array) {
  594. // 创建TextDecoder对象来转换Uint8Array到字符串
  595. const decoder = new TextDecoder('utf-8');
  596. const str = decoder.decode(message);
  597. message = str; //转换后的字符串
  598. }
  599. console.log('🚀 ~ this.$mqttTool.client.on ~ message:', message);
  600. console.log('🚀 ~ this.$mqttTool.client.on ~ topics:', topic);
  601. message = JSON.parse(message.toString());
  602. if (!message) {
  603. return;
  604. }
  605. if (topics[3] == 'status' || topics[2] == 'status') {
  606. this.$busEvent.$emit('updateStatus', {
  607. serialNumber: topics[2],
  608. productId: this.form.productId,
  609. data: message,
  610. });
  611. console.log('接收到【设备状态-详情】主题:', topic);
  612. console.log('接收到【设备状态-详情】内容:', message);
  613. // 更新列表中设备的状态
  614. if (this.form.serialNumber == deviceNum) {
  615. this.oldDeviceStatus = message.status;
  616. this.form.status = message.status;
  617. this.form.isShadow = message.isShadow;
  618. this.form.rssi = message.rssi;
  619. }
  620. }
  621. if (topic.endsWith('ws/service')) {
  622. this.$busEvent.$emit('updateData', {
  623. serialNumber: topics[2],
  624. productId: this.form.productId,
  625. data: message,
  626. });
  627. }
  628. if (topic.endsWith('service/reply')) {
  629. this.$busEvent.$emit('updateLog', {
  630. serialNumber: topics[2],
  631. productId: this.form.productId,
  632. data: message,
  633. });
  634. }
  635. /**mqtt测试 */
  636. if (topic.endsWith('message/post')) {
  637. this.$busEvent.$emit('updateMqttMessage', {
  638. serialNumber: topics[2],
  639. data: message,
  640. });
  641. }
  642. });
  643. },
  644. /** Mqtt topics array */
  645. getMqttTopics(device) {
  646. // 订阅当前设备状态和实时监测
  647. const topicService = '/ws/service';
  648. const topicStatus = '/status/post';
  649. const topicFunction = '/function/post';
  650. const topicMonitor = '/monitor/post';
  651. const topicReply = '/service/reply';
  652. //订阅mqtt测试
  653. let messagePost = '/message/post';
  654. const topics = [topicService, topicStatus, topicFunction, topicMonitor, topicReply, messagePost];
  655. return topics.map((topic) => {
  656. return `/${device.productId}/${device.serialNumber}${topic}`;
  657. });
  658. },
  659. // 获取子组件订阅的设备状态
  660. getDeviceStatusData(status) {
  661. this.form.status = status;
  662. },
  663. /** Mqtt取消订阅主题 */
  664. mqttUnSubscribe(device) {
  665. const topics = this.getMqttTopics(device);
  666. this.$mqttTool.unsubscribe(topics);
  667. },
  668. /** Mqtt订阅主题 */
  669. mqttSubscribe(device) {
  670. const topics = this.getMqttTopics(device);
  671. this.$mqttTool.subscribe(topics);
  672. },
  673. // 获取直播子组件传递的激活选项卡名称
  674. getPlayerData(data) {
  675. this.activeName = data.tabName;
  676. this.channelId = data.channelId;
  677. // this.$set(this.form, 'channelId', this.channelId);
  678. this.$nextTick(() => {
  679. if (this.channelId) {
  680. this.$refs.deviceLiveStream.channelId = this.channelId;
  681. this.$refs.deviceLiveStream.changeChannel();
  682. }
  683. });
  684. },
  685. /** 选项卡改变事件*/
  686. tabChange(panel) {
  687. this.$nextTick(() => {
  688. if (this.form.deviceType == 3 && panel.name != 'deviceReturn') {
  689. if (panel.name === 'sipPlayer') {
  690. if (this.$refs.deviceVideo && this.$refs.deviceVideo.destroy) {
  691. this.$refs.deviceVideo.destroy();
  692. }
  693. if (this.channelId) {
  694. if (this.$refs.deviceLiveStream && this.$refs.deviceLiveStream.channelId !== undefined) {
  695. this.$refs.deviceLiveStream.channelId = this.channelId;
  696. }
  697. this.$refs.deviceLiveStream.changeChannel();
  698. }
  699. if (this.$refs.deviceLiveStream.channelId !== undefined) {
  700. this.$refs.deviceLiveStream.changeChannel();
  701. }
  702. } else if (panel.name === 'sipVideo') {
  703. if (this.$refs.deviceLiveStream && this.$refs.deviceLiveStream.destroy) {
  704. this.$refs.deviceLiveStream.destroy();
  705. }
  706. if (this.$refs.deviceVideo && this.$refs.deviceVideo.channelId !== undefined && this.$refs.deviceVideo.queryDate) {
  707. this.$refs.deviceVideo.loadDevRecord();
  708. }
  709. } else if (panel.name === 'sipChannel') {
  710. this.$nextTick(() => {
  711. this.$refs.Channel.getList();
  712. });
  713. }
  714. //关闭直播流
  715. if (panel.name !== 'sipPlayer' && this.$refs.deviceLiveStream && this.$refs.deviceLiveStream.playing) {
  716. this.$refs.deviceLiveStream.closeDestroy(false);
  717. }
  718. //关闭录像流
  719. if (panel.name !== 'sipVideo' && this.$refs.deviceVideo && this.$refs.deviceVideo.playing) {
  720. this.$refs.deviceVideo.closeDestroy();
  721. }
  722. }
  723. });
  724. this.$nextTick(() => {
  725. // 获取监测统计数据
  726. if (panel.name === 'deviceStastic') {
  727. this.$refs.deviceStatistic.getListHistory();
  728. } else if (panel.name === 'deviceTimer') {
  729. this.$refs.deviceTimer.getList();
  730. } else if (panel.name === 'deviceSub') {
  731. if (this.form.serialNumber) {
  732. this.$refs.deviceSub.queryParams.gwDeviceId = this.form.deviceId;
  733. this.$refs.deviceSub.gateway.gwDeviceId = this.form.deviceId;
  734. this.$refs.deviceSub.getList();
  735. }
  736. }
  737. });
  738. if (this.form.deviceType !== 3) {
  739. // 用于关闭视频推流(页面切换时候需要关闭推流)
  740. if (panel.name !== 'inlineVideo') {
  741. this.$refs.deviceInlineVideo && this.$refs.deviceInlineVideo.handleClose();
  742. }
  743. if (panel.name !== 'scada') {
  744. const scadaRef = this.$refs.deviceScada || {};
  745. if (scadaRef && scadaRef.$refs && scadaRef.$refs.deviceScada) {
  746. const copmRef = scadaRef.$refs.deviceScada;
  747. if (copmRef.$refs && copmRef.$refs.spirit) {
  748. copmRef.$refs.spirit.forEach((item) => {
  749. if (item.$vnode.tag.includes('ViewInlineVideo')) {
  750. item.handleCloseJessibuca();
  751. }
  752. });
  753. }
  754. }
  755. }
  756. }
  757. },
  758. /** 数据同步*/
  759. deviceSynchronization() {
  760. deviceSynchronization(this.form.serialNumber).then(async (response) => {
  761. // 获取缓存物模型
  762. response.data.cacheThingsModel = await this.getCacheThingsModdel(response.data.productId);
  763. // 获取设备运行状态
  764. response.data.thingsModels = await this.getDeviceStatus(this.form);
  765. // 格式化物模型,拆分出监测值,数组添加前缀
  766. this.formatThingsModel(response.data);
  767. this.form = response.data;
  768. // 选项卡切换
  769. this.activeName = 'runningStatus';
  770. this.oldDeviceStatus = this.form.status;
  771. this.loadMap();
  772. });
  773. },
  774. /**获取设备详情*/
  775. getDevice(deviceId) {
  776. getDevice(deviceId).then(async (response) => {
  777. this.form.protocolCode = response.data.protocolCode;
  778. // 获取设备状态和物模型
  779. this.getDeviceStatusWitchThingsModel(response);
  780. });
  781. },
  782. /**用户是否拥有分享设备权限*/
  783. // hasShrarePerm(permission) {
  784. // if (this.form.isOwner == 0) {
  785. // // 分享设备权限
  786. // if (this.form.userPerms.indexOf(permission) == -1) {
  787. // return false;
  788. // }
  789. // }
  790. // return true;
  791. // },
  792. /** 获取缓存物模型*/
  793. getCacheThingsModdel(productId) {
  794. return new Promise((resolve, reject) => {
  795. cacheJsonThingsModel(productId)
  796. .then((response) => {
  797. resolve(JSON.parse(response.data));
  798. })
  799. .catch((error) => {
  800. reject(error);
  801. });
  802. });
  803. },
  804. /**获取设备运行状态*/
  805. getDeviceStatus(data) {
  806. const params = {
  807. deviceId: data.deviceId,
  808. slaveId: data.slaveId,
  809. };
  810. return new Promise((resolve, reject) => {
  811. getDeviceRunningStatus(params)
  812. .then((response) => {
  813. resolve(response.data.thingsModels);
  814. })
  815. .catch((error) => {
  816. reject(error);
  817. });
  818. });
  819. },
  820. formatThingsModel(data) {
  821. data.chartList = [];
  822. data.monitorList = [];
  823. data.staticList = [];
  824. // 物模型格式化
  825. for (let i = 0; i < data.thingsModels.length; i++) {
  826. // 数字类型设置默认值并转换未数值
  827. if (data.thingsModels[i].datatype.type == 'integer' || data.thingsModels[i].datatype.type == 'decimal') {
  828. if (data.thingsModels[i].shadow == '') {
  829. data.thingsModels[i].shadow = Number(data.thingsModels[i].datatype.min);
  830. } else {
  831. data.thingsModels[i].shadow = Number(data.thingsModels[i].shadow);
  832. }
  833. }
  834. // 物模型分类放置
  835. if (data.thingsModels[i].datatype.type == 'array') {
  836. if (data.thingsModels[i].datatype.arrayType == 'object' && data.thingsModels[i].datatype.arrayParams.length > 0) {
  837. for (let k = 0; k < data.thingsModels[i].datatype.arrayParams.length; k++) {
  838. for (let j = 0; j < data.thingsModels[i].datatype.arrayParams[k].length; j++) {
  839. // 数组元素中参数ID添加前缀,例如:array_00_
  840. let index = k > 9 ? String(k) : '0' + k;
  841. let prefix = 'array_' + index + '_';
  842. data.thingsModels[i].datatype.arrayParams[k][j].id = prefix + data.thingsModels[i].datatype.arrayParams[k][j].id;
  843. // 图表、实时监测、监测统计分类放置
  844. if (data.thingsModels[i].datatype.arrayParams[k][j].isChart == 1) {
  845. // 图表
  846. data.thingsModels[i].datatype.arrayParams[k][j].name = '[' + data.thingsModels[i].name + (k + 1) + '] ' + data.thingsModels[i].datatype.arrayParams[k][j].name;
  847. data.thingsModels[i].datatype.arrayParams[k][j].datatype.arrayType = 'object';
  848. data.chartList.push(data.thingsModels[i].datatype.arrayParams[k][j]);
  849. if (data.thingsModels[i].datatype.arrayParams[k][j].isHistory == 1) {
  850. // 监测统计
  851. data.staticList.push(data.thingsModels[i].datatype.arrayParams[k][j]);
  852. }
  853. if (data.thingsModels[i].datatype.arrayParams[k][j].isMonitor == 1) {
  854. // 实时监测
  855. data.monitorList.push(data.thingsModels[i].datatype.arrayParams[k][j]);
  856. }
  857. data.thingsModels[i].datatype.arrayParams[k].splice(j--, 1);
  858. }
  859. }
  860. }
  861. } else if (data.thingsModels[i].datatype.arrayCount > 0) {
  862. // 字符串拆分为物模型数组 model=id/name/type/isReadonly/value/shadow
  863. let values = data.thingsModels[i].value != '' ? data.thingsModels[i].value.split(',') : [];
  864. let shadows = data.thingsModels[i].shadow != '' ? data.thingsModels[i].shadow.split(',') : [];
  865. for (let j = 0; j < data.thingsModels[i].datatype.arrayCount; j++) {
  866. if (!data.thingsModels[i].datatype.arrayModel) {
  867. data.thingsModels[i].datatype.arrayModel = [];
  868. }
  869. // 数组里面的ID需要添加前缀和索引,例如:array_00_temperature
  870. let index = j > 9 ? String(j) : '0' + j;
  871. let prefix = 'array_' + index + '_';
  872. data.thingsModels[i].datatype.arrayModel[j] = {
  873. id: prefix + data.thingsModels[i].id,
  874. name: data.thingsModels[i].name,
  875. type: data.thingsModels[i].type,
  876. isReadonly: data.thingsModels[i].isReadonly,
  877. value: values[j] ? values[j] : '',
  878. shadow: shadows[j] ? shadows[j] : '',
  879. };
  880. }
  881. }
  882. } else if (data.thingsModels[i].datatype.type == 'object' && data.thingsModels[i].datatype.params.length > 0) {
  883. for (let j = 0; j < data.thingsModels[i].datatype.params.length; j++) {
  884. // 图表、实时监测、监测统计分类放置
  885. if (data.thingsModels[i].datatype.params[j].isChart == 1) {
  886. // 图表
  887. data.thingsModels[i].datatype.params[j].name = '[' + data.thingsModels[i].name + '] ' + data.thingsModels[i].datatype.params[j].name;
  888. data.chartList.push(data.thingsModels[i].datatype.params[j]);
  889. if (data.thingsModels[i].datatype.params[j].isHistory == 1) {
  890. // 监测统计
  891. data.staticList.push(data.thingsModels[i].datatype.params[j]);
  892. }
  893. if (data.thingsModels[i].datatype.params[j].isMonitor == 1) {
  894. // 实时监测
  895. data.monitorList.push(data.thingsModels[i].datatype.params[j]);
  896. }
  897. data.thingsModels[i].datatype.params.splice(j--, 1);
  898. }
  899. }
  900. } else if (data.thingsModels[i].isChart == 1) {
  901. // // 图表、实时监测、监测统计分类放置
  902. data.chartList.push(data.thingsModels[i]);
  903. if (data.thingsModels[i].isHistory == 1) {
  904. // 监测统计
  905. data.staticList.push(data.thingsModels[i]);
  906. }
  907. if (data.thingsModels[i].isMonitor == 1) {
  908. // 实时监测
  909. data.monitorList.push(data.thingsModels[i]);
  910. }
  911. // 使用i--解决索引变更问题
  912. data.thingsModels.splice(i--, 1);
  913. }
  914. }
  915. },
  916. /**加载地图*/
  917. loadMap() {
  918. this.$nextTick(() => {
  919. loadBMap().then(() => {
  920. this.getmap();
  921. });
  922. });
  923. },
  924. /** 返回按钮 */
  925. goBack() {
  926. const obj = {
  927. path: '/iot/device',
  928. query: {
  929. t: Date.now(),
  930. pageNum: this.$route.query.pageNum,
  931. },
  932. };
  933. this.$tab.closeOpenPage(obj);
  934. this.reset();
  935. },
  936. // 表单重置
  937. reset() {
  938. this.form = {
  939. deviceId: 0,
  940. deviceName: null,
  941. productId: null,
  942. productName: null,
  943. userId: null,
  944. userName: null,
  945. tenantId: null,
  946. tenantName: null,
  947. serialNumber: '',
  948. firmwareType: 1,
  949. firmwareVersion: 1,
  950. status: 1,
  951. rssi: null,
  952. networkAddress: null,
  953. networkIp: null,
  954. longitude: null,
  955. latitude: null,
  956. activeTime: null,
  957. createBy: null,
  958. createTime: null,
  959. updateBy: null,
  960. updateTime: null,
  961. remark: null,
  962. locationWay: 1,
  963. clientId: 0,
  964. };
  965. this.deviceStatus = 0;
  966. this.resetForm('form');
  967. },
  968. /** 提交按钮 */
  969. async submitForm() {
  970. if (this.form.serialNumber == null || this.form.serialNumber == 0) {
  971. this.$modal.alertError(this.$t('device.device-edit.148398-65'));
  972. return;
  973. }
  974. let reg = /^[0-9a-zA-Z]+$/;
  975. if (!reg.test(this.form.serialNumber)) {
  976. this.$modal.alertError(this.$t('device.device-edit.148398-66'));
  977. return;
  978. }
  979. if (this.form.productId == null || this.form.productId == 0) {
  980. this.$modal.alertError(this.$t('device.device-edit.148398-67'));
  981. return;
  982. }
  983. this.$refs['form'].validate((valid) => {
  984. if (valid) {
  985. if (this.form.deviceId != 0) {
  986. updateDevice(this.form).then((response) => {
  987. if (response.data == 0) {
  988. this.$modal.alertError(response.msg);
  989. } else {
  990. this.$modal.alertSuccess(this.$t('device.device-edit.148398-68'));
  991. this.form = JSON.parse(JSON.stringify(this.form));
  992. this.loadMap();
  993. //是否设备设置为禁用状态,则踢出设备
  994. if (this.form.status === 2) {
  995. const params = { clientId: this.form.serialNumber };
  996. clientOut(params).then((res) => {});
  997. }
  998. }
  999. });
  1000. } else {
  1001. addDevice(this.form).then(async (response) => {
  1002. // 获取设备状态
  1003. await this.getDeviceStatusWitchThingsModel(response);
  1004. if (this.form.deviceId == null || this.form.deviceId == 0) {
  1005. this.$modal.alertError(this.$t('device.device-edit.148398-69'));
  1006. } else {
  1007. if (this.form.status == 2) {
  1008. this.deviceStatus = 1;
  1009. }
  1010. this.$modal.alertSuccess(this.$t('device.device-edit.148398-70'));
  1011. this.loadMap();
  1012. }
  1013. });
  1014. }
  1015. }
  1016. });
  1017. },
  1018. /** 获取设备状态和物模型 **/
  1019. async getDeviceStatusWitchThingsModel(response) {
  1020. // 获取缓存物模型
  1021. response.data.cacheThingsModel = await this.getCacheThingsModdel(response.data.productId);
  1022. // 获取设备运行状态
  1023. response.data.thingsModels = await this.getDeviceStatus(response.data);
  1024. //分享设备过滤没有权限的物模型
  1025. // if (response.data.isOwner == 0) {
  1026. // for (let i = 0; i < response.data.thingsModels.length; i++) {
  1027. // if (response.data.userPerms.indexOf(response.data.thingsModels[i].id) == -1) {
  1028. // response.data.thingsModels.splice(i--, 1)
  1029. // }
  1030. // }
  1031. // }
  1032. // 格式化物模型,拆分出监测值,数组添加前缀
  1033. this.formatThingsModel(response.data);
  1034. this.form = response.data;
  1035. // 解析设备摘要
  1036. if (this.form.summary != null && this.form.summary != '') {
  1037. this.summary = JSON.parse(this.form.summary);
  1038. }
  1039. this.oldDeviceStatus = this.form.status;
  1040. this.loadMap();
  1041. //Mqtt订阅
  1042. this.connectMqtt();
  1043. this.mqttSubscribe(this.form);
  1044. },
  1045. /**选择产品 */
  1046. selectProduct() {
  1047. this.$refs.productList.open = true;
  1048. this.$refs.productList.getList();
  1049. },
  1050. genSipID() {
  1051. this.$refs.sipidGen.open = true;
  1052. },
  1053. /**获取选中的产品 */
  1054. getProductData(product) {
  1055. this.form.productId = product.productId;
  1056. this.form.productName = product.productName;
  1057. this.form.deviceType = product.deviceType;
  1058. this.form.protocolCode = product.protocolCode;
  1059. this.form.tenantId = product.tenantId;
  1060. this.form.tenantName = product.tenantName;
  1061. if (product.transport === 'TCP') {
  1062. this.openServerTip = true;
  1063. this.serverType = 3;
  1064. } else {
  1065. this.openServerTip = false;
  1066. this.serverType = 1;
  1067. }
  1068. },
  1069. // 获取监控产品设备编号
  1070. getSipIDData(devsipid) {
  1071. this.form.serialNumber = devsipid;
  1072. },
  1073. // 获取选中的用户
  1074. getUserData(user) {},
  1075. /**关闭物模型 */
  1076. openSummaryDialog() {
  1077. let json = {
  1078. type: 1, // 1=扫码关联设备
  1079. deviceNumber: this.form.serialNumber,
  1080. productId: this.form.productId,
  1081. // productName: this.form.productName,
  1082. };
  1083. this.qrText = JSON.stringify(json);
  1084. this.openSummary = true;
  1085. },
  1086. /**关闭物模型 */
  1087. closeSummaryDialog() {
  1088. this.openSummary = false;
  1089. this.openViewMqtt = false;
  1090. },
  1091. doCopy() {
  1092. const input = document.createElement('input');
  1093. if (this.form.transport == 'MQTT') {
  1094. input.value =
  1095. '{clientId:' +
  1096. this.listQuery.clientId +
  1097. ',username:' +
  1098. this.listQuery.username +
  1099. ',passwd:' +
  1100. this.listQuery.passwd +
  1101. ',subscribeTopic:' +
  1102. this.listQuery.subscribeTopic +
  1103. ',reportTopic:' +
  1104. this.listQuery.reportTopic +
  1105. ',port:' +
  1106. this.listQuery.port +
  1107. '}';
  1108. } else if (this.form.transport == 'TCP') {
  1109. input.value = '{enrollPackage:' + this.listQuery.enrollPackage + ',port:' + this.listQuery.port + '}';
  1110. } else if (this.form.transport == 'HTTP') {
  1111. input.value = '{type:' + this.httpForm.type + ',username:' + this.httpForm.username + ',password:' + this.httpForm.password + '}';
  1112. }
  1113. if (this.form.transport == 'GB28181') {
  1114. input.value = '{domainAlias:' + this.GBform.domainAlias + ',serverSipid:' + this.GBform.serverSipid + ',password:' + this.GBform.password + ',port:' + this.GBform.port + '}';
  1115. }
  1116. document.body.appendChild(input);
  1117. input.select(); //选中输入框
  1118. document.execCommand('Copy'); //复制当前选中文本到剪切板
  1119. document.body.removeChild(input);
  1120. this.$message.success(this.$t('device.device-edit.148398-71'));
  1121. },
  1122. openCodeDialog() {
  1123. let json = {
  1124. type: 1, // 1=扫码关联设备
  1125. deviceNumber: this.form.serialNumber,
  1126. productId: this.form.productId,
  1127. productName: this.form.productName,
  1128. };
  1129. this.qrText = JSON.stringify(json);
  1130. this.openCode = true;
  1131. },
  1132. // 地图定位
  1133. getmap() {
  1134. this.map = new BMap.Map('map');
  1135. let point = null;
  1136. if (this.form.longitude != null && this.form.longitude != '' && this.form.latitude != null && this.form.latitude != '') {
  1137. point = new BMap.Point(this.form.longitude, this.form.latitude);
  1138. } else {
  1139. point = new BMap.Point(116.404, 39.915);
  1140. }
  1141. this.map.centerAndZoom(point, 19);
  1142. this.map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
  1143. this.map.addControl(new BMap.NavigationControl());
  1144. // 标注设备位置
  1145. this.mk = new BMap.Marker(point);
  1146. this.map.addOverlay(this.mk);
  1147. this.map.panTo(point);
  1148. },
  1149. // 生成随机字母和数字
  1150. generateNum() {
  1151. if (!this.form.productId || this.form.productId == 0) {
  1152. this.$modal.alertError(this.$t('device.device-edit.148398-72'));
  1153. return;
  1154. }
  1155. this.genDisabled = true;
  1156. const params = { type: this.serverType };
  1157. generatorDeviceNum(params).then((response) => {
  1158. this.form.serialNumber = response.data;
  1159. this.genDisabled = false;
  1160. });
  1161. },
  1162. //mqtt参数查看
  1163. handleViewMqtt() {
  1164. this.openViewMqtt = true;
  1165. this.loading = true;
  1166. if (this.form.transport === 'MQTT' || this.form.transport === 'TCP') {
  1167. const params = {
  1168. deviceId: this.form.deviceId,
  1169. };
  1170. getMqttConnect(params).then((response) => {
  1171. if (response.code == 200) {
  1172. this.listQuery = response.data;
  1173. this.loading = false;
  1174. }
  1175. });
  1176. } else if (this.form.transport === 'GB28181') {
  1177. const deviceSipId = this.form.deviceId;
  1178. getSipConfig(deviceSipId).then((response) => {
  1179. if (response.code == 200) {
  1180. this.GBform = response.data;
  1181. this.loading = false;
  1182. }
  1183. });
  1184. } else if (this.form.transport === 'HTTP') {
  1185. const params = {
  1186. deviceId: this.form.deviceId,
  1187. };
  1188. getHttpConfig(params).then((response) => {
  1189. if (response.code == 200) {
  1190. this.httpForm = response.data;
  1191. this.loading = false;
  1192. }
  1193. });
  1194. }
  1195. },
  1196. },
  1197. };
  1198. </script>
  1199. <style lang="scss" scoped>
  1200. .device-edit {
  1201. padding: 20px;
  1202. .top-card {
  1203. margin-bottom: 10px;
  1204. .title-wrap {
  1205. display: flex;
  1206. flex-direction: row;
  1207. align-items: center;
  1208. .top-button {
  1209. height: 22px;
  1210. color: #909399;
  1211. background: #f4f5f7;
  1212. padding: 0px 8px;
  1213. border: none;
  1214. }
  1215. .info-item {
  1216. font-weight: normal;
  1217. font-size: 14px;
  1218. color: #333333;
  1219. line-height: 20px;
  1220. margin-left: 36px;
  1221. .status {
  1222. position: relative;
  1223. margin-left: 4px;
  1224. .dot {
  1225. position: absolute;
  1226. top: 3px;
  1227. left: -8px;
  1228. width: 4px;
  1229. height: 4px;
  1230. border-radius: 50%;
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. .custom-tabs {
  1237. .basic-span {
  1238. margin-top: 16px;
  1239. }
  1240. ::v-deep .el-card__body {
  1241. padding: 0 20px;
  1242. }
  1243. ::v-deep .el-tabs__active-bar {
  1244. background-color: transparent;
  1245. }
  1246. ::v-deep.el-tabs__nav {
  1247. margin-bottom: 12px;
  1248. }
  1249. ::v-deep .el-tabs__item {
  1250. padding: 0px 25px !important;
  1251. box-sizing: border-box;
  1252. display: inline-block;
  1253. list-style: none;
  1254. font-size: 14px;
  1255. font-weight: 500;
  1256. color: #303133;
  1257. position: relative;
  1258. }
  1259. ::v-deep .el-tabs__item.is-active {
  1260. color: #fff;
  1261. background-color: #486ff2;
  1262. border-radius: 4px;
  1263. height: 32px;
  1264. line-height: 34px;
  1265. }
  1266. .alert-wrap {
  1267. height: 35px;
  1268. margin-top: 10px;
  1269. ::v-deep .el-alert__icon {
  1270. font-size: 16px;
  1271. width: 16px;
  1272. }
  1273. ::v-deep .el-alert__description {
  1274. font-size: 12px;
  1275. margin: 0;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. </style>