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

vue-tree-chart樹形組件的實現(xiàn)(含鼠標(biāo)右擊事件)

 更新時間:2022年02月28日 10:47:08   作者:aibujin  
Vue-Tree-Chart,一個Vue.js2組件,本文就詳細(xì)的介紹一下vue-tree-chart樹形組件的實現(xiàn)(含鼠標(biāo)右擊事件),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于 vue-tree-chart,生成項目效果預(yù)覽,包含鼠標(biāo)右擊事件;

在這里插入圖片描述

vue-tree-chart:https://github.com/tower1229/Vue-Tree-Chart

大家可以直接安裝使用(具體事例可以查看官網(wǎng))

但是個人建議最好是下載整個項目,封裝成組件調(diào)用

基于官網(wǎng)初始代碼,封裝組件:

<template>
    <table v-if="treeData.name">
      <tr>
        <td :colspan="Array.isArray(treeData.children) ? treeData.children.length * 2 : 1" 
          :class="{parentLevel: Array.isArray(treeData.children) && treeData.children.length, extend: Array.isArray(treeData.children) && treeData.children.length && treeData.extend}"
        >
          <div :class="{node: true, hasMate: treeData.mate}">
            <div class="person" 
              :class="Array.isArray(treeData.class) ? treeData.class : []"
             
            >
              <div class="avat">
                <img :src="treeData.image_url" @contextmenu="$emit('click-node', treeData)"/>
              </div>
              <!-- <div class="name">{{treeData.name}}</div> -->
            </div>
             <div class="paeson_name">{{treeData.name}}</div>
            <template v-if="Array.isArray(treeData.mate) && treeData.mate.length">
              <div class="person" v-for="(mate, mateIndex) in treeData.mate" :key="treeData.name+mateIndex"
                :class="Array.isArray(mate.class) ? mate.class : []"
                @click="$emit('click-node', mate)"
              >
                <div class="avat">
                  <img :src="mate.image_url" />
                </div>
                <!-- <div class="name">{{mate.name}}</div> -->
              </div>
              <div class="paeson_name">{{treeData.name}}</div>
            </template>
          </div>
          <div class="extend_handle" v-if="Array.isArray(treeData.children) && treeData.children.length" @click="toggleExtend(treeData)"></div>
        </td>
      </tr>
      <tr v-if="Array.isArray(treeData.children) && treeData.children.length && treeData.extend">
        <td v-for="(children, index) in treeData.children" :key="index" colspan="2" class="childLevel">
          <TreeChart :json="children" @click-node="$emit('click-node', $event)"/>
        </td>
      </tr>
    </table>
</template>

<script>
export default {
  name: "TreeChart",
  props: ["json"],
  data() {
    return {
      treeData: {}
    }
  },
  watch: {
    json: {
      handler: function(Props){
        let extendKey = function(jsonData){
          jsonData.extend = (jsonData.extend===void 0 ? true: !!jsonData.extend);
          if(Array.isArray(jsonData.children)){
            jsonData.children.forEach(c => {
              extendKey(c)
            })
          }
          return jsonData;
        }
        if(Props){
          this.treeData = extendKey(Props);
        }
      },
      immediate: true
    }
  },
  methods: {
    toggleExtend: function(treeData){
      treeData.extend = !treeData.extend;
      this.$forceUpdate();
    }
  }
}
</script>

<style scoped>
table{border-collapse: separate!important;border-spacing: 0!important;}
td{position: relative; vertical-align: top;padding:0 0 50px 0;text-align: center; }
.extend_handle{position: absolute;left:50%;bottom:30px; width:10px;height: 10px;padding:10px;transform: translate3d(-15px,0,0);cursor: pointer;}
.extend_handle:before{content:""; display: block; width:100%;height: 100%;box-sizing: border-box; border:2px solid;border-color:#ccc #ccc transparent transparent;
transform: rotateZ(135deg);transform-origin: 50% 50% 0;transition: transform ease 300ms;}
.extend_handle:hover:before{border-color:#333 #333 transparent transparent;}
/* .extend .extend_handle:before{transform: rotateZ(-45deg);} */
.extend::after{content: "";position: absolute;left:50%;bottom:15px;height:15px;border-left:2px solid #ccc;transform: translate3d(-1px,0,0)}
.childLevel::before{content: "";position: absolute;left:50%;bottom:100%;height:15px;border-left:2px solid #ccc;transform: translate3d(-1px,0,0)}
.childLevel::after{content: "";position: absolute;left:0;right:0;top:-15px;border-top:2px solid #ccc;}
.childLevel:first-child:before, .childLevel:last-child:before{display: none;}
.childLevel:first-child:after{left:50%;height:15px; border:2px solid;border-color:#ccc transparent transparent #ccc;border-radius: 6px 0 0 0;transform: translate3d(1px,0,0)}
.childLevel:last-child:after{right:50%;height:15px; border:2px solid;border-color:#ccc #ccc transparent transparent;border-radius: 0 6px 0 0;transform: translate3d(-1px,0,0)}
.childLevel:first-child.childLevel:last-child::after{left:auto;border-radius: 0;border-color:transparent #ccc transparent transparent;transform: translate3d(1px,0,0)}
.node{position: relative; display: inline-block;margin: 0 1em;box-sizing: border-box; text-align: center;}
.node:hover{color: #2d8cf0;cursor: pointer;}
.node .person{position: relative; display: inline-block;z-index: 2;width:6em; overflow: hidden;}
.node .person .avat{display: block;width:4em;height: 4em;margin:auto;overflow:hidden; background:#fff;border:1px solid #ccc;box-sizing: border-box;}
.node .person .avat:hover{ border: 1px solid #2d8cf0;}
.node .person .avat img{width:100%;height: 100%;}
.node .person .name{height:2em;line-height: 2em;overflow: hidden;width:100%;}
.node.hasMate::after{content: "";position: absolute;left:2em;right:2em;top:2em;border-top:2px solid #ccc;z-index: 1;}
.node .paeson_name{transform: rotate(90deg);position: absolute; top: 68px;right: 39px;width: 88px;text-align: center;text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}


.landscape{transform:translate(-100%,0) rotate(-90deg);transform-origin: 100% 0;}
.landscape .node{text-align: left;height: 8em;width:8em;right: 18px;}
.landscape .person{position: absolute; transform: rotate(90deg);height: 4em;top:4em;left: 2.5em;}
.landscape .person .avat{position: absolute;left: 0;border-radius: 2em;border-width:2px;}
.landscape .person .name{height: 4em; line-height: 4em;}
.landscape .hasMate{position: relative;}
.landscape .hasMate .person{position: absolute; }
.landscape .hasMate .person:first-child{left:auto; right:-4em;}
.landscape .hasMate .person:last-child{left: -4em;margin-left:0;}
</style>

新建一個組件,調(diào)用組件并增加鼠標(biāo)右擊事件:

<template>
  <div id="app">
    <TreeChart :json="data" :class="{landscape: 1}" @click-node="clickNode" />

    <div class="gl_prs_ctn" :style='[contextstyle]'>
          <ul class='gl_prs_li'>
              <li >添加</li>
              <li >詳情</li>
              <li >編輯</li>
              <li >刪除</li>
          </ul>
    </div>  

  </div>
</template>

<script>
import TreeChart from "./treechar";
export default {
  name: 'app',
  components: {
    TreeChart
  },
  data() {
    return {
      data: {
        name: 'root',
        image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg",
        class: ["rootNode"],
        children: [
          {
            name: 'children1',
            image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg"
          },
          {
            name: 'children2',
            image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg",
            children: [
              {
                name: 'grandchild',
                image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg"
              },
              {
                name: 'grandchild2',
                image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg"
              },
              {
                name: 'grandchild3',
                image_url: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3689173839,956040439&fm=26&gp=0.jpg"
              }
            ]
          }
        ]
      },
      contextstyle: {
          display: 'none',
          right: '0px',
          top: '0px',
          left: '0px',
          bottom: '0px',
      }, 
    }
  },
  created(){
      document.oncontextmenu = ()=>{return false}
      document.addEventListener("click", (event) => {
            if(this.contextstyle.display == 'block'){
                this.contextstyle.display = 'none'
            }
      })
  },
  methods: {
      clickNode(node){
        if(window.event.x + 188 > document.documentElement.clientWidth){
            this.contextstyle.left = 'unset';
            this.contextstyle.right = document.documentElement.clientWidth - window.event.x + 'px';
        }else{
            this.contextstyle.left = window.event.x + 'px';
        }
        if(window.event.y + 166 > document.documentElement.clientHeight){
            this.contextstyle.top = 'unset';
            this.contextstyle.bottom = document.documentElement.clientHeight - window.event.y + 'px';
        }else{
            this.contextstyle.top = window.event.y + 'px';
        }                       
        this.contextstyle.display = 'block';
      },
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.gl_prs_ctn{
            width: 188px;
            background: rgb(255, 255, 255);
            box-shadow: rgba(0, 0, 0, 0.075) 0px 1px 1px inset, rgba(102, 175, 233, 0.6) 0px 0px 8px;
            z-index: 99999;
            position: fixed;
            padding: 10px;
            box-sizing: content-box;
            height: 142px;
}
.gl_prs_li{padding: unset;margin: unset;}
.gl_prs_li>li{
    cursor: pointer;   
    list-style: none;
    border-bottom: 1px solid #efefef;
    padding: 7px 10px;
}
li:last-child { border: unset }
li:hover{
      background: #ccc;
      color: #fff;
}
</style>

到此這篇關(guān)于vue-tree-chart樹形組件的實現(xiàn)(含鼠標(biāo)右擊事件)的文章就介紹到這了,更多相關(guān)vue-tree-chart 樹形組件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue3中Vite和Vue-cli的特點與區(qū)別詳解

    Vue3中Vite和Vue-cli的特點與區(qū)別詳解

    vue-cli是Vue早期推出的一款腳手架,使用webpack創(chuàng)建Vue項目,可以選擇安裝需要的各種插件,比如Vuex、VueRouter,下面這篇文章主要給大家介紹了關(guān)于Vue3中Vite和Vue-cli的特點與區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • vue3動態(tài)路由addRoute實例詳解

    vue3動態(tài)路由addRoute實例詳解

    這篇文章主要介紹了vue3動態(tài)路由addRoute的相關(guān)知識,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • Vue3中列表拖拽排序的實現(xiàn)示例

    Vue3中列表拖拽排序的實現(xiàn)示例

    本文主要介紹了Vue3中列表拖拽排序的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • vue keep-alive中的生命周期解讀

    vue keep-alive中的生命周期解讀

    這篇文章主要介紹了vue keep-alive中的生命周期,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • 深入理解Vue 的條件渲染和列表渲染

    深入理解Vue 的條件渲染和列表渲染

    本篇文章主要介紹了深入理解Vue 的條件渲染和列表渲染,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • vue-next/runtime-core 源碼閱讀指南詳解

    vue-next/runtime-core 源碼閱讀指南詳解

    這篇文章主要介紹了vue-next/runtime-core 源碼閱讀指南詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Vue3源碼分析組件掛載創(chuàng)建虛擬節(jié)點

    Vue3源碼分析組件掛載創(chuàng)建虛擬節(jié)點

    這篇文章主要為大家介紹了Vue3源碼分析組件掛載創(chuàng)建虛擬節(jié)點,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Vue中代碼編輯器與實時預(yù)覽功能

    Vue中代碼編輯器與實時預(yù)覽功能

    CodeMirror提供了強大的代碼編輯功能,而Vue.js使得組件的創(chuàng)建和數(shù)據(jù)綁定變得非常簡單,當(dāng)用戶編輯代碼時,實時預(yù)覽會根據(jù)代碼的變化進行更新,從而為用戶提供了一個交互式的編程環(huán)境,這篇文章主要介紹了Vue中如何進行代碼編輯器與實時預(yù)覽,需要的朋友可以參考下
    2023-10-10
  • 如何用vue封裝axios請求

    如何用vue封裝axios請求

    對axios進行封裝以及將API接口按業(yè)務(wù)模塊統(tǒng)一管理,有助于我們簡化代碼,方便后期維護。本文介紹了如何用vue封裝axios請求,感興趣的同學(xué),可以參考下。
    2021-06-06
  • vue中向data添加新屬性的三種方式小結(jié)

    vue中向data添加新屬性的三種方式小結(jié)

    這篇文章主要介紹了vue中向data添加新屬性的三種方式小結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04

最新評論

怀远县| 南开区| 萨迦县| 吐鲁番市| 湘潭县| 阳谷县| 鱼台县| 明光市| 玛曲县| 金门县| SHOW| 遂川县| 锦州市| 年辖:市辖区| 资溪县| 张掖市| 库伦旗| 临江市| 于都县| 武城县| 新密市| 佳木斯市| 措美县| 贵州省| 茶陵县| 湖南省| 昌邑市| 乐亭县| 姜堰市| 泽普县| 剑河县| 抚远县| 连山| 秭归县| 阳谷县| 长兴县| 共和县| 临朐县| 新龙县| 杭锦后旗| 澄迈县|