index.vue 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <el-col :span="4" :xs="24">
  5. <div class="head-container">
  6. <el-input v-model="areaName" placeholder="请输入区域名称" clearable size="small" prefix-icon="el-icon-search"
  7. style="margin-bottom: 20px"
  8. />
  9. </div>
  10. <div class="head-container" style="height: 100vh; overflow: hidden; position: relative;">
  11. <el-tree :data="treeAreaOptions" :props="defaultProps" :expand-on-click-node="false"
  12. :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
  13. @node-click="handleNodeClick" style="height: calc(100vh - 50px); overflow-y: auto;"
  14. />
  15. </div>
  16. </el-col>
  17. <el-col :span="20" :xs="24">
  18. <el-tabs v-model="queryParams.deviceCategory" @tab-click="deviceCategoryChange">
  19. <el-tab-pane label="产能设备" name="E"></el-tab-pane>
  20. <el-tab-pane label="储能设备" name="C"></el-tab-pane>
  21. <el-tab-pane label="输配设备" name="W"></el-tab-pane>
  22. <el-tab-pane label="用能设备" name="Z"></el-tab-pane>
  23. </el-tabs>
  24. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  25. label-width="68px"
  26. >
  27. <el-form-item label="设备分类" prop="deviceSubCategory">
  28. <el-select v-model="queryParams.deviceSubCategory">
  29. <el-option v-for="item in subCategoryOptions" placeholder="设备分类" :label="item.name" :value="item.code"
  30. :key="item.code"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="归属设施" prop="refFacs">
  35. <el-select v-model="queryParams.refFacs">
  36. <el-option v-for="item in facsOptions" :label="item.facsName" :value="item.facsCode"
  37. :key="item.facsCode"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="子系统" prop="subsystemCode">
  42. <el-select v-model="queryParams.subsystemCode">
  43. <el-option v-for="item in subsystemOptions" :label="item.systemName" :value="item.systemCode"
  44. :key="item.systemCode"
  45. />
  46. </el-select>
  47. </el-form-item>
  48. <el-form-item label="设备工艺" prop="psCode" v-if="queryParams.deviceCategory === 'W'">
  49. <el-select v-model="queryParams.psCode">
  50. <el-option v-for="item in devOptions" :label="item.psName" :value="item.psCode" :key="item.psCode"/>
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item>
  54. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  55. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  56. </el-form-item>
  57. </el-form>
  58. <el-row :gutter="10" class="mb8">
  59. <el-col :span="1.5">
  60. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  61. v-hasPermi="['ems:device:add']"
  62. >新增
  63. </el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
  67. v-hasPermi="['ems:device:edit']"
  68. >修改
  69. </el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  73. v-hasPermi="['ems:device:remove']"
  74. >删除
  75. </el-button>
  76. </el-col>
  77. <el-col :span="1.5">
  78. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  79. v-hasPermi="['ems:device:export']"
  80. >导出
  81. </el-button>
  82. </el-col>
  83. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  84. </el-row>
  85. <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
  86. <el-table-column type="selection" width="55" align="center"/>
  87. <el-table-column label="设备名称" align="left" prop="deviceName"/>
  88. <el-table-column label="安装位置" align="left" prop="areaPath" width="220px"/>
  89. <el-table-column label="归属设施" align="center" prop="refFacsName"/>
  90. <el-table-column label="设备分类" align="center" prop="deviceCategoryName"/>
  91. <el-table-column label="子系统" align="center" prop="subsystemName"/>
  92. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  93. <template slot-scope="scope">
  94. <el-button size="mini" type="text" icon="el-icon-info" @click="handleDevProcess(scope.row)"
  95. v-hasPermi="['basecfg:device:edit']" v-if="shouldShowDevProcessButton(scope.row)"
  96. >器件
  97. </el-button>
  98. <el-button size="mini" type="text" icon="el-icon-s-tools" @click="handleDetail(scope.row)"
  99. v-hasPermi="['basecfg:device:edit']"
  100. >管理
  101. </el-button>
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
  106. :limit.sync="queryParams.pageSize"
  107. @pagination="getList"
  108. />
  109. <!-- 调用日志弹窗 -->
  110. <el-dialog :visible.sync="callLog" title="调用日志" width="60%">
  111. <el-form inline>
  112. <el-form-item label="记录时间">
  113. <el-date-picker
  114. v-model="callDaterangeTime"
  115. style="width: 240px"
  116. value-format="yyyy-MM-dd HH:mm"
  117. type="datetimerange"
  118. range-separator="-"
  119. start-placeholder="开始日期"
  120. end-placeholder="结束日期"
  121. ></el-date-picker>
  122. </el-form-item>
  123. <el-form-item label="能力标识">
  124. <el-select v-model="callLogQueryParams.abilityKey" placeholder="请选择能力标识" clearable>
  125. <el-option
  126. v-for="item in abilityData"
  127. :key="item.abilityKey"
  128. :label="item.abilityName"
  129. :value="item.abilityKey"
  130. ></el-option>
  131. </el-select>
  132. </el-form-item>
  133. <el-form-item label="调用状态">
  134. <el-select v-model="callLogQueryParams.callStatus" placeholder="请选择调用状态" clearable>
  135. <el-option
  136. v-for="(value, key) in callStatusOptions"
  137. :key="key"
  138. :label="value"
  139. :value="key"
  140. ></el-option>
  141. </el-select>
  142. </el-form-item>
  143. <el-form-item>
  144. <el-button type="primary" @click="handleCallLogQuery">查询</el-button>
  145. <el-button @click="resetCallLogQuery">重置</el-button>
  146. </el-form-item>
  147. </el-form>
  148. <el-table :data="callLogData" style="width: 100%" :show-header="true" :empty-text="'暂无数据'">
  149. <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
  150. <el-table-column label="对象编号" prop="objCode"></el-table-column>
  151. <el-table-column label="对象名称" prop="objName"></el-table-column>
  152. <el-table-column label="对象能力" prop="abilityName"></el-table-column>
  153. <el-table-column label="调用时间" prop="callTime"></el-table-column>
  154. <el-table-column label="调用结果" align="center" width="100">
  155. <template slot-scope="scope">
  156. <span>{{ formatCallStatus(scope.row.callStatus) }}</span>
  157. </template>
  158. </el-table-column> <el-table-column label="操作" align="center" width="100">
  159. <template slot-scope="scope">
  160. <el-button type="text" size="mini" icon="el-icon-info" @click="handleCallLogDetail(scope.row)">详情
  161. </el-button>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. </el-dialog>
  166. <!-- 调用日志详情弹窗 -->
  167. <el-dialog :visible.sync="callLogDetailDialog" title="调用日志详情" width="50%">
  168. <div v-if="callLogDetailData">
  169. <p><strong>对象编号:</strong>{{ callLogDetailData.objCode }}</p>
  170. <p><strong>对象名称:</strong>{{ callLogDetailData.objName }}</p>
  171. <p><strong>对象类型:</strong>{{ formatObjType(callLogDetailData.objType) }}</p>
  172. <p><strong>模型代码:</strong>{{ callLogDetailData.modelCode }}</p>
  173. <p><strong>能力标识:</strong>{{ callLogDetailData.abilityKey }}</p>
  174. <p><strong>对象能力:</strong>{{ callLogDetailData.abilityName }}</p>
  175. <p><strong>调用时间:</strong>{{ callLogDetailData.callTime }}</p>
  176. <p><strong>响应时间:</strong>{{ callLogDetailData.resTime }}</p>
  177. <p><strong>调用结果:</strong>{{ formatCallStatus(callLogDetailData.callStatus) }}</p>
  178. <p><strong>调用载体:</strong></p>
  179. <pre style="white-space: pre-wrap; background-color: #f5f5f5; padding: 10px; border-radius: 4px;"
  180. >{{ callLogDetailData.callPayload }}</pre>
  181. <p><strong>响应载体:</strong></p>
  182. <pre style="white-space: pre-wrap; background-color: #f5f5f5; padding: 10px; border-radius: 4px;"
  183. >{{ callLogDetailData.resPayload }}</pre>
  184. </div>
  185. </el-dialog>
  186. <!-- 设备日志弹窗 -->
  187. <el-dialog :visible.sync="reportLog" title="设备日志" width="60%">
  188. <el-form inline>
  189. <el-form-item label="记录时间">
  190. <el-date-picker
  191. v-model="logDaterangeTime"
  192. style="width: 240px"
  193. value-format="yyyy-MM-dd HH:mm"
  194. type="datetimerange"
  195. range-separator="-"
  196. start-placeholder="开始日期"
  197. end-placeholder="结束日期"
  198. ></el-date-picker>
  199. </el-form-item>
  200. <el-form-item>
  201. <el-button type="primary" @click="handleLogQuery">查询</el-button>
  202. <el-button @click="resetLogQuery">重置</el-button>
  203. </el-form-item>
  204. </el-form>
  205. <el-table :data="reportLogData" style="width: 100%" :show-header="true" :empty-text="'暂无数据'">
  206. <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
  207. <el-table-column label="对象编号" prop="objCode"></el-table-column>
  208. <el-table-column label="对象名称" prop="objName"></el-table-column>
  209. <el-table-column label="消息类型" prop="msgDesc"></el-table-column>
  210. <el-table-column label="上报时间" prop="reportTime" width="180"></el-table-column>
  211. <el-table-column label="操作" align="center" width="100">
  212. <template slot-scope="scope">
  213. <el-button type="text" size="mini" icon="el-icon-info" @click="handleReportLogDetail(scope.row)">详情
  214. </el-button>
  215. </template>
  216. </el-table-column>
  217. </el-table>
  218. </el-dialog>
  219. <!-- 设备日志详情弹窗 -->
  220. <el-dialog :visible.sync="reportDetailDialog" title="设备日志详情" width="50%">
  221. <div v-if="reportDetailData">
  222. <p><strong>对象编号:</strong>{{ reportDetailData.objCode }}</p>
  223. <p><strong>对象名称:</strong>{{ reportDetailData.objName }}</p>
  224. <p><strong>对象类型:</strong>{{ formatObjType(reportDetailData.objType) }}</p>
  225. <p><strong>消息类型:</strong>{{ reportDetailData.msgDesc }}</p>
  226. <p><strong>上报时间:</strong>{{ reportDetailData.reportTime }}</p>
  227. <p><strong>上报载体:</strong></p>
  228. <pre style="white-space: pre-wrap; background-color: #f5f5f5; padding: 10px; border-radius: 4px;"
  229. >{{ reportDetailData.reportPayload }}</pre>
  230. </div>
  231. </el-dialog>
  232. <!-- 添加或修改能源设备对话框 -->
  233. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  234. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  235. <div>
  236. <el-form-item label="归属设施" prop="refFacs">
  237. <el-select v-model="form.refFacs" placeholder="请选择归属设施" @change="handleFacilityChange">
  238. <el-option v-for="item in facsOptions" :key="item.facsCode" :label="item.facsName" :value="item.facsCode"></el-option>
  239. </el-select>
  240. </el-form-item>
  241. <el-form-item label="归属区域" prop="areaCode" v-if="queryParams.deviceCategory === 'W' || queryParams.deviceCategory === 'Z'">
  242. <el-select v-model="form.areaCode" placeholder="请选择归属区域" @change="handleAreaChange">
  243. <el-option v-for="item in areaOptions" :key="item.id" :label="item.label" :value="item.id"></el-option>
  244. </el-select>
  245. </el-form-item>
  246. <el-form-item label="归属子区" prop="locationRef" v-if="queryParams.deviceCategory === 'W' || queryParams.deviceCategory === 'Z'">
  247. <el-select v-model="form.locationRef" placeholder="请选择归属子区">
  248. <el-option v-for="item in subAreaOptions" :key="item.id" :label="item.label" :value="item.id"></el-option>
  249. </el-select>
  250. </el-form-item>
  251. <el-form-item label="安装位置" prop="location" v-if="queryParams.deviceCategory === 'W' || queryParams.deviceCategory === 'Z'">
  252. <el-input v-model="form.location" placeholder="请输入安装位置"></el-input>
  253. </el-form-item>
  254. <el-form-item label="设备代码" prop="deviceCode">
  255. <el-input v-model="form.deviceCode" placeholder="请输入设备代码"/>
  256. </el-form-item>
  257. <el-form-item label="设备名称" prop="deviceName">
  258. <el-input v-model="form.deviceName" placeholder="请输入设备名称"/>
  259. </el-form-item>
  260. <el-form-item label="设备工艺" prop="psCode" v-if="queryParams.deviceCategory === 'W'">
  261. <el-select v-model="form.psCode">
  262. <el-option v-for="item in devOptions" :label="item.psName" :value="item.psCode"
  263. :key="item.psCode"
  264. />
  265. </el-select>
  266. </el-form-item>
  267. <el-form-item label="设备模型" prop="deviceModel">
  268. <el-select v-model="form.deviceModel" style="width:100%" @change="handleModelChange" clearable>
  269. <el-option
  270. v-for="item in modelList"
  271. :label="item.modelName"
  272. :value="item.modelCode"
  273. :key="item.modelCode"
  274. />
  275. </el-select>
  276. </el-form-item>
  277. <el-form-item label="子系统" prop="subsystemCode">
  278. <el-select v-model="form.subsystemCode" clearable>
  279. <el-option v-for="item in subsystemOptions" :label="item.systemName" :value="item.systemCode"
  280. :key="item.systemCode"
  281. />
  282. </el-select>
  283. </el-form-item>
  284. </div>
  285. <!-- 属性名称、属性值 -->
  286. <div v-if="attrList.length > 0" class="attr-list-container">设备参数:
  287. <ul>
  288. <li v-for="attr in attrList" :key="attr.attrKey" class="attr-item">
  289. <span class="attr-name">{{ attr.attrName }} ({{ attr.attrUnit }}): </span>
  290. <el-input
  291. v-model="attrValuesMap[attr.attrKey]"
  292. placeholder="点击编辑"
  293. size="small"
  294. @blur="updateAttrValue(attr.attrKey, attrValuesMap[attr.attrKey])"
  295. class="attr-input"
  296. />
  297. </li>
  298. </ul>
  299. </div>
  300. <div v-if="attrList.length > 0" class="attr-list-container">设备自定义参数:
  301. <el-form-item label="" prop="attrList">
  302. <el-table class="attr-table" v-loading="loading" :data="form.customAttrs" max-height="280px"
  303. key="'customAttrs'"
  304. >
  305. <el-table-column label="标识" align="center" prop="attrKey">
  306. <template slot-scope="scope">
  307. <el-input size="mini" v-model="scope.row.attrKey" placeholder="请输入标识"/>
  308. </template>
  309. </el-table-column>
  310. <el-table-column label="属性名" align="center" prop="attrName">
  311. <template slot-scope="scope">
  312. <el-input size="mini" v-model="scope.row.attrName" placeholder="请输入属性名"/>
  313. </template>
  314. </el-table-column>
  315. <el-table-column label="属性值" align="center" prop="attrValue">
  316. <template slot-scope="scope">
  317. <el-input size="mini" v-model="scope.row.attrValue" placeholder="请输入属性值"/>
  318. </template>
  319. </el-table-column>
  320. <el-table-column align="center" label="操作">
  321. <template slot="header">
  322. <div class="operateBtns" @click="addCustomAttr">
  323. <span>添加</span><i class="el-icon-circle-plus-outline"></i>
  324. </div>
  325. </template>
  326. <template slot-scope="scope">
  327. <i class="el-icon-delete" @click="deleteCustomAttr(scope.$index)"></i>
  328. </template>
  329. </el-table-column>
  330. </el-table>
  331. </el-form-item>
  332. </div>
  333. </el-form>
  334. <div slot="footer" class="dialog-footer">
  335. <el-button type="primary" @click="submitForm">确 定</el-button>
  336. <el-button @click="cancel">取 消</el-button>
  337. </div>
  338. </el-dialog>
  339. <!--设备器件-->
  340. <el-drawer :title=ComponentRow.deviceName size="80%" :visible.sync="showDevProcessDrawer" direction="rtl">
  341. <div class="drawer-content" style="padding-left:50px">
  342. <el-row :gutter="10" class="mb8">
  343. <el-col :span="1.5">
  344. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleComponentAdd"
  345. v-hasPermi="['ems:component:add']"
  346. >新增
  347. </el-button>
  348. </el-col>
  349. </el-row>
  350. <el-table v-loading="loading" :data="ComponentList">
  351. <el-table-column type="selection" width="55" align="center"/>
  352. <el-table-column label="部件编码" align="center" prop="compoCode"/>
  353. <el-table-column label="部件标签" align="center" prop="compoTag">
  354. <template slot-scope="scope">
  355. {{ objComTypeMapping[scope.row.compoTag] }}
  356. </template>
  357. </el-table-column>
  358. <el-table-column label="工艺标识代码" align="center" prop="psCode"/>
  359. <el-table-column label="外系统部件编码" align="center" prop="extCompoCode"/>
  360. <el-table-column label="部件模型" align="center" prop="compoModel"/>
  361. <el-table-column label="部件品牌" align="center" prop="compoBrand"/>
  362. <el-table-column label="部件型号" align="center" prop="compoSpec"/>
  363. <el-table-column label="祖籍列表" align="center" prop="ancestors"/>
  364. <el-table-column label="上级部件" align="center" prop="parentEqpt"/>
  365. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  366. <template slot-scope="scope">
  367. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleComponentUpdate(scope.row)"
  368. v-hasPermi="['ems:component:edit']"
  369. >
  370. 修改
  371. </el-button>
  372. <el-button size="mini" type="text" icon="el-icon-delete" class="deleteBtn"
  373. @click="handleComponentDelete(scope.row)" v-hasPermi="['ems:component:remove']"
  374. >
  375. 删除
  376. </el-button>
  377. </template>
  378. </el-table-column>
  379. </el-table>
  380. <pagination v-show="total>0" :total="total" :page.sync="queryComponentParams.pageNum"
  381. :limit.sync="queryComponentParams.pageSize"
  382. @pagination="getComponentList"
  383. />
  384. <!-- 添加或修改设备器件对话框 -->
  385. <el-dialog :title="title" :visible.sync="componentOpen" width="600px" append-to-body>
  386. <el-form ref="componentForm" :model="componentForm" :rules="componentRules" label-width="150px">
  387. <el-form-item label="部件编码" prop="compoCode">
  388. <el-input v-model="componentForm.compoCode" placeholder="请输入部件编码"/>
  389. </el-form-item>
  390. <el-form-item label="部件标签" prop="compoTag">
  391. <el-select v-model="componentForm.compoTag" placeholder="请输入部件标签">
  392. <el-option v-for="item in objComTypeOptions"
  393. :label="item.name"
  394. :value="item.code"
  395. :key="item.code"
  396. />
  397. </el-select>
  398. </el-form-item>
  399. <el-form-item label="工艺标签代码" prop="psCode">
  400. <el-select v-model="componentForm.psCode" placeholder="请输入工艺标签代码">
  401. <el-option v-for="item in devOptions" :label="item.psCode" :value="item.psCode" :key="item.psCode"/>
  402. </el-select>
  403. </el-form-item>
  404. <el-form-item label="外系统部件编码" prop="extCompoCode">
  405. <el-input v-model="componentForm.extCompoCode" placeholder="请输入外系统部件编码"/>
  406. </el-form-item>
  407. <el-form-item label="部件模型" prop="compoModel">
  408. <el-select v-model="componentForm.compoModel" placeholder="请输入部件模型">
  409. <el-option v-for="item in this.modelList" :label="item.modelCode" :value="item.modelCode"
  410. :key="item.modelCode"
  411. />
  412. </el-select>
  413. </el-form-item>
  414. <el-form-item label="部件品牌" prop="compoBrand">
  415. <el-input v-model="componentForm.compoBrand" placeholder="请输入部件品牌"/>
  416. </el-form-item>
  417. <el-form-item label="部件型号" prop="compoSpec">
  418. <el-input v-model="componentForm.compoSpec" placeholder="请输入部件型号"/>
  419. </el-form-item>
  420. <el-form-item label="祖籍列表" prop="ancestors">
  421. <el-input v-model="componentForm.ancestors" placeholder="请输入祖籍列表"/>
  422. </el-form-item>
  423. <el-form-item label="上级列表" prop="parentCompo">
  424. <el-input v-model="componentForm.parentCompo" placeholder="请输入上级列表"/>
  425. </el-form-item>
  426. </el-form>
  427. <div slot="footer" class="dialog-footer">
  428. <el-button type="primary" @click="submitComponentForm">确 定</el-button>
  429. <el-button @click="ComponentCancel">取 消</el-button>
  430. </div>
  431. </el-dialog>
  432. </div>
  433. </el-drawer>
  434. <!-- 详情弹框 -->
  435. <el-dialog :visible.sync="showDrawer" title="设备状态详情" custom-class="detail-dialog">
  436. <div class="button-group">
  437. <el-button type="primary" plain icon="el-icon-edit" size="mini" @click="handleUpdate(curRow)"
  438. v-hasPermi="['ems:device:edit']"
  439. >修改
  440. </el-button>
  441. <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleDelete(curRow)"
  442. v-hasPermi="['ems:device:remove']"
  443. >删除
  444. </el-button>
  445. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="showCallLog(curRow)">调用日志
  446. </el-button>
  447. <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="showReportLog(curRow)">设备日志
  448. </el-button>
  449. </div>
  450. <div v-if="curRow">
  451. <!-- 分页导航 -->
  452. <el-tabs v-model="activeTab">
  453. <el-tab-pane label="设备基本信息" name="basic"></el-tab-pane>
  454. <el-tab-pane label="设备参数" name="attr"></el-tab-pane>
  455. <el-tab-pane label="设备事件" name="event"></el-tab-pane>
  456. <el-tab-pane label="设备能力" name="ability"></el-tab-pane>
  457. </el-tabs>
  458. <!-- 设备基本信息 -->
  459. <div v-if="activeTab === 'basic'">
  460. <el-card class="box-card">
  461. <div slot="header" class="clearfix">
  462. <span class="section-title">设备状态基本信息</span>
  463. </div>
  464. <div>
  465. <p><span class="bold">设备名称:</span>{{ curRow.deviceName }}</p>
  466. <p><span class="bold">设备代码:</span>{{ curRow.deviceCode }}</p>
  467. <p><span class="bold">子系统:</span>{{ curRow.subsystemName }}</p>
  468. <p><span class="bold">设备类型:</span>{{ curRow.deviceCategoryName }}</p>
  469. <p><span class="bold">归属设施:</span>{{ curRow.refFacsName }}</p>
  470. </div>
  471. </el-card>
  472. </div>
  473. <!-- 属性信息 -->
  474. <div v-if="activeTab === 'attr'">
  475. <el-card class="box-card">
  476. <div v-for="(tableData, tableName) in attrTables" :key="tableName">
  477. <p class="section-title">{{ tableData.title }}</p>
  478. <el-table :data="tableData.data" style="width: 100%" :show-header="true" :empty-text="'暂无数据'">
  479. <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
  480. <el-table-column label="属性名称" prop="attrName"></el-table-column>
  481. <el-table-column label="属性标识" prop="attrKey"></el-table-column>
  482. <!-- 动态显示属性值 -->
  483. <el-table-column label="属性值" align="center">
  484. <template slot-scope="scope">
  485. <span v-if="tableData.title === '状态属性'">
  486. {{ scope.row.attrValueName || getAttrValueText(scope.row.attrValue) }}
  487. <span v-if="scope.row.attrUnit">{{ scope.row.attrUnit }}</span>
  488. </span>
  489. <span v-else>
  490. {{ scope.row.attrValue }}
  491. </span>
  492. </template>
  493. </el-table-column>
  494. </el-table>
  495. </div>
  496. </el-card>
  497. </div>
  498. <!-- 设备能力-->
  499. <div v-if="activeTab === 'ability'">
  500. <el-card class="box-card">
  501. <div slot="header" class="clearfix">
  502. <span class="section-title">设备能力</span>
  503. </div>
  504. <el-table :data="abilityData" style="width: 100%" :show-header="true" :empty-text="'暂无数据'">
  505. <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
  506. <el-table-column label="能力名称" prop="abilityName"></el-table-column>
  507. <el-table-column label="能力键" prop="abilityKey"></el-table-column>
  508. <el-table-column label="能力描述" prop="abilityDesc"></el-table-column>
  509. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  510. <template slot-scope="scope">
  511. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAbilityEdit(scope.row)">
  512. 执行
  513. </el-button>
  514. </template>
  515. </el-table-column>
  516. </el-table>
  517. </el-card>
  518. </div>
  519. <el-dialog title="设备能力执行" :visible.sync="abilityDialogVisible" width="60%" append-to-body>
  520. <el-form ref="abilityForm" :model="abilityForm" label-width="120px">
  521. <el-form-item label="能力名称">
  522. <el-input v-model="abilityForm.abilityName" placeholder="请输入能力名称" disabled></el-input>
  523. </el-form-item>
  524. <el-form-item label="能力键">
  525. <el-input v-model="abilityForm.abilityKey" placeholder="请输入能力键" disabled></el-input>
  526. </el-form-item>
  527. <el-form-item label="能力描述">
  528. <el-input type="textarea" v-model="abilityForm.abilityDesc" placeholder="请输入能力描述" disabled
  529. ></el-input>
  530. </el-form-item>
  531. <el-form-item label="能力参数">
  532. <el-input type="textarea" v-model="abilityForm.abilityParam" placeholder="请输入能力参数"></el-input>
  533. </el-form-item>
  534. </el-form>
  535. <div slot="footer" class="dialog-footer">
  536. <el-button type="primary" @click="saveAbilityEdit">执行</el-button>
  537. <el-button @click="cancelAbilityEdit">取消</el-button>
  538. </div>
  539. </el-dialog>
  540. <!-- 设备事件= -->
  541. <div v-if="activeTab === 'event'">
  542. <el-card class="box-card">
  543. <div slot="header" class="clearfix">
  544. <span class="section-title">设备事件</span>
  545. </div>
  546. <el-table :data="eventData" style="width: 100%" :show-header="true" :empty-text="'暂无数据'">
  547. <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
  548. <el-table-column label="事件名称" prop="eventKey"></el-table-column>
  549. <el-table-column label="事件类型" prop="eventType" :formatter="formatEventType"></el-table-column>
  550. <el-table-column label="事件代码" prop="eventCode"></el-table-column>
  551. <el-table-column label="外部事件代码" prop="extEventCode"></el-table-column>
  552. </el-table>
  553. </el-card>
  554. </div>
  555. </div>
  556. </el-dialog>
  557. </el-col>
  558. </el-row>
  559. </div>
  560. </template>
  561. <script>
  562. import { listDevRecursionByArea, getDevice, delDevice, addDevice, updateDevice } from '@/api/device/device'
  563. import { areaTreeSelect,getAreaTreeSelect} from '@/api/basecfg/area'
  564. import { getFacsCategorygetByCode, listAllFacs } from '@/api/basecfg/emsfacs'
  565. import { listSubsystemAll } from '@/api/adapter/subsystem'
  566. import { getModelByCode, listAllModel } from '@/api/basecfg/objModel'
  567. import { getObjAttr } from '@/api/basecfg/objAttribute'
  568. import { addAttrValueBatch } from '@/api/basecfg/objAttributeValue'
  569. import { getDevProcess } from '@/api/commonApi'
  570. import { addComponent, delComponent, getComponent, listByDevice, updateComponent } from '@/api/basecfg/component'
  571. import Treeselect from '@riophae/vue-treeselect'
  572. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  573. import { listcallAbility } from '@/api/basecfg/objAbility'
  574. import { getCallLog, getReportLog, listCallLog, listReportLog } from '@/api/basecfg/objLog'
  575. export default {
  576. name: 'Device',
  577. components: { Treeselect },
  578. data() {
  579. return {
  580. // 归属区域下拉选项
  581. areaOptions: [],
  582. // 归属子区下拉选项
  583. subAreaOptions: [],
  584. abilityDialogVisible: false,
  585. abilityForm: {
  586. abilityName: '',
  587. abilityKey: '',
  588. abilityParam: '',
  589. abilityDesc: ''
  590. },
  591. currentAbilityIndex: -1,
  592. activeTab: 'basic',
  593. ComponentRow: [],
  594. componentForm: {},
  595. subcategoryCode: '',
  596. // 属性模板数组
  597. attrList: [],
  598. attrValues: [],
  599. ComponentList: [],
  600. abilityDevice: [],
  601. attrValuesMap: {},
  602. modelList: [],
  603. showDrawer: false,
  604. showDevProcessDrawer: false,
  605. componentOpen: false,
  606. // 遮罩层
  607. loading: true,
  608. // 选中数组
  609. ids: [],
  610. // 非单个禁用
  611. single: true,
  612. // 非多个禁用
  613. multiple: true,
  614. // 显示搜索条件
  615. showSearch: true,
  616. // 总条数
  617. total: 0,
  618. // 能源设备表格数据
  619. deviceList: [],
  620. // 弹出层标题
  621. title: '',
  622. // 是否显示弹出层
  623. open: false,
  624. // 区域名称
  625. areaName: undefined,
  626. // 区域树选项
  627. treeAreaOptions: undefined,
  628. totalAreaOptions: undefined,
  629. // 设施选项
  630. facsOptions: undefined,
  631. // 设备分类
  632. subCategoryOptions: undefined,
  633. subsystemOptions: undefined,
  634. devOptions: undefined,
  635. defaultProps: {
  636. children: 'children',
  637. label: 'label'
  638. },
  639. callDaterangeTime: [],
  640. logDaterangeTime: [],
  641. logQueryParams: {
  642. startTime: '',
  643. endTime: ''
  644. },
  645. callLogQueryParams: {
  646. abilityKey: '',
  647. callStatus: '',
  648. startTime: '',
  649. endTime: ''
  650. },
  651. callStatusOptions: {
  652. 0: '成功',
  653. 1: '进行中',
  654. 2: '失败'
  655. },
  656. callLogDetailDialog: false,
  657. callLogDetailData: {},
  658. reportDetailDialog: false,
  659. reportDetailData: {},
  660. callLog: false,
  661. reportLog: false,
  662. callLogData: [],
  663. reportLogData: [],
  664. // 查询参数
  665. queryParams: {
  666. psCode: null,
  667. pageNum: 1,
  668. pageSize: 10,
  669. deviceCode: null,
  670. deviceSubCategory: '',
  671. deviceCategory: 'E',
  672. locationRef: null,
  673. locationRefName:null,
  674. refFacs: null,
  675. customAttrs: null,
  676. areaCode: null,
  677. location: null
  678. },
  679. queryComponentParams: {
  680. pageNum: 1,
  681. pageSize: 10
  682. },
  683. objComTypeMapping: {
  684. 1: '总开',
  685. 2: '照明',
  686. 3: '风机'
  687. },
  688. objComTypeOptions: [
  689. { code: 1, name: '总开' },
  690. { code: 2, name: '照明' },
  691. { code: 3, name: '风机' }
  692. ],
  693. curRow: {},
  694. abilityData: [],
  695. eventData: [],
  696. BaseData: [],
  697. ProtocolData: [],
  698. StateData: [],
  699. MeasureData: [],
  700. attrTables: {
  701. Base: { title: '基础属性', data: [] },
  702. Protocol: { title: '协议属性', data: [] },
  703. State: { title: '状态属性', data: [] },
  704. Measure: { title: '计量属性', data: [] }
  705. },
  706. // 表单参数
  707. form: {
  708. customAttrs: [],
  709. },
  710. // 表单校验
  711. rules: {
  712. refFacs: [
  713. { required: true, message: '归属设施', trigger: 'blur' }
  714. ],
  715. refArea: [
  716. { required: true, message: '安装位置', trigger: 'blur' }
  717. ],
  718. deviceCode: [
  719. { required: true, message: '设备代码不能为空', trigger: 'blur' }
  720. ],
  721. deviceName: [
  722. { required: true, message: '设备名称不能为空', trigger: 'blur' }
  723. ]
  724. },
  725. componentRules: {
  726. deviceCode: [
  727. { required: true, message: '设备code不能为空', trigger: 'blur' }
  728. ],
  729. compoCode: [
  730. { required: true, message: '部件编码不能为空', trigger: 'blur' }
  731. ],
  732. psCode: [
  733. { required: true, message: '工艺标签代码不能为空', trigger: 'blur' }
  734. ]
  735. }
  736. }
  737. },
  738. watch: {
  739. // 根据名称筛选区域树
  740. areaName(val) {
  741. this.$refs.tree.filter(val)
  742. }
  743. },
  744. created() {
  745. this.getList()
  746. this.getAreaTree('0', 2)
  747. this.getFacsOptions()
  748. this.getSubsystem()
  749. this.getSubCategorygetByCode()
  750. this.getFacsModel()
  751. this.getAllDevProcess(this.subcategoryCode)
  752. const now = new Date()
  753. const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)
  754. const endOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59)
  755. this.logQueryParams.startTime = this.formatDate(startOfDay)
  756. this.logQueryParams.endTime = this.formatDate(endOfDay)
  757. this.callLogQueryParams.startTime = this.formatDate(startOfDay)
  758. this.callLogQueryParams.endTime = this.formatDate(endOfDay)
  759. // 设置默认日期范围
  760. this.callDaterangeTime = [this.formatDate(startOfDay), this.formatDate(endOfDay)]
  761. this.logDaterangeTime = [this.formatDate(startOfDay), this.formatDate(endOfDay)]
  762. this.loadAreaOptions(); // 加载归属区域数据
  763. },
  764. methods: {
  765. /** 归属设施*/
  766. handleFacilityChange(selectedFacilityCode) {
  767. const selectedFacility = this.facsOptions.find(f => f.facsCode === selectedFacilityCode);
  768. if (selectedFacility) {
  769. this.form.areaName = selectedFacility.refAreaName;
  770. this.form.areaCode = selectedFacility.refArea;
  771. this.loadSubAreaOptions(selectedFacility.refArea);
  772. }
  773. },
  774. /** 归属设施*/
  775. handleAreaChange(value) {
  776. this.form.locationRef = null;
  777. this.loadSubAreaOptions(value);
  778. },
  779. /**下拉归属区域*/
  780. loadAreaOptions() {
  781. getAreaTreeSelect('0', 1 ).then(response => {
  782. this.areaOptions = response.data || [];
  783. });
  784. },
  785. /**下拉归属子区*/
  786. loadSubAreaOptions(rootCode) {
  787. getAreaTreeSelect(rootCode, 2 ).then(response => {
  788. this.subAreaOptions = response.data || [];
  789. });
  790. },
  791. getFacsOptions() {
  792. const getFacsParams = {
  793. facsCategory: this.queryParams.deviceCategory,
  794. subCategory: this.queryParams.deviceSubCategory
  795. }
  796. listAllFacs(getFacsParams).then(response => {
  797. this.facsOptions = response.data
  798. })
  799. },
  800. formatDate(date) {
  801. if (!date) return ''
  802. const year = date.getFullYear()
  803. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  804. const day = date.getDate().toString().padStart(2, '0')
  805. const hours = date.getHours().toString().padStart(2, '0')
  806. const minutes = date.getMinutes().toString().padStart(2, '0')
  807. const seconds = date.getSeconds().toString().padStart(2, '0')
  808. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  809. },
  810. formatObjType(value) {
  811. const objTypeMap = {
  812. 2: '设备'
  813. }
  814. return objTypeMap[value] || '未知类型'
  815. },
  816. formatCallStatus(status) {
  817. const statusMap = {
  818. 0: '成功',
  819. 1: '进行中',
  820. 2: '失败'
  821. }
  822. return statusMap[status] || '未知状态'
  823. },
  824. /**日志*/
  825. showCallLog(row) {
  826. this.curRow = row
  827. this.getCallLog(row.deviceCode, this.callLogQueryParams.startTime, this.callLogQueryParams.endTime)
  828. this.callLog = true
  829. },
  830. showReportLog(row) {
  831. this.curRow = row
  832. // 加载设备日志数据
  833. this.getReportLog(row.deviceCode, this.logQueryParams.startTime, this.logQueryParams.endTime)
  834. this.reportLog = true
  835. },
  836. /**重置调用日志*/
  837. resetCallLogQuery() {
  838. this.callDaterangeTime = []
  839. this.callLogQueryParams.abilityKey = ''
  840. this.callLogQueryParams.callStatus = ''
  841. this.handleCallLogQuery()
  842. },
  843. /**查询调用日志*/
  844. handleCallLogQuery() {
  845. if (this.curRow) {
  846. const startTime = this.callDaterangeTime[0]
  847. const endTime = this.callDaterangeTime[1]
  848. const abilityKey = this.callLogQueryParams.abilityKey
  849. const callStatus = this.callLogQueryParams.callStatus
  850. this.getCallLog(this.curRow.deviceCode, startTime, endTime, abilityKey, callStatus)
  851. }
  852. },
  853. /**调用日志表格*/
  854. getCallLog(deviceCode, startTime, endTime, abilityKey, callStatus) {
  855. const query = {
  856. objCode: deviceCode,
  857. objType: '2',
  858. startRecTime: startTime,
  859. endRecTime: endTime,
  860. abilityKey: abilityKey,
  861. callStatus: callStatus
  862. }
  863. listCallLog(query).then(response => {
  864. this.callLogData = response.rows || []
  865. })
  866. },
  867. /**调用日志详情*/
  868. handleCallLogDetail(row) {
  869. getCallLog(row.id).then(response => {
  870. this.callLogDetailData = response.data || {}
  871. this.callLogDetailDialog = true
  872. })
  873. },
  874. /**重置设备日志*/
  875. resetLogQuery() {
  876. this.logDaterangeTime = []
  877. this.handleLogQuery() // 重新查询
  878. },
  879. /** 查询设备日志*/
  880. handleLogQuery() {
  881. if (this.curRow) {
  882. const startTime = this.logDaterangeTime[0]
  883. const endTime = this.logDaterangeTime[1]
  884. this.getReportLog(this.curRow.deviceCode, startTime, endTime)
  885. }
  886. },
  887. /**设备日志表格*/
  888. getReportLog(deviceCode, startTime, endTime) {
  889. const query = {
  890. objCode: deviceCode,
  891. objType: '2',
  892. startRecTime: startTime,
  893. endRecTime: endTime,
  894. }
  895. listReportLog(query).then(response => {
  896. this.reportLogData = response.rows || []
  897. })
  898. },
  899. /**设备日志详情*/
  900. handleReportLogDetail(row) {
  901. getReportLog(row.id).then(response => {
  902. this.reportDetailData = response.data || {}
  903. this.reportDetailDialog = true
  904. })
  905. },
  906. formatEventType(row, column, cellValue) {
  907. return cellValue === 1 ? '消息上报' : '异常告警'
  908. },
  909. getAttrValueText(attrValue) {
  910. const valueMap = {
  911. 0: '关闭',
  912. 1: '开启',
  913. 2: '通电'
  914. }
  915. return valueMap[attrValue] || attrValue
  916. },
  917. /** 查询能源设备列表 */
  918. getList() {
  919. this.loading = true
  920. listDevRecursionByArea(this.queryParams).then(response => {
  921. this.deviceList = response.rows
  922. this.total = response.total
  923. this.loading = false
  924. })
  925. },
  926. /**新增、修改、删除*/
  927. handleComponentAdd() {
  928. this.componentReset()
  929. this.componentOpen = true
  930. this.title = '添加设备器件属性'
  931. this.componentForm.deviceCode = this.ComponentRow.deviceCode // 设置默认设备代码
  932. },
  933. handleComponentUpdate(row) {
  934. this.componentReset()
  935. const id = row.id || this.ids
  936. getComponent(id).then(response => {
  937. this.componentForm = response.data
  938. this.componentOpen = true
  939. this.title = '修改设备器件属性'
  940. this.componentForm.deviceCode = this.ComponentRow.deviceCode // 设置默认设备代码
  941. })
  942. },
  943. handleComponentDelete(row) {
  944. const ids = row.id || this.ids
  945. this.$modal.confirm('是否确认删除能源对象属性编号为"' + ids + '"的数据项?').then(function() {
  946. return delComponent(ids)
  947. }).then(() => {
  948. this.getComponentList(row.deviceCode)
  949. this.$modal.msgSuccess('删除成功')
  950. }).catch(() => {
  951. })
  952. },
  953. submitComponentForm() {
  954. this.$refs['componentForm'].validate(valid => {
  955. if (valid) {
  956. if (this.componentForm.id != null) {
  957. updateComponent(this.componentForm).then(response => {
  958. this.$modal.msgSuccess('修改成功')
  959. this.componentOpen = false
  960. this.getComponentList(this.componentForm.deviceCode)
  961. })
  962. } else {
  963. addComponent(this.componentForm).then(response => {
  964. this.$modal.msgSuccess('新增成功')
  965. this.componentOpen = false
  966. this.getComponentList(this.componentForm.deviceCode)
  967. })
  968. }
  969. }
  970. })
  971. },
  972. ComponentCancel() {
  973. this.componentOpen = false
  974. this.componentReset()
  975. },
  976. /**查询部件列表*/
  977. getComponentList(deviceCode) {
  978. listByDevice(deviceCode).then(response => {
  979. this.ComponentList = response.data
  980. })
  981. },
  982. /** 查询区域树结构 */
  983. getAreaTree(areaCode, layer) {
  984. getAreaTreeSelect(areaCode, layer).then(response => {
  985. this.treeAreaOptions = [{
  986. id: null,
  987. label: '全部',
  988. children: response.data
  989. }]
  990. })
  991. },
  992. // 筛选节点
  993. filterNode(value, data) {
  994. if (!value) return true
  995. return data.label.indexOf(value) !== -1
  996. },
  997. // 节点单击事件
  998. handleNodeClick(data) {
  999. this.queryParams.locationRef = data.id
  1000. this.handleQuery()
  1001. },
  1002. // 取消按钮
  1003. cancel() {
  1004. this.open = false
  1005. this.reset()
  1006. },
  1007. /** 执行弹框 */
  1008. handleAbilityEdit(row) {
  1009. // 复制当前行记录的值到弹框表单中
  1010. this.abilityForm = JSON.parse(JSON.stringify(row))
  1011. this.currentAbilityIndex = this.abilityData.indexOf(row)
  1012. this.abilityDialogVisible = true
  1013. },
  1014. /**设备能力-执行按钮*/
  1015. saveAbilityEdit() {
  1016. if (this.currentAbilityIndex !== -1) {
  1017. const updatedAbility = { ...this.abilityForm }
  1018. const abilityParams = {
  1019. objCode: this.curRow.deviceCode,
  1020. objType: 2,
  1021. modeCode: updatedAbility.modelCode,
  1022. abilityKey: updatedAbility.abilityKey,
  1023. abilityParam: updatedAbility.abilityParam
  1024. }
  1025. listcallAbility(abilityParams)
  1026. .then((response) => {
  1027. if (response.code === 200) {
  1028. this.$message.success('保存成功')
  1029. this.abilityData.splice(this.currentAbilityIndex, 1, updatedAbility)
  1030. }
  1031. })
  1032. this.abilityDialogVisible = false
  1033. }
  1034. },
  1035. /** 取消执行按钮 */
  1036. cancelAbilityEdit() {
  1037. this.abilityDialogVisible = false
  1038. this.abilityForm = {
  1039. abilityName: '',
  1040. abilityKey: '',
  1041. abilityParam: '',
  1042. abilityDesc: ''
  1043. }
  1044. this.currentAbilityIndex = -1
  1045. },
  1046. // 表单重置
  1047. reset() {
  1048. this.form = {
  1049. id: null,
  1050. areaCode:null,
  1051. location:null,
  1052. locationRef:null,
  1053. deviceCode: null,
  1054. deviceName: null,
  1055. deviceType: null,
  1056. deviceStatus: null,
  1057. deviceModel: null,
  1058. refArea: null,
  1059. refFacs: null,
  1060. subsystemCode: null,
  1061. psCode: null,
  1062. createTime: null,
  1063. updateTime: null,
  1064. customAttrs: []
  1065. }
  1066. this.attrList = []
  1067. this.attrValuesMap = {}
  1068. this.resetForm('form')
  1069. },
  1070. componentReset() {
  1071. this.componentForm = {
  1072. id: null,
  1073. deviceCode: this.ComponentRow.deviceCode || '',
  1074. compoCode: null,
  1075. compoTag: null,
  1076. psCode: null,
  1077. extCompoCode: null,
  1078. compoModel: null,
  1079. compoBrand: null,
  1080. compoSpec: null,
  1081. ancestors: null,
  1082. parentCompo: null
  1083. }
  1084. this.resetForm('componentForm')
  1085. },
  1086. /** 搜索按钮操作 */
  1087. handleQuery() {
  1088. this.queryParams.pageNum = 1
  1089. this.getList()
  1090. },
  1091. /** 重置按钮操作 */
  1092. resetQuery() {
  1093. this.queryParams.locationRef = null
  1094. this.resetForm('queryForm')
  1095. this.handleQuery()
  1096. },
  1097. // 多选框选中数据
  1098. handleSelectionChange(selection) {
  1099. this.ids = selection.map(item => item.id)
  1100. this.single = selection.length !== 1
  1101. this.multiple = !selection.length
  1102. },
  1103. /** 新增按钮操作 */
  1104. handleAdd() {
  1105. this.reset()
  1106. this.open = true
  1107. this.title = '添加能源设备'
  1108. this.attrList = []
  1109. this.form.customAttrs = []
  1110. this.attrValuesMap = {}
  1111. // 加载归属子区
  1112. this.loadSubAreaOptions(this.form.areaCode);
  1113. },
  1114. /**设备器件按钮*/
  1115. handleDevProcess(row) {
  1116. this.showDevProcessDrawer = true
  1117. this.ComponentRow = row
  1118. listByDevice(this.ComponentRow.deviceCode).then(response => {
  1119. this.ComponentList = response.data
  1120. })
  1121. },
  1122. shouldShowDevProcessButton(row) {
  1123. const categoryIsW = this.queryParams.deviceCategory === 'W'
  1124. const validPsCodes = ['AA', 'AH', 'AJ', 'AM', 'AP', 'AL', 'APE', 'ALE', 'AF', 'ACC']
  1125. const psCodeIsValid = validPsCodes.includes(row.psCode)
  1126. // 只有当设备分类为输能设备且设备工艺代码有效时,才返回true
  1127. return categoryIsW && psCodeIsValid
  1128. },
  1129. /**设备管理按钮*/
  1130. handleDetail(row) {
  1131. this.showDrawer = true
  1132. this.curRow = row
  1133. console.log("设备详情",this.curRow)
  1134. this.subKey = this.$options.data().subKey
  1135. getModelByCode(this.curRow.deviceModel).then(response => {
  1136. this.eventData = response.data?.eventList || []
  1137. this.abilityData = response.data?.abilityList || []
  1138. })
  1139. getObjAttr(2, this.curRow.deviceCode).then(response => {
  1140. this.attrTables.Base.data = response.data?.Base || []
  1141. this.attrTables.Protocol.data = response.data?.Protocol || []
  1142. this.attrTables.State.data = response.data?.State || []
  1143. this.attrTables.Measure.data = response.data?.Measure || []
  1144. })
  1145. this.activeTab = 'basic'
  1146. },
  1147. /** 修改按钮操作 */
  1148. handleUpdate(row) {
  1149. this.reset()
  1150. const id = row.id || this.ids
  1151. getDevice(id).then(response => {
  1152. this.form = response.data
  1153. // 加载归属子区
  1154. this.loadSubAreaOptions(this.form.areaCode);
  1155. console.log('this.form', this.form)
  1156. this.open = true
  1157. this.title = '修改能源设备'
  1158. this.attrList = []
  1159. this.form.customAttrs = []
  1160. this.attrValuesMap = {}
  1161. this.getObjAttr(2, this.form.deviceCode)
  1162. })
  1163. },
  1164. /** 提交按钮 */
  1165. submitForm() {
  1166. if (!this.attrList) {
  1167. this.attrList = []
  1168. }
  1169. if (!this.form.customAttrs) {
  1170. this.form.customAttrs = []
  1171. }
  1172. let dataToSubmit = []
  1173. this.attrList.forEach(attr => {
  1174. const attrName = attr.attrName
  1175. const attrKey = attr.attrKey
  1176. const attrValue = this.attrValuesMap[attrKey]
  1177. const existingIndex = dataToSubmit.findIndex(item => item.attrKey === attrKey)
  1178. if (existingIndex === -1) {
  1179. dataToSubmit.push({
  1180. modelCode: this.form.deviceModel,
  1181. objCode: this.form.deviceCode,
  1182. objType: 2,
  1183. attrKey: attrKey,
  1184. attrValue: attrValue,
  1185. attrName: attrName
  1186. })
  1187. }
  1188. })
  1189. // 添加自定义属性数据
  1190. this.form.customAttrs.forEach(customAttr => {
  1191. const attrName = customAttr.attrName
  1192. const attrKey = customAttr.attrKey
  1193. const attrValue = customAttr.attrValue
  1194. const existingIndex = dataToSubmit.findIndex(item => item.attrKey === attrKey)
  1195. if (existingIndex === -1) {
  1196. dataToSubmit.push({
  1197. modelCode: '',
  1198. objCode: this.form.deviceCode,
  1199. objType: 2,
  1200. attrKey: attrKey,
  1201. attrValue: attrValue,
  1202. attrName: attrName
  1203. })
  1204. }
  1205. })
  1206. this.$refs['form'].validate(valid => {
  1207. if (valid) {
  1208. if (this.form.id != null) {
  1209. updateDevice(this.form).then(response => {
  1210. this.$modal.msgSuccess('修改成功')
  1211. this.open = false
  1212. this.showDrawer=false
  1213. this.getList()
  1214. if (this.showDrawer && this.curRow && this.curRow.id === this.form.id) {
  1215. this.handleDetail(this.form)
  1216. }
  1217. })
  1218. if (dataToSubmit.length > 0) {
  1219. addAttrValueBatch(dataToSubmit)
  1220. .then(response => {
  1221. if (response.code === 200) {
  1222. this.$message.success('属性添加成功')
  1223. }
  1224. })
  1225. }
  1226. } else {
  1227. addDevice(this.form).then(response => {
  1228. this.$modal.msgSuccess('新增成功')
  1229. this.open = false
  1230. this.getList() // 刷新设备列表
  1231. })
  1232. if (dataToSubmit.length > 0) {
  1233. addAttrValueBatch(dataToSubmit)
  1234. .then(response => {
  1235. if (response.code === 200) {
  1236. this.$message.success('属性添加成功')
  1237. }
  1238. })
  1239. }
  1240. }
  1241. }
  1242. })
  1243. },
  1244. /** 删除按钮操作 */
  1245. handleDelete(row) {
  1246. const ids = row.id || this.ids
  1247. this.$modal.confirm('是否确认删除能源设备编号为"' + ids + '"的数据项?').then(function() {
  1248. return delDevice(ids)
  1249. }).then(() => {
  1250. this.getList()
  1251. this.$modal.msgSuccess('删除成功')
  1252. }).catch(() => {
  1253. })
  1254. },
  1255. /** 导出按钮操作 */
  1256. handleExport() {
  1257. this.download('ems/basecfg/device/export', {
  1258. ...this.queryParams
  1259. }, `device_${new Date().getTime()}.xlsx`)
  1260. },
  1261. getSubCategorygetByCode() {
  1262. getFacsCategorygetByCode(this.queryParams.deviceCategory).then(response => {
  1263. this.subCategoryOptions = response.data.subtypeList || []
  1264. })
  1265. },
  1266. getSubsystem() {
  1267. listSubsystemAll().then(response => {
  1268. this.subsystemOptions = response.data
  1269. })
  1270. },
  1271. getAllDevProcess(subcategoryCode) {
  1272. getDevProcess(subcategoryCode).then(response => {
  1273. this.devOptions = response.data
  1274. })
  1275. },
  1276. deviceCategoryChange() {
  1277. this.queryParams.deviceSubCategory = ''
  1278. if (this.queryParams.deviceCategory === 'E' || this.queryParams.deviceCategory === 'W'
  1279. || this.queryParams.deviceCategory === 'T' || this.queryParams.deviceCategory === 'C') {
  1280. this.getAreaTree('0', 2)
  1281. } else if (this.queryParams.deviceCategory === 'Z') {
  1282. this.getAreaTree('0', 2)
  1283. }
  1284. this.getSubCategorygetByCode()
  1285. this.getFacsOptions()
  1286. this.handleQuery()
  1287. },
  1288. /**自定义属性表格*/
  1289. addCustomAttr() {
  1290. // 添加一个新的自定义属性
  1291. if (!Array.isArray(this.form.customAttrs)) {
  1292. this.form.customAttrs = []
  1293. }
  1294. this.form.customAttrs.push({
  1295. attrKey: '',
  1296. attrName: '',
  1297. attrValue: ''
  1298. })
  1299. // 强制更新视图
  1300. this.$forceUpdate()
  1301. },
  1302. deleteCustomAttr(index) {
  1303. // 删除指定索引的自定义属性
  1304. if (this.form.customAttrs.length > 0) {
  1305. this.form.customAttrs.splice(index, 1)
  1306. }
  1307. },
  1308. /**设备模型*/
  1309. updateAttrValue(attrKey, newValue) {
  1310. this.attrValuesMap[attrKey] = newValue
  1311. },
  1312. getFacsModel() {
  1313. listAllModel(2).then(response => {
  1314. this.modelList = response.data
  1315. })
  1316. },
  1317. handleModelChange(modelCode) {
  1318. if (modelCode) {
  1319. this.getModelByCode(modelCode)
  1320. this.getObjAttr(2, this.form.deviceCode)
  1321. }
  1322. },
  1323. getModelByCode(modelCode) {
  1324. getModelByCode(modelCode).then(response => {
  1325. const filteredAttrList = response.data.attrList.filter(attr => attr.attrType === 0)
  1326. this.attrList = filteredAttrList
  1327. })
  1328. },
  1329. /** getObjAttr存在问题 */
  1330. getObjAttr(objType, deviceCode) {
  1331. getObjAttr(objType, deviceCode).then(response => {
  1332. // const attrs = response.data.attrs;
  1333. const attrs = response.data.attrs.filter(attr => attr.attrType === 0)
  1334. const attrValues = response.data.attrValues || [] // 确保是一个数组
  1335. // 创建一个映射对象,用于存储 attrKey 与对应的 attrValue
  1336. const attrValuesMap = {}
  1337. // 遍历 attrs 数组
  1338. attrs.forEach(attr => {
  1339. // 查找 attrValues 数组中是否有匹配的 attrKey
  1340. const attrValueObj = attrValues.find(value => value.attrKey === attr.attrKey)
  1341. if (attrValueObj) {
  1342. attrValuesMap[attr.attrKey] = attrValueObj.attrValue
  1343. } else {
  1344. attrValuesMap[attr.attrKey] = ''
  1345. }
  1346. })
  1347. // 更新 attrValuesMap 到组件的数据中
  1348. this.attrValuesMap = attrValuesMap
  1349. })
  1350. }
  1351. }
  1352. }
  1353. </script>
  1354. <style lang="scss" scoped>
  1355. .divider {
  1356. border-bottom: 2px solid #ebeef5;
  1357. margin: 10px 0;
  1358. }
  1359. .section-title {
  1360. font-size: 18px;
  1361. font-weight: bold;
  1362. margin-top: 20px;
  1363. margin-bottom: 10px;
  1364. }
  1365. .drawer-content {
  1366. padding: 0 20px;
  1367. }
  1368. .section-title {
  1369. font-size: 18px;
  1370. font-weight: bold;
  1371. }
  1372. .attr-list-container {
  1373. border: 1px solid #ccc;
  1374. padding: 10px;
  1375. margin: 10px 0;
  1376. font-weight: bold;
  1377. }
  1378. .attr-list-container ul {
  1379. padding: 0;
  1380. list-style: none;
  1381. }
  1382. .attr-item {
  1383. display: flex;
  1384. align-items: center;
  1385. margin-bottom: 10px;
  1386. }
  1387. .attr-input {
  1388. min-width: 100px;
  1389. flex: 1;
  1390. }
  1391. .status-online {
  1392. color: #00FF00; /* 在线状态颜色 */
  1393. background-color: #DDFFDD;
  1394. padding: 2px 6px;
  1395. border-radius: 4px;
  1396. }
  1397. .status-offline {
  1398. color: #FF0000; /* 离线状态颜色 */
  1399. background-color: #FFDDDD;
  1400. padding: 2px 6px;
  1401. border-radius: 4px;
  1402. }
  1403. .detail-dialog .el-dialog {
  1404. width: 80%;
  1405. }
  1406. .section-title {
  1407. font-size: 16px;
  1408. font-weight: bold;
  1409. margin: 10px 0;
  1410. padding: 5px 0;
  1411. border-bottom: 1px solid #ebeef5;
  1412. }
  1413. .dialog-header {
  1414. display: flex;
  1415. justify-content: space-between;
  1416. align-items: center;
  1417. width: 100%;
  1418. }
  1419. .button-group {
  1420. display: flex;
  1421. gap: 10px;
  1422. }
  1423. /* 禁用状态的输入框样式 */
  1424. .el-input.is-disabled .el-input__inner,
  1425. .el-textarea.is-disabled .el-textarea__inner {
  1426. background-color: #f5f7fa;
  1427. border-color: #e4e7ed;
  1428. color: #c0c4cc;
  1429. }
  1430. </style>