index.vue 19 KB

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