封裝echarts

封裝Echarts

1黄琼、頁(yè)面形式
父組件
<template>
    <div class="container">
        <el-card>
            <div class="box">
                <Echart v-for="(item, index) in echatsList" :key="index" :idName="item.idName" :options="item.options"
                    :width=33></Echart>
            </div>
        </el-card>
    </div>
</template>
<script>
import * as echarts from 'echarts';
import Echart from "../../components/Echart";

export default {
    components: {
        Echart
    },
    data() {
        return {

            echatsList: [{
                idName: "mainOne",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            },
            {

                idName: "mainTwo",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },

                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainThr",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainFou",

                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainFiv",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            },
            {
                idName: "mainSix",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }

            }]

        }
    },
}
</script>
<style lang="scss" scoped>
.container {
    margin: 20px;
}

.box {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;

}
</style>
子組件(封裝)
<template>
    <div :id="idName" :style="{ width: width + '%', height: '500px' }"></div>
</template>
<script>
import * as echarts from 'echarts';
export default {
    name: "echart",
    props: {
        idName: {
            type: String,
            default: () => ""
        },
        options: {
            type: Object,
            default: () => { }
        },
        width: {
            type: Number,
            default: () => 100
        }
    },
    data() {
        return {
        }
    },
    mounted() {
        // 調(diào)用echarts(渲染在頁(yè)面)
        this.getEcharts()
    },
    methods: {
        // 初始化數(shù)據(jù)(echarts復(fù)制過(guò)來(lái)的)
        getEcharts() {
            var myChart = echarts.init(document.getElementById(this.idName));
            window.addEventListener('resize', function () {
                myChart.resize();
            });
            myChart.setOption(this.options);
        },

    }
}
</script>
<style lang="scss" scoped></style>

2干毅、彈窗

父組件
<template>
    <div class="app-container">
        <!-- 模糊搜素 -->
        <el-card class="box-card">
            <el-form class="top" :model="queryParams" ref="queryForm" :inline="true">
                <el-form-item label="衛(wèi)星編號(hào)" prop="satCode">
                    <el-select v-model="queryParams.satCode" placeholder="請(qǐng)選擇衛(wèi)星編號(hào)" @keyup.enter.native="handleQuery">
                        <el-option v-for="item in options" :key="item.satId" :label="item.satCode"
                            :value="item.satCode"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="目標(biāo)編號(hào)" prop="satName">
                    <el-select v-model="queryParams.satName" placeholder="請(qǐng)選擇目標(biāo)編號(hào)" @keyup.enter.native="handleQuery">
                        <el-option v-for="item in options" :key="item.satId" :label="item.satName"
                            :value="item.satName"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="載荷編號(hào)" prop="satName">
                    <el-select v-model="queryParams.satName" placeholder="請(qǐng)選擇目標(biāo)編號(hào)" @keyup.enter.native="handleQuery">
                        <el-option v-for="item in options" :key="item.satId" :label="item.satName"
                            :value="item.satName"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="目標(biāo)搜索" prop="satName">
                    <el-select v-model="queryParams.satName" placeholder="請(qǐng)選擇目標(biāo)編號(hào)" @keyup.enter.native="handleQuery">
                        <el-option v-for="item in options" :key="item.satId" :label="item.satName"
                            :value="item.satName"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="進(jìn)站時(shí)間">
                    <el-date-picker v-model="queryParams.time" style="width: 380px" type="datetimerange" range-separator="-"
                        start-placeholder="開(kāi)始日期" end-placeholder="結(jié)束日期" value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">查詢</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <!-- 表格 -->
        <el-card class="box">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain>導(dǎo)出</el-button>
                </el-col>
            </el-row>
            <el-table :data="tableData" stripe border @row-dblclick="handleRowDblclick">
                <el-table-column label="序號(hào)" type="index" align="center" width="60px">
                    <template slot-scope="scope">
                        <span>{{ scope.row['index'] }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="載荷編號(hào)" align="center" prop="satCode" :show-overflow-tooltip="true" />
                <el-table-column label="平臺(tái)編號(hào)" prop="deviceInfo" :show-overflow-tooltip="true" align="center" />
                <el-table-column label="任務(wù)編號(hào)" prop="circleNo" align="center" />
                <el-table-column label="目標(biāo)編號(hào)" prop="satCode" align="center" />
                <el-table-column label="開(kāi)始時(shí)間" prop="satCode" align="center" />
                <el-table-column label="結(jié)束時(shí)間" prop="satCode" align="center" />
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize v-model="satCode" placeholder="請(qǐng)輸入專家意見(jiàn)" style="width: 130px" />
                    </template>
                </el-table-column>
            </el-table>
            <!-- @pagination="lookList" -->
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" />
        </el-card>

        <el-dialog v-dialogDrag :visible.sync="isShow" width="60%" append-to-body :before-close="cancel">
            <editDialogView ></editDialogView>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="cancel">關(guān)閉</el-button>
            </div>
        </el-dialog>

    </div>
</template>
  
<script>

export default {
    components: {
        "editDialogView": () => import("./components/editDialogView.vue")
    },
    data() {

        return {
            isShow: false,
            satCode: "",
            options: [],
            // 查詢參數(shù)
            queryParams: {
                isUsed: "",
                satCode: "",
                satName: "",
                time: [],
                pageNum: 1,
                pageSize: 10,
            },
            // 表格數(shù)據(jù)
            tableData: [
                {
                    index: 1,
                    satCode: 111,
                    deviceInfo: "fuhvuv",
                    circleNo: 'ded'
                },
                {
                    index: 2,
                    satCode: 222,
                    deviceInfo: "sefef",
                    circleNo: 'vfvsd'
                },
                {
                    index: 3,
                    satCode: 333,
                    deviceInfo: "thyt",
                    circleNo: 'edef'
                }
            ],
            // 總條數(shù)
            total: 0,
            rowData: {}
        }
    },
    methods: {
        handleQuery() { },
        hanldenChange() { },
        resetQuery() { },
        handleRowDblclick(row) {
            console.log("雙擊666", row)
            this.isShow = true
            this.rowData = row

        },
        viewClose() {
            this.isShow = false
        },
        cancel() {
            this.isShow = false
        }

    }

}
</script>
  
  
<style lang="scss" scoped>
.box-card {
    margin-bottom: 10px;
}

.top {
    margin-top: 20px;
}
</style>
子組件
<template>
    <div class="container">
        <el-card>
            <div class="box">
                <Echart v-for="(item, index) in echatsList" :key="index" :idName="item.idName" :options="item.options"
                    :width=33></Echart>
            </div>
        </el-card>
    </div>
</template>
<script>
import * as echarts from 'echarts';
import Echart from "@/components/Echart";

export default {
    components: {
        Echart
    },
    data() {
        return {

            echatsList: [{
                idName: "mainOne",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            },
            {

                idName: "mainTwo",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },

                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainThr",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainFou",

                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            }, {
                idName: "mainFiv",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            },
            {
                idName: "mainSix",
                options: {
                    grid: {
                        bottom: '60px' // 距離底部60個(gè)像素
                    },

                    legend: {
                        data: ['Email'],
                        textStyle: {
                            fontSize: 14,
                            fontWeight: 'bold'
                        },
                        left: 'center',
                        bottom: '0px'
                    },
                    xAxis: {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: 'Email',
                            data: [150, 230, 224, 218, 135, 147, 260],
                            type: 'line'
                        }
                    ]
                }
            } ]
        }
    },
}
</script>
<style lang="scss" scoped>
.container {
    margin: 20px;
}

.box {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;

}
</style>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末祷愉,一起剝皮案震驚了整個(gè)濱河市涡戳,隨后出現(xiàn)的幾起案子执解,更是在濱河造成了極大的恐慌帝洪,老刑警劉巖款青,帶你破解...
    沈念sama閱讀 222,104評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件做修,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡抡草,警方通過(guò)查閱死者的電腦和手機(jī)饰及,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,816評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)康震,“玉大人燎含,你說(shuō)我怎么就攤上這事⊥榷蹋” “怎么了屏箍?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,697評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)橘忱。 經(jīng)常有香客問(wèn)我赴魁,道長(zhǎng),這世上最難降的妖魔是什么鹦付? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,836評(píng)論 1 298
  • 正文 為了忘掉前任尚粘,我火速辦了婚禮,結(jié)果婚禮上敲长,老公的妹妹穿的比我還像新娘郎嫁。我一直安慰自己,他們只是感情好祈噪,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,851評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布泽铛。 她就那樣靜靜地躺著,像睡著了一般辑鲤。 火紅的嫁衣襯著肌膚如雪盔腔。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 52,441評(píng)論 1 310
  • 那天,我揣著相機(jī)與錄音弛随,去河邊找鬼瓢喉。 笑死,一個(gè)胖子當(dāng)著我的面吹牛舀透,可吹牛的內(nèi)容都是我干的栓票。 我是一名探鬼主播,決...
    沈念sama閱讀 40,992評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼愕够,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼走贪!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起惑芭,我...
    開(kāi)封第一講書(shū)人閱讀 39,899評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤坠狡,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后遂跟,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體逃沿,經(jīng)...
    沈念sama閱讀 46,457評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,529評(píng)論 3 341
  • 正文 我和宋清朗相戀三年漩勤,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了感挥。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片缩搅。...
    茶點(diǎn)故事閱讀 40,664評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡越败,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出硼瓣,到底是詐尸還是另有隱情究飞,我是刑警寧澤,帶...
    沈念sama閱讀 36,346評(píng)論 5 350
  • 正文 年R本政府宣布堂鲤,位于F島的核電站亿傅,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏瘟栖。R本人自食惡果不足惜葵擎,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,025評(píng)論 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望半哟。 院中可真熱鬧酬滤,春花似錦、人聲如沸寓涨。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,511評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)戒良。三九已至体捏,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背几缭。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,611評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工河泳, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人年栓。 一個(gè)月前我還...
    沈念sama閱讀 49,081評(píng)論 3 377
  • 正文 我出身青樓乔询,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親韵洋。 傳聞我的和親對(duì)象是個(gè)殘疾皇子竿刁,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,675評(píng)論 2 359