zxl
2025-02-27 387b898a3c38c0905d0f9309175de39ccb29cd82
在库项目,隐藏列可操作保存
4个文件已修改
352 ■■■■ 已修改文件
package.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/projectEngineering/projectInfo.js 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/VisibilityToolbar/index.vue 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/projectEngineering/projectLibrary/index.vue 222 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
package.json
@@ -43,6 +43,7 @@
    "bpmn-js-bpmnlint": "^0.15.0",
    "bpmnlint": "^6.4.0",
    "bpmnlint-loader": "^0.1.4",
    "circular-json": "^0.5.9",
    "clipboard": "2.0.8",
    "core-js": "3.37.1",
    "diagram-js": "^11.4.1",
src/api/projectEngineering/projectInfo.js
@@ -79,4 +79,25 @@
    method: 'get',
    params: data
  })
}
export function getHiddenList(data){
  return request({
    url:'/hidden-admin/page',
    method:'get',
    params: data
  })
}
export function saveHiddenList(data){
  return request({
    url:'/hidden-admin/updateList',
    method:'put',
    data:data
  })
}
export function addList(data){
    return request({
      url:'/hidden-admin/addList',
      method:'post',
      data:data
    })
}
src/components/VisibilityToolbar/index.vue
@@ -23,7 +23,7 @@
        <span>信息显隐筛选</span>
      </div>
      <div slot="default" style="margin-left: 20px;margin-top: 20px">
        <el-table :data="pagedColumns" style="width: 95%; height: 80%;;margin-bottom: 40px;">
        <el-table :data="getPage" style="width: 95%; height: 80%;;margin-bottom: 40px;">
          <el-table-column prop="index" label="序号" width="80"></el-table-column>
          <el-table-column prop="label" label="数据名称"></el-table-column>
          <el-table-column prop="visible" label="是否显示">
@@ -53,6 +53,7 @@
        ></el-pagination>
      </div>
      <div style="position: absolute; bottom: 0; left: 0; right: 0; padding: 20px; text-align: right;">
        <el-button type="primary" @click="save" v-if="isAdmin()">保 存</el-button>
        <el-button @click="table = false">取 消</el-button>
        <el-button type="primary" @click="resetSort">重 置</el-button>
      </div>
@@ -61,6 +62,9 @@
</template>
<script>
import {saveHiddenList} from "@/api/projectEngineering/projectInfo";
import CircularJSON from 'circular-json'
export default {
  data() {
@@ -68,7 +72,8 @@
      table: false,
      currentPage: 1,
      columnRef: null,
      cpList: []
      cpList: [],
      saveList:[],
    };
  },
  props: {
@@ -79,6 +84,10 @@
    columns: {
      type: Array,
      default: () => [],
    },
    hiddenTotal:{
      type: Number,
      default: 0,
    },
    search: {
      type: Boolean,
@@ -99,15 +108,17 @@
      return 10;
    },
    total() {
      return this.columns.length;
      return this.hiddenTotal;
    },
    pagedColumns() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.columns.slice(start, end);
    getPage(){
      return this.columns;
    }
    },
  },
  methods: {
    isAdmin(){
      return this.$auth.hasRole("admin")
    },
    toggleSearch() {
      this.$emit('update:showSearch', !this.showSearch);
    },
@@ -118,12 +129,87 @@
      this.table = true;
    },
    switchChange(row) {
      row.sort = row.serialNumber;
      if (row.visible === true){
        row.display = "1"
      }else {
        row.display = "0"
      }
      if(this.saveList.length === 0){
        this.saveList.push(row)
      }else {
        let have = true;
        this.saveList.forEach((item ,index)=>{
          if (item.id === row.id){
              item[index] =item;
            have =false;
          }
        })
        if (have){
          this.saveList.push(row)
        }
      }
      console.log(this.saveList)
      this.$emit('update:columns', row);
    },
    handlePageChange(page) {
      this.currentPage = page;
      this.$emit('update:page', page);
      // this.currentPage = page;
      // this.queryParams.currentPage = page;
      // getHiddenList(this.queryParams).then(res =>{
      //   //转换
      //   res.data.forEach((item,index)=>{
      //     item.index = index + 1;
      //     item.key = index;
      //     item.serialNumber = index + 1;
      //     item.label = item.name;
      //     if(item.display === '0'){
      //       item.visible = false
      //     }else {
      //       item.visible = true;
      //     }
      //     if(item.columns ==='usedStatus' ){
      //       if(projectPhase !== '6') {
      //         item.visible = false
      //       }  else {
      //         item.visible = true
      //       }
      //     }
      //   });
      //   this.columns = res.data;
      // })
    },
    save(){
      //保存逻辑
      if (this.saveList.length !== 0){
        saveHiddenList(CircularJSON.stringify(this.saveList)).then(res =>{
          this.$modal.msgSuccess(res.msg);
        });
      }
    },
    sortChange(row, val) {
      row.sort = row.serialNumber;
      if (row.visible === true){
        row.display = "1"
      }else {
        row.display = "0"
      }
      if(this.saveList.length === 0){
        this.saveList.push(row)
      }else {
        let have = true;
        this.saveList.forEach((item ,index)=>{
          if (item.id === row.id){
            item[index] =item;
            have =false;
          }
        })
        if (have){
          this.saveList.push(row)
        }
      }
      // // 创建一个新的columns数组,以避免直接修改原始数组
      // this.cpList = this.columns.map(item => ({ ...item })); // 使用解构来创建对象的浅拷贝
      //
@@ -142,10 +228,14 @@
      this.$emit('update:sort', row);
    },
    resetSort() {
      //重置保存集合
      this.currentPage = 1;
      this.saveList = [];
      this.$emit('update:resetSort');
    },
  },
  mounted() {
    this.columns.forEach((item, index) => {
      if (item.visible) {
src/views/projectEngineering/projectLibrary/index.vue
@@ -180,15 +180,17 @@
          <VisibilityToolbar
            v-model:showSearch="showSearch"
            :columns="defaultColumns"
            :hiddenTotal="hiddenTotal"
            @queryTable="handleQuery"
            @update:sort="handleUpdateSort"
            @update:columns="handleUpdateColumns"
            @update:resetSort="handleResetSort"
            @update:page="handlePage"
          ></VisibilityToolbar>
        </div>
      </div>
    </el-form>
<!--  <el-button  type="primary" @click="save">初始化添加list.js</el-button>-->
    <el-table
      :key="tableKey"
      ref="elTable"
@@ -202,10 +204,10 @@
      <el-table-column type="selection" width="55" align="center"/>
      <!-- 动态列 -->
      <el-table-column
        v-for="item in columns"
        :key="item.id"
        v-for="item in columnsNew"
        :key="item.columns"
        v-if="item.visible"
        :prop="item.id"
        :prop="item.columns"
        :label="item.label"
        :min-width="item.minWidth"
      >
@@ -250,7 +252,7 @@
            </template>
          </template>
          <!-- 默认显示 -->
          <span v-else>{{ scope.row[item.id] }}</span>
          <span v-else>{{ scope.row[item.columns] }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="this.$route.query.projectPhase==6" label="审核备注" width="140" align="center" prop="remark"/>
@@ -314,14 +316,14 @@
      :fileDialogVisible.sync="fileDialogVisible"
      :isImportOrExport="isImportOrExport"
      @fileDialogCancel="fileDialogCancel"
      :currentColumns="columns"
      :currentColumns="columnsNew"
      :dataIdList="ids"
    />
  </div>
</template>
<script>
import {listProject, getProject, delProject, addProject, updateProject} from "@/api/projectEngineering/projectInfo";
import {listProject, getProject, delProject, addProject, updateProject,getHiddenList,addList} from "@/api/projectEngineering/projectInfo";
import {current, currentRest} from '@/views/projectEngineering/projectLibrary/list';
import FileDialog from '@/views/projectEngineering/projectLibrary/component/FileDialog';
import Cookies from "js-cookie";
@@ -344,8 +346,13 @@
      //项目状态筛选条件
      isProjectCategory: false,
      //表头
      columns: [],
      columnsNew: [],
      //显隐组件的表头集合
      defaultColumns: [],
      //重置表头
      resetColumns:[],
      //显隐组件的查询总数
      hiddenTotal: 0,
      //控制更多筛选显隐
      popoverValue: false,
      // 遮罩层
@@ -377,6 +384,10 @@
        projectCode: null,
        projectStartTime: null,
        projectEndTime: null,
      },
      //显隐列表查询参数
      pageQueryParams:{
        currentPage: 1,
      },
      moreQueryParams: {
        projectType: '', // 项目类型
@@ -415,27 +426,60 @@
    if (projectPhase) {
      this.isProjectCategory = true;
    }
    const columns = current.map((item, index) => {
      item.index = index + 1;
      item.key = index;
      item.serialNumber = index + 1;
      if(item.id ==='usedStatus' ){
        if(projectPhase !== '6') {
          item.visible = false
        }  else {
          item.visible = true
        }
      }
      return item;
    });
    this.columns = columns;
    this.defaultColumns = JSON.parse(JSON.stringify(columns));
    // const columns = current.map((item, index) => {
    //   item.index = index + 1;
    //   item.key = index;
    //   item.serialNumber = index + 1;
    //   if(item.id ==='usedStatus' ){
    //     if(projectPhase !== '6') {
    //       item.visible = false
    //     }  else {
    //       item.visible = true
    //     }
    //   }
    //   return item;
    // });
    // this.columns = columns;
    // this.defaultColumns = JSON.parse(JSON.stringify(columns));
    this.hiddenList();
    this.getList(this.$route.query.projectPhase == '5' || this.$route.query.projectPhase == '6' ? null : this.$route.query.projectPhase);
  },
  beforeDestroy() {
    this.removeStore();
  },
  methods: {
    hiddenList(){
       getHiddenList().then(res =>{
        const projectPhase = this.$route.query.projectPhase;
        //转换
         res.data.forEach((item,index)=>{
           item.index = index + 1;
           item.key = index;
           item.serialNumber = item.sort;
           item.label = item.name;
           // item.slotName = item.columns;
          if(item.display === '0'){
            item.visible = false
          }else {
            item.visible = true;
          }
          if(item.columns ==='usedStatus' ){
            if(projectPhase !== '6') {
              item.visible = false
            }  else {
              item.visible = true
            }
          }
        });
        this.defaultColumns = res.data;
        this.columnsNew = res.data;
        console.log(this.columnsNew)
        this.hiddenTotal = res.total;
      })
    },
    // async getProjectSubType(projectType, projectSubType) {
    //   if (!projectType || !projectSubType) {
    //     return ''
@@ -478,42 +522,108 @@
      localStorage.removeItem("policyInfoForm")
      localStorage.removeItem("documentsInfoForm")
    },
    //隐藏列表翻页
    handlePage(page){
      this.pageQueryParams.currentPage = page;
      getHiddenList(this.pageQueryParams).then(res =>{
        this.buildColumns(res.data);
      })
    },
    buildColumns(data){
        const projectPhase = this.$route.query.projectPhase;
        //转换
        data.forEach((item,index)=>{
          item.index = index + 1;
          item.key = index;
          item.serialNumber = item.sort;
          item.label = item.name;
          // item.slotName = item.columns;
          if(item.display === '0'){
            item.visible = false
          }else {
            item.visible = true;
          }
          if(item.columns ==='usedStatus' ){
            if(projectPhase !== '6') {
              item.visible = false
            }  else {
              item.visible = true
            }
          }
        });
        this.columnsNew = data;
        this.defaultColumns = data;
    },
    save(){
      const list =current.map((item, index) => {
            item.name = item.label;
            item.sort = index + 1;
            item.columns = item.id;
            item.id = 0;
            if(item.slotName === undefined){
              item.slotName = null;
            }
            if(item.visible){
              item.display = "1";
            }else {
              item.display ="0";
            }
            return item;
          });
      console.log(list)
      addList(list).then(res=>{
        console.log(res.msg)
      })
    },
    // 重置排序的方法
    handleResetSort() {
      const projectPhase = this.$route.query.projectPhase;
      this.defaultColumns = currentRest.map((item, index) => {
        item.index = index + 1;
        item.key = index;
        item.serialNumber = index + 1
        if(item.id ==='usedStatus' ){
          if(projectPhase !== '6') {
            item.visible = false
          }  else {
            item.visible = true
          }
        }
        return item;
      });
      this.columns = currentRest.map((item, index) => {
        item.index = index + 1;
        item.key = index;
        item.serialNumber = index + 1
        if(item.id ==='usedStatus' ){
          if(projectPhase !== '6') {
            item.visible = false
          }  else {
            item.visible = true
          }
        }
        return item;
      });
      this.hiddenList()
      // const projectPhase = this.$route.query.projectPhase;
      // this.defaultColumns= currentRest.map((item, index) => {
      //   item.index = index + 1;
      //   item.key = index;
      //   item.serialNumber = index + 1
      //   if(item.id ==='usedStatus' ){
      //     if(projectPhase !== '6') {
      //       item.visible = false
      //     }  else {
      //       item.visible = true
      //     }
      //   }
      //   return item;
      // });
      // this.columnsNew = currentRest.map((item, index) => {
      //   item.index = index + 1;
      //   item.key = index;
      //   item.serialNumber = index + 1
      //   if(item.id ==='usedStatus' ){
      //     if(projectPhase !== '6') {
      //       item.visible = false
      //     }  else {
      //       item.visible = true
      //     }
      //   }
      //   return item;
      // });
      //强制table渲染
      // this.defaultColumns = this.resetColumns;
      //
      //
      // this.columnsNew = this.resetColumns;
      this.tableKey = this.tableKey + 1;
    },
    // 更新列的方法
    handleUpdateColumns(row) {
      // this.currentColumns = row;
      this.columns = this.columns.map(item => {
      row.key = Number(row.key)
      this.columnsNew = this.columnsNew.map(item => {
        if (item.key === row.key) {
          return row;
        }
@@ -521,18 +631,18 @@
      });
    },
    handleUpdateSort(row) {
      console.log(this.columns, '排序前的列');
      this.columns = this.columns.map(item => {
      console.log(this.columnsNew, '排序前的列');
      this.columnsNew = this.columnsNew.map(item => {
        if (item.key === row.key) {
          return row;
        }
        return item;
      });
      this.defaultColumns = JSON.parse(JSON.stringify(this.columns)).sort((a, b) => a.index - b.index);
      this.columns.sort((a, b) => a.serialNumber - b.serialNumber);
      this.defaultColumns = this.columnsNew.sort((a, b) => a.index - b.index);
      this.columnsNew.sort((a, b) => a.serialNumber - b.serialNumber);
      //强制table渲染
      this.tableKey = this.tableKey + 1;
      console.log(this.columns, '排序后的列');
      console.log(this.columnsNew, '排序后的列');
    },
    // 关闭文件处理弹框的方法
    fileDialogCancel() {