equipTable.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div>
  3. <el-tabs v-model="activeRelation" @tab-click="changeTabs">
  4. <el-tab-pane v-for=" (item,index) in relationList" :key="index" :label="item.name" :name="item.code">
  5. <el-table :data="tableData" height="300" class="data-table border" :stripe="true" border size="small" v-loading="isLoading" style="width: 100%">
  6. <el-table-column width="180" label="设备名称">
  7. <template slot-scope="scope">
  8. <span>
  9. <el-tooltip :content="scope.row.infos.EquipName" placement="top">
  10. <span>{{scope.row.infos.EquipLocalName || scope.row.infos.EquipName | cutString(15)}}</span>
  11. </el-tooltip>
  12. </span>
  13. </template>
  14. </el-table-column>
  15. <el-table-column width="160" label="设备类">
  16. <template slot-scope="scope">
  17. <span>
  18. <span>{{getName(scope.row.category)}}</span>
  19. </span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="操作">
  23. <template slot-scope="scope">
  24. <el-button plain @click="lockDetails(scope.row)">详情</el-button>
  25. <el-button v-if="scope.row.inSpace" plain type="danger" @click="deleteSpace(scope.row)">从空间移除</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <div class="right" v-show="tableData.length">
  30. <my-pagination :page="page" @change="pageChange"></my-pagination>
  31. </div>
  32. </el-tab-pane>
  33. </el-tabs>
  34. <el-dialog width="40%" title="设备详情" :visible.sync="innerVisible" append-to-body>
  35. <iframe height="400px" width="100%" :src="iframeSrc"></iframe>
  36. </el-dialog>
  37. </div>
  38. </template>
  39. <script>
  40. import myPagination from "@/components/common/myPagination.vue";
  41. import {
  42. getSpaceEquip,
  43. getEqCode,
  44. deleteRelation,
  45. getGraphyId,
  46. getSysToEq
  47. } from "@/api/scan/request";
  48. import {
  49. mapGetters,
  50. mapActions
  51. } from "vuex";
  52. export default {
  53. name: "equip-table",
  54. components: {
  55. myPagination
  56. },
  57. computed: {
  58. ...mapGetters("layout", [
  59. "projectId",
  60. "secret",
  61. "userId"
  62. ])
  63. },
  64. props: {
  65. param: {
  66. type: Object
  67. },
  68. activeTabType: {
  69. type: Object,
  70. default: function() {
  71. return {
  72. "code": "GeneralZone",
  73. "name": "默认分区",
  74. "rel_type": "99"
  75. }
  76. }
  77. }
  78. },
  79. data() {
  80. return {
  81. page: {
  82. size: 50,
  83. sizes: [10, 30, 50, 100, 150, 200],
  84. total: 0,
  85. currentPage: 1
  86. },
  87. tableData: [],
  88. data: {},
  89. EqCode: [],
  90. innerVisible: false,
  91. iframeSrc: "",
  92. title: "",
  93. graphyId: "",
  94. isLoading: false,
  95. relationList: [{
  96. name: "空间内的设备",
  97. code: "EquipinSpace"
  98. }, {
  99. name: "服务于空间的设备",
  100. code: "EquipforSpace"
  101. }, {
  102. name: "其他关系的设备",
  103. code: "EquipXSpace"
  104. }],
  105. activeRelation: "EquipinSpace",
  106. CalcUrl: {
  107. "code": "GeneralZone",
  108. "name": "默认分区",
  109. "rel_type": "99"
  110. },
  111. relType: 0
  112. };
  113. },
  114. created() {
  115. this.getEqCode();
  116. },
  117. methods: {
  118. changeTabs() {
  119. let param = {
  120. data: {
  121. limit: {
  122. // 可选
  123. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  124. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  125. },
  126. criteria: {
  127. space: this.data.id, // 必填, 指定业务空间id
  128. type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
  129. }
  130. },
  131. ProjId: this.projectId, //项目id
  132. secret: this.secret
  133. };
  134. this.isLoading = true
  135. if (this.CalcUrl.rel_type == 99 && this.activeRelation == "EquipinSpace") {
  136. this.dataChange(param);
  137. } else {
  138. this.getRlations()
  139. }
  140. },
  141. getEqCode() {
  142. getEqCode()
  143. .then(res => {
  144. if (res.data.Result == "success") {
  145. this.EqCode = res.data.Content;
  146. } else {
  147. this.$message.error(res.data.ResultMsg);
  148. }
  149. })
  150. .catch(() => {
  151. this.$message.error("请求失败");
  152. });
  153. },
  154. getGraphyId(row) {
  155. let param = {
  156. type: this.activeRelation,
  157. ProjId: this.projectId, //项目id
  158. secret: this.secret
  159. };
  160. getGraphyId(param)
  161. .then(res => {
  162. if (res.data.Result == "success") {
  163. this.graphyId = res.data.graph_id;
  164. this.deleteOwn(row)
  165. } else {
  166. this.$message.error(res.data.ResultMsg);
  167. }
  168. })
  169. .catch(() => {
  170. this.$message.error("请求错误");
  171. });
  172. },
  173. getRlations() {
  174. this.isLoading = true
  175. this.relType = 0
  176. if (this.CalcUrl.rel_type == 99) {
  177. this.relType = "1"
  178. } else {
  179. if (this.CalcUrl.rel_type > 9) {
  180. this.relType = (this.CalcUrl.rel_type * 100).toString()
  181. } else {
  182. this.relType = '0' + (this.CalcUrl.rel_type * 100)
  183. }
  184. }
  185. let param = {
  186. data: {
  187. "limit": { // 可选
  188. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  189. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  190. },
  191. criteria: {
  192. graphType: this.activeRelation,
  193. relType: this.relType,
  194. toId: this.data.id,
  195. fromId: this.data.fromId,
  196. type: ["Eq"]
  197. }
  198. },
  199. ProjId: this.projectId, //项目id
  200. secret: this.secret
  201. }
  202. getSysToEq(param, res => {
  203. this.tableData = res.Content.map(item => {
  204. item.inSpace = true
  205. return item
  206. })
  207. this.page.total = res.TotalCount;
  208. this.isLoading = false
  209. })
  210. },
  211. deleteOwn(row) {
  212. let param = {
  213. data: {
  214. criterias: [{
  215. from_id: row.id, //选填
  216. to_id: this.data.id, //选填
  217. graph_id: this.graphyId, //选填
  218. rel_type: this.relType
  219. }]
  220. },
  221. ProjId: this.projectId, //项目id
  222. secret: this.secret
  223. };
  224. this.$confirm("正在删除设备关系, 是否继续?", "删除", {
  225. confirmButtonText: "确定",
  226. cancelButtonText: "取消",
  227. type: "warning"
  228. })
  229. .then(() => {
  230. deleteRelation(param)
  231. .then(res => {
  232. if (res.data.Result == "success") {
  233. this.$message.success("删除成功");
  234. this.change();
  235. } else {
  236. this.$message.error(res.data.ResultMsg);
  237. }
  238. })
  239. .catch(() => {
  240. this.$message.error("请求出错");
  241. });
  242. })
  243. .catch(() => {
  244. this.$message("取消删除");
  245. });
  246. },
  247. getName(code) {
  248. let text = "",
  249. myClass = code.substring(0, 2),
  250. system = code.substring(2, 4),
  251. last = code.substring(2, 6);
  252. if (this.EqCode && this.EqCode.length) {
  253. this.EqCode.map(item => {
  254. if (item.code == myClass) {
  255. item.content.map(i => {
  256. if (i.code == system) {
  257. i.content.map(e => {
  258. if ((e.code == last)) {
  259. text = e.facility;
  260. }
  261. });
  262. }
  263. });
  264. }
  265. });
  266. }
  267. return text;
  268. },
  269. /**
  270. * 删除
  271. * @param row 点击的当条数据
  272. */
  273. deleteSpace(row) {
  274. this.getGraphyId(row)
  275. },
  276. /**
  277. * 获取数据
  278. * @param data 由上级页面传入,初始化table表格
  279. */
  280. getData(data, type) {
  281. this.activeRelation = "EquipinSpace"
  282. this.CalcUrl = type
  283. this.page = {
  284. size: 50,
  285. sizes: [10, 30, 50, 100, 150, 200],
  286. total: 0,
  287. currentPage: 1
  288. };
  289. this.data = data;
  290. this.change();
  291. },
  292. change() {
  293. let param = {
  294. data: {
  295. limit: {
  296. // 可选
  297. skip: this.page.size * (this.page.currentPage - 1), // 跳过多少数据
  298. count: this.page.size // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
  299. },
  300. criteria: {
  301. space: this.data.id, // 必填, 指定业务空间id
  302. type: ["Eq"] // 必填, 查询类型, 允许四位编码的详细设备类
  303. }
  304. },
  305. ProjId: this.projectId, //项目id
  306. secret: this.secret
  307. };
  308. this.isLoading = true
  309. if (this.CalcUrl.rel_type == 99) {
  310. this.dataChange(param);
  311. } else {
  312. this.getRlations()
  313. }
  314. },
  315. dataChange(param) {
  316. getSpaceEquip(param)
  317. .then(res => {
  318. if (res.data.Result == "success") {
  319. this.page.total = res.data.TotalCount;
  320. this.tableData = res.data.Content;
  321. this.isLoading = false
  322. } else {
  323. this.$message.error(res.data.ResultMsg);
  324. }
  325. })
  326. .catch(() => this.$message.error("请求失败"));
  327. },
  328. /**
  329. * 查看详情
  330. * @param row 点击的当条数据
  331. */
  332. lockDetails(row) {
  333. this.innerVisible = true;
  334. this.iframeSrc = this.iframeSrc =
  335. // "http://172.16.0.181:8889/#/details?perjectId=" +
  336. process.env.BASE_URL + ":8889/#/details?perjectId=" +
  337. this.projectId +
  338. "&secret=" +
  339. this.secret +
  340. "&FmId=" +
  341. row.id +
  342. "&type=0&code=" +
  343. row.category.substring(2, 6);
  344. },
  345. pageChange() {
  346. this.change();
  347. }
  348. },
  349. filters: {
  350. cutString: function(str, len) {
  351. //length属性读出来的汉字长度为1
  352. if (!!str && typeof str == "string" && str.length > len) {
  353. return str.substring(0, len) + "...";
  354. } else {
  355. return str || "--";
  356. }
  357. }
  358. }
  359. };
  360. </script>
  361. <style>
  362. /* .el-table tr th { */
  363. /* background: #fafafa !important; */
  364. /* } */
  365. </style>