VUE--ElementUI--后端界面--用户管理(三)

一、用户管理

  1. 界面
<template>
  <!-- 用户管理 -->
  <div>
    <el-row class="topRow">
      <el-button type="primary" @click="addUser">添加用户</el-button>
      <el-button type="success" @click="batchDel">批量删除</el-button>
    </el-row>
    <el-table
      ref="multipleTable"
      :data="userData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <!-- 复选接钮 -->
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="编号" prop="id" width="120"></el-table-column>
      <el-table-column prop="username" label="用户" width="120"></el-table-column>
      <el-table-column prop="createTime" label="创建日期" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="编号">
          <el-input v-model="form.id"></el-input>
        </el-form-item>
        <el-form-item label="用户">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: { id: "", username: "", createTime: "" },
      userData: [
        { id: 1, username: "王小虎", createTime: "2019-08-13 15:00:00" },
        { id: 2, username: "李小七", createTime: "2019-08-13 15:00:00" },
        { id: 3, username: "张小八", createTime: "2019-08-13 15:00:00" }
      ],
      multipleSelection: [],
      title: "",
      dialogVisible: false
    };
  },
  methods: {
    // 选择
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleClose() {
    this.dialogVisible = false;
   },
  }
};
</script>
<style scoped>
.topRow {
  margin-bottom: 10px;
  float: left;
}
</style>
  1. 删除事件
    // 删除
    handleDelete(index, rows) {
      this.userData.splice(index, 1);
    },
    batchDel() {
      this.multipleSelection.forEach(element => {
        this.userData.forEach((item, index) => {
          if (item.username == element.username) {
            this.userData.splice(index, 1);
          }
        });
      });
    },
  1. 添加编辑事件
    addUser() {
      this.form.id = "";
      this.form.username = "";
      this.title = "添加用户";
      this.dialogVisible = true;
    },
    // 编辑
    handleEdit(index, rows) {
      this.title = "编辑用户";
      this.dialogVisible = true;
      this.form.id = rows.id;
      this.form.username = rows.username;
      console.log(index + "->" + rows.username);
    },
  1. 保存事件
    save() {
      if (this.title == "添加用户") {
         let user = { id: "", username: "", createTime: "" };
        user.id = this.form.id;
        user.username = this.form.username;
        user.createTime= "2019-08-14 10:00:00";
        this.userData.push(user);
        this.dialogVisible = false;
      } else if (this.title == "编辑用户") {
         this.userData.forEach((item,index)=>{
           if(item.username==this.form.username){
             item.username=this.form.username;
              this.dialogVisible = false;
              return;
           }
         });
      }
    },
界面

添加对话框
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  •   JavaScript 与 HTML 之间的交互是通过事件实现的。   事件,就是文档或浏览器窗口中发生的一些特...
    霜天晓阅读 3,526评论 1 11
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,498评论 0 17
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,135评论 1 32
  • 平台概述 平台定位 软件产品交付过程中IT工具链的打通,开发运维一体化,使得各个团队减少时间损耗,更加高效地协同工...
    Lalaraine阅读 4,218评论 0 4
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,803评论 0 10