中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Element中怎么實現一個樹形控件

發布時間:2021-06-18 15:54:16 來源:億速云 閱讀:159 作者:Leah 欄目:大數據

Element中怎么實現一個樹形控件,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

1.前端布局

<div id="home" >
    <el-row>
        <el-col :span="8">
            <el-form label-width="100px">
                <el-form-item label="選擇業務">
                    <el-select v-model="searchBkId"  @change="bizChange">
                        <el-option v-for="item in bkBizData" :label="item.bk_biz_name" :value="item.bk_biz_id"></el-option>
                    </el-select>
                </el-form-item>
                <el-tree :data="bkTopoData" :props="setProps" @node-click="handleNodeClick" ></el-tree>
            </el-form>
        </el-col>
        <el-col :span="16">
            <el-form label-width="100px" >
                <el-form-item label="搜索字段">
                    <el-row :gutter="60">
                        <el-col :span="16">
                            <el-input v-model="searchContent" placeholder="請輸入搜索字段"></el-input>
                        </el-col>
                        <el-col :span="4">
                            <el-button type="primary" @click="search">搜索</el-button>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-table :data="hostData" border width="100%" max-height="300" header-align="center">
                  <el-table-column prop="bk_host_id" label="主機ID"></el-table-column>
                  <el-table-column prop="bk_os_name" label="系統名"></el-table-column>
                  <el-table-column prop="bk_host_name" label="主機名稱"></el-table-column>
                  <el-table-column prop="bk_host_innerip" label="IP地址"></el-table-column>
                  <el-table-column prop="bk_cloud_id" label="云區域ID"></el-table-column>
                  <el-table-column prop="bk_cloud_name" label="云區域名稱"></el-table-column>
                </el-table>
                <el-divider></el-divider>
                <el-table :data="hostData" border >
                  <el-table-column prop="bk_host_id" label="主機ID"></el-table-column>
                  <el-table-column prop="bk_os_name" label="系統名"></el-table-column>
                  <el-table-column prop="bk_host_name" label="主機名稱"></el-table-column>
                  <el-table-column prop="bk_host_innerip" label="IP地址"></el-table-column>
                  <el-table-column prop="bk_cloud_id" label="云區域ID"></el-table-column>
                  <el-table-column prop="bk_cloud_name" label="云區域名稱"></el-table-column>
                </el-table>
            </el-form>
        </el-col>
     </el-row>
</div>

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            bkTopoData: [
                {
                    bk_inst_name: '一級 1',
                    child: [
                        {
                            bk_inst_name: '二級 1-1',
                            child: [
                                {
                                    bk_inst_name: '三級 1-1-1'
                                }
                            ]
                        }
                    ]
                },
                {
                    bk_inst_name: '一級 2',
                    child: [
                        {
                            bk_inst_name: '二級 2-1',
                            child: [
                                {
                                    bk_inst_name: '三級 2-1-1'
                                }
                            ]
                        },
                        {
                            bk_inst_name: '二級 2-2',
                            child: [
                                {
                                    bk_inst_name: '三級 2-2-1'
                                }
                            ]
                        }
                    ]
                },
                {
                    bk_inst_name: '一級 3',
                    child: [
                        {
                            bk_inst_name: '二級 3-1',
                            child: [
                                {
                                    bk_inst_name: '三級 3-1-1'
                                }
                            ]
                        },
                        {
                            bk_inst_name: '二級 3-2',
                            child: [
                                {
                                    bk_inst_name: '三級 3-2-1'
                                }
                            ]
                        }
                    ]
                }
            ],
            setProps: {
                children: 'child',
                label: 'bk_inst_name'
            },
            searchBkId:'',
            searchContent:'',
            bkBizData:[],
            tableData:[],
            hostData: []
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                axios.get(site_url + "get_biz_list/").then(res => {
                    if (res.data.result){
                        this.bkBizData = res.data.data;
                    }else{
                        this.$message.error('獲取業務失敗');
                    }
                },'json');
            },
            handleNodeClick(data) {
                axios.post(site_url + "search_host/", data).then(res => {
                    if (res.data.result) {
                        this.hostData = res.data.data;
                    } else {
                        this.$message.error('獲取主機失敗');
                    }
                }, 'json');
            },
            bizChange() {
                axios.get(site_url + "get_bk_topo/?bk_biz_id=" + this.searchBkId).then(res => {
                    if (res.data.result){
                        this.bkTopoData = res.data.data;
                    }else{
                        this.$message.error('獲取業務失敗');
                    }
                },'json');
            },
            search() {
                console.log("aaa")
            }
        }
    })
</script>
<style>
/* table表頭及表內數據居中CSS */
.el-table .cell {
    text-align: center;
}
</style>

2.后端接口

from django.views.decorators.csrf import csrf_exempt

def get_bk_topo(request):
    bk_biz_id = request.GET.get("bk_biz_id")
    res_data = cc_search_biz_inst_topo(request, bk_biz_id)
    return JsonResponse({"result": True, "data": res_data})

def get_biz_list(request):
    fields = ["bk_biz_id", "bk_biz_name"]
    data = cc_search_business(fields)
    return JsonResponse({"result": True, "data": data})

def search_host(request):
    res_data = []
    data = json.loads(request.body)
    bk_obj_id = data.get("bk_obj_id")
    bk_inst_id = data.get("bk_inst_id")
    host_data = cc_search_host(request, bk_obj_id, bk_inst_id)
    for h in host_data:
        bk_host_name = h.get("host", {}).get("bk_host_name")
        bk_os_name = h.get("host", {}).get("bk_os_name")
        bk_cloud_id = h.get("host", {}).get("bk_cloud_id")[0].get("bk_inst_id")
        bk_cloud_name = h.get("host", {}).get("bk_cloud_id")[0].get("bk_inst_name")
        bk_host_id = h.get("host", {}).get("bk_host_id")
        bk_host_innerip = h.get("host", {}).get("bk_host_innerip")
        res_data.append({
            "bk_host_name": bk_host_name,
            "bk_os_name": bk_os_name,
            "bk_cloud_id": bk_cloud_id,
            "bk_cloud_name": bk_cloud_name,
            "bk_host_id": bk_host_id,
            "bk_host_innerip": bk_host_innerip,
        })
    return JsonResponse({"result": True, "data": res_data})

實現效果Element中怎么實現一個樹形控件

看完上述內容,你們掌握Element中怎么實現一個樹形控件的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

珲春市| 顺平县| 隆安县| 永定县| 石阡县| 张家口市| 渝北区| 朔州市| 泰兴市| 兴宁市| 加查县| 麻江县| 成武县| 稷山县| 渝中区| 内乡县| 吉木萨尔县| 怀集县| 广平县| 宣汉县| 博野县| 博兴县| 基隆市| 平和县| 绿春县| 北辰区| 淄博市| 呼图壁县| 大冶市| 崇州市| 延庆县| 无锡市| 遂宁市| 红原县| 德昌县| 吴忠市| 彭水| 阿克苏市| 五峰| 布尔津县| 曲靖市|