123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- <template>
- <div id="deviceList">
- <el-row class="right">
- <!-- <span style="float:left;">当前选择的部件类型:{{page.total || '--'}}</span> -->
- <el-select v-model="showType" @change="initTable" style="width:125px;margin-right:10px;vertical-align:bottom;">
- <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
- </el-select>
- <span>增加</span>
- <el-input-number v-model="addNum" :controls="false" style="width:50px;" :min="1" :max="50"></el-input-number>
- <span>个竖井</span>
- <el-button @click="handleAddTableRow">增加</el-button>
- </el-row>
- <div class="tableBox">
- <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
- <p>
- <i class="icon-wushuju iconfont"></i>
- 暂无数据
- </p>
- </div>
- <div class="tableLeft" v-show="tableData && tableData.length">
- <handson-table ref="table"></handson-table>
- </div>
- </div>
- <el-row class="center">
- <el-button type="primary" size="medium" @click="handleCreateTableData">创建竖井</el-button>
- </el-row>
- </div>
- </template>
- <script>
- import tools from "@/utils/scan/tools"
- import handsonUtils from "@/utils/hasontableUtils"
- import showTools from "@/utils/handsontable/notShow"
- import text from "@/utils/handsontable/mainText"
- import session from "@/framework/utils/storage"
- import handsonTable from "@/components/common/handsontable"
- import { createCenoteTableData } from "@/api/scan/request"
- import { getDataDictionary } from "@/api/dict";
- import { mapGetters, mapActions } from "vuex";
- export default {
- components: {
- handsonTable
- },
- data() {
- return {
- addNum: 1,
- shaftId: "",//要操作的竖井id
- isTableRightShow: false,
- relationids: "",
- onlyRead: false,
- showTypes: [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }],
- inputMap: {
- flowBuild: {
- editable: true,
- code: "flowBuild",
- name: "建筑楼层",
- path: "flowBuild",
- category: 'STATIC',
- dataType: "ENUM"
- }
- }, //信息点和输入方式映射表
- showType: this.$route.query.showType,
- tableHeader: [],
- tableData: session.get("cenoteAddData") ? session.get("cenoteAddData").length ? session.get("cenoteAddData") : [{}] : [{}],
- copyTableData: []
- };
- },
- computed: {
- ...mapGetters("layout", ["projectId", "secret", "userId"])
- },
- created() {
- this.getTableHeader()
- },
- // watch: {
- // },
- methods: {
- // 获取表头数据(初始化表格)
- async getTableHeader() {
- let param = {
- orders: "sort asc, name desc",
- pageNumber: 1,
- pageSize: 1000,
- type: 'shaft'
- }
- await getDataDictionary(param, res => {
- this.tableHeader = res.content;
- this.tableHeader.forEach(item => {
- if (item.path) {
- this.inputMap[item.path] = item;
- }
- })
- this.initTable()
- })
- },
- // 创建竖井数据
- async handleCreateTableData() {
- let params = {}
- let flag = 0;//1.存在未填写竖井本地名称的数据;2.存在未选择竖井功能的数据
- let newData = this.tableData.filter((item) => {
- let keys = Object.keys(item)
- keys.map((key) => { //将值为空字符串的属性删除
- if (item[key] == "") {
- delete item[key]
- }
- })
- if (!item.localName) {
- flag = 1
- } else if (!item.hasOwnProperty('infos') || !item.infos.shaftFuncType) {
- flag = 2
- }
- if (keys.length && Object.keys(item).length) {
- return item
- }
- })
- if (!newData.length) {
- this.$message("创建信息为空,请录入信息后再创建!")
- return
- } else if (flag == 1) {
- this.$message("存在未填写竖井本地名称的数据,请填写信息后再创建!")
- return
- } else if (flag == 2) {
- this.$message("存在未选择竖井功能的数据,请选择信息后再创建!")
- return
- }
- params.content = newData
- await createCenoteTableData(params, (res) => {
- this.$message.success("添加成功!")
- session.remove("cenoteAddData")
- this.$router.push({ name: 'cenotelist' })
- })
- },
- // 删除表格行
- handleDeleteTableRow() {
- this.$message.success("删除成功")
- this.formaTableData()
- },
- // 添加行
- handleAddTableRow() {
- let addRowLength = this.addNum
- for (let i = 0; i < addRowLength; i++) {
- this.tableData.push({})
- }
- this.initTable()
- this.formaTableData()
- },
- //修改
- handleUpdataTable(changeData, source) {
- this.formaTableData()
- },
- //保存去掉空字段的新增数据
- formaTableData() {
- let newData = this.tableData.filter((item) => {
- let keys = Object.keys(item)
- keys.map((key) => { //将值为空字符串的属性删除
- if (item[key] == "") {
- delete item[key]
- }
- })
- if (keys.length && Object.keys(item).length) {
- return item
- }
- })
- session.set("cenoteAddData", newData)
- },
- //关闭右侧关联元空间输入按钮
- handleCloseRight() {
- this.isTableRightShow = false
- },
- formatHeaderData(list) {//格式化表头显示的数据
- let arr = tools.copyArr(list)
- let data = showTools.headerTextFilter(arr, "shaft", this.onlyRead, this.showType)
- // data.unshift("关联的元空间");
- return data;
- },
- formatHeaderType(list) {//格式化表头头映射的数据
- let arr = tools.copyArr(list);
- let data = showTools.headerTypeFilter(arr, "shaft", this.onlyRead, this.showType)
- // data.unshift({
- // data: "SpaceCount",
- // readOnly: this.onlyRead
- // })
- return data;
- },
- initTable() {//实例化表格
- let settings = {
- data: this.tableData,
- colHeaders: this.formatHeaderData(this.tableHeader),
- columns: this.formatHeaderType(this.tableHeader),
- rowHeights: 30,
- maxRows: this.tableData.length,
- contextMenu: this.onlyRead ? false : {
- items: {
- remove_row: {
- name: "删除竖井"
- }
- }
- },
- // 事件
- afterChange: this.handleUpdataTable, //修改后
- afterFilter: this.trimmedRows, //排序前
- afterRemoveRow: this.handleDeleteTableRow, //右键删除
- afterOnCellMouseDown: this.handleTdClick //鼠标点击
- };
- this.$nextTick(() => {
- console.log(this.$refs.table);
- this.tableExample = this.$refs.table.init(settings);
- });
- },
- //获取到了正确的信息
- getInfors(infos, row) {
- //其他的开始判断
- let val = this.tableExample.colToProp(row.col);
- let inputData = this.inputMap[val];
- this.row = row.row //要操作的列号
- this.messKey = val //要操作的列类型
- if (!this.onlyRead && !inputData.editable) {
- this.$message("该信息点的值为自动生成,不可人工维护!");
- return false;
- }
- //点击关联的元空间
- // if (val === "SpaceCount") {
- // this.isTableRightShow = true;
- // }
- },
- //表格点击事件
- handleTdClick(el, rowArr) {
- //点击的是表头
- if (rowArr.row < 0) {
- return;
- }
- //被筛选过后的数组
- let trimmedArr = this.trimmedRows();
- //是否启用了排序
- let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
- if (trimmedArr.length && isSort) {
- let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
- .__arrayMap;
- let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
- this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
- } else if (isSort) {
- //排序后的数组
- let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper.__arrayMap;
- let infos = this.tableData[sortArr[rowArr.row]];
- this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
- } else if (trimmedArr.length) {
- let infos = this.tableData[trimmedArr[rowArr.row]];
- this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
- } else {
- let infos = this.tableData[rowArr.row];
- this.getInfors(infos, rowArr);
- }
- },
- //获取被筛选掉的行号
- trimmedRows() {
- // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
- var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
- let dataLength = this.tableData.length;
- let dataArr = new Array();
- for (let i = 0; i < dataLength; i++) {
- dataArr.push(i);
- }
- if (plugin.length <= 0) {
- dataArr = undefined;
- } else {
- dataArr = this.array_diff(dataArr, plugin);
- }
- return dataArr || [];
- // var DataArray = new Array();
- // for (var i = 0; i < plugin.length; i++) {
- // // 通过行号获取数据
- // DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
- // }
- },
- //去除数组中相同的元素
- array_diff(a, b) {
- for (var i = 0; i < b.length; i++) {
- for (var j = 0; j < a.length; j++) {
- if (a[j] == b[i]) {
- a.splice(j, 1);
- j = j - 1;
- }
- }
- }
- return a;
- }
- }
- };
- </script>
- <style lang="less" scoped>
- #deviceList {
- overflow: hidden;
- height: 100%;
- background-color: #fff;
- padding: 10px;
- position: relative;
- .right {
- background: #fff;
- }
- .search-header {
- overflow: hidden;
- padding: 0 10px 10px 10px;
- border-bottom: 1px solid #bcbcbc;
- }
- .tableBox {
- display: flex;
- height: calc(100% - 100px);
- margin-top: 10px;
- .tableLeft {
- flex: 2;
- }
- .tableRight {
- flex: 1;
- // display: none;
- border-left: 1px solid #dadada;
- padding: 5px 15px;
- margin-right: 5px;
- box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
- .table_right_box::after {
- display: block;
- content: "";
- clear: both;
- }
- .close_right {
- float: right;
- cursor: pointer;
- }
- }
- }
- .create_button {
- margin-top: 10px;
- }
- }
- </style>
|