首页 > 其他分享 >element ui 列表页 新增修改查看表单

element ui 列表页 新增修改查看表单

时间:2023-10-09 21:32:59浏览次数:42  
标签:false val true 表单 dataForm ui element data id

element ui 列表页 新增修改查看表单_elementui

element ui 列表页 新增修改查看表单_表单_02

列表页直接操作删除,新增修改查看用一个子组件表单实现

列表

<template>
  <div class="mod-config ml10">
    <!--搜索-->
    <div class="search searchHead" v-show="showSearch">
      <el-form ref="searchForm" :model="searchForm" :inline="true" size="mini">
        <el-form-item label="申请时间" prop="timeArray">
          <el-date-picker style="width: 360px" type="daterange" range-separator="至" v-model.trim="timeArray"
                          value-format="yyyy-MM-dd hh:mm:ss" start-placeholder="申请开始时间" end-placeholder="申请结束时间" size="small"
                          @change="timeArrayChange"></el-date-picker>
        </el-form-item>
        <el-form-item label="是否启用" prop="enableStatus">
          <el-select
            v-model="searchForm.enableStatus"
            clearable
            placeholder="请选择是否启用"
            size="small"
          >
            <el-option label="关闭" :value="0"></el-option>
            <el-option label="开启" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" size="small" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-delete" size="small" @click="resetQuery">清空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tableContent">
      <!--搜索刷新-->
      <toolbar @refreshTable="getDataList" :showSearch.sync="showSearch">
        <el-button slot="add" type="primary" icon="el-icon-plus" size="small" @click="addOrUpdateHandle()">新增模板</el-button>
      </toolbar>

      <div class="avue-crud">
        <el-table
            :data="dataList"
            border
            :default-sort = "{prop: 'createTime', order: 'descending'}"
            v-loading="dataListLoading">
          <el-table-column label="序号" align="left" min-width="50px" width="50">
            <template slot-scope="scope">
              {{ helper.generateIndex(scope.$index, searchForm) }}
            </template>
          </el-table-column>
          <el-table-column
              prop="name"
              header-align="left"
              align="left"
              label="模板名称">
          </el-table-column>

          <el-table-column
            align="center"
            label="是否启用"
            prop="enableStatus"
            width="150"
          >
            <template slot-scope="{ row }">

              <el-switch
                v-if="permissions.service_mailtemplate_edit"
                class="eval-switch"
                v-model="row.enableStatus"
                :active-value="1"
                :inactive-value="0"
                @change="switchChange(row,$event)"
              >
              </el-switch>

              <template v-else>
                <el-tooltip effect="dark" content="无此权限" placement="top">
                  <el-switch
                    v-model="row.enableStatus"
                    :active-value="0"
                    :inactive-value="1"
                    disabled
                  >
                  </el-switch>
                </el-tooltip>
              </template>
            </template>
          </el-table-column>

          <el-table-column
            prop="createTime"
            header-align="left"
            align="left"
            label="创建时间"
            width="300"
          >
          </el-table-column>
          <el-table-column
              header-align="center"
              align="center"
              label="操作">
            <template slot-scope="scope">
              <el-button v-if="permissions.service_mailtemplate_view" type="text" size="small" icon="el-icon-view"
                         @click="addOrUpdateHandle(scope.row.mailTemplateId,1)">查看
              </el-button>
              <el-button v-if="permissions.service_mailtemplate_edit" type="text" size="small" icon="el-icon-edit"
                         @click="addOrUpdateHandle(scope.row.mailTemplateId)">编辑
              </el-button>
              <el-button v-if="permissions.service_mailtemplate_del" type="text" size="small" icon="el-icon-delete"
                         @click="deleteHandle(scope.row.mailTemplateId,scope.row.name)">删除
              </el-button>
            </template>
          </el-table-column>
          <template v-slot:empty>
            <el-image
              src="https://cdn.hnjngl.hnrrcz.com/common/noData.png"
              style="margin-top: 70px; width: 255px"
              fit="fill"
            ></el-image>
            <div
              class="noData"
              style="
                  position: relative;
                  margin: -70px auto -5px;
                  font-size: 14px;
                  color: #999;
                "
            >
              你还没有邮件模板信息,请点击去新增
            </div>
            <el-button
              type="primary"
              size="medium"
              style="min-width: 129px; margin-bottom: 50px"
              @click="addOrUpdateHandle()"
            >去新增</el-button
            >
          </template>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
                       :current-page="searchForm.current" :page-sizes="[10,20,50,100]"
                       :page-size="searchForm.size" :total="totalPage" background
                       layout="total,sizes,prev,pager,next,jumper"></el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
    </div>



  </div>
</template>

<script>
import {fetchList,delObj,putObj,} from '@/api/service/mailTemplate'
import TableForm from './mailTemplate-form'
import Toolbar from "@/components/Toolbar"
import {mapGetters} from 'vuex'
import {getDicDataSource} from "@/util/common";
import {getStore} from "@/util/store";



export default {
  data() {
    return {
      searchForm: {
        current: 1,
        size: 10,
        enableStatus: '',
      },
      timeArray: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      showSearch: true,
      dataListLoading: false,
      addOrUpdateVisible: false,
      load: false,
      userInfo: {},
    }
  },
  components: {
    TableForm,
    Toolbar
  },
  created() {
    this.userInfo = getStore({name: 'userInfo'});
    console.log("this.userInfo:",this.userInfo);
    this.getDataList()
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    //时间搜索
    timeArrayChange(val) {
      if (val) {
        val[0] = val[0].substr(0, 10) + " 00:00:00";
        val[1] = val[1].substr(0, 10) + " 23:59:59";
      }
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.load = false;
      let data = {
        timeArray: this.timeArray,
        ...this.searchForm
      }
      fetchList(data).then(response => {
        this.dataList = response.data.data.records
        this.totalPage = response.data.data.total
        this.load = true;
      })
      this.dataListLoading = false
      console.log("list");
    },
    //每页数
    sizeChangeHandle(val) {
      this.searchForm.size = val;
      this.searchForm.current = 1;
      this.load = false;//重新加载
      this.getDataList();
    },
    //当前页
    currentChangeHandle(val) {
      console.log("page");
      this.searchForm.current = val;
      this.load = false;//重新加载
      this.getDataList();
    },
    // 新增 / 修改
    addOrUpdateHandle(id,views) {
      this.addOrUpdateVisible = true
      console.log(id, views);
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id,views);
      })
    },
    // 删除
    deleteHandle(id, name) {
      let that = this
      this.$confirm('是否确认删除:' + name, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        delObj(id).then(res => {
          if (res.data.data){
            that.$message.success('删除成功')
            that.getDataList()
          }else {
            that.$message.error('删除失败,当前文件有模板选用')
            that.getDataList()
          }
        })
      }).then(data => {

      })
    },
    handleQuery() {
      this.searchForm.current = 1;
      this.load = false;//重新加载
      this.getDataList();
    },
    resetQuery() {
      this.searchForm.enableStatus = "";
      this.timeArray = [];
      this.searchForm.name = '';

      this.$refs['searchForm'].resetFields();
      this.handleQuery();
    },
    switchChange(row,val) {

      this.$confirm(
        `是否确认${row.enableStatus !== 1 ? "打开" : "关闭"}该邮件模板(${
          row.name
        })的启用功能`,
        "提示"
      ).then((res) => {
        this.dataListLoading = true;

        //const result = row.enableStatus == 1 ? 0 : 1;

        putObj({
          mailTemplateId: row.mailTemplateId,
          enableStatus: val,
        })
          .then((res) => {

            this.dataListLoading = false;
            row.enableStatus = result;
            this.getDataList();

          })
          .catch(() => {
            this.dataListLoading = false;
          });
      });
    },

  }
}
</script>
<style scoped lang="scss">
/deep/.cell {
  max-height: 110px;
  overflow-y: hidden;
}
/*查看截图水平居中*/
/*
/deep/.drag-inner {
  top: 50%!important;
  left: 50%;
  transform: translate(-50%,-50%);
}
*/

/deep/.el-icon-zoom-in {
  margin-right: 0!important;
}


.div-mask-one {
  position: absolute;
  bottom: 0px;
  left: 0px;
  width: 100px;
  cursor: pointer;
  height: 100px;
  background-color: rgba(0, 0, 0, 0.37);
  /* 垂直居中展示 注意点 如果使用绝对居中,其内容内容要用一个div包起来 */
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: 16px;
  color: #ffffff;
  transition: height 300ms;
  top: 1px;
}

.mask-one-p {
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}



</style>


表单

<template>
  <el-dialog
    :title="!dataForm.mailTemplateId ? '新增邮件模板' : views && dataForm.mailTemplateId ? '查看邮件模板' : '修改邮件模板'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    v-if="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="95px"
      label-position="left"
    >
      <el-form-item label="模板名称" prop="name">
        <cl-input v-model="dataForm.name" placeholder="请输入模板名称" :disabled="views"></cl-input>
      </el-form-item>

      <el-form-item label="模板内容" prop="content">
        <cl-input v-model="dataForm.content" placeholder="请输入模板内容" :disabled="views" type="textarea"  ></cl-input>
      </el-form-item>

    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit"
        >确认{{ !dataForm.mailTemplateId ? '新增邮件模板' : '修改邮件模板'}}</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { getObj, addObj, putObj } from "@/api/service/mailTemplate";

import { getDicDataSource } from "@/util/common";

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      views: false,
      dataForm: {
        name: "",
        content: "",
      },
      dataRule: {
        name: [{ required: true, message: "模板名称不能为空", trigger: "blur" }],
        content: [{ required: true, message: "模板内容不能为空", trigger: "blur" }],
      },
      load:false
    };
  },
  created() {
  },
  components: { },
  methods: {
    init(id,views) {
      console.log('views', id, views);
      if (views == 1) {
        this.views = true;
        this.canSubmit = false;
      } else {
        this.views = false;
        this.canSubmit = true;
      }
      this.dataForm.mailTemplateId = id || '';

      this.dataForm.content = "";
      this.dataForm.name = "";
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()

        if (this.dataForm.mailTemplateId) {
          getObj(this.dataForm.mailTemplateId).then((response) => {
            this.dataForm = response.data.data;
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      console.log(this.dataForm);

      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.canSubmit = false;
          if (this.dataForm.mailTemplateId) {
            putObj(this.dataForm)
              .then((data) => {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          } else {
            addObj(this.dataForm)
              .then((data) => {
                this.$message({
                  message: "添加成功",
                  type: "success",
                });
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          }
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
/deep/ #uploadContent {
  width: 440px;
}
</style>

接口

/*
 *    Copyright (c) 2018-2025, rs All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: rs
 */

import request from '@/router/axios'

//分页
export function fetchList(query) {
  return request({
    url: '/rs-service/mailtemplate/page',
    method: 'get',
    params: query
  })
}

//新增
export function addObj(obj) {
  return request({
    url: '/rs-service/mailtemplate',
    method: 'post',
    data: obj
  })
}

//修改
export function putObj(obj) {
  return request({
    url: '/rs-service/mailtemplate',
    method: 'put',
    data: obj
  })
}

//查询
export function getObj(id) {
  return request({
    url: '/rs-service/mailtemplate/' + id,
    method: 'get',
  })
}

//删除
export function delObj(id) {
  return request({
    url: '/rs-service/mailtemplate/' + id,
    method: 'delete'
  })
}


标签:false,val,true,表单,dataForm,ui,element,data,id
From: https://blog.51cto.com/u_15694202/7781250

相关文章

  • opentelement源码分析
    provider和trace持续分析。关于traceId生成与traceId复用当前运行的trace/pkg/mod/go.opentelemetry.io/otel/[email protected]/trace/provider.go 生成traceId/pkg/mod/go.opentelemetry.io/otel/[email protected]/trace/tracer.go r.provider.idGenerator.NewIDs(ctx) ......
  • Rust Druid桌面应用框架
    目录Github管方文档简介声明式UI数据绑定高性能可扩展性跨平台事件处理生命周期管理社区支持设置国内镜像添加依赖官方示例下载依赖并编译运行Githubhttps://github.com/linebender/druid管方文档https://docs.rs/druid/latest/druid/简介Druid是一个用于构建现代、高......
  • 使用 Webpack 的 require.context 来获取组件
    代码constrequireComponent=require.context('@/views',//组件文件夹的相对路径true,//是否查找子文件夹/\.vue$///匹配组件文件的正则表达式)输出console.log(requireComponent.keys())原理require.context在生产环境中也能获......
  • JuiceFS 目录配额功能设计详解
    JuiceFS在最近v1.1版本中加入了社区中呼声已久的目录配额功能。已发布的命令支持为目录设置配额、获取目录配额信息、列出所有目录配额等。完整的详细信息,请查阅文档。在设计此功能时,对于它的统计准确性,实效性以及对性能的影响,团队内部经历过多次讨论和权衡。在本文中,我们会详......
  • Builder,LayoutBuilder,StatefulBuilder
    Builder拿到contextStatefulBuilder拿到 context和状态LayoutBuilder拿到 context和父组件约束https://cloud.tencent.com/developer/article/2137054?areaSource=102001.1&traceId=F9yKRBl4-YYJ344Cdecv8......
  • EasyUI关闭当前Tab
    1.根据title名字window.parent.$("#mainTab").tabs('close','title名字');2.根据indexvartab=window.parent.$('#centerTab').tabs('getSelected');//获取当前选中tabsvarindex=window.parent......
  • Microsoft Visual C++ 14.0 or greater is required.
    MicrosoftVisualC++14.0orgreaterisrequired.表示缺少VisualStudio2015及以上版本可以通过以下途径解决。最好是第二、三种途径。 一、直接下载对应版本的.whl文件,然后运行pipinstallxxx.whl 二、按照提示去官网下载VisualStudio2015及以上版本都可以,必须安装C++......
  • WinForm UI 库
    WinFormUI库HZH_ControlsHZHControls是基于.NetFramework4.0原生控件开发完全开源的一套控件,你不需要担心有其他控件或版权问题。提供完整的示例代码,方便学习使用。**GitHub:https://github.com/kwwwvagaa/NetWinformControl** 效果图展示:**2.MetroFramework......
  • This kernel requires an x86-64 CPU, but only detected an i686CPU. Unable to boot
    原文链接:https://www.longkui.site/program/other/i686/4759/ 0.背景买了一台小电脑,STARTC-8080型号,想给他装个Linux系统。给他装Ubuntu18的时候,开始报错:Thiskernelrequiresanx86-64CPU,butonlydetectedani686CPU.Unabletoboot–pleaseuseakernelapp......
  • An unhandled exception occurred: Could not find the implementation for builder @
    原文链接:https://www.longkui.site/error/angular-cli/4795/调试一个新的angula项目时,报上面的错误。断定基本是版本不匹配导致的。看了看网上的一些信息说是升级一下angular-cli的版本就行了。但是升级后也不好用,后来发现,不是要升级,而是要根据packa.json里面的信息安装指定......