最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+ElementUI更像Excel的表格組件使用詳解

 更新時間:2025年12月17日 15:57:39   作者:我的心巴  
這篇文章主要介紹了如何在前端處理表格數(shù)據(jù)并展示在Element?UI的el-table組件中,核心思想是先構(gòu)建表頭和第一列,然后根據(jù)表頭和第一行的數(shù)據(jù)填充表格內(nèi)容

一、表格效果

二、核心思想

不做前端的人,會覺得“一”中圖展示的就是一張表格;做前端的,看完“四”中注釋的業(yè)務(wù)邏輯(可能看不懂,但無所謂,業(yè)務(wù)邏輯嘛,重要的是處理思想),會更覺得像Excel,自然也就不能直接將“三”中數(shù)據(jù)賦給el-table。

處理的核心思想就是先處理出表頭(列prop賦值為順序排列的小寫字母)、第一列,再根據(jù)每一列的表頭和第一行的數(shù)據(jù)找出填充的值(有點像直接坐標(biāo)系,表頭為X軸,第一列為Y軸)。

三、數(shù)據(jù)格式

四、組件代碼

<template>
    <div>
        <div v-for="(table, index) in tables" :key="'table'+index" class="tables">
            <el-tag size="medium" effect="dark">{{ table.name }}</el-tag>
            <el-table :data="table.dataSource" border>
                <el-table-column v-for="column in table.columns" :key="'table'+index+column.prop" :prop="column.prop" :label="column.label" :min-width="column.minWidth" :align="column.align" :show-overflow-tooltip="column.tooltip"></el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        params: {
            type: Object,
            default () {
                return {
                        tempCheck: [],
                        temperatureCompensation: [],
                        linear: [],
                        linearCheck: []
                }
            }
        }
    },
    computed: {
        tables () {
            let tables = [
                {
                    //表格名稱
                    name: '溫補結(jié)果',
                    //表格列,數(shù)據(jù)未處理之前寫死在columns中的是固定列,其余列根據(jù)需求及數(shù)據(jù)處理而來
                    columns: [ //其余列是數(shù)據(jù)里不重復(fù)的pressPoint字段值+單位kPa
                        {
                            prop: 'a',
                            label: '溫度℃', //列數(shù)據(jù)為不重復(fù)的temperaturePoint值
                            minWidth: 100,
                            align: 'center'
                        },
                        {
                            prop: 'b',
                            label: '溫度AD', //只和溫度temperaturePoint有關(guān),列數(shù)據(jù)為不同temperaturePoint對應(yīng)的temperatureAD值
                            minWidth: 100,
                            align: 'center'
                        }
                    ],
                    //表格數(shù)據(jù),展示temperaturePoint和pressPoint對應(yīng)的pressAD,數(shù)據(jù)來源params.temperatureCompensation
                    dataSource: []
                },
                {
                    name: '線性化結(jié)果',
                    columns: [], //不重復(fù)的pressPoint字段值+單位kPa
                    dataSource: [{}] //只會有一行數(shù)據(jù),展示pressPoint對應(yīng)的pressAD,    數(shù)據(jù)來源params.linear
                },
                {
                    name: '溫補校驗結(jié)果',
                    columns: [ //其余列是數(shù)據(jù)里不重復(fù)的temperaturePoint+單位℃
                        {
                            prop: 'a',
                            label: '壓力', //列數(shù)據(jù)為不重復(fù)的pressPoint
                            minWidth: 100,
                            align: 'center'
                        }
                    ],
                    dataSource: [] //展示temperaturePoint和pressPoint對應(yīng)的press,數(shù)據(jù)來源params.tempCheck
                },
                {
                    name: '線性化校驗結(jié)果',
                    columns: [], //不重復(fù)的pressPoint字段值+單位kPa
                    dataSource: [{}] //只會有一行數(shù)據(jù),展示pressPoint對應(yīng)的press,數(shù)據(jù)來源params.linearCheck
                }
            ],
//根據(jù)tables注釋的業(yè)務(wù)邏輯開始處理數(shù)據(jù)
columns = this.getXYNoRepeatData('temperatureCompensation', 'pressPoint').map((li, index) => {
                return {
                    prop: String.fromCharCode(99+index),
                    label: li+'kPa',
                    minWidth: 100,
                    align: 'center'
                }
            }), dataSource = this.getXYNoRepeatData('temperatureCompensation', 'temperaturePoint').map(li => {
                return {
                    a: li,
                    b: this.getADColumn('temperatureCompensation', li, 'temperaturePoint', 'temperatureAD')
                };
            }), errorRateList = [], errorRate = '', errorRateRrop = '';
            columns.forEach(column => {
                dataSource.forEach(d => {
                    Object.assign(d, {
                        [column.prop]: this.getValueByXY('temperatureCompensation', column.label.replace('kPa', ''), d.a, 'pressPoint', 'temperaturePoint', 'pressAD')
                    });
                });
            });
            tables[0].columns = tables[0].columns.concat(columns);
            tables[0].dataSource = dataSource; //完成溫補結(jié)果columns、dataSource計算

            //計算線性化結(jié)果columns、dataSource
            columns = this.getXYNoRepeatData('linear', 'pressPoint').map((li, index) => {
                return {
                    prop: String.fromCharCode(97+index), //列prop處理為順序排列的小寫英文字母
                    label: li+'kPa',
                    minWidth: 100,
                    align: 'center'
                }
            });
            tables[1].columns = columns;
            columns.forEach(column => {
                Object.assign(tables[1].dataSource[0], {
                    [column.prop]: this.getValueByX('linear', column.label.replace('kPa', ''), 'pressPoint', 'pressAD')
                });
            });

            //計算溫補校驗結(jié)果columns、dataSource
            columns = this.getXYNoRepeatData('tempCheck', 'temperaturePoint').map((li, index) => {
                return {
                    prop: String.fromCharCode(98+index),
                    label: li+'℃',
                    minWidth: 100,
                    align: 'center'
                }
            });
            dataSource = this.getXYNoRepeatData('tempCheck', 'pressPoint').map(li => {
                return {
                    a: li+'kPa'
                };
            });
            columns.forEach(column => {
                dataSource.forEach(d => {
                    Object.assign(d, {
                        [column.prop]: this.getValueByXY('tempCheck', column.label.replace('℃', ''), d.a.replace('kPa', ''), 'temperaturePoint', 'pressPoint', 'press')
                    });
                });
            });
            errorRateRrop = String.fromCharCode(98+columns.length);
            columns.push({ //固定最后一列
                prop: errorRateRrop,
                label: '最大誤差%', //列數(shù)據(jù)為每行temperaturePoint、pressPoint對應(yīng)的errorRate的最大值
                minWidth: 100,
                align: 'center'
            });
            dataSource.forEach(d => {
                errorRateList = [];
                for(let i=0; i<columns.length-1; i++) {
                    errorRate = this.getValueByXY('tempCheck', columns[i].label.replace('℃', ''), d.a.replace('kPa', ''), 'temperaturePoint', 'pressPoint', 'errorRate');
                    errorRate===''?'':errorRateList.push(errorRate);
                }
                if(errorRateList.length>0) {
                    errorRateList.sort((a, b) => {
                        return b-a;
                    });
                    Object.assign(d, {
                        [errorRateRrop]: errorRateList[0]
                    });
                } else {
                    Object.assign(d, {
                        [errorRateRrop]: ''
                    });
                }
            });
            tables[2].columns = tables[2].columns.concat(columns);
            tables[2].dataSource = dataSource;

            //計算線性化校驗結(jié)果columns、dataSource
            columns = this.getXYNoRepeatData('linearCheck', 'pressPoint').map((li, index) => {
                return {
                    prop: String.fromCharCode(97+index),
                    label: li+'kPa',
                    minWidth: 100,
                    align: 'center'
                }
            });
            columns.forEach(column => {
                Object.assign(tables[3].dataSource[0], {
                    [column.prop]: this.getValueByX('linearCheck', column.label.replace('kPa', ''), 'pressPoint', 'press')
                });
            });
            errorRateRrop = String.fromCharCode(97+columns.length);
            columns.push({
                prop: errorRateRrop,
                label: '最大誤差%',
                minWidth: 100,
                align: 'center'
            });
            errorRateList = this.params.result.linearCheck.map(li => {
                return li.errorRate;
            }).sort((a, b) => {
                return b-a;
            });
            Object.assign(tables[3].dataSource[0], {
                [errorRateRrop]: errorRateList.length>0?errorRateList[0]:''
            });
            tables[3].columns = columns;
            return tables;
        }
    },
    methods: {
        getXYNoRepeatData (vari, variable) {
            let arr = this.params[vari].map(li => {
                return li[variable];
            }).sort((a, b) => {
                return a-b;
            }), set = new Set(arr);
            return Array.from(set.values());
        },
        getADColumn (vari, val, valueField, labelField) {
            let item = this.params[vari].find(li => li[valueField]===val);
            return item?item[labelField].toFixed(1):'';
        },
        getValueByXY (vari, x, y, xField, yField, valueField) {
            let item = this.params[vari].find(li => li[xField]==x&&li[yField]==y);
            return item?item[valueField].toFixed(valueField.includes('AD')?1:3):'';
        },
        getValueByX (vari, x, xField, valueField) {
            let item = this.params[vari].find(li => li[xField]==x);
            return item?item[valueField].toFixed(valueField.includes('AD')?1:3):'';
        }
    }
}
</script>
<style scoped>
.tables >>>.el-tag {
    margin: 20px 0 10px 0;
}
</style>

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于vue實現(xiàn)圓形菜單欄組件

    基于vue實現(xiàn)圓形菜單欄組件

    這篇文章主要介紹了基于vue實現(xiàn)的圓形菜單欄組件,本文通過實例代碼,圖文詳解的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • vue圖片上傳組件使用詳解

    vue圖片上傳組件使用詳解

    這篇文章主要為大家詳細(xì)介紹了vue圖片上傳組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • Vue2.0 實現(xiàn)移動端圖片上傳功能

    Vue2.0 實現(xiàn)移動端圖片上傳功能

    本文主要介紹VUE2.0圖片上傳功能的實現(xiàn)。原理是通過js控制和input標(biāo)簽的方式完成這一效果,無需加載其他組件。具體實例大家大家參考下本文
    2018-05-05
  • 零配置使用vue編寫excel預(yù)覽組件

    零配置使用vue編寫excel預(yù)覽組件

    這篇文章主要為大家詳細(xì)介紹了如何使用vue編寫excel預(yù)覽組件,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2026-03-03
  • Vue中el-tree樹全部展開或收起的實現(xiàn)示例

    Vue中el-tree樹全部展開或收起的實現(xiàn)示例

    本文主要介紹了Vue中el-tree樹全部展開或收起的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • 基于vue實現(xiàn)分頁組件的示例代碼

    基于vue實現(xiàn)分頁組件的示例代碼

    分頁組件是一種用戶界面元素,用于在長列表或數(shù)據(jù)集中分割內(nèi)容,分頁組件是每個開發(fā)人員必須掌握的一個組件,廣泛應(yīng)用在各個場所,用以用戶方便閱讀等,本文就給大家介紹一下如何基于vue寫出的分頁組件,需要的朋友可以參考下
    2023-08-08
  • Vue實現(xiàn)一個返回頂部backToTop組件

    Vue實現(xiàn)一個返回頂部backToTop組件

    本篇文章主要介紹了Vue實現(xiàn)一個返回頂部backToTop組件,可以實現(xiàn)回到頂部效果,具有一定的參考價值,有興趣的可以了解一下
    2017-07-07
  • vue動畫—通過鉤子函數(shù)實現(xiàn)半場動畫操作

    vue動畫—通過鉤子函數(shù)實現(xiàn)半場動畫操作

    這篇文章主要介紹了vue動畫—通過鉤子函數(shù)實現(xiàn)半場動畫操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue動態(tài)添加表單validateField驗證功能實現(xiàn)

    vue動態(tài)添加表單validateField驗證功能實現(xiàn)

    這篇文章主要介紹了vue動態(tài)添加表單validateField驗證功能實現(xiàn),本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • 利用Nuxt.js做Vuex數(shù)據(jù)持久化

    利用Nuxt.js做Vuex數(shù)據(jù)持久化

    這篇文章主要介紹了利用Nuxt.js做Vuex數(shù)據(jù)持久化問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10

最新評論

萨嘎县| 乳山市| 陇南市| 长垣县| 海南省| 黄石市| 奈曼旗| 隆安县| 夏邑县| 滨海县| 镇康县| 昆山市| 桐柏县| 赤壁市| 昆山市| 鄢陵县| 泰顺县| 唐山市| 邹平县| 泰来县| 丰都县| 安宁市| 吴忠市| 永兴县| 板桥市| 常熟市| 辉南县| 安吉县| 中山市| 勃利县| 巴东县| 大关县| 安陆市| 饶平县| 米林县| 呼伦贝尔市| 红桥区| 留坝县| 达尔| 霍州市| 泗阳县|