美文网首页
el-table回显复选框和设置el-table表头全选框隐藏或

el-table回显复选框和设置el-table表头全选框隐藏或

作者: jesse28 | 来源:发表于2023-06-15 17:13 被阅读0次

    1.设置el-table表头全选框隐藏或禁用:参考链接https://blog.csdn.net/weixin_63896561/article/details/128922622

    2.el-table表格勾选判断当前操作是勾选还是取消勾选(只支持用户手动点击表格前面勾选框的勾选)参考链接
    https://blog.csdn.net/Amnesiac666/article/details/111602066

    <template>
      <el-dialog :title="title" width="850px" :visible="show" @close="onClose" :close-on-click-modal="false">
        <div class="containner" style="height:600px">
          <el-form :model="form" ref="form" label-width="80px" :inline="true" size="small">
            <el-form-item label="姓名:">
              <el-input v-model="form.name" style="width:200px"></el-input>
            </el-form-item>
            <el-form-item label="账号:">
              <el-input v-model="form.account" style="width:200px"></el-input>
            </el-form-item>
            <el-form-item label="部门:">
              <treeselect style="width:200px" :default-expand-level="3" v-model="form.orgId" noResultsText="暂无结果" :searchable="true" :options="orgList" :normalizer="normalizer" :show-count="true" placeholder="请选择部门" />
            </el-form-item>
            <el-form-item label="电话号码:">
              <el-input style="width:200px" v-model="form.mobile"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="getList" type="primary" icon="el-icon-search">查询</el-button>
              <el-button @click="cacelList" icon="el-icon-delete">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table @select='onTableSelect' border :row-key="getRowKeys" highlight-current-row :height="430" class="tableAll" ref="multipleTable" :header-cell-style="{ background: '#F4F4F4' }" :data="tableData" style="width: 100%;margin-bottom: 20px;">
            <el-table-column align="center" type="selection" :reserve-selection="true" width="80" />
            <el-table-column prop="name" label="用户名"></el-table-column>
            <el-table-column prop="account" label="账号"></el-table-column>
            <el-table-column prop="mobile" label="账号"></el-table-column>
          </el-table>
          <pagination :total="total" :page.sync="pageNum" :limit.sync="pageSize" @pagination="pagination" />
        </div>
      </el-dialog>
    </template>
        
    <script>
    import Pagination from "@/components/Pagination";
    import Treeselect from "@riophae/vue-treeselect";
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    import { changeTree } from "@/utils/index";
    import {
      allUserListApi,
      systemOrgFindList,
      addBindingUser,
      deleteBindingUser,
    } from "@/api/system/sys";
    export default {
      props: ["title", "id"],
      data() {
        return {
          show: true,
          pageNum: 1,
          pageSize: 10,
          total: 0, // 总页数
          orgList: [], //部门数组
          tableData: [],
          form: {
            name: "", //用户名
            account: "", //账号
            orgId: null, //部门
            mobile: "", //电话
          },
        };
      },
      components: {
        Treeselect,
        Pagination,
      },
      created() {
        this.getOrg();
        this.getList();
      },
      methods: {
        getRowKeys(row) {
          if (row.isCheck == "1") {
            //判断条件,根据自己的项目进行添加
            return row.id;
          }
        },
        /** 转换菜单数据结构 */
        normalizer(node) {
          return {
            id: node.id,
            label: node.orgName,
            children: node.children,
          };
        },
        getList() {
          let params = Object.assign(
            {},
            { roleId: this.id },
            this.form,
            { pageNum: this.pageNum },
            { pageSize: this.pageSize }
          );
          allUserListApi(params).then((res) => {
            console.log("输出参数", res);
            if (res.data) {
              if (this.pageNum > 1 && res.data.list.length === 0) {
                this.pageNum = 1
                this.getList()
              }
              this.tableData = res.data.list;
              this.total = res.data.total;
              this.tableData = JSON.parse(JSON.stringify(res.data.list));
              this.$nextTick(()=>{
                this.tableData.forEach((item) => {
                  console.log("输出什么", item.isCheck);
                  if (item.isCheck == "1") {
                    //判断条件,根据自己的项目进行添加
                    this.$refs.multipleTable.toggleRowSelection(item, true);
                  } else if (item.isCheck == "0") {
                    this.$refs.multipleTable.toggleRowSelection(item, false);
                  }
                });
              })
            }
          });
        },
        // 获取部门
        getOrg() {
          systemOrgFindList({}).then((res) => {
            if (res && res.data) {
              this.orgList = changeTree(res.data, "order");
            }
          });
        },
        // 重置
        cacelList() {
          this.pageNum = 1
          this.form.name = "";
          this.form.account = "";
          this.form.orgId = null;
          this.form.mobile = "";
          this.getList();
        },
    
        onTableSelect(rows, row) {
          console.log("触发表格", rows, row);
          let selected = rows.length && rows.indexOf(row) !== -1;
          console.log(selected); // true就是选中,0或者false是取消选中
          if (selected) {
            addBindingUser({
              roleId: this.id,
              userId: row.id,
            }).then((res) => {});
          } else {
            deleteBindingUser({
              roleId: this.id,
              userId: row.id,
            }).then((res) => {});
          }
        },
        // 分页查询
        pagination(val) {
          this.pageNum = val.page;
          this.pageSize = val.limit;
          this.getList();
        },
        //关闭事件
        onClose() {
          this.$emit("onClose");
        },
      },
    };
    </script>
        
    <style lang="scss" scoped>
    
    ::v-deep .el-table__header-wrapper .el-checkbox {
      // display: none;//设置不成功,页面卡顿
      visibility: hidden;
    }
    .el-dialog__wrapper {
      ::v-deep .el-dialog {
        border-top-left-radius: 2px;
        border-top-right-radius: 2px;
    
        .el-dialog__header {
          border-top-left-radius: 2px;
          border-top-right-radius: 2px;
          background-color: #1890ff;
    
          .el-dialog__title {
            color: #fff;
            font-size: 16px;
            font-weight: 600;
          }
    
          .el-dialog__close {
            color: #fff;
          }
        }
    
        .el-dialog__body {
          padding: 10px;
        }
    
        .el-dialog__footer {
          // border-top: 1px solid #e8eaec !important;
          padding: 10px;
          padding-top: 30px;
        }
      }
    }
    </style>
        
    

    相关文章

      网友评论

          本文标题:el-table回显复选框和设置el-table表头全选框隐藏或

          本文链接:https://www.haomeiwen.com/subject/oggnedtx.html