index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <el-row style="height: 100%" :gutter="10">
  3. <el-col :span="18" style="height: 100%">
  4. <el-row style="height: 66%" :gutter="10">
  5. <el-col :span="8" style="height: 100%">
  6. <el-card class="tableHeight">
  7. <div slot="header" class="clearfix">
  8. <span>网络组参数设置</span>
  9. <el-select v-model="selectedGroupId" size="mini" style="width: 40%;float: right;background-color: #8CC0FB;"
  10. @change="selectChange">
  11. <el-option v-for="item in networkGroupList"
  12. :key="item.id"
  13. :label="item.name"
  14. :value="item.id"/>
  15. </el-select>
  16. </div>
  17. <el-table height="90%" :data="params" style="width: 100%;overflow-y: auto" fit size="mini">
  18. <el-table-column width="80" prop="label" label="属性"></el-table-column>
  19. <el-table-column width="80" prop="value" label="当前值"></el-table-column>
  20. <el-table-column label="操作" align="center">
  21. <template slot-scope="scope">
  22. <!-- ID不显示操作 -->
  23. <template v-if="scope.row.controlType === 'text'">
  24. <span>不可修改</span>
  25. </template>
  26. <!-- 是否在线开关 -->
  27. <el-switch
  28. v-if="scope.row.controlType === 'switch-online'"
  29. v-model="scope.row.value"
  30. active-value="开"
  31. inactive-value="关"
  32. @change="val => handleSwitchChange('isOnline', val)"
  33. ></el-switch>
  34. <!-- 是否静默开关 -->
  35. <el-switch
  36. v-if="scope.row.controlType === 'switch-status'"
  37. v-model="scope.row.value"
  38. active-value="静默"
  39. inactive-value="非静默"
  40. @change="val => handleSwitchChange('status', val)"
  41. ></el-switch>
  42. <!-- 连接模式下拉框 -->
  43. <el-select
  44. v-if="scope.row.controlType === 'select'"
  45. v-model="scope.row.value"
  46. placeholder="请选择"
  47. @change="val => handleSelectChange(val)"
  48. >
  49. <el-option
  50. v-for="item in linkOptions"
  51. :key="item"
  52. :label="item"
  53. :value="item"
  54. ></el-option>
  55. </el-select>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <div >
  60. <el-select size="mini" v-model="selectPlatId" @change="getParams">
  61. <el-option v-for="item in platList"
  62. :key="item.id"
  63. :label="item.name"
  64. :value="item.id"/>
  65. </el-select>
  66. <el-button size="mini" type="success" style="float: right"
  67. :disabled="editable()"
  68. @click="editParams"
  69. >修改参数</el-button>
  70. <el-button size="mini" type="info" style="float: right"
  71. :disabled="editable()"
  72. @click="getParamsPre"
  73. >刷新</el-button>
  74. </div>
  75. </el-card>
  76. </el-col>
  77. <el-col :span="16" style="height: 100%">
  78. <el-card class="radar" border>
  79. <div slot="header" class="clearfix" >
  80. <span>通信状态显示</span>
  81. </div>
  82. <div class="echarts-box">
  83. <div ref="chart" id="radarEchart"></div>
  84. </div>
  85. </el-card>
  86. </el-col>
  87. </el-row>
  88. <el-row style="height: calc(34% - 6px); margin-top: 6px;" :gutter="10">
  89. <el-card class="box-card">
  90. <div slot="header" class="clearfix" style="height: 28px">
  91. <span>已接收消息</span>
  92. </div>
  93. <el-table :data="receivedMessage" size="mini" height="tableHeight">
  94. <el-table-column prop="time" label="时间"></el-table-column>
  95. <el-table-column prop="translation" label="传输双方" ></el-table-column>
  96. <el-table-column prop="type" label="主题"></el-table-column>
  97. <el-table-column prop="status" label="状态" width="150">
  98. </el-table-column>
  99. </el-table>
  100. </el-card>
  101. </el-row>
  102. </el-col>
  103. <el-col :span="6" style="height: 100%;overflow-y: auto">
  104. <el-row style="height: calc(36%)">
  105. <el-card class="box-card">
  106. <div slot="header" class="clearfix" style="height: 28px">
  107. <span>已发送消息</span>
  108. </div>
  109. <el-table :data="sendMessage" fit size="mini" height="sendMessageHeight">
  110. <el-table-column width="80" prop="time" label="时间"></el-table-column>
  111. <el-table-column width="90" prop="translation" label="传输双方"></el-table-column>
  112. <el-table-column prop="type" label="主题"></el-table-column>
  113. <el-table-column width="60" prop="status" label="状态"></el-table-column>
  114. </el-table>
  115. </el-card>
  116. </el-row>
  117. <el-row style="height: calc(64% - 6px); margin-top: 6px;">
  118. <el-card class="target">
  119. <div slot="header" class="clearfix" style="height: 28px">
  120. <span>成员列表</span>
  121. </div>
  122. <el-table height="tableHeight" :data="members" border fit size="mini">
  123. <el-table-column prop="id" label="平台ID"> </el-table-column>
  124. <el-table-column prop="isOnline" label="是否在网"> </el-table-column>
  125. <el-table-column prop="status" label="静默状态"> </el-table-column>
  126. <el-table-column prop="linkModel" label="连接方式"> </el-table-column>
  127. </el-table>
  128. </el-card>
  129. </el-row>
  130. </el-col>
  131. </el-row>
  132. </template>
  133. <script>
  134. import {Message} from "element-ui";
  135. export default {
  136. data() {
  137. return {
  138. selectedGroupId: null,
  139. selectedGroup: null,
  140. networkGroupList: [],
  141. chartInstance: null,
  142. nodes: [],
  143. edges: [],
  144. sendMessage: [],
  145. receivedMessage: [],
  146. members: [],
  147. tableHeight: "calc(100vh - 30px)",
  148. selectPlatId: null,
  149. platList: [],
  150. params: [],
  151. originData: {},
  152. linkOptions: ['实时性','可靠性'],
  153. };
  154. },
  155. created() {
  156. },
  157. activated() {
  158. this.init();
  159. this.interval=setInterval(this.fetchData, 5000)
  160. },
  161. deactivated() {
  162. if(this.interval){
  163. clearInterval(this.interval)
  164. }
  165. },
  166. mounted() {
  167. this.init();
  168. // 页面加载设置高度自适应
  169. window.onresize = () => {
  170. this.resizeDom();
  171. };
  172. // 页面加载设置高度自适应
  173. this.resizeDom();
  174. },
  175. methods: {
  176. async init() {
  177. await this.getNetworkGroupList();
  178. this.initGroup()
  179. if (this.selectedGroupId != null) {
  180. this.initChart()
  181. this.initSend()
  182. this.initReceived()
  183. this.initMembers()
  184. this.getParams()
  185. }else {
  186. this.selectPlatId = null;
  187. }
  188. },
  189. initGroup() {
  190. let flag = true;
  191. if (this.selectedGroupId !== 0) {
  192. for (let i = 0; i < this.networkGroupList.length; i++) {
  193. if (this.selectedGroupId === this.networkGroupList[i].id) {
  194. flag = false;
  195. this.selectedGroup = this.networkGroupList[i]
  196. }
  197. }
  198. if (flag) {
  199. this.selectedGroupId = null;
  200. this.selectedGroup = null;
  201. }
  202. }
  203. },
  204. selectChange() {
  205. for (let i = 0; i < this.networkGroupList.length; i++) {
  206. if (this.selectedGroupId === this.networkGroupList[i].id) {
  207. this.selectedGroup = this.networkGroupList[i];
  208. break
  209. }
  210. }
  211. this.selectPlatId=null;
  212. this.originData=null;
  213. this.params=[];
  214. this.initPlatList();
  215. this.initChart();
  216. this.initSend();
  217. this.initReceived();
  218. this.initMembers();
  219. },
  220. async getParamsPre(){
  221. try {
  222. await this.getParams();
  223. // 请求成功后显示提示
  224. this.$message({
  225. message: "刷新成功",
  226. type: "success",
  227. duration: 1500,
  228. });
  229. } catch (error) {
  230. // 可选:添加错误处理
  231. this.$message.error('操作失败: ' + error.message);
  232. }
  233. },
  234. getParams(){
  235. this.$http({
  236. url: this.$http.adornUrl("/communication/getParams?id=" + this.selectPlatId),
  237. method: "get",
  238. }).then(({data}) => {
  239. if (data && data.code === 0) {
  240. this.produceData(data.data)
  241. return data
  242. }else {
  243. throw new Error(data.msg || '请求失败')
  244. }
  245. })
  246. },
  247. produceData(data){
  248. this.originData = {...data}
  249. this.params = [
  250. {
  251. propKey: 'id',
  252. label: '平台ID',
  253. value: data.id,
  254. controlType: 'text'
  255. },
  256. {
  257. propKey: 'isOnline',
  258. label: '链路开关',
  259. value: data.isOnline,
  260. controlType: 'switch-online'
  261. },
  262. {
  263. propKey: 'status',
  264. label: '静默状态',
  265. value: data.status,
  266. controlType: 'switch-status'
  267. },
  268. {
  269. propKey: 'linkModel',
  270. label: '连接模式',
  271. value: data.linkModel,
  272. controlType: 'select'
  273. }
  274. ];
  275. },
  276. editParams(){
  277. this.$http({
  278. url: this.$http.adornUrl("/communication/updateParams"),
  279. method: "post",
  280. data: this.originData,
  281. }).then(({ data }) => {
  282. if (data && data.code === 0) {
  283. Message({
  284. message: "操作成功",
  285. type: "success",
  286. duration: 1500,
  287. });
  288. } else {
  289. Message.error(data.msg);
  290. }
  291. this.getParams();
  292. });
  293. },
  294. // 开关修改事件
  295. handleSwitchChange(key, value) {
  296. this.originData[key] = value;
  297. },
  298. // 下拉框修改事件
  299. handleSelectChange(value) {
  300. this.originData.linkModel = value;
  301. },
  302. getNetworkGroupList() {
  303. this.$http({
  304. url: this.$http.adornUrl("/communication/getNetworkGroups"),
  305. method: "get",
  306. }).then(({data}) => {
  307. if (data && data.code === 0) {
  308. this.networkGroupList = data.data;
  309. if (this.networkGroupList.length === 0) {
  310. Message.info("暂未设置网络组信息")
  311. }
  312. } else {
  313. this.networkGroupList = [];
  314. Message.error("无法获取网络组信息")
  315. }
  316. })
  317. },
  318. editable() {
  319. return this.selectPlatId===null || this.selectPlatId === 0;
  320. },
  321. fetchData(){
  322. if(this.selectedGroupId!=null){
  323. this.initMembers();
  324. this.initChart();
  325. this.initSend();
  326. this.initReceived();
  327. }
  328. },
  329. initPlatList(){
  330. if(this.selectedGroupId!=null){
  331. this.$http({
  332. url: this.$http.adornUrl("/communication/getMembers?id=" + this.selectedGroupId),
  333. method: "get",
  334. }).then(({data}) => {
  335. if (data && data.code === 0) {
  336. this.platList = data.data;
  337. }
  338. })
  339. }
  340. },
  341. initChart() {
  342. this.$http({
  343. url: this.$http.adornUrl("/communication/getChart?id=" + this.selectedGroupId),
  344. method: "get",
  345. }).then(({data}) => {
  346. if (data && data.code === 0) {
  347. this.nodes = data.nodes;
  348. this.edges = data.edges;
  349. if (this.chartInstance == null) {
  350. this.createChartInstance(this.$refs.chart);
  351. }
  352. this.chartInstance.setOption({
  353. series: [{
  354. data: this.nodes,
  355. links: this.edges,
  356. }]
  357. })
  358. }
  359. })
  360. },
  361. initSend() {
  362. this.$http({
  363. url: this.$http.adornUrl("/communication/getSendMessage?id=" + this.selectedGroupId),
  364. method: "get",
  365. }).then(({data}) => {
  366. if (data && data.code === 0) {
  367. this.sendMessage = data.data;
  368. }
  369. })
  370. },
  371. initReceived() {
  372. this.$http({
  373. url: this.$http.adornUrl("/communication/getSendMessage?id=" + this.selectedGroupId),
  374. method: "get",
  375. }).then(({data}) => {
  376. if (data && data.code === 0) {
  377. this.receivedMessage = data.data;
  378. }
  379. })
  380. },
  381. initMembers(){
  382. this.$http({
  383. url: this.$http.adornUrl("/communication/getMembers?id=" + this.selectedGroupId),
  384. method: "get",
  385. }).then(({data}) => {
  386. if (data && data.code === 0) {
  387. this.members = data.data;
  388. }
  389. })
  390. },
  391. createChartInstance(dom) {
  392. this.chartInstance = this.$echarts.init(dom)
  393. const chartOption = {
  394. title: {},
  395. animation: true,
  396. series: [
  397. {
  398. type: "graph",
  399. layout: "force",
  400. symbolSize: 30,
  401. roam: true,
  402. label: {
  403. show: true,
  404. },
  405. edgeSymbol: ["circle"],
  406. edgeSymbolSize: [4, 10],
  407. edgeLabel: {
  408. fontSize: 12,
  409. },
  410. emphasis: {
  411. focus: "adjacency",
  412. lineStyle: {
  413. width: 10,
  414. },
  415. },
  416. force: {
  417. repulsion: 1000,
  418. edgeLength: [10, 50],
  419. },
  420. draggable: true,
  421. cursor: "pointer",
  422. lineStyle: {
  423. opacity: 0.9,
  424. width: 2,
  425. curveness: 0.2,
  426. },
  427. },
  428. ],
  429. };
  430. this.chartInstance.setOption(chartOption)
  431. },
  432. //通过窗体高宽计算容器高宽,渲染echart图表的div的宽高度以达到自适应目的
  433. resizeDom() {
  434. const boxHeight =
  435. document.getElementsByClassName("echarts-box")[0].clientHeight;
  436. var Echart = document.getElementById("radarEchart");
  437. Echart.style.height = boxHeight - 65 + "px";
  438. this.$echarts.init(document.getElementById("radarEchart")).resize();
  439. },
  440. }
  441. }
  442. </script>
  443. <style scoped>
  444. .echarts-box {
  445. height: 100%;
  446. width: 100%;
  447. }
  448. .radar {
  449. height: 100%;
  450. }
  451. </style>