ControlArea.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /* 控制区 */
  2. <template>
  3. <gy-card
  4. title="控制区"
  5. area-style="control"
  6. circle-style="green"
  7. content-style="44"
  8. @contextmenu="contextmenu"
  9. >
  10. <ControlMatrixCard
  11. title="待启动"
  12. :datas="ls.start"
  13. :operateStyle="1"
  14. ref="start"
  15. ></ControlMatrixCard>
  16. <ControlMatrixCard
  17. title="待停机"
  18. :datas="ls.stop"
  19. :operateStyle="2"
  20. ref="stop"
  21. ></ControlMatrixCard>
  22. <ControlMatrixCard
  23. title="待维护"
  24. :datas="ls.maintain"
  25. :operateStyle="6"
  26. ref="maintain"
  27. ></ControlMatrixCard>
  28. <ControlMatrixCard
  29. title="待取消维护"
  30. :datas="ls.unmaintain"
  31. :operateStyle="8"
  32. ref="unmaintain"
  33. ></ControlMatrixCard>
  34. <ControlMatrixCard
  35. title="待复位"
  36. :datas="ls.reset"
  37. :operateStyle="5"
  38. ref="reset"
  39. ></ControlMatrixCard>
  40. <el-button
  41. style="
  42. z-index: 2;
  43. position: absolute;
  44. bottom: 10px;
  45. right: 10px;
  46. background: #292929;
  47. font-size: 15px;
  48. width: 90px;
  49. border: none;
  50. color: rgb(220, 220, 220);
  51. "
  52. size="small"
  53. @click="menuClicked({ type: 'send' })"
  54. >发送</el-button
  55. >
  56. </gy-card>
  57. <el-button-group
  58. style="z-index: 3; position: absolute; top: 6px; left: 120px"
  59. >
  60. <el-button :class="buttonLeftStyle" size="mini" @click="controlClick(false)"
  61. >手动</el-button
  62. >
  63. <el-button :class="buttonRightStyle" size="mini" @click="controlClick(true)"
  64. >自动</el-button
  65. >
  66. </el-button-group>
  67. </template>
  68. <script>
  69. import ControlMatrixCard from "./windturbine/control/ControlMatrixCard.vue";
  70. import MessageBridge from "../../assets/script/MessageBridge";
  71. import BackgroundData from "../../assets/script/BackgroundData";
  72. export default {
  73. name: "ControlArea",
  74. components: {
  75. ControlMatrixCard,
  76. },
  77. props: {},
  78. computed: {
  79. buttonLeftStyle: function () {
  80. return this.IsAutoControl ? "button-unselected" : "button-selected";
  81. },
  82. buttonRightStyle: function () {
  83. return this.IsAutoControl ? "button-selected" : "button-unselected";
  84. },
  85. },
  86. created: function () {
  87. this.initData();
  88. },
  89. data() {
  90. return {
  91. ls: {
  92. start: { key: "待启动", value: [] },
  93. stop: { key: "待停机", value: [] },
  94. maintain: { key: "待维护", value: [] },
  95. unmaintain: { key: "待取消维护", value: [] },
  96. reset: { key: "待复位", value: [] },
  97. },
  98. IsAutoControl: false,
  99. controlErorCodes:[
  100. "控制成功",
  101. "控制命令发送失败",
  102. "无效的控制地址",
  103. "被控设备异常",
  104. "网络连接错误,检查场站通信",
  105. "控制结果读取超时",
  106. "未知错误",
  107. "控制命令错误",
  108. "收到无法识别数据",
  109. "未读取到数据包",
  110. "未知错误",
  111. "风机操作过频繁",
  112. "风机被挂牌",
  113. "风机操作与风机状态不符",
  114. "需要登录",
  115. ],
  116. };
  117. },
  118. methods: {
  119. initData: function () {
  120. var mb = MessageBridge.getInstance();
  121. var vs = [{ key: "/topic/suggestion", action: this.suggestion }];
  122. mb.register(vs);
  123. },
  124. suggestion(msg, headers) {
  125. var val = JSON.parse(msg);
  126. var tp = headers["operate-type"];
  127. if (tp == "UnMaintain") {
  128. this.updateSuggestion(this.ls.unmaintain.value, val);
  129. } else if (tp == "Start") {
  130. //推荐启动
  131. this.updateSuggestion(this.ls.start.value, val);
  132. } else if (tp == "Stop") {
  133. // 推荐停机
  134. this.updateSuggestion(this.ls.stop.value, val);
  135. } else if (tp == "Reset") {
  136. // 推荐复位
  137. this.updateSuggestion(this.ls.reset.value, val);
  138. } else if (tp == "Maintain") {
  139. // 推荐维护
  140. this.updateSuggestion(this.ls.maintain.value, val);
  141. }
  142. },
  143. /* 获取推荐类型 */
  144. getSuggestionType(val) {
  145. if (typeof val === "undefined") return null;
  146. for (var v in val) {
  147. return val[v].adviceOperateStyle;
  148. }
  149. return null;
  150. },
  151. /* 更新推荐数据 */
  152. updateSuggestion(ll, val) {
  153. var lls = new Array();
  154. for (var v1 in ll) {
  155. var v2 = val[ll[v1]];
  156. if (typeof v2 === "undefined") {
  157. lls.push(v1);
  158. }
  159. }
  160. for (var v3 in lls) {
  161. ll.splice(v3, 1);
  162. }
  163. for (var v in val) {
  164. var vl = val[v];
  165. if (!ll.includes(vl.windturbineId)) {
  166. ll.push(vl.windturbineId);
  167. }
  168. }
  169. },
  170. /* 右键菜单 */
  171. contextmenu() {
  172. const { remote } = require("electron");
  173. var that = this;
  174. const menuTemplate = [
  175. {
  176. label: "发送",
  177. click() {
  178. that.menuClicked({ type: "send" });
  179. },
  180. },
  181. {
  182. label: "挂牌",
  183. submenu: [
  184. {
  185. label: "检修",
  186. click() {
  187. that.menuClicked({ type: "lock", value: "CheckLock" });
  188. },
  189. },
  190. {
  191. label: "故障维修",
  192. click() {
  193. that.menuClicked({ type: "lock", value: "FaultLock" });
  194. },
  195. },
  196. {
  197. label: "场内受累检修",
  198. click() {
  199. that.menuClicked({ type: "lock", value: "StationCheckLock" });
  200. },
  201. },
  202. {
  203. label: "场内受累故障",
  204. click() {
  205. that.menuClicked({ type: "lock", value: "StationFaulLock" });
  206. },
  207. },
  208. {
  209. label: "场外受累电网",
  210. click() {
  211. that.menuClicked({
  212. type: "lock",
  213. value: "StationPowerLineLock",
  214. });
  215. },
  216. },
  217. {
  218. label: "场外受累天气",
  219. click() {
  220. that.menuClicked({ type: "lock", value: "StationWeatherLock" });
  221. },
  222. },
  223. ],
  224. },
  225. {
  226. label: "标注",
  227. click() {
  228. that.menuClicked({ type: "marking" });
  229. },
  230. },
  231. ];
  232. const menu = remote.Menu.buildFromTemplate(menuTemplate);
  233. menu.popup(remote.getCurrentWindow());
  234. },
  235. menuClicked(msg) {
  236. var bd = BackgroundData.getInstance();
  237. if (!bd.LoginUser) {
  238. this.$notify({
  239. title: "请登录",
  240. message: "控制风机需要先登录!",
  241. type: "warning",
  242. position: "bottom-right",
  243. offset: 60,
  244. });
  245. return;
  246. }
  247. if (msg.type == "lock") {
  248. // 挂牌
  249. var los = this.getSelectedItems();
  250. for (var id in los) {
  251. los[id].lockType = msg.value;
  252. }
  253. bd.windturbineControl(
  254. los,
  255. true,
  256. this.controlSuccess,
  257. this.controlError
  258. );
  259. } else if (msg.type == "send") {
  260. // 发送
  261. var vs = this.getSelectedItems(true);
  262. bd.windturbineControl(
  263. vs,
  264. false,
  265. this.controlSuccess,
  266. this.controlError
  267. );
  268. } else if (msg.type == "marking") {
  269. // 标注
  270. var vvs = this.getSelectedItems();
  271. bd.marking(vvs);
  272. }
  273. this.clearSelected();
  274. },
  275. /* 控制成功 */
  276. controlSuccess(msg) {
  277. console.log(msg);
  278. var mss = ''; // 信息
  279. var iserror=false;// 是否有控制错误的风机
  280. for(var v in msg.data){
  281. var val = msg.data[v];
  282. if(val.errorCode>0){
  283. iserror=true;
  284. mss+=`${val.windturbineId} ${this.controlErorCodes[val.errorCode]}\n`;
  285. }
  286. }
  287. var tp = iserror?"warning":"success";
  288. var dt = iserror?0:4500;
  289. if(!iserror){
  290. mss="控制成功";
  291. }
  292. this.$notify({
  293. title: "控制",
  294. message: mss,
  295. type: tp,
  296. position: "bottom-right",
  297. offset: 60,
  298. duration: dt,
  299. });
  300. },
  301. /* 控制失败 */
  302. controlError(err) {
  303. this.$notify({
  304. title: "控制出现错误",
  305. message: err.message,
  306. type: "warning",
  307. position: "bottom-right",
  308. offset: 60,
  309. });
  310. },
  311. /* 获取选中的项目,isControl:是否是控制 */
  312. getSelectedItems(isControl) {
  313. var ls = new Array();
  314. this.$refs.start.outputSelectedItems(ls);
  315. this.$refs.stop.outputSelectedItems(ls);
  316. if (isControl) return ls;
  317. this.$refs.maintain.outputSelectedItems(ls);
  318. this.$refs.unmaintain.outputSelectedItems(ls);
  319. this.$refs.reset.outputSelectedItems(ls);
  320. return ls;
  321. },
  322. /* 清除所有选择 */
  323. clearSelected() {
  324. this.$refs.start.clearSelected();
  325. this.$refs.stop.clearSelected();
  326. this.$refs.maintain.clearSelected();
  327. this.$refs.unmaintain.clearSelected();
  328. this.$refs.reset.clearSelected();
  329. },
  330. controlClick(isAuto) {
  331. var bd = BackgroundData.getInstance();
  332. if (isAuto) {
  333. if (!bd.LoginUser) {
  334. this.$notify({
  335. title: "请登录",
  336. message: "切换为自动控制需要先登录!",
  337. type: "warning",
  338. position: "bottom-right",
  339. offset: 60,
  340. });
  341. return;
  342. }
  343. this.AutoSendTimer = setInterval(this.AutoSend, 60000);
  344. /* this.$message({
  345. message: "已切换为自动控制",
  346. type: "success",
  347. }); */
  348. } else {
  349. /* this.$message({
  350. message: "已切换为手动控制",
  351. type: "success",
  352. }); */
  353. clearInterval(this.AutoSendTimer);
  354. }
  355. this.IsAutoControl = isAuto;
  356. },
  357. /* 自动发送命令 */
  358. AutoSend() {
  359. var ls = new Array();
  360. this.$refs.start.outputAllItems(ls);
  361. this.$refs.stop.outputAllItems(ls);
  362. console.log("自动发送命令 " + ls.length);
  363. if (ls.length <= 0) return;
  364. var bd = BackgroundData.getInstance();
  365. bd.windturbineControlSystem(ls, false);
  366. },
  367. },
  368. };
  369. </script>
  370. <style scoped>
  371. .button-selected {
  372. background: black;
  373. font-size: 14px;
  374. width: 80px;
  375. border: none;
  376. color: rgb(220, 220, 220);
  377. }
  378. .button-unselected {
  379. background: #202020;
  380. font-size: 14px;
  381. width: 80px;
  382. border: none;
  383. color: rgb(220, 220, 220);
  384. }
  385. </style>