對(duì)element-table/和搜索 進(jìn)行二次封裝

table組件的封裝

<!--
代碼結(jié)構(gòu):
data:
1.pagingList -- table 數(shù)據(jù)
2.hasSelect -- 是否開啟第一行的選擇框
3.selectWidth -- 定義選擇框大小 只支持?jǐn)?shù)字
4.option -- 整個(gè)表格的配置項(xiàng) 例子格式如下:
    4.1 opition 對(duì)象中的opition字段是用來(lái)配置table列規(guī)則參考ele 即可 其中自定義一個(gè)hasColumn用來(lái)增加這個(gè)表格是否可以點(diǎn)擊
    4.2 button  用來(lái)配置table 最后一列是否是按鈕形式顯示
    4.3 popoverLiList 適用于本項(xiàng)目的下拉菜單,如果是下拉菜單請(qǐng)直接配置這個(gè)選項(xiàng)
    4.4 buttonContent 需要自己定義不適用本項(xiàng)目的通用下拉配置這個(gè)項(xiàng)
        4.4.1 parentFun 回調(diào)方法 根據(jù)定義名稱在子組件使用即可
        4.4.2 title 配置文字按鈕
        4.4.3 icon 配置圖標(biāo)直接放入圖標(biāo)的class
    {
        opition:[
           {prop:'name',label:'姓名',width:320},
           {prop:'date',label:'日期',width:320},
           {prop:'address',label:'地址',hasColumn:true,width:120},
        ],
        button:{hasButton:true,label:'操作',fixed:'right',},
        // popoverLiList:[
        //     {parentFun:'handleResetPwd',title:'重置密碼'},
        //     {parentFun:'handleEdit',title:'編輯'},
        //     {parentFun:'handlePermission',title:'設(shè)置權(quán)限'},
        //     {parentFun:'handleDisable',title:'停用'},
        // ],
        buttonContent:[
            {parentFun:'handleResetPwd',icon:'icon-sousuo'},
            {parentFun:'handleEdit',title:'編輯'},
            {parentFun:'handlePermission',title:'設(shè)置權(quán)限'},
            {parentFun:'handleDisable',title:'停用'},
        ],
     }
樣式:
1.tableRowClassName -- table行的樣式
2.tableTheadClassName -- 頭部樣式
3.tableTheadClassName -- 頭部標(biāo)題樣式
方法:
1.multipleTable -- ref 對(duì)外暴露的組件,可以在父組件中直接使用這個(gè)ref 獲取組件中所有內(nèi)容
2.handleSelectionChange -- 選擇框如果在父組件使用這個(gè)選擇框,需要在父組件定義handleSelect 這個(gè)方法,用數(shù)組來(lái)接收每一個(gè)選擇內(nèi)容
3.handleDetailRow 當(dāng)設(shè)置 hasColumn 使用使用handleDetailRow 回調(diào)給父組件的方法
4.handleParentFun 對(duì)自定義的一些按鈕配置方法給會(huì)父組件
-->
<template>
    <div class="customized-table">
        <el-table v-bind:data="pagingList" border v-bind:row-class-name="tableRowClassName" v-on:selection-change="handleSelectionChange"
                  v-bind:header-cell-class-name="tableTheadClassName" style="width: 100%" ref="multipleTable">
           <!--是否有選擇框-->
            <el-table-column
                    v-if="hasSelect"
                    type="selection"
                    :width="selectWidth">
            </el-table-column>
            <!--只展示不可點(diǎn)擊-->
            <el-table-column
                    v-for="(item,index) in option.opition"
                    v-if="!item.hasColumn"
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                    :sortable="item.sort"
                    :formatter="item.formatter"
                    :fixed='item.fixed'
                    :resizable="item.resizable||false"
                    :key="index">
            </el-table-column>
            <!--展示可以點(diǎn)擊-->
            <el-table-column
                    v-else
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                    :sortable="item.sort"
                    :formatter="item.formatter"
                    :fixed='item.fixed'
                    :resizable="item.resizable||false"
                    :key="index">
                <template slot-scope="scope">
                    <a class="cursor-pointer" @click.prevent="handleDetailRow(scope.row)">{{ scope.row[item.prop] }}</a>
                </template>
            </el-table-column>
            <el-table-column
                    v-if="option.button.hasButton"
                    :label="option.button.label"
                    :fixed="option.button.fixed">
                    <template  slot-scope="scope">
                        <!--自定義按鈕-->
                        <ul class="buttonContent" v-if="option.buttonContent">
                            <li v-for="item in option.buttonContent" >
                                <a v-if="item.icon" @click="handleParentFun(scope.row,item.parentFun)" href="javascript:;" >
                                  <i :class="['iconfont',item.icon]"></i>
                                </a>
                                <a v-else @click="handleParentFun(scope.row,item.parentFun)" href="javascript:;" >
                                    {{item.title}}
                                </a>
                            </li>
                        </ul>
                        <!--項(xiàng)目下拉按鈕-->
                        <el-popover v-else
                                    placement="bottom"
                                    :width="option.button.width||160"
                                    trigger="hover"
                                    :popper-class="option.button.popperClass||'tMoreEdit'">
                            <ul>
                                <li v-for="item in option.popoverLiList">
                                    <a @click="handleParentFun(scope.row,item.parentFun)" href="javascript:;" >{{item.title}}</a>
                                </li>
                            </ul>
                            <a class="iconfont icon-gengduo" slot="reference"></a>
                        </el-popover>
                    </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "CustomizedTable",
        props:{
            pagingList:{
                type:Array,
            },
            selectWidth:{
              type:Number,
              default:55,
            },
            hasSelect:{
                type:Boolean,
                default:true,
            },
            option:{
                type:Object,
                required:true,
            },
        },
        methods:{
            tableRowClassName (row) {return 'cyTatble-row';},
            tableTheadClassName(){return "cyTable-thead"; },
            handleSelectionChange(val){
                this.$emit('handleSelect',val);
            },
            handleDetailRow(val){
                this.$emit('handleDetailRow',val);
            },
            handleParentFun(val,parentFun){
                this.$emit(parentFun,val);
            }
        }
    }

</script>

<style  lang="less">
    .customized-table{
        border-right: 1px solid #ebeef5;
        .tMoreEdit.el-popover{padding:0;}
        .tMoreEdit[x-placement^=bottom] {margin-top: 0px !important;}
        .tMoreEdit li{height:40px;}
        .tMoreEdit li:hover{background-color: #F2F4F7;}
        .tMoreEdit li>a{display: block;line-height: 40px;border-bottom: 1px solid #f2f4f7;margin: 0 10px;color: black;}
        .tMoreEdit li:last-child a{border-bottom:none;}
        .cursor-pointer{cursor:pointer ;}
        .el-table {
            .cyTable-thead{
                background-color:#fafafa;color:#000;border:none;
                .cyTable-evenRow {background-color:#f5f7fb; border:none;color:#000}/*偶數(shù)行顏色*/
                .cytatble-row{color:#000;}
                .cytatble-row.userStatus-false {color:#999999;}
            }
        }
        .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed {
            border-right: none !important;
        }
        a.icon-gengduo{
            cursor: pointer;
            color: #337ab7;
            transform:rotate(90deg);
        }
        a.icon-gengduo:hover{
            color:#576B95;
        }
        .buttonContent{
            li{
                float: left;
                margin-right: 10px;
                >a{
                    color:#576B95!important;
                }
            }
            li:last-child{
                margin-right: 0;
            }

        }
    }

</style>

input 搜索的封裝

<template>
    <div class="input-search">
        <input class="input input-clear" :value="value" @input="$emit('input', $event.target.value)"  :placeholder="placeholder"  @keyup.enter="handleSearch"/>
        <div class="input input-icon" v-on:click="handleSearch"  >
            <slot v-if="$slots.icon"></slot>
            <i class="iconfont icon-sousuo" v-else></i>
        </div>
    </div>
</template>

<script>
    import {extend} from '@/lib/tools'
    export default {
        name: "Search",
        props:{
            value:{
                type:String,
            },
            placeholder:{
                type:String,
            },
            backEndSearch:{
                type:Boolean,
                default:false,
            },
            tableData:{
                type:Array,
            },
            opitionSearchItem:{
                type:Array,
                required:true,
            },
        },
       data(){
            return{

            }
       },
        methods:{
            handleSearch(){
                if(this.backEndSearch){
                    this.$emit('backEndSearch',value);
                }else{
                    let searchData = [];
                    if (this.value === ''){
                        extend(this.tableData,searchData )
                    } else{
                        let _this = this;
                        let str = '';
                        this.opitionSearchItem.forEach((ele, index)=>{
                            str += `ele.${ele}===_this.value||` ;
                        });
                        str = str.substr(0,str.length-2);
                        searchData = this.tableData.filter((ele)=>{
                            if(eval(str)){
                                return ele
                            }
                        })
                    }
                    this.$emit('handleSreach',searchData);
                };
            },
        }
    }
</script>

<style scoped lang="less">

    .input-search{
        width: 100%;
        height: 100%;
        border: 1px solid #E2E2E2;
        /*height: 32px;*/
        box-sizing: border-box;
        padding: 6px 12px;
        font-size: 16px;
        border-radius:3px;
        background-color: #FFFFFF;
        /*position: relative;*/
        .input{
            /*position: absolute;*/
            line-height: 20px;
            /*top:0;*/
            &-clear{
                float: left;
                border: none;
                outline: none;
            }
            &-icon{
                border-left: 1px solid #E2E2E2;
                float: right;
                color:#B9C0CB;
                padding-left: 10px;
            }
        }
    }
</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末楷掉,一起剝皮案震驚了整個(gè)濱河市肖揣,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌捂寿,老刑警劉巖牡拇,帶你破解...
    沈念sama閱讀 218,941評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件胖烛,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡诅迷,警方通過(guò)查閱死者的電腦和手機(jī)佩番,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)罢杉,“玉大人趟畏,你說(shuō)我怎么就攤上這事√沧猓” “怎么了赋秀?”我有些...
    開封第一講書人閱讀 165,345評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)律想。 經(jīng)常有香客問(wèn)我猎莲,道長(zhǎng),這世上最難降的妖魔是什么技即? 我笑而不...
    開封第一講書人閱讀 58,851評(píng)論 1 295
  • 正文 為了忘掉前任著洼,我火速辦了婚禮,結(jié)果婚禮上而叼,老公的妹妹穿的比我還像新娘身笤。我一直安慰自己,他們只是感情好葵陵,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評(píng)論 6 392
  • 文/花漫 我一把揭開白布液荸。 她就那樣靜靜地躺著,像睡著了一般脱篙。 火紅的嫁衣襯著肌膚如雪娇钱。 梳的紋絲不亂的頭發(fā)上伤柄,一...
    開封第一講書人閱讀 51,688評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音文搂,去河邊找鬼响迂。 笑死,一個(gè)胖子當(dāng)著我的面吹牛细疚,可吹牛的內(nèi)容都是我干的蔗彤。 我是一名探鬼主播,決...
    沈念sama閱讀 40,414評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼疯兼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼然遏!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起吧彪,我...
    開封第一講書人閱讀 39,319評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤待侵,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后姨裸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體秧倾,經(jīng)...
    沈念sama閱讀 45,775評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年傀缩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了那先。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,096評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡赡艰,死狀恐怖售淡,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情慷垮,我是刑警寧澤揖闸,帶...
    沈念sama閱讀 35,789評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站料身,受9級(jí)特大地震影響汤纸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜芹血,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評(píng)論 3 331
  • 文/蒙蒙 一贮泞、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧祟牲,春花似錦隙畜、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)慎颗。三九已至乡恕,卻和暖如春言询,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背傲宜。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工运杭, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人函卒。 一個(gè)月前我還...
    沈念sama閱讀 48,308評(píng)論 3 372
  • 正文 我出身青樓辆憔,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親报嵌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子虱咧,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 暗戀對(duì)于每個(gè)女生來(lái)說(shuō)并不陌生腕巡,在每個(gè)青春期的女生眼里那份對(duì)于不懂愛情的自己,心里都會(huì)有一份蠢蠢欲動(dòng)的所謂的愛...
    微微情緣閱讀 388評(píng)論 0 2
  • 當(dāng)我那純潔的靈魂被世俗感染 我的世界便開始沉淪 即使圣水洗滌 也是骯臟
    讓我獨(dú)醉閱讀 296評(píng)論 1 1
  • SpringMVC接收數(shù)組 個(gè)人比較喜歡打開F12 ---> Network 查看提交的信息 主要看這里參數(shù)名稱上...
    試毅_思偉閱讀 1,700評(píng)論 0 18
  • 《朱子家訓(xùn)》 黎明即起血筑,灑掃庭除绘沉,要內(nèi)外整潔。 既昏便息豺总,關(guān)鎖門戶车伞,必親自檢點(diǎn)。 一粥一飯喻喳,當(dāng)思來(lái)處不易帖世;半絲半縷...
    劉偉書法_沈陽(yáng)閱讀 2,924評(píng)論 5 12
  • 暫停了一周。 其實(shí)每天都有寫日記沸枯,只是在心里寫了很多日矫。閉上眼睛就會(huì)開始說(shuō)話,會(huì)整理一天的七七八八绑榴,然后和自己說(shuō)晚安...
    朱泓默閱讀 324評(píng)論 2 6