首页 > 其他分享 >vue 3 + element UI 表格分页及增删查改

vue 3 + element UI 表格分页及增删查改

时间:2022-08-22 18:15:53浏览次数:59  
标签:vue msgContent true element loading UI DataDictionary data response

使用vue版本:[email protected]

使用element-plus版本:[email protected]

使用axios版本:[email protected]

引用了如下脚本:

<script src="~/lib/vue/vue.global.min.js"></script>

<link href="~/lib/element-plus2/index.min.css" rel="stylesheet" />

<link href="~/lib/element-plus2/theme-chalk/index.min.css" rel="stylesheet" />
<script src="~/lib/element-plus2/index.full.js"></script>
<script src="~/lib/element-plus2/locale/en.js"></script>
<script src="~/lib/element-plus2/locale/zh-cn.js"></script>
<script src="~/lib/element-plus2/icons-vue/dist/global.iife.min.js"></script>
<script src="~/lib/axios/axios.min.js"></script>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
效果如图:

 

 

代码如下:

<div id="app" v-cloak>
    <el-row type="flex" :gutter="10">
        <el-col :span="4">
            <el-input placeholder="DictionaryName" v-model="dataDictionaryName" size="mini" clearable></el-input>
        </el-col>
        <el-col :span="6">
            <el-select v-model="DataDictionaryTypeId" placeholder="please select">
                <el-option key="0" label="All" value="0">
                </el-option>
                <el-option v-for="item in dataDictionaryTypeList"
                           :key="item.dataDictionaryTypeId"
                           :label="item.dictionaryTypeName"
                           :value="item.dataDictionaryTypeId">
                </el-option>
            </el-select>
        </el-col>
        <el-col :span="2" style="text-align:right">
            <el-button type="primary" plain v-on:click="getDataDictionary(1)" size="mini" class="has-gutter">Search</el-button>
        </el-col>
    </el-row>
    <div style="width: 100%; margin-top: 10px;">
        <el-button type="primary" icon="Plus" plain circle v-on:click="addDataDictionary" class="has-gutter"></el-button>
        <el-button type="primary" icon="Delete" plain circle v-if="dataDictionaryData && dataDictionaryData?.length > 0" v-on:click="deleteDataDictionary" class="has-gutter"></el-button>
    </div>
    <el-row type="flex" :gutter="10">
        <el-table :data="dataDictionaryData" border size="mini" style="width: 100%; margin-top: 10px;" :header-cell-style="getRowClass" v-on:row-click="queryDataDictionaryById" @@selection-change="handleSelectionChange">
            <el-table-column type="selection" prop="dataDictionaryId" width="55"></el-table-column>
            <el-table-column label="DictionaryName" prop="dictionaryName" width="200"></el-table-column>
            <el-table-column label="Dictionary Desc " prop="dictionaryDesc" align="center" width="200"></el-table-column>
            <el-table-column label="DataDictionary Type" prop="dataDictionaryType" align="center" width="200"></el-table-column>
            <el-table-column label="SequenceNo" prop="sequenceNo" align="center"></el-table-column>
        </el-table>
        <el-pagination v-show="isPage"
                       :hide-on-single-page="true"
                       v-on:current-change="handleCurrentChange"
                       :current-page="Page.currentPage"
                       :page-size="Page.pageSize"
                       :page-sizes="[10,15,20,30,50]"
                       layout="total,sizes,prev, pager, next,jumper"
                       :total="Page.totalCount"
                       style="float:right;margin:10px 20px 0 0;">
        </el-pagination>
    </el-row>

    <el-drawer title="Data Dictionary Info"
               v-model="DataDictionary_drawer"
               :direction="rtl"
               size="46%"
               :before-close="DataDictionaryHandleClose" destroy-on-close>
        <el-card class="box-card">
            <el-form :model="DataDictionaryInfo" ref="DataDictionaryInfo" label-width="180px">
                <el-row :gutter="20">
                    <el-form-item label="DictionaryName">
                        <el-input v-model="DataDictionaryInfo.dictionaryName" placeholder="Please input" type="text" />
                    </el-form-item>

                    <el-form-item label="Dictionary Desc">
                        <el-input v-model="DataDictionaryInfo.dictionaryDesc" placeholder="Please input" type="text" />
                    </el-form-item>

                    <el-form-item label="Dictionary Type">
                        <el-select v-model="DataDictionaryInfo.dataDictionaryTypeId" placeholder="please select">
                            <el-option v-for="item in dataDictionaryTypeList"
                                       :key="item.dataDictionaryTypeId"
                                       :label="item.dictionaryTypeName"
                                       :value="item.dataDictionaryTypeId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="SequenceNo">
                        <el-input-number v-model="DataDictionaryInfo.sequenceNo" :min="1" :max="9999" />
                    </el-form-item>
                </el-row>
                <el-button type="primary" @@click="DataDictionarySave">Save</el-button>
                <el-button type="primary" @@click="resetDataDictionaryForm">Reset</el-button>
                <el-row :gutter="20">
                </el-row>
            </el-form>
        </el-card>
    </el-drawer>
</div>

<script>
    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
    const loadOptions = {
        lock: true,
        text: 'Loading...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0)',
        fullscreen: true,
    }

    const Main = {
        data() {
            return {
                dataDictionaryTypeList:@(Json.Serialize(ViewBag.DataDictionaryTypeList)),
                dataDictionaryData: [],
                isPage: true,
                DataDictionary_drawer: false,
                isDisabled: false,
                Page: {
                    currentPage: 1,
                    pageSize: 10,
                    totalCount: 0
                },
                DataDictionaryInfo: {
                    dataDictionaryId:"",
                    dataDictionaryTypeId: "",
                    dictionaryName: "",
                    dictionaryDesc: "",
                    sequenceNo: "",
                },
                dataDictionaryName: '',
                DataDictionaryTypeId:'',                
                params: {
                    PageIndex: 1,
                    PageSize: 0,
                    DictionaryName: this.dataDictionaryName,
                    DataDictionaryType: this.DataDictionaryTypeId,
                },
                multipleSelectionData: [],
            }
        },
        created() {
            this.handleCurrentChange(1);
        },
        methods: {
            //多选内容更新
            handleSelectionChange(val) {
                this.multipleSelectionData.value = val;
            },
            //清空内容
            resetDataDictionaryForm() {
                this.DataDictionaryInfo = {};
                this.$refs['DataDictionaryInfo'].resetFields();
            },
            //保存
            DataDictionarySave() {
                this.$refs['DataDictionaryInfo'].validate((valid) => {
                    const loading = this.$loading(loadOptions);
                    if (valid) {
                        axios({
                            method: 'post',
                            url: '/DataDictionary/DataDictionaryEdit',
                            responseType: 'application/json',
                            params: this.DataDictionaryInfo
                        }).then(response => {
                            if (response.data) {
                                this.showMessage(response.data.code, response.data.message,false);
                                if (response.data.code == 200) {
                                    this.handleCurrentChange(1);
                                    this.DataDictionary_drawer = false;
                                    this.DataDictionaryHandleClose();
                                }
                            }
                        })
                        .catch(function (error) {
                            loading.close()
                        })
                        .finally(() => {
                            loading.close()
                        });
                    }
                });
            },
            //打开窗口新增
            addDataDictionary() {
                this.DataDictionary_drawer = true;
                this.isDisabled = true;
            },
            //删除数据
            deleteDataDictionary() {
                if (!this.multipleSelectionData || !this.multipleSelectionData.value || this.multipleSelectionData.value.length == 0) {
                    this.$message.warning("please select data!");
                    return false;
                }
                this.$confirm('Are you sure you want to delete the data??', 'tips', {
                    confirmButtonText: 'Yes',
                    cancelButtonText: 'Cancel',
                    type: 'warning'
                }).then(() => {
                    axios({
                        method: 'post',
                        url: '/DataDictionary/DeleteDataDictionaryById',
                        responseType: 'json',
                        data: this.multipleSelectionData.value
                    }).then(response => {
                        if (response.data) {
                            this.handleCurrentChange(1);
                        }
                    }).catch(error => {
                    });
                }).catch(() => {
                });
            },
            //查询内容
            queryDataDictionaryById(row) {
                if (row.dataDictionaryId) {
                    axios({
                        method: 'post',
                        url: '/DataDictionary/QueryDataDictionaryById',
                        responseType: 'json',
                        params: {
                            DictionaryId: row.dataDictionaryId
                        }
                    }).then(response => {
                        if (response.data) {
                            this.DataDictionaryInfo = response.data;
                            this.DataDictionary_drawer = true;
                            this.isDisabled = true;
                        }
                    }).catch(error => {
                        loading.close()
                    });
                }
            },
            //关闭窗口
            DataDictionaryHandleClose(done) {
                this.resetDataDictionaryForm();
                this.isDisabled = false;
                done();
            },
            //获取列头样式
            getRowClass({ row, column, rowIndex, columnIndex }) {
                let style = {};
                if (rowIndex === 0) {
                    style = {
                        backgroundColor: '#7E8796',
                        color: '#fff',
                        fontWeight: 'bold'
                    };
                }
                else
                    style = {};
                return style;
            },
            //分页
            handleCurrentChange(pageNo) {
                this.getDataDictionary(pageNo)
            },
            getDataDictionary(pageNo) {
                const loading = this.$loading(loadOptions);
                this.isPage = true;
                this.Page.currentPage = pageNo;
                axios({
                    method: 'post',
                    url: '/DataDictionary/QueryDataDictionary',
                    responseType: 'json',
                    params: {
                        PageIndex: pageNo,
                        PageSize: this.Page.pageSize,
                        DictionaryName: this.dataDictionaryName,
                        DataDictionaryType: this.DataDictionaryTypeId,
                    }
                }).then(response => {
                    if (response.data) {
                        this.Page.totalCount= response.data.totalRows;
                        this.dataDictionaryData = response.data.data;
                    }
                })
                .catch(error => {
                    loading.close()
                });
                loading.close()
            },
            //显示操作提示信息
            showMessage(msgCode, msgContent, showColse = true) {
                var msgType = '';
                switch (msgCode) {
                    case 200:
                        msgType = 'success';
                        if (msgContent == undefined || msgContent == "")
                            msgContent = 'Operation Successfully.';
                        break;
                    case 404:
                        if (msgContent == undefined || msgContent == "")
                            msgContent= 'Operation Failed.';
                        msgType = 'error';
                        break;
                    default:
                        if (msgContent == undefined || msgContent == "")
                            msgContent = 'Form data submission error '
                        msgType = 'error';
                }
                this.$message({
                    showClose: showColse,
                    message: msgContent,
                    type: msgType
                });
            },
        }
    };

    const app = Vue.createApp(Main);
    app.use(ElementPlus)
    var Icons = Object.entries(ElementPlusIconsVue).filter((item) => { return ["Plus", "Delete"].includes(item[0]) })
    for (const [key, component] of Icons) {
        app.component(key, component)
    }
    app.mount("#app");
</script>
<style>
    .col2 {
        width: 100%;
        flex: 1;
        padding: 10px;
        border: solid 1px #eee;
        border-radius: 5px;
        float: left;
        margin-top: 10px;
    }
</style>

  

 

标签:vue,msgContent,true,element,loading,UI,DataDictionary,data,response
From: https://www.cnblogs.com/bingshao/p/16613758.html

相关文章

  • jwbasta-vue
    平台简介  jwbasta-vue是一套全部开源的快速开发java后台API平台,毫无保留给个人及企业一次性付费使用。采用前后端分离的模式,微服务版本前端基于vue开发(无前端页面)......
  • Vue3+Vite+Vant报错Uncaught SyntaxError: The requested module '/node_modules/.vit
    原因在开发过程中Vue3的依赖版本有变更,直接使用的npminstall下载新的版本,会导致node_modules下存在旧版本的缓存,从而影响了本地项目的启动编译。解决方案删除项目的......
  • vue记录
    #查看版本node-v#安装Node.js淘宝镜像加速器(cnpm)cnpminstallcnpm-g#全局安装vue-clicnpminstallvue-cli-g#查看是否安装成功webpack-v或vuelist#......
  • vue 无限滚动插件
    在线演示:https://chenxuan1993.gitee.io/component-document/index_prod#/component/seamless-otherscnpminstallvue-seamless-scroll--save引入importvueSeamless......
  • 基于element-ui 动态换肤的代码详解
    1、在安装好[email protected]以后,首先安装sass-loadernpmisass-loadernode-sass-D2、安装element-themenpmielement-theme-D3、安装theme-chalknpmielem......
  • Vue新建项目
    输入项目名teset2  自定义安装  选择所需要的包  选择vue版本  选择路由类型,是否选用历史路由(默认hash路由 选择scss  选择标准版eslint ......
  • HDLBits答案——Circuits
    1CombinationalLogic1.1BasicGates1.1.1Exams/m2014q4hmoduletop_module(inputin,outputout); assignout=in;endmodule1.1.2Exams/m2014q......
  • Arduino MKR Shield to 控制 DYNAMIXEL舵机- 快速启动
    嘿,有机器人专家!您可能熟悉Arduino的原装DYNAMIXEL Shield,该Shield与ArduinoUno和“1.0”ArduinoPinout兼容。然而,由于多年来芯片技术的改进,现在有许多较新的Arduino板,......
  • vue动态添加class 三个以上的条件做判断(转)
    原文:https://blog.csdn.net/Akatsuki233/article/details/100653049:class="{'redRoom':Number(items.status)===1,'greenRoom1':Number(items.status)===2,green......
  • elementui table 表格使用固定列(fixed)之后滚动表格出现错行问题
        效果图,如上图  这里是初始化表格数据的     beforeDestroy(){this.tableBodyWrapper.removeEventListener('scroll',this.setSc......