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

vue3使用element-plus搭建后臺管理系統(tǒng)之菜單管理功能

 更新時(shí)間:2022年04月13日 10:02:30   作者:搬磚狗-小強(qiáng)  
這篇文章主要介紹了vue3使用element-plus搭建后臺管理系統(tǒng)之菜單管理,使用element-plus el-tree組件快速開發(fā)樹形菜單結(jié)構(gòu),el-tree組件中filter-node-method事件便可以實(shí)現(xiàn)樹形菜單篩選過濾功能,需要的朋友可以參考下

菜單管理是一套系統(tǒng)中最常見最核心的系統(tǒng)管理模塊之一,我把菜單管理分成了2個(gè)部分,左邊可以管理維護(hù)菜單,在菜單的最右側(cè)可以維護(hù)每個(gè)菜單按鈕權(quán)限配置

使用element-plus el-tree組件快速開發(fā)樹形菜單結(jié)構(gòu),el-tree組件中filter-node-method事件便可以實(shí)現(xiàn)樹形菜單篩選過濾功能

<template>
  <div class="common-tree">
    <el-tree
      :ref="treeRef"
      :data="treeData"
      :check-strictly="checkStrictly"
      show-checkbox
      :accordion="false"
      node-key="id"
      default-expand-all
      :highlight-current="true"
      :expand-on-click-node="false"
      @node-click="nodeClick"
      :filter-node-method="filterNode"
      empty-text="暫無數(shù)據(jù)"
    >
     <template #default="{ node, data }">
        <span class="custom-tree-node">
          <span style="margin-right: 15px;">{{ data.name }}</span>
           <slot
            :data="data"
            :node="node"
          />
        </span>
      </template>
    </el-tree>
  </div>
</template>
<script>
import { ref, reactive } from 'vue'
import { returnStatement } from '@babel/types';
 
export default {
  name: 'CommonTree',
  props: {
    treeRef: {
      type: String,
      default: "treeRef"
    },
    treeData: {
      type: Array,
      required: true,
      default () {
        return []
      }
    },
    checkStrictly: {
      type: Boolean,
      default () {
        return true
      }
    }
  },
  setup(props, { emit }) {
    const nodeClick = (data, node, tree) => {
      emit('nodeClick', data, node, tree)
    }
    const filterNode = (value, data) => {
      if (!value) return true
      return data.label.includes(value)
    }
    
    return { nodeClick, filterNode }
  }
}
</script>

使用element-plus el-dialog、el-icon、el-form組件實(shí)現(xiàn)菜單新增編輯

el-dialog組件實(shí)現(xiàn)彈窗,選擇圖標(biāo)功能,父組件通過v-model綁定變量,子組件通過emit('update語法糖實(shí)現(xiàn)父子組件屬性快速傳遞

子組件代碼:

<template>
  <el-dialog width="800px" v-model="visible" title="圖標(biāo)" :before-close="handleClose" >
    <ul class="iconUl">
      <li v-for="icon in iconList" :key="icon">
        <span :class="{'active':choosedIcon === icon}"
          @click="chooseIcon(icon)"
          @dblclick="confirm(icon)"
        >
            <el-icon style="width:48px;height: 48px;"><component class="icon" :is="icon" /></el-icon>
        </span>
        <p>{{ icon }}</p>
      </li>
    </ul>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="confirm(choosedIcon)">確認(rèn)</el-button>
        <el-button @click="this.$emit('update:visible', false)">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { ref, reactive } from 'vue'
import * as IconsModule from '@element-plus/icons-vue'
 
export default {
  name: 'Icons',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  setup(props, { emit }) {
    const iconList = ref([])
    const choosedIcon = ref(null)
 
    for (var key in IconsModule) {
      iconList.value.push(IconsModule[key].name)
    }
    const chooseIcon = (icon) => {
      choosedIcon.value = icon
    }
    const confirm = (icon) => {
      emit('update:icon', icon)
      emit('update:visible', false)
    }
    const handleClose = (done) => {
      emit('update:visible', false)
    } 
    return { iconList, choosedIcon, chooseIcon, confirm, handleClose }
  }
}

父組件代碼:

<icons v-model:visible="dialogIconVisible" v-model:icon="menu.icon" />

使用element-plus el-table組件實(shí)現(xiàn)菜單按鈕權(quán)限配置

 菜單按鈕權(quán)限配置表格部分代碼:

 <el-table
  ref="resourceTableKey"
  :data="resource.tableData.records"
  stripe 
  empty-text="暫無數(shù)據(jù)"
  :header-cell-style="{background:'#FCFBFF',border:'0'}"
  style="width: 100%"
  @selection-change="resourceSelectChange"
>
  <el-table-column type="selection" width="40" />
  <el-table-column label="編碼" width="80" show-overflow-tooltip>
    <template #default="scope">{{ scope.row.code }}</template>
  </el-table-column>
  <el-table-column label="名稱" width="80" show-overflow-tooltip>
    <template #default="scope">{{ scope.row.name }}</template>
  </el-table-column>
  <el-table-column label="請求方式" width="80" show-overflow-tooltip>
    <template #default="scope">{{ scope.row.method }}</template>
  </el-table-column>
  <el-table-column label="請求地址" width="80" show-overflow-tooltip>
    <template #default="scope">{{ scope.row.url }}</template>
  </el-table-column>
  <el-table-column label="操作" width="140">
    <template #default="scope">
      <el-button type="primary" size="small" @click="resourceEdit(scope.$index, scope.row)"
        >修改</el-button
      >
      <el-button
        type="danger"
        size="small"
        @click="resourceSingleDelete(scope.$index, scope.row)"
        >刪除</el-button
      >
    </template>
  </el-table-column>
</el-table>
 
// ----------------------編輯菜單按鈕權(quán)限配置----------------------------
<script>
const resourceTableKey = ref(null)
 
const resource = reactive({
  queryParams: {
    code: null,
    name: null,
    menuId: null
  },
  tableData: {
    total: 2,
    records: []
  },
  pagination: {
    size: 10,
    current: 1
  },
  formData: {},
  selection: []
})
 
const resourceSearch = () => {
  getResourceList().then(data => {
    resource.tableData.records = data.data
  })
}
 
const resourceAdd = () => {
  dialogEditVisible.value = true
  resource.formData = {}
}
 
const resourceEdit = (index, row) => {
  dialogEditVisible.value = true
  resource.formData = row
}
 
const resourceSingleDelete = (index, row) => {
  ElMessageBox.confirm('確認(rèn)刪除?',
  '確認(rèn)刪除',
  {
    confirmButtonText: '確認(rèn)',
    cancelButtonText: '取消',
    confirmButtonClass: 'confirmButton',
    type: 'warning',
  })
  .then(() => {
    resource.tableData.records.splice(index, 1)
  })
  .catch(() => { })
}
 
const resourceSelectChange = (selection) => {
  resource.selection = selection
}
 
const resourceBatchDelete = () => {
  if (!resource.selection.length) {
    ElMessageBox.alert('請選擇要刪除項(xiàng)!', '提示', { confirmButtonText: '確認(rèn)', type: 'warning' })
    return
  }
  ElMessageBox.confirm('確認(rèn)刪除?',
  '確認(rèn)刪除',
  {
    confirmButtonText: '確認(rèn)',
    cancelButtonText: '取消',
    type: 'warning',
  })
  .then(() => {
    resource.tableData.records = resource.tableData.records.filter(function(items){
      return (resource.selection.filter(function(selectionItems){
        return selectionItems.id == items.id
      })).length == 0
    })
  })
  .catch(() => { })
}
 
const resourceReturn = { resourceTableKey, resource, resourceEdit, resourceAdd, resourceSingleDelete, resourceSelectChange, resourceBatchDelete }
</script>
// ----------------------編輯菜單按鈕權(quán)限配置----------------------------

菜單按鈕權(quán)限配置表單部分代碼:

<template>
  <el-dialog width="800px" v-model="visible" title="修改" :before-close="handleClose" >
    <el-form ref="form" :model="fromData" label-position="right" label-width="100px">
      <el-form-item label="編碼" prop="code">
        <el-input v-model="fromData.code" />
        <p class="note">建議使用:作為分隔符,并以view、add、update、delete、export、import、download、upload等關(guān)鍵詞結(jié)尾</p>
        <p class="note">如:menu:add、 resource:view、 file:upload</p>
      </el-form-item>
      <el-form-item label="名稱" prop="name">
        <el-input v-model="fromData.name" />
      </el-form-item>
      <el-form-item label="請求方式" prop="describe" >
        <el-input v-model="fromData.method" />
      </el-form-item>
      <el-form-item label="請求地址" prop="describe" >
        <el-input v-model="fromData.url" />
      </el-form-item>
      <el-form-item label="描述" prop="describe" >
        <el-input v-model="fromData.describe" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="confirm()">確認(rèn)</el-button>
        <el-button @click="this.$emit('update:visible', false)" >取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { ref, reactive, watch } from 'vue'
import { returnStatement } from '@babel/types';
 
export default {
  name: 'edit',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    resource: {
      type: Object,
      default: () => ({})
    }
  },
  setup(props, { emit }) {
    const fromData = reactive({})
 
    watch(() => props.resource, (newResource) => {
        for (const key in fromData) {
          fromData[key] = ''
        }
        for (const key in newResource) {
          fromData[key] = newResource[key]
        }
    }, { immediate: true })
    
    const confirm = () => {
      for (const key in fromData) {
        props.resource[key] = fromData[key]
      }
      emit('update:visible', false)
    }
    const handleClose = (done) => {
      emit('update:visible', false)
    }
    
    return { confirm, handleClose, fromData }
  }
}
</script>

到此這篇關(guān)于vue3使用element-plus搭建后臺管理系統(tǒng)---菜單管理的文章就介紹到這了,更多相關(guān)vue3 element-plus后臺管理系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue+ ArcGIS JavaScript APi詳解

    Vue+ ArcGIS JavaScript APi詳解

    這篇文章主要介紹了Vue+ ArcGIS JavaScript APi,文中需要注意ArcGIS JavaScript3.x 和ArcGIS JavaScript 4.x框架差異較大,本文從環(huán)境搭建開始到測試運(yùn)行給大家講解的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • Vue transition過渡組件詳解

    Vue transition過渡組件詳解

    我們現(xiàn)在可以了解一下vue的過渡,vue在插入、更新以及移除DOM元素的時(shí)候,提供了很多不同方式過渡的效果,如果在css過渡自動應(yīng)用class,在過渡鉤子函數(shù)中使用JavaScript直接操作DOM就可以了
    2022-08-08
  • Vue中使用 ElementUi 的 el-select 實(shí)現(xiàn)全選功能(思路詳解)

    Vue中使用 ElementUi 的 el-select 實(shí)現(xiàn)全選功能(思路詳解

    在開發(fā)中,有一個(gè)需求是 選項(xiàng)組件中使用到一個(gè) 全選的功能,特在這記錄下實(shí)現(xiàn)的方法,方便后續(xù)的查閱,以及方便大家查閱借鑒,對vue   ElementUi 全選功能感興趣的朋友一起看看吧
    2024-02-02
  • Vue2學(xué)習(xí)筆記之請求數(shù)據(jù)交互vue-resource

    Vue2學(xué)習(xí)筆記之請求數(shù)據(jù)交互vue-resource

    本篇文章主要介紹了Vue2學(xué)習(xí)筆記之?dāng)?shù)據(jù)交互vue-resource ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • el-table 行合并的實(shí)現(xiàn)示例

    el-table 行合并的實(shí)現(xiàn)示例

    本文主要介紹了el-table 行合并的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue開發(fā)之moment的介紹與使用

    vue開發(fā)之moment的介紹與使用

    moment是一款多語言支持的日期處理類庫, 在vue中如何使用呢?這篇文章主要給大家介紹了關(guān)于vue之moment使用的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • Vue封裝實(shí)現(xiàn)可配置的搜索列表組件

    Vue封裝實(shí)現(xiàn)可配置的搜索列表組件

    在Vue.js開發(fā)中,經(jīng)常會遇到需要展示搜索和列表的需求,為了提高代碼復(fù)用性和開發(fā)效率,我們可以封裝一個(gè)可配置的搜索列表組件,下面我們就來講講如何實(shí)現(xiàn)這樣一個(gè)組件吧
    2023-08-08
  • Vue出現(xiàn)首屏白屏的六種解決方法小結(jié)

    Vue出現(xiàn)首屏白屏的六種解決方法小結(jié)

    這篇文章主要為大家詳細(xì)介紹了Vue中出現(xiàn)首屏白屏的六種解決方法,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下
    2025-02-02
  • Vue3中結(jié)合ElementPlus實(shí)現(xiàn)彈窗的封裝方式

    Vue3中結(jié)合ElementPlus實(shí)現(xiàn)彈窗的封裝方式

    這篇文章主要介紹了Vue3中結(jié)合ElementPlus實(shí)現(xiàn)彈窗的封裝方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • vue組件打包并發(fā)布到npm的全過程

    vue組件打包并發(fā)布到npm的全過程

    這篇文章主要介紹了vue組件打包并發(fā)布到npm的全過程,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01

最新評論

兴仁县| 静海县| 石嘴山市| 集贤县| 达日县| 嘉黎县| 蒙山县| 桐城市| 思南县| 邵武市| 建始县| 南丹县| 浦北县| 晋江市| 韶关市| 确山县| 浙江省| 盐津县| 明光市| 天镇县| 乐亭县| 右玉县| 宁都县| 张家川| 重庆市| 教育| 保康县| 噶尔县| 尼玛县| 开封市| 天全县| 洪泽县| 北安市| 轮台县| 耒阳市| 高尔夫| 平舆县| 井陉县| 荣成市| 邢台市| 宜丰县|