国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue + elementUI 實現(xiàn)下拉樹形結(jié)構選擇部門,支持多選,支持檢索

這篇具有很好參考價值的文章主要介紹了vue + elementUI 實現(xiàn)下拉樹形結(jié)構選擇部門,支持多選,支持檢索。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

<template>
  <div>
    <el-select v-model="multiple?choosedValue:choosedValue[0]" element-loading-background="rgba(0,0,0,0.8)"
               :disabled="disableFlag" @visible-change="visibleChange"
               filterable clearable collapse-tags :filter-method="filterMethod" @clear="clear" @remove-tag="removeTag"
               :multiple="multiple" ref="selectRef" v-loading="loading" style="width: 100%">
      <el-option :label="option.name" :value="option.id" v-for="option in options" :key="option.id"
                 class="optionClass"/>
      <template v-slot:empty>
        <div/>
      </template>
      <el-tree :props="treeProps" :load="loadNode" :data="treeData" :show-checkbox="multiple" @check="handleCheck"
               :expand-on-click-node="false" @node-click="chooseNode" :filter-node-method="filterNodeMethod"
               class="treeClass" ref="treeRef" :node-key="'id'" :default-checked-keys="choosedValue"/>
    </el-select>
  </div>
</template>

<script>
import {getDwxxOfTree} from "@/api/commentTable/api";

export default {
  name: "chooseUnitTree",
  props: {
    disableFlag: {
      Type: Boolean,
      required: false,
      default: false
    },
    value: {
      Type: Object,
      required: true
    },
    multiple: {
      Type: Boolean,
      required: false,
      default: false
    }
  },
  data() {
    return {
      treeProps: {
        label: 'name',
        value: 'id',
        children: 'children'
      },
      deptMap: {},
      treeData: [],
      options: [],
      loading: false,
      choosedValue: [],
      choosedOptions: [],
    }
  },
  computed: {},
  watch: {
    // choosedValue: {
    //   handler(n, o) {
    //     if (this.$refs.treeRef) {
    //       this.$refs.treeRef.filter()
    //     }
    //   },
    //   immediate: true,
    //   deep: true
    // }
  },
  mounted() {
    this.choosedValue = []
    this.getNodeData()
  },
  methods: {
    visibleChange(visible) {
      if (!visible) {
        this.$refs.treeRef.filter()
      }
    },
    removeTag(nodeId) {
      this.choosedValue = this.choosedValue.filter(item => item !== nodeId)
      this.choosedOptions = this.choosedOptions.filter(item => item.id !== nodeId)
      this.$refs.treeRef.setCheckedKeys(this.choosedValue, false)
      this.$emit('input', this.multiple ? this.choosedValue : this.choosedValue[0])
    },
    clear() {
      this.choosedValue = []
      this.choosedOptions = []
      this.$refs.treeRef.setCheckedKeys([], false)
      this.$emit('input', '')
    },
    filterMethod(keyWord) {
      this.$refs.treeRef.filter(keyWord)
    },
    filterNodeMethod(keyWord, node) {
      if (!keyWord) {
        return true
      }
      return (node.name + node.id).includes(keyWord)
    },
    init() {
      this.choosedValue = []
      if (typeof this.value === 'string') {
        this.choosedOptions.push(this.deptMap[this.value])
        this.choosedValue.push(this.value)
      } else {
        this.value.forEach(item => {
          this.choosedOptions.push(this.deptMap[item.id])
          this.choosedValue = this.value
        })
      }
    },
    getNodeData(resolve) {
      this.loading = true
      getDwxxOfTree().then(dwxxResult => {
        // dwxxResult.data :
        // [{
        //   id  : "123456"
        //   name : "xx集團"
        //   pid : "000000"
        // }]
        this.loading = false
        if (dwxxResult.data) {
          this.options = dwxxResult.data
          const rootDept = []
          this.deptMap = {}
          for (let deptInfo of dwxxResult.data) {
            this.deptMap[deptInfo.id] = deptInfo
          }
          for (let deptInfo of dwxxResult.data) {
            if (!this.deptMap[deptInfo.pid]) {
              rootDept.push(deptInfo)
            }
          }
          if (resolve) {
            resolve(rootDept)
          }
        } else {
          if (resolve) {
            resolve([])
          }
        }
        this.init()
        this.createTree(dwxxResult.data)
      })
    },
    createNodeChildren(node) {
      let children = []
      for (let deptId in this.deptMap) {
        let tmpNode = this.deptMap[deptId]
        if (tmpNode.pid === node.id) {
          children.push(this.createNodeChildren(tmpNode))
        }
      }
      node.children = children
      return node
    },
    createTree() {
      this.treeData = []
      for (let deptId in this.deptMap) {
        let node = this.deptMap[deptId]
        if (!this.deptMap[node.pid]) {
          this.treeData.push(this.createNodeChildren(node))
        }
      }
    },
    loadNode(node, resolve) {
      if (node.level === 0) {
        this.getNodeData(resolve)
      } else {
        const children = []
        for (let deptId in this.deptMap) {
          if (this.deptMap[deptId].pid === node.data.id) {
            children.push(this.deptMap[deptId])
          }
          resolve(children)
        }
      }
    },
    handleCheck(data, currentData) {
      this.choosedOptions = this.multiple ? [data] : currentData.checkedNodes // this.$refs.treeRef.getCheckedNodes(false, false)
      if (this.choosedOptions.length > 0) {
        const tempMap = {}
        this.choosedOptions.forEach(op => {
          tempMap[op.id] = op
        })
        let tmpOps = []
        this.choosedOptions.forEach(op => {
          if (!tempMap[op.pid]) {
            tmpOps.push(op)
          }
        })
        this.choosedOptions = tmpOps
        this.choosedValue = this.choosedOptions.map(item => item.id)
      } else {
        this.choosedValue = []
      }
      this.$emit('input', this.multiple ? this.choosedValue : this.choosedValue[0])
    },
    chooseNode(data) {
      this.choosedOptions = [data]
      this.choosedValue = [data.id]
      this.$emit('input', data.id)
      this.$refs.selectRef.visible = false
    }
  }
}
</script>

<style scoped lang="scss">
.optionClass {
  display: none;
}

.treeClass {
  background: transparent;
  margin: 10px;
}
</style>

文章來源地址http://www.zghlxwxcb.cn/news/detail-640708.html

到了這里,關于vue + elementUI 實現(xiàn)下拉樹形結(jié)構選擇部門,支持多選,支持檢索的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • vue實現(xiàn)elementUI table表格樹形結(jié)構-使用懶加載時-解決子節(jié)點增刪改后,不刷新子節(jié)點數(shù)據(jù)問題

    vue實現(xiàn)elementUI table表格樹形結(jié)構-使用懶加載時-解決子節(jié)點增刪改后,不刷新子節(jié)點數(shù)據(jù)問題

    在使用element-ui的table組件時,使用樹形結(jié)構,并使用了懶加載,可出現(xiàn)了一個問題,在對當前節(jié)點添加一個子節(jié)點數(shù)據(jù),或刪除一個子節(jié)點數(shù)據(jù)時,當前節(jié)點的子節(jié)點數(shù)據(jù)并不自動刷新出來。element-ui官方?jīng)]有提供實時刷新子節(jié)點數(shù)據(jù)的方法。 可以使用window.location.reload();但每

    2024年02月09日
    瀏覽(26)
  • 微信小程序多列下拉框的實現(xiàn)(樹形數(shù)據(jù)結(jié)構和單數(shù)組數(shù)據(jù)結(jié)構形式)

    微信小程序多列下拉框的實現(xiàn)(樹形數(shù)據(jù)結(jié)構和單數(shù)組數(shù)據(jù)結(jié)構形式)

    利用微信小程序api,實現(xiàn)不同傳輸數(shù)據(jù)格式下的多列下拉框?qū)崿F(xiàn) 首先了解一下picker中的事件 這里是官方文檔,具體意思就是 當你滑動多列中的某一列的時候, bindcolumnchange 事件就會觸發(fā)。當選擇完畢點擊確定的時候 bindchange 事件就會觸發(fā) 微信小程序的多列下拉框是真的反人

    2024年02月07日
    瀏覽(25)
  • vue2 Elementui 樹形組件怎么實現(xiàn)多選并獲取選中節(jié)點的node對象

    vue2 Elementui 樹形組件怎么實現(xiàn)多選并獲取選中節(jié)點的node對象

    一.前言 樹形組件是我們經(jīng)常用到的組件,主要場景就是:公司后臺管理的部門管理,做文章目錄等。 二.常用的幾種方法及說明 1.node-click:節(jié)點被點擊時的回調(diào) 共三個參數(shù),依次為:傳遞給? data ?屬性的數(shù)組中該節(jié)點所對應的對象、 節(jié)點對應的 Node 、節(jié)點組件本身。 2.c

    2024年02月16日
    瀏覽(20)
  • uni-app-使用tkiTree組件實現(xiàn)樹形結(jié)構選擇

    uni-app-使用tkiTree組件實現(xiàn)樹形結(jié)構選擇

    前言 在實際開發(fā)中我們經(jīng)常遇見樹結(jié)構-比如樓層區(qū)域-組織架構-部門崗位-系統(tǒng)類型等情況 往往需要把這個樹結(jié)構當成條件來查詢數(shù)據(jù),在PC端可以使用Tree,table,Treeselect等組件展示 在uni-app的內(nèi)置組件中似乎沒有提供這樣組件來展示,但是是有第三方包tkiTree組件來解決這個

    2024年02月14日
    瀏覽(68)
  • elementUI之下拉選項加多選框功能實現(xiàn)vue3+ts

    根據(jù) @牛先森家的牛奶 的代碼修改后實現(xiàn) 具體參考原博主文章,這里只對部分細節(jié)調(diào)整,記錄一下

    2024年02月17日
    瀏覽(25)
  • vue3+elementUI-plus實現(xiàn)select下拉框的虛擬滾動

    網(wǎng)上查了幾個方案,要不就是不兼容,要不就是不支持vue3, 最終找到一個合適的,并且已上線使用,需要修改一下樣式: 代碼如下: main.js里引用 vue文件: js代碼: css代碼:

    2024年02月13日
    瀏覽(29)
  • [VUE]Element_UI 實現(xiàn)TreeSelect 樹形選擇器

    [VUE]Element_UI 實現(xiàn)TreeSelect 樹形選擇器

    最近在做一個人員管理系統(tǒng),在增改用戶信息時,可能會設置用戶所在的部門,因為部門是多級的,于是想到用Element_UI的TreeSelect組件實現(xiàn) 效果: 安裝完成后,打開package.json 可以看到@riophae/vue-treeselect的版本: 在需要使用TreeSelect的組件中引入 并將Treeselect加到components中:

    2024年02月09日
    瀏覽(26)
  • Vue+EleMentUI實現(xiàn)el-table-colum表格select下拉框可編輯

    Vue+EleMentUI實現(xiàn)el-table-colum表格select下拉框可編輯

    在進行采購入庫的過程中,有必要對表格中的一行進行快速編輯保存,節(jié)省時間,提高工作效率!,而不是每次編輯都要彈窗才可編輯 源碼:https://gitee.com/charlinchenlin/store-pos 控制是否顯示select下拉框 如果showInput的值與當前的inboundId相同,則顯示下拉選項,否則顯示數(shù)據(jù)信息

    2024年02月01日
    瀏覽(26)
  • elementUI --- el-select 下拉框 日歷 級聯(lián)選擇

    elementUI --- el-select 下拉框 日歷 級聯(lián)選擇

    element UI 組件庫中的 select 選擇器 中下拉列表的樣式,在頁面渲染的時候,總是渲染為僅次于body級別的div ,這樣子覆蓋樣子會影響全局其他的select選擇器下拉框樣式,試圖通過給el-select加父標簽來覆蓋,然而并沒有卵用。 控制臺看到的渲染結(jié)果: 解決方法: 通過 popper-cla

    2024年02月15日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包