index.vue 19 KB

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