index.vue 18 KB

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