index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <template>
  2. <div id="deviceList">
  3. <div class="search-header">
  4. <cenote-type @change="changeFloor"></cenote-type>
  5. </div>
  6. <el-row class="left">
  7. <span style="float:right;">当前筛选条件下共{{ page.total || '--' }}竖井</span>
  8. <el-select v-model="onlyRead" @change="getTableHeader"
  9. style="width:100px;margin-right:20px;vertical-align:bottom;">
  10. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  11. </el-select>
  12. <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
  13. <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
  14. </el-select>
  15. <el-button @click="handleCreateTableData">添加竖井</el-button>
  16. <el-button @click="getTableHeader">刷新</el-button>
  17. <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
  18. </el-row>
  19. <div class="tableBox">
  20. <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
  21. <p>
  22. <i class="icon-wushuju iconfont"></i>
  23. 暂无数据
  24. </p>
  25. </div>
  26. <div class="tableLeft" v-show="tableData && tableData.length">
  27. <handson-table ref="table"></handson-table>
  28. </div>
  29. </div>
  30. <el-pagination class="right" v-show="tableData && tableData.length" @size-change="handleSizeChange"
  31. @current-change="handleCurrentChange"
  32. :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize"
  33. layout="total, sizes, prev, pager, next, jumper"
  34. :total="page.total">
  35. </el-pagination>
  36. <!-- 不支持的输入方式 -->
  37. <el-dialog title="临时维护信息点" :visible.sync="myDialog.update" @close="handleCloseUpdate" width="670px">
  38. <el-row>
  39. 该信息点未定义对应组件,现在维护数据不确定后续是否可用。如确实需要维护,请点击
  40. <el-link @click="updateInputShow = true" type="primary" :underline="false">继续维护</el-link>
  41. </el-row>
  42. <el-row style="margin-top:20px;" v-show="updateInputShow">
  43. <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" placeholder="请输入内容"
  44. v-model="updateInput"></el-input>
  45. </el-row>
  46. <span slot="footer" class="dialog-footer">
  47. <el-button @click="myDialog.update = false">取 消</el-button>
  48. <el-button type="primary" @click="handleClickUpdate">确 认</el-button>
  49. </span>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. import tools from "@/utils/scan/tools"
  55. import handsonUtils from "@/utils/hasontableUtils"
  56. import showTools from "@/utils/handsontable/notShow"
  57. import cenoteType from "@/components/ledger/lib/cenoteType";
  58. import handsonTable from "@/components/common/handsontable";
  59. import {getDataDictionary} from "@/api/dict";
  60. import {
  61. BeatchQueryParam,
  62. deleteCenoteTableData,
  63. queryCenoteTableData,
  64. saveCenoteRelateSpace,
  65. updataCenoteTableData
  66. } from "@/api/scan/request"
  67. import {mapGetters} from "vuex";
  68. export default {
  69. components: {
  70. cenoteType,
  71. handsonTable
  72. },
  73. data() {
  74. return {
  75. cenoteId: "",//竖井类型id
  76. shaftId: "",//要操作的竖井id
  77. spaceList: "",
  78. options: [{
  79. value: true,
  80. label: '只读模式'
  81. }, {
  82. value: false,
  83. label: '编辑模式'
  84. }],
  85. onlyRead: true,
  86. showType: "",
  87. // allMess: true,
  88. tableHeader: [],
  89. page: {
  90. pageSize: 50,
  91. pageSizes: [10, 20, 50, 100],
  92. pageNumber: 1,
  93. total: 0
  94. },
  95. tableData: [],
  96. copyTableData: [],
  97. tableExample: null,
  98. myDialog: {
  99. update: false,//临时维护信息点
  100. },
  101. inputMap: {
  102. flowBuild: {
  103. editable: true,
  104. code: "flowBuild",
  105. name: "建筑楼层",
  106. path: "flowBuild",
  107. category: 'STATIC',
  108. dataType: "ENUM"
  109. }
  110. }, //信息点和输入方式映射表
  111. updateInputShow: false, //是否显示临时维护输入框
  112. updateInfoPoint: '',//临时维护信息点
  113. updateInput: '', //临时维护信息点值
  114. };
  115. },
  116. computed: {
  117. ...mapGetters("layout", ["projectId", "secret", "userId", "group_code"]),
  118. showTypes() {
  119. return this.onlyRead ?
  120. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }] :
  121. [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }]
  122. }
  123. },
  124. created() {
  125. this.getTableHeader()
  126. },
  127. watch: {
  128. showTypes: {
  129. handler(newName, oldName) {
  130. if (newName && newName[0] && newName[0].value) {
  131. this.showType = newName[0].value
  132. } else {
  133. this.showType = ""
  134. }
  135. },
  136. immediate: true,
  137. deep: true
  138. }
  139. },
  140. methods: {
  141. // 获取表头数据(初始化表格)
  142. async getTableHeader() {
  143. let param = {
  144. orders: "sort asc, name desc",
  145. pageNumber: 1,
  146. pageSize: 1000,
  147. type: 'shaft'
  148. }
  149. await getDataDictionary(param, res => {
  150. this.tableHeader = res.content;
  151. this.codeToDataSource = {}
  152. this.tableHeader.forEach(item => {
  153. if (item.path) {
  154. this.inputMap[item.path] = item
  155. }
  156. if (item.dataSource) {
  157. try {
  158. this.codeToDataSource[item.code] = {}
  159. item.dataSource.forEach(dic => {
  160. this.codeToDataSource[item.code][dic.code] = dic.name;
  161. })
  162. } catch (e) {
  163. console.log(e);
  164. }
  165. }
  166. })
  167. this.getTableData()
  168. })
  169. },
  170. async getTableData() {//获取表格数据
  171. let params = {
  172. cascade: [{ name: 'spaceList' }],
  173. orders: "createTime desc, localName desc, localId desc, id asc",
  174. pageNumber: this.page.pageNumber,
  175. pageSize: this.page.pageSize
  176. }
  177. if (this.cenoteId) {
  178. params.filters = `infos.shaftFuncType='${this.cenoteId}'`
  179. }
  180. await queryCenoteTableData(params, (res) => {
  181. this.tableData = res.content
  182. this.copyTableData = tools.deepCopy(res.content)
  183. this.page.pageNumber = res.pageNumber
  184. this.page.total = res.total
  185. if (this.tableData && this.tableData.length) {
  186. if (this.onlyRead) {
  187. this.getBatch(res.content)
  188. }
  189. this.initTable()
  190. }
  191. })
  192. },
  193. // 修改表格内容
  194. async updateTableData(data, change) {
  195. let param = {
  196. Content: [],
  197. Projection: []
  198. }, keyList = [];
  199. //生成要修改字段列表
  200. change.map(item => {
  201. let key = item[1].split(".")[0]
  202. if (item[1] && keyList.indexOf(key) == -1) {
  203. keyList.push(key);
  204. }
  205. if (item[1] && item[3] == "" && param.Projection.indexOf(key) == -1) {
  206. param.Projection.push(key);
  207. }
  208. });
  209. //生成对应修改数据
  210. data.map((item, index) => {
  211. keyList.map(value => {
  212. let itemData = tools.dataForKey(item, value)
  213. tools.setDataForKey(item, value, itemData == "" ? null : itemData)
  214. })
  215. // let keyarr = change[index][1].split(".")
  216. // if (keyarr && keyarr.length > 1) {
  217. // item[keyarr[0]][keyarr[1]] = item[keyarr[0]][keyarr[1]] != ""? item[keyarr[0]][keyarr[1]]: null
  218. // } else {
  219. // item[keyarr[0]] = item[keyarr[0]] != ""? item[keyarr[0]]: null
  220. // }
  221. param.Content.push(item);
  222. })
  223. await updataCenoteTableData(param, (res) => {
  224. })
  225. },
  226. // 删除表格数据
  227. async deleteTableData(params) {
  228. await deleteCenoteTableData(params, (res) => {
  229. this.$message.success("删除成功!")
  230. this.getTableHeader()
  231. })
  232. },
  233. //保存元空间关联
  234. async saveSpaceList() {
  235. let params = {
  236. ShaftId: this.shaftId,
  237. SpaceId: this.spaceList
  238. }
  239. await saveCenoteRelateSpace(params, (res) => {
  240. this.$message.success("关联成功!")
  241. this.getTableHeader()
  242. })
  243. },
  244. // 添加竖井
  245. handleCreateTableData() {
  246. this.$router.push({
  247. path: '/ledger/cenoteadd',
  248. query: {
  249. showType: this.showType
  250. }
  251. })
  252. },
  253. // 删除表格行
  254. handleDeleteTableRow() {
  255. let params = tools.differenceArr(this.tableData, this.copyTableData)
  256. if (params.length < 1 || this.tableData > this.copyTableData) {
  257. return
  258. }
  259. let param = []
  260. params.map(item => {
  261. param.push({ id: item.id })
  262. })
  263. this.$confirm("此操作将删除竖井,是否继续?", "提示", {
  264. confirmButtonText: '确定',
  265. cancelButtonText: '取消',
  266. type: 'warning'
  267. }).then(() => {
  268. this.deleteTableData(param)
  269. }).catch(() => {
  270. this.getTableHeader()
  271. this.$message("取消删除")
  272. })
  273. },
  274. //修改
  275. handleUpdataTable(changeData, source) {
  276. if (!this.onlyRead) {
  277. if (changeData) {
  278. let trimmedArr = this.trimmedRows();
  279. let param = handsonUtils.getParam(changeData, source, this.tableExample, trimmedArr);
  280. let data = [];
  281. for (let i = 0; i < param.length; i++) {
  282. data.push(param[i]);
  283. }
  284. //如果data中包含/且data长度为1,将其转换成.
  285. if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
  286. changeData[0][1] = changeData[0][1].split("/").join(".")
  287. }
  288. // 存在data进行修改请求
  289. if (data && data.length) {
  290. this.updateTableData(data, changeData);
  291. }
  292. }
  293. }
  294. },
  295. //撤回
  296. undo() {
  297. this.tableExample.undo();
  298. },
  299. //切换竖井类型
  300. changeFloor(value) {
  301. this.cenoteId = value.Id
  302. this.getTableHeader()
  303. },
  304. //切换每页显示多少条数据
  305. handleSizeChange(val) {
  306. this.page.pageSize = val
  307. this.getTableHeader()
  308. },
  309. //切换页数
  310. handleCurrentChange(val) {
  311. this.page.pageNumber = val
  312. this.getTableHeader()
  313. },
  314. formatHeaderData(list) {//格式化表头显示的数据
  315. let arr = tools.copyArr(list)
  316. let data = showTools.headerTextFilter(arr, "shaft", this.onlyRead, this.showType)
  317. data.unshift("关联的业务空间", "其他关系");
  318. return data;
  319. },
  320. formatHeaderType(list) {//格式化表头头映射的数据
  321. let arr = tools.copyArr(list);
  322. let data = showTools.headerTypeFilter(arr, "shaft", this.onlyRead, this.showType)
  323. data.unshift({
  324. data: "spaceList",
  325. renderer: (instance, td, row, col, prop, value, cellProperties) => {
  326. td.style.color = "#409EFF";
  327. td.innerHTML = `<span>${value ? value.length : 0}</span>`
  328. return td;
  329. },
  330. readOnly: true
  331. }, {
  332. data: "otheRelations",
  333. renderer: (instance, td, row, col, prop, value, cellProperties) => {
  334. td.style.color = "#409EFF";
  335. td.style.cursor = "pointer";
  336. td.innerHTML = "查看";
  337. return td;
  338. },
  339. readOnly: true
  340. })
  341. return data;
  342. },
  343. initTable() {//实例化表格
  344. let settings = {
  345. data: this.tableData,
  346. fixedColumnsLeft: 4,
  347. colHeaders: this.formatHeaderData(this.tableHeader),
  348. columns: this.formatHeaderType(this.tableHeader),
  349. rowHeights: 30,
  350. maxRows: this.tableData.length,
  351. contextMenu: this.onlyRead ? false : {
  352. items: {
  353. remove_row: {
  354. name: "删除竖井"
  355. }
  356. }
  357. },
  358. // 事件
  359. afterChange: this.handleUpdataTable, //修改后
  360. afterFilter: this.trimmedRows, //排序前
  361. afterRemoveRow: this.handleDeleteTableRow, //右键删除
  362. afterOnCellMouseDown: this.handleTdClick //鼠标点击
  363. };
  364. this.$nextTick(() => {
  365. console.log(this.$refs.table)
  366. this.tableExample = this.$refs.table.init(settings)
  367. });
  368. },
  369. //获取到了正确的信息
  370. getInfors(infos, row) {
  371. //其他的开始判断
  372. let val = this.tableExample.colToProp(row.col)
  373. let inputData = this.inputMap[val]
  374. let name = infos.localName ? infos.localName : infos.name
  375. this.shaftId = infos.id //要操作的数据id
  376. //点击关联的业务空间
  377. if (val === "spaceList") {
  378. this.$router.push({
  379. path: '/ledger/relatedSpace',
  380. query: { ShaftId: this.shaftId, name: name, onlyRead: this.onlyRead }
  381. })
  382. return false
  383. } else if (val === "otheRelations") {
  384. this.$router.push({
  385. path: "/ledger/cenoteDetail",
  386. query: {
  387. ShaftID: this.shaftId,
  388. name: name
  389. }
  390. })
  391. return false
  392. }
  393. if (!this.onlyRead && !inputData.editable) {
  394. this.$message("该信息点的值为自动生成,不可人工维护!");
  395. return false;
  396. }
  397. if (!this.onlyRead && showTools.inputModeArr.indexOf(inputData.dataType) == '-1') {
  398. this.updateInfoPoint = val;
  399. this.updateInput = tools.dataForKey(this.tableData[row.row], val);
  400. this.myDialog.update = true;
  401. return false;
  402. }
  403. },
  404. //关闭临时维护弹窗回调
  405. handleCloseUpdate() {
  406. this.updateInputShow = false
  407. this.updateInfoPoint = ''
  408. this.updateInput = ''
  409. },
  410. //更新临时维护信息点
  411. handleClickUpdate() {
  412. tools.setDataForKey(this.tableData[this.row], this.updateInfoPoint, this.updateInput)
  413. this.handleUpdataTable([[this.row, this.updateInfoPoint, null, this.updateInput]], "edit")
  414. this.updateInputShow = false
  415. this.myDialog.update = false
  416. this.updateInput = ''
  417. },
  418. //表格点击事件
  419. handleTdClick(el, rowArr) {
  420. //点击的是表头
  421. if (rowArr.row < 0) {
  422. return;
  423. }
  424. //被筛选过后的数组
  425. let trimmedArr = this.trimmedRows();
  426. //是否启用了排序
  427. let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
  428. if (trimmedArr.length && isSort) {
  429. let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
  430. .__arrayMap;
  431. let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
  432. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  433. } else if (isSort) {
  434. //排序后的数组
  435. let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper.__arrayMap;
  436. let infos = this.tableData[sortArr[rowArr.row]];
  437. this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
  438. } else if (trimmedArr.length) {
  439. let infos = this.tableData[trimmedArr[rowArr.row]];
  440. this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
  441. } else {
  442. let infos = this.tableData[rowArr.row];
  443. this.getInfors(infos, rowArr);
  444. }
  445. },
  446. //获取被筛选掉的行号
  447. trimmedRows() {
  448. // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
  449. var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
  450. let dataLength = this.tableData.length;
  451. let dataArr = new Array();
  452. for (let i = 0; i < dataLength; i++) {
  453. dataArr.push(i);
  454. }
  455. if (plugin.length <= 0) {
  456. dataArr = undefined;
  457. } else {
  458. dataArr = this.array_diff(dataArr, plugin);
  459. }
  460. return dataArr || [];
  461. // var DataArray = new Array();
  462. // for (var i = 0; i < plugin.length; i++) {
  463. // // 通过行号获取数据
  464. // DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
  465. // }
  466. },
  467. //去除数组中相同的元素
  468. array_diff(a, b) {
  469. for (var i = 0; i < b.length; i++) {
  470. for (var j = 0; j < a.length; j++) {
  471. if (a[j] == b[i]) {
  472. a.splice(j, 1);
  473. j = j - 1;
  474. }
  475. }
  476. }
  477. return a;
  478. },
  479. //获取动态参数
  480. getBatch(data) {
  481. let param = {
  482. groupCode: this.group_code,
  483. appId: "datacenter",
  484. projectId: this.projectId,
  485. data: []
  486. };
  487. this.tableHeader.map(head => {
  488. if (head.category != 'STATIC') {
  489. data.map(item => {
  490. let cur = tools.dataForKey(item, head.path);
  491. if (cur) {
  492. param.data.push({
  493. objectId: item.id,
  494. infoCode: head.code
  495. });
  496. }
  497. });
  498. }
  499. });
  500. if (param.data.length) {
  501. BeatchQueryParam(param, res => {
  502. this.tableData = data.map(item => {
  503. res.Content.map(child => {
  504. if (item.id == child.objectId) {
  505. if (child.data || child.data == 0) {
  506. this.tableHeader.map(head => {
  507. if (head.code == child.infoCode) {
  508. let contentVal = child.data
  509. if (this.codeToDataSource[child.infoCode]) {
  510. contentVal = this.codeToDataSource[child.infoCode][child.data]
  511. }
  512. tools.setDataForKey(item, head.path, contentVal);
  513. }
  514. });
  515. } else {
  516. this.tableHeader.map(head => {
  517. if (head.code == child.infoCode) {
  518. tools.setDataForKey(
  519. item,
  520. head.path,
  521. child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
  522. );
  523. }
  524. });
  525. }
  526. }
  527. });
  528. return item;
  529. });
  530. this.tableExample.loadData(this.tableData);
  531. });
  532. }
  533. }
  534. }
  535. };
  536. </script>
  537. <style lang="less" scoped>
  538. #deviceList {
  539. overflow: hidden;
  540. height: 100%;
  541. background-color: #fff;
  542. padding: 10px;
  543. position: relative;
  544. .right {
  545. background: #fff;
  546. }
  547. .search-header {
  548. overflow: hidden;
  549. padding-bottom: 10px;
  550. border-bottom: 1px solid #bcbcbc;
  551. }
  552. .tableBox {
  553. display: flex;
  554. height: calc(100% - 140px);
  555. margin-top: 10px;
  556. .tableLeft {
  557. flex: 2;
  558. margin-right: 20px;
  559. }
  560. .tableRight {
  561. flex: 1;
  562. // display: none;
  563. border-left: 1px solid #dadada;
  564. padding: 5px 15px;
  565. margin-right: 5px;
  566. box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
  567. .table_right_box::after {
  568. display: block;
  569. content: "";
  570. clear: both;
  571. }
  572. .close_right {
  573. float: right;
  574. cursor: pointer;
  575. }
  576. }
  577. }
  578. }
  579. .el-pagination button,
  580. .el-pagination span:not([class*="suffix"]) {
  581. vertical-align: middle;
  582. }
  583. </style>