index.vue 18 KB

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