detail.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. <template>
  2. <div class="system-dic-container">
  3. <div class="content">
  4. <div class="cont_box">
  5. <div class="title">设备:{{ detail.name }}</div>
  6. <div class="pro-status"><span :class="developer_status == 2 ? 'on' : 'off'"></span>{{ developer_status == 2 ? '在线' : '离线' }}</div>
  7. <!-- <div class="pro-option" @click="CkOption">{{ developer_status == 2 ? '下线' : '上线' }}</div> -->
  8. </div>
  9. </div>
  10. <div class="content-box">
  11. <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
  12. <el-tab-pane label="运行状态" name="3">
  13. <div style=" display: flex; padding: 10px;flex-wrap: wrap;" >
  14. <div class="ant-card">
  15. <div class="ant-card-body">
  16. <div class="cardflex">
  17. <div>设备状态</div>
  18. <div @click="getrunData()" style="cursor: pointer;">
  19. <el-icon style="font-size: 18px;">
  20. <ele-Refresh />
  21. </el-icon>
  22. </div>
  23. </div>
  24. <div class="statusname" v-if="areaData.status==0">未启用</div>
  25. <div class="statusname" v-if="areaData.status==1">离线</div>
  26. <div class="statusname" v-if="areaData.status==2">在线</div>
  27. <div class="cardflex comtest">
  28. <div> 数据时间</div>
  29. <div>{{areaData.lastOnlineTime || '未启用'}}</div>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="ant-card" v-for="(item, index) in areaData.properties" :key="index">
  34. <div class="ant-card-body">
  35. <div class="cardflex">
  36. <div>{{item.name}}</div>
  37. <div style="cursor: pointer;">
  38. <el-icon style="font-size: 18px;" @click="getrunData()">
  39. <ele-Refresh />
  40. </el-icon>
  41. <el-icon style="font-size: 18px; margin-left: 10px;" @click="onOpenListDetail(item)">
  42. <ele-Expand />
  43. </el-icon>
  44. </div>
  45. </div>
  46. <div class="statusname">{{item.value}}{{item.unit}}</div>
  47. <div class="">
  48. <devantd :json="item.list" :antdid="item.key" v-if="item.type=='int' || item.type=='float'"/>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </el-tab-pane>
  54. <el-tab-pane label="设备信息" name="1">
  55. <div class="pro-box">
  56. <div class="protitle">设备信息</div>
  57. <div>
  58. <el-button type="primary" @click="onOpenEditDic(detail)">编辑</el-button>
  59. </div>
  60. </div>
  61. <div class="ant-descriptions-view">
  62. <table>
  63. <tbody>
  64. <tr class="ant-descriptions-row">
  65. <th class="ant-descriptions-item-label ant-descriptions-item-colon">设备标识</th>
  66. <td class="ant-descriptions-item-content" colspan="1">{{ detail.key }}</td>
  67. <th class="ant-descriptions-item-label ant-descriptions-item-colon">设备名称</th>
  68. <td class="ant-descriptions-item-content" colspan="1">{{ detail.name }}</td>
  69. <th class="ant-descriptions-item-label ant-descriptions-item-colon">所属产品</th>
  70. <td class="ant-descriptions-item-content" colspan="1">{{ detail.productName }}</td>
  71. </tr>
  72. <tr class="ant-descriptions-row">
  73. <th class="ant-descriptions-item-label ant-descriptions-item-colon">消息协议</th>
  74. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.messageProtocol }}</td>
  75. <th class="ant-descriptions-item-label ant-descriptions-item-colon">链接协议</th>
  76. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.transportProtocol }}</td>
  77. <th class="ant-descriptions-item-label ant-descriptions-item-colon">设备类型</th>
  78. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.deviceType }}</td>
  79. </tr>
  80. <tr class="ant-descriptions-row">
  81. <th class="ant-descriptions-item-label ant-descriptions-item-colon">固件版本</th>
  82. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.version }}</td>
  83. <th class="ant-descriptions-item-label ant-descriptions-item-colon">注册时间</th>
  84. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.updatedAt }}</td>
  85. <th class="ant-descriptions-item-label ant-descriptions-item-colon">最后上线时间</th>
  86. <td class="ant-descriptions-item-content" colspan="1">{{ prodetail.lastOnlineTime || '' }}</td>
  87. </tr>
  88. <tr class="ant-descriptions-row">
  89. <th class="ant-descriptions-item-label ant-descriptions-item-colon">说明</th>
  90. <td class="ant-descriptions-item-content" colspan="5">{{ prodetail.desc }}</td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. </div>
  95. <div class="flex" style="margin-top: 20px;" >
  96. <el-input type="number" style="width: 380px;margin-right: 20px;" v-model.number="detail.onlineTimeout">
  97. <template #prepend>设备超时时间</template>
  98. <template #append>秒</template>
  99. </el-input>
  100. <el-button type="primary" @click="onlineTimeoutUpdate">
  101. <el-icon style="font-size: 18px;"><ele-Refresh /></el-icon>更新</el-button>
  102. </div>
  103. </el-tab-pane>
  104. <el-tab-pane label="物模型" name="2">
  105. <div class="wu-box">
  106. <el-tabs type="border-card" v-model="activetab" @tab-click="wuhandleClick">
  107. <el-tab-pane label="属性定义" name="attr">
  108. <div class="wu-title">
  109. <div class="title">属性定义</div>
  110. <div>
  111. <el-button type="primary" @click="onOpenEditAttr()">添加</el-button>
  112. </div>
  113. </div>
  114. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'attr'">
  115. <el-table-column label="属性标识" align="center" prop="key" />
  116. <el-table-column label="属性名称" prop="name" :show-overflow-tooltip="true" />
  117. <el-table-column prop="valueType" label="数据类型" width="100" align="center">
  118. <template #default="scope">
  119. <span>{{ scope.row.valueType.type }}</span>
  120. </template>
  121. </el-table-column>
  122. <el-table-column prop="decimals" label="精度" width="60" align="center">
  123. <template #default="scope">
  124. <span>{{ scope.row.valueType.decimals }}</span>
  125. </template>
  126. </el-table-column>
  127. <el-table-column prop="unit" label="单位" width="60" align="center">
  128. <template #default="scope">
  129. <span>{{ scope.row.valueType.unit }}</span>
  130. </template>
  131. </el-table-column>
  132. <el-table-column prop="accessMode" label="是否只读" width="120" align="center">
  133. <template #default="scope">
  134. <el-tag type="info" size="small" v-if="scope.row.accessMode">只读</el-tag>
  135. <el-tag type="success" size="small" v-else>读写</el-tag>
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="说明" prop="desc" :show-overflow-tooltip="true" />
  139. <el-table-column label="操作" width="300" align="center" fixed="right">
  140. <template #default="scope">
  141. <el-button size="small" text type="warning" @click="onEditAttr(scope.row)">修改</el-button>
  142. <el-button size="small" text type="danger" @click="onRowDel(scope.row.key, 'attr')">删除</el-button>
  143. </template>
  144. </el-table-column>
  145. </el-table>
  146. </el-tab-pane>
  147. <el-tab-pane label="功能定义" name="fun">
  148. <div class="wu-title">
  149. <div class="title">功能定义</div>
  150. <div>
  151. <el-button type="primary" @click="onOpenEditFun()">添加</el-button>
  152. </div>
  153. </div>
  154. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'fun'">
  155. <el-table-column label="功能标识" align="center" prop="key" />
  156. <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" />
  157. <el-table-column label="描述" prop="desc" :show-overflow-tooltip="true" />
  158. <el-table-column label="操作" width="300" align="center" fixed="right">
  159. <template #default="scope">
  160. <el-button size="small" text type="warning" @click="onEditFun(scope.row)">修改</el-button>
  161. <el-button size="small" text type="danger" @click="onRowDel(scope.row.key, 'fun')">删除</el-button>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. </el-tab-pane>
  166. <el-tab-pane label="事件定义" name="event">
  167. <div class="wu-title">
  168. <div class="title">事件定义</div>
  169. <div>
  170. <el-button type="primary" @click="onOpenEditEvent()">添加</el-button>
  171. </div>
  172. </div>
  173. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'event'">
  174. <el-table-column label="事件标识" align="center" prop="key" />
  175. <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" />
  176. <el-table-column prop="level" label="事件级别" width="120" align="center">
  177. <template #default="scope">
  178. <el-tag type="primary" size="small" v-if="scope.row.level == 0">普通</el-tag>
  179. <el-tag type="warning" size="small" v-if="scope.row.level == 1">警告</el-tag>
  180. <el-tag type="danger" size="small" v-if="scope.row.level == 2">紧急</el-tag>
  181. </template>
  182. </el-table-column>
  183. <el-table-column label="描述" prop="desc" :show-overflow-tooltip="true" />
  184. <el-table-column label="操作" width="300" align="center" fixed="right">
  185. <template #default="scope">
  186. <el-button size="small" text type="warning" @click="onEditEvent(scope.row)">修改</el-button>
  187. <el-button size="small" text type="danger" @click="onRowDel(scope.row.key, 'event')">删除</el-button>
  188. </template>
  189. </el-table-column>
  190. </el-table>
  191. </el-tab-pane>
  192. <el-tab-pane label="标签定义" name="tab">
  193. <div class="wu-title">
  194. <div class="title">标签定义</div>
  195. <div>
  196. <el-button type="primary" @click="onOpenEditTab()">添加</el-button>
  197. </div>
  198. </div>
  199. <el-table style="width: 100%" :data="tableData.data" v-if="activetab == 'tab'">
  200. <el-table-column label="属性标识" align="center" prop="key" />
  201. <el-table-column label="属性名称" prop="name" :show-overflow-tooltip="true" />
  202. <el-table-column prop="valueType" label="数据类型" width="120" align="center">
  203. <template #default="scope">
  204. <span>{{ scope.row.valueType.type }}</span>
  205. </template>
  206. </el-table-column>
  207. <el-table-column prop="accessMode" label="是否只读" width="120" align="center">
  208. <template #default="scope">
  209. <el-tag type="info" size="small" v-if="scope.row.accessMode">只读</el-tag>
  210. <el-tag type="success" size="small" v-else>读写</el-tag>
  211. </template>
  212. </el-table-column>
  213. <el-table-column label="描述" prop="desc" :show-overflow-tooltip="true" />
  214. <el-table-column label="操作" width="300" align="center" fixed="right">
  215. <template #default="scope">
  216. <el-button size="small" text type="warning" @click="onEditTag(scope.row)">修改</el-button>
  217. <el-button size="small" text type="danger" @click="onRowDel(scope.row.key, 'tab')">删除</el-button>
  218. </template>
  219. </el-table-column>
  220. </el-table>
  221. </el-tab-pane>
  222. </el-tabs>
  223. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getList" />
  224. </div>
  225. </el-tab-pane>
  226. <el-tab-pane label="设备功能" name="5">
  227. <functionCom :device-key="detail.key" :product-key="prodetail.key" v-if="detail.key && prodetail.key"></functionCom>
  228. </el-tab-pane>
  229. <el-tab-pane label="日志管理" name="4">
  230. <div class="system-user-search mb15">
  231. <el-form :model="logtableData.param" ref="queryRef" :inline="true" label-width="68px">
  232. <el-form-item label="日志类型" prop="types">
  233. <el-select v-model="logtableData.param.types" placeholder="日志类型" clearable size="default">
  234. <el-option v-for="item in logTypeData" :key="item" :label="item" :value="item" />
  235. </el-select>
  236. </el-form-item>
  237. <el-form-item label="创建时间" prop="dateRange">
  238. <el-date-picker v-model="logtableData.param.dateRange" size="default" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  239. </el-form-item>
  240. <el-form-item>
  241. <el-button size="default" type="primary" class="ml10" @click="getlog">
  242. <el-icon>
  243. <ele-Search />
  244. </el-icon>
  245. 查询
  246. </el-button>
  247. <el-button size="default" @click="resetQuery(queryRef)">
  248. <el-icon>
  249. <ele-Refresh />
  250. </el-icon>
  251. 重置
  252. </el-button>
  253. </el-form-item>
  254. </el-form>
  255. </div>
  256. <el-table style="width: 100%" :data="logtableData.data">
  257. <el-table-column label="类型" align="center" prop="type" />
  258. <el-table-column label="时间" prop="ts" :show-overflow-tooltip="true" />
  259. <el-table-column label="内容" prop="content" :show-overflow-tooltip="true" />
  260. <el-table-column label="操作" width="300" align="center" fixed="right">
  261. <template #default="scope">
  262. <el-button size="small" text type="warning" @click="onLogDetail(scope.row)">查看</el-button>
  263. </template>
  264. </el-table-column>
  265. </el-table>
  266. <pagination v-show="logtableData.total > 0" :total="logtableData.total" v-model:page="logtableData.param.pageNum" v-model:limit="logtableData.param.pageSize" @pagination="getlog" />
  267. </el-tab-pane>
  268. <el-tab-pane v-if="prodetail.deviceType == '网关'" label="子设备" name="6">
  269. <div class="wu-box">
  270. <div class="wu-title">
  271. <div class="title">子设备列表</div>
  272. <div>
  273. <el-button v-auth="'mutipleBind'" type="primary" @click="onOpenMutipleBind()">批量绑定</el-button>
  274. <el-button :disabled="!deviceKeyList.length" type="primary" @click="mutipleUnbind()">批量解绑</el-button>
  275. </div>
  276. </div>
  277. <el-table :data="deviceTableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="deviceTableData.loading">
  278. <el-table-column type="selection" width="55" align="center" />
  279. <el-table-column label="标识" prop="key" width="130" :show-overflow-tooltip="true" />
  280. <el-table-column label="设备名称" prop="name" :show-overflow-tooltip="true" />
  281. <el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true" />
  282. <el-table-column prop="status" label="状态" width="100" align="center">
  283. <template #default="scope">
  284. <el-tag type="info" size="small" v-if="scope.row.status==1">离线</el-tag>
  285. <el-tag type="success" size="small" v-if="scope.row.status==2">在线</el-tag>
  286. <el-tag type="info" size="small" v-if="scope.row.status==0">未启用</el-tag>
  287. </template>
  288. </el-table-column>
  289. <el-table-column prop="registryTime" label="激活时间" align="center" width="150"></el-table-column>
  290. <el-table-column prop="desc" label="说明"></el-table-column>
  291. <el-table-column label="操作" width="80" align="center" fixed="right">
  292. <template #default="scope">
  293. <el-button size="small" text type="warning" v-auth="'detail'" @click="onOpenDetail(scope.row)">详情</el-button>
  294. </template>
  295. </el-table-column>
  296. </el-table>
  297. <pagination v-show="deviceTableData.total>0" :total="deviceTableData.total" v-model:page="deviceTableData.param.pageNum" v-model:limit="deviceTableData.param.pageSize" @pagination="getDeviceTableData" />
  298. </div>
  299. </el-tab-pane>
  300. </el-tabs>
  301. </div>
  302. <EditDic ref="editDicRef" @typeList="typeList" />
  303. <EditAttr ref="editAttrRef" @typeList="getproperty" />
  304. <EditFun ref="editFunRef" @typeList="getfunction" />
  305. <EditEvent ref="editEventRef" @typeList="getevent" />
  306. <EditTab ref="editTabRef" @typeList="gettab" />
  307. <ListDic ref="listDicRef" />
  308. <SubDevice ref="subDeviceRef" />
  309. <!-- 子设备-批量绑定弹窗 -->
  310. <SubDeviceMutipleBind ref="mutipleBindRef" @bindSuccess="getDeviceTableData" />
  311. <el-dialog v-model="dialogVisible" title="返回Json数据" width="30%">
  312. <JsonViewer :value="jsonData" boxed sort theme="jv-dark" @click="onKeyclick" />
  313. <template #footer>
  314. <span class="dialog-footer">
  315. <el-button @click="dialogVisible = false">关闭</el-button>
  316. </span>
  317. </template>
  318. </el-dialog>
  319. </div>
  320. </template>
  321. <script lang="ts">
  322. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  323. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  324. import functionCom from './component/function.vue';
  325. import 'vue3-json-viewer/dist/index.css';
  326. import EditDic from './component/edit.vue';
  327. // import EditDic from '../product/component/editPro.vue';
  328. import EditAttr from '../product/component/editAttr.vue';
  329. import EditFun from '../product/component/editFun.vue';
  330. import EditEvent from '../product/component/editEvent.vue';
  331. import EditTab from '../product/component/editTab.vue';
  332. import devantd from '/@/components/devantd/index.vue';
  333. import ListDic from './component/list.vue';
  334. import SubDevice from './component/subDevice.vue';
  335. import SubDeviceMutipleBind from './component/subDeviceMutipleBind.vue';
  336. import api from '/@/api/device';
  337. import { useRoute } from 'vue-router';
  338. interface TableDataState {
  339. ids: number[];
  340. detail: any;
  341. deviceKeyList: string[];
  342. deviceTableData: {
  343. data: [];
  344. total: number;
  345. loading: boolean;
  346. param: {
  347. pageNum: number;
  348. pageSize: number;
  349. gatewayKey: string;
  350. dateRange: string[];
  351. };
  352. };
  353. tableData: {
  354. data: [];
  355. total: number;
  356. loading: boolean;
  357. param: {
  358. pageNum: number;
  359. pageSize: number;
  360. name: string;
  361. deviceType: string;
  362. status: string;
  363. dateRange: string[];
  364. };
  365. };
  366. logtableData: {
  367. data: [];
  368. total: number;
  369. loading: boolean;
  370. param: {
  371. pageNum: number;
  372. pageSize: number;
  373. name: string;
  374. deviceType: string;
  375. status: string;
  376. dateRange: string[];
  377. };
  378. };
  379. }
  380. export default defineComponent({
  381. name: 'deviceEditPro',
  382. components: { SubDeviceMutipleBind, SubDevice, EditDic, EditAttr, EditFun, EditEvent, EditTab, devantd, ListDic, functionCom },
  383. setup(prop, context) {
  384. const route = useRoute();
  385. const editDicRef = ref();
  386. const editAttrRef = ref();
  387. const editFunRef = ref();
  388. const listDicRef=ref();
  389. const editEventRef = ref();
  390. const editTabRef = ref();
  391. const subDeviceRef = ref();
  392. const mutipleBindRef = ref();
  393. const state = reactive<TableDataState>({
  394. deviceKeyList: [],
  395. areaData:[],
  396. isShowDialog: false,
  397. dialogVisible: false,
  398. logTypeData: [],
  399. jsonData: '',
  400. activeName: '3', // 分类数据
  401. activetab: 'attr', // 分类数据
  402. detail: {},
  403. prodetail: [],
  404. product_id: 0,
  405. developer_status: 0,
  406. deviceTableData: {
  407. data: [],
  408. total: 0,
  409. loading: false,
  410. param: {
  411. pageNum: 1,
  412. gatewayKey: '',
  413. pageSize: 10,
  414. dateRange: [],
  415. },
  416. },
  417. tableData: {
  418. data: [],
  419. total: 0,
  420. loading: false,
  421. param: {
  422. pageNum: 1,
  423. productId: 0,
  424. pageSize: 10,
  425. status: '',
  426. dateRange: [],
  427. },
  428. },
  429. logtableData: {
  430. data: [],
  431. total: 0,
  432. loading: false,
  433. param: {
  434. pageNum: 1,
  435. productId: 0,
  436. pageSize: 10,
  437. status: '',
  438. dateRange: [],
  439. },
  440. },
  441. });
  442. onMounted(() => {
  443. const ids = route.params && route.params.id;
  444. api.instance.detail(ids).then((res: any) => {
  445. state.detail = res.data;
  446. state.developer_status = res.data.status;
  447. state.tableData.param.productId = res.data.product.id;
  448. state.product_id = res.data.product.id;
  449. getrunData();
  450. api.product.detail(res.data.product.id).then((res: any) => {
  451. state.prodetail = res.data;
  452. });
  453. //第一次加载
  454. api.model.property(state.tableData.param).then((res: any) => {
  455. state.tableData.data = res.Data;
  456. state.tableData.total = res.Total;
  457. });
  458. getDeviceTableData()
  459. });
  460. });
  461. const mutipleUnbind = () => {
  462. let msg = '是否进行批量解绑?';
  463. if (state.deviceKeyList.length === 0) {
  464. ElMessage.error('请选择要批量解绑的数据。');
  465. return;
  466. }
  467. ElMessageBox.confirm(msg, '提示', {
  468. confirmButtonText: '确认',
  469. cancelButtonText: '取消',
  470. type: 'warning',
  471. })
  472. .then(() => {
  473. api.device.mutipleUnbind({
  474. "gatewayKey":state.deviceTableData.param.gatewayKey,
  475. "subKeys": state.deviceKeyList
  476. }).then(() => {
  477. ElMessage.success('解绑成功');
  478. // typeList();
  479. getDeviceTableData();
  480. });
  481. })
  482. .catch(() => { });
  483. }
  484. const getDeviceTableData = () => {
  485. state.deviceTableData.param.gatewayKey = state.detail.key;
  486. api.device.getList(state.deviceTableData.param).then((res: any) => {
  487. state.deviceTableData.data = res.list;
  488. state.deviceTableData.total = res.Total;
  489. });
  490. };
  491. // 多选框选中数据
  492. const handleSelectionChange = (selection: any[]) => {
  493. state.deviceKeyList = selection.map((item) => item.key);
  494. };
  495. // 打开修改产品弹窗
  496. const onOpenDetail = (row: any) => {
  497. subDeviceRef.value.openDialog(row)
  498. };
  499. const onLogDetail = (row: TableDataRow) => {
  500. state.jsonData = JSON.parse(row.content);
  501. state.dialogVisible = true;
  502. };
  503. const onOpenMutipleBind = () => {
  504. mutipleBindRef.value.openDialog(state.deviceTableData.param.gatewayKey);
  505. };
  506. //编辑属性
  507. const onEditAttr = (row: TableDataRow) => {
  508. editAttrRef.value.openDialog(row, state.product_id);
  509. };
  510. //编辑功能
  511. const onEditFun = (row: TableDataRow) => {
  512. editFunRef.value.openDialog(row, state.product_id);
  513. };
  514. //编辑事件
  515. const onEditEvent = (row: TableDataRow) => {
  516. editEventRef.value.openDialog(row, state.product_id);
  517. };
  518. //编辑标签
  519. const onEditTag = (row: TableDataRow) => {
  520. editTabRef.value.openDialog(row, state.product_id);
  521. };
  522. //打开添加属性弹窗
  523. const onOpenEditAttr = () => {
  524. editAttrRef.value.openDialog({ product_id: state.product_id, id: 0, accessMode: 0 });
  525. };
  526. //打开添加功能弹窗
  527. const onOpenEditFun = () => {
  528. editFunRef.value.openDialog({ product_id: state.product_id, id: 0 });
  529. };
  530. //打开添加事件弹窗
  531. const onOpenEditEvent = () => {
  532. editEventRef.value.openDialog({ product_id: state.product_id, id: 0, level: 0 });
  533. };
  534. //打开添加事件弹窗
  535. const onOpenEditTab = () => {
  536. editTabRef.value.openDialog({ product_id: state.product_id, id: 0, accessMode: 0 });
  537. };
  538. //查看日志列表
  539. const onOpenListDetail = (row: TableDataRow) => {
  540. listDicRef.value.openDialog(row, state.detail.id);
  541. };
  542. // 打开修改产品弹窗
  543. const onOpenEditDic = (row: TableDataRow) => {
  544. editDicRef.value.openDialog(row);
  545. };
  546. // 删除产品
  547. const onRowDel = (key, type) => {
  548. let msg = `此操作将永久删除该数据吗?,是否继续?`;
  549. if (key.length === 0) {
  550. ElMessage.error('请选择要删除的数据。');
  551. return;
  552. }
  553. ElMessageBox.confirm(msg, '提示', {
  554. confirmButtonText: '确认',
  555. cancelButtonText: '取消',
  556. type: 'warning',
  557. })
  558. .then(() => {
  559. if (type == 'attr') {
  560. api.model.propertydel(state.product_id, key).then(() => {
  561. ElMessage.success('删除成功');
  562. getproperty();
  563. });
  564. }
  565. if (type == 'fun') {
  566. api.model.functiondel(state.product_id, key).then(() => {
  567. ElMessage.success('删除成功');
  568. getfunction();
  569. });
  570. }
  571. if (type == 'event') {
  572. api.model.eventdel(state.product_id, key).then(() => {
  573. ElMessage.success('删除成功');
  574. getevent();
  575. });
  576. }
  577. if (type == 'tab') {
  578. api.model.tagdel(state.product_id, key).then(() => {
  579. ElMessage.success('删除成功');
  580. tagdel();
  581. });
  582. }
  583. })
  584. .catch(() => { });
  585. };
  586. //根据不同类型获取列表
  587. const getList = () => {
  588. switch (state.activetab) {
  589. case 'attr':
  590. getproperty();
  591. break;
  592. case 'fun':
  593. getfunction();
  594. break;
  595. case 'event':
  596. getevent();
  597. break;
  598. case 'tab':
  599. gettab();
  600. break;
  601. }
  602. };
  603. const getproperty = () => {
  604. api.model.property(state.tableData.param).then((res: any) => {
  605. state.tableData.data = res.Data;
  606. state.tableData.total = res.Total;
  607. });
  608. };
  609. const getfunction = () => {
  610. api.model.function(state.tableData.param).then((res: any) => {
  611. state.tableData.data = res.Data;
  612. state.tableData.total = res.Total;
  613. });
  614. };
  615. const getevent = () => {
  616. api.model.event(state.tableData.param).then((res: any) => {
  617. state.tableData.data = res.Data;
  618. state.tableData.total = res.Total;
  619. });
  620. };
  621. const gettab = () => {
  622. api.model.tag(state.tableData.param).then((res: any) => {
  623. state.tableData.data = res.Data;
  624. state.tableData.total = res.Total;
  625. });
  626. };
  627. const wuhandleClick = (tab: TabsPaneContext) => {
  628. state.activetab = tab.props.name;
  629. switch (tab.props.name) {
  630. case 'attr':
  631. getproperty();
  632. break;
  633. case 'fun':
  634. getfunction();
  635. break;
  636. case 'event':
  637. getevent();
  638. break;
  639. case 'tab':
  640. gettab();
  641. break;
  642. }
  643. };
  644. const handleClick = (tab: TabsPaneContext, event: Event) => {
  645. if (tab.props.name == 4) {
  646. //获取日志
  647. getlog();
  648. getlogtype();
  649. } else if (tab.props.name == 2) {
  650. getList();
  651. } else if (tab.props.name == 3) {
  652. getrunData();
  653. }
  654. };
  655. const getrunData = () => {
  656. api.instance.getrun_status({ id: state.detail.id }).then((res: any) => {
  657. state.areaData = res
  658. let properties=state.areaData.properties || [];
  659. var temp = new Array();
  660. properties.forEach(function (item, index) {
  661. let datalist=item.list || [];
  662. temp[index] = [];
  663. var temps = new Array();
  664. datalist.forEach(function (a, b) {
  665. if(b<15){
  666. temps.push(a);
  667. }
  668. });
  669. temp[index]['name']=item.name
  670. temp[index]['key']=item.key
  671. temp[index]['type']=item.type
  672. temp[index]['unit']=item.unit
  673. temp[index]['value']=item.value
  674. temp[index]['list']=temps
  675. });
  676. state.areaData.properties=temp;
  677. });
  678. };
  679. const getlogtype = () => {
  680. api.instance.getlogcate({}).then((res: any) => {
  681. state.logTypeData = res.list;
  682. });
  683. };
  684. const getlog = () => {
  685. state.logtableData.param.deviceKey = state.detail.key;
  686. api.instance.getLogList(state.logtableData.param).then((res: any) => {
  687. state.logtableData.data = res.list;
  688. state.logtableData.total = res.Total;
  689. });
  690. };
  691. const CkOption = () => {
  692. if (state.developer_status == 2) {
  693. api.instance.devoffline({ id: state.detail.id }).then((res: any) => {
  694. ElMessage.success('操作成功');
  695. state.developer_status = 1;
  696. });
  697. } else {
  698. api.instance.devonline({ id: state.detail.id }).then((res: any) => {
  699. ElMessage.success('操作成功');
  700. state.developer_status = 2;
  701. });
  702. }
  703. };
  704. const tinyAreas = () => {
  705. var data = state.data;
  706. const tinyArea = new TinyArea('container', {
  707. height: 60,
  708. autoFit: false,
  709. data,
  710. smooth: true,
  711. areaStyle: {
  712. fill: '#d6e3fd',
  713. },
  714. });
  715. tinyArea.render();
  716. }
  717. const onlineTimeoutUpdate = () => {
  718. if(!state.detail.onlineTimeout) return ElMessage('请先输入设备超时时间')
  719. api.device.updateOnlineTimeout({ id: state.detail.id, onlineTimeout: state.detail.onlineTimeout }).then(() => {
  720. ElMessage.success('设置成功')
  721. })
  722. }
  723. return {
  724. onlineTimeoutUpdate,
  725. tinyAreas,
  726. editDicRef,
  727. editAttrRef,
  728. listDicRef,
  729. editFunRef,
  730. editEventRef,
  731. editTabRef,
  732. subDeviceRef,
  733. mutipleBindRef,
  734. onOpenListDetail,
  735. getrunData,
  736. getlog,
  737. getlogtype,
  738. onLogDetail,
  739. CkOption,
  740. onRowDel,
  741. onEditFun,
  742. onEditEvent,
  743. onEditTag,
  744. onEditAttr,
  745. getList,
  746. getproperty,
  747. getDeviceTableData,
  748. handleSelectionChange,
  749. getfunction,
  750. getevent,
  751. gettab,
  752. wuhandleClick,
  753. onOpenEditTab,
  754. onOpenEditEvent,
  755. onOpenEditAttr,
  756. onOpenEditFun,
  757. onOpenEditDic,
  758. onOpenDetail,
  759. handleClick,
  760. onOpenMutipleBind,
  761. mutipleUnbind,
  762. ...toRefs(state),
  763. };
  764. },
  765. });
  766. </script>
  767. <style>
  768. .content {
  769. background: #fff;
  770. width: 100%;
  771. padding: 20px;
  772. }
  773. .content-box {
  774. background: #fff;
  775. width: 100%;
  776. padding: 20px;
  777. margin-top: 20px;
  778. }
  779. .cont_box {
  780. display: flex;
  781. }
  782. .cont_box .title {
  783. font-size: 24px;
  784. }
  785. .cont_box .pro-status {
  786. line-height: 40px;
  787. margin-left: 30px;
  788. }
  789. .cont_box .pro-status .on {
  790. background: #52c41a;
  791. }
  792. .cont_box .pro-status .off {
  793. background: #c41a1a;
  794. }
  795. .cont_box .pro-status span {
  796. position: relative;
  797. top: -1px;
  798. display: inline-block;
  799. width: 6px;
  800. height: 6px;
  801. vertical-align: middle;
  802. border-radius: 50%;
  803. margin-right: 5px;
  804. }
  805. .cont_box .pro-option {
  806. line-height: 40px;
  807. margin-left: 10px;
  808. color: #1890ff;
  809. cursor: pointer;
  810. }
  811. .content-box .pro-box {
  812. display: flex;
  813. padding: 10px;
  814. justify-content: space-between;
  815. }
  816. .content-box .pro-box .protitle {
  817. font-size: 18px;
  818. font-weight: bold;
  819. line-height: 35px;
  820. }
  821. .content-box .pro-box .buttonedit {
  822. border: 0px;
  823. color: #1890ff;
  824. }
  825. table {
  826. border-collapse: collapse;
  827. text-indent: initial;
  828. border-spacing: 2px;
  829. }
  830. tbody {
  831. box-sizing: border-box;
  832. display: table-row-group;
  833. vertical-align: middle;
  834. border-color: inherit;
  835. }
  836. tr {
  837. display: table-row;
  838. vertical-align: inherit;
  839. border-color: inherit;
  840. }
  841. .ant-descriptions-view {
  842. width: 100%;
  843. overflow: hidden;
  844. border-radius: 4px;
  845. }
  846. .ant-descriptions-view {
  847. border: 1px solid #e8e8e8;
  848. }
  849. .ant-descriptions-view table {
  850. width: 100%;
  851. table-layout: fixed;
  852. }
  853. .ant-descriptions-view > table {
  854. table-layout: auto;
  855. }
  856. .ant-descriptions-row {
  857. border-bottom: 1px solid #e8e8e8;
  858. }
  859. .ant-descriptions-item-label {
  860. color: rgba(0, 0, 0, 0.85);
  861. font-weight: 400;
  862. font-size: 14px;
  863. line-height: 1.5;
  864. }
  865. .ant-descriptions-item-label {
  866. padding: 16px 24px;
  867. border-right: 1px solid #e8e8e8;
  868. }
  869. .ant-descriptions-item-label {
  870. background-color: #fafafa;
  871. }
  872. .ant-descriptions-item-content {
  873. padding: 16px 24px;
  874. border-right: 1px solid #e8e8e8;
  875. display: table-cell;
  876. color: rgba(0, 0, 0, 0.65);
  877. font-size: 14px;
  878. line-height: 1.5;
  879. }
  880. .wu-box {
  881. border: #e8e8e8 solid 1px;
  882. padding: 20px;
  883. width: 100%;
  884. }
  885. .wu-box .wu-title {
  886. display: flex;
  887. flex-direction: row;
  888. justify-content: space-between;
  889. padding: 20px;
  890. border-bottom: #e8e8e8 1px solid;
  891. }
  892. .wu-box .wu-title .title {
  893. font-size: 18px;
  894. }
  895. .ant-card {
  896. box-sizing: border-box;
  897. margin: 10px;
  898. width: 23.2%;
  899. font-size: 14px;
  900. font-variant: tabular-nums;
  901. border: 1px solid var(--next-border-color-light);
  902. line-height: 1.5;
  903. list-style: none;
  904. font-feature-settings: 'tnum';
  905. position: relative;
  906. border-radius: 2px;
  907. transition: all 0.3s;
  908. }
  909. .ant-card-body {
  910. padding: 24px;
  911. zoom: 1;
  912. }
  913. .cardflex {
  914. display: flex;
  915. justify-content: space-between;
  916. }
  917. .statusname {
  918. font-size: 30px;
  919. margin-top: 10px;
  920. margin-bottom: 15px;
  921. }
  922. .comtest {
  923. margin-top: 20px;
  924. height: 30px;
  925. line-height: 30px;
  926. }
  927. </style>