欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

<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="暫無(wú)數(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)功能,父組件通過(guò)v-model綁定變量,子組件通過(guò)emit('update語(yǔ)法糖實(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="暫無(wú)數(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="請(qǐng)求方式" width="80" show-overflow-tooltip>
    <template #default="scope">{{ scope.row.method }}</template>
  </el-table-column>
  <el-table-column label="請(qǐng)求地址" 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('請(qǐng)選擇要?jiǎng)h除項(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="請(qǐng)求方式" prop="describe" >
        <el-input v-model="fromData.method" />
      </el-form-item>
      <el-form-item label="請(qǐng)求地址" 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ái)管理系統(tǒng)---菜單管理的文章就介紹到這了,更多相關(guān)vue3 element-plus后臺(tái)管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue3通用API功能示例剖析

    Vue3通用API功能示例剖析

    這篇文章主要為大家介紹了Vue3通用API功能示例剖析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • 基于vue封裝下拉刷新上拉加載組件

    基于vue封裝下拉刷新上拉加載組件

    這篇文章主要為大家詳細(xì)介紹了基于vue封裝下拉刷新上拉加載組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • 淺談vue同一頁(yè)面中擁有兩個(gè)表單時(shí),的驗(yàn)證問(wèn)題

    淺談vue同一頁(yè)面中擁有兩個(gè)表單時(shí),的驗(yàn)證問(wèn)題

    今天小編就為大家分享一篇淺談vue同一頁(yè)面中擁有兩個(gè)表單時(shí),的驗(yàn)證問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • vue實(shí)現(xiàn)圖片拖拽及鼠標(biāo)滾輪放大縮小的示例代碼

    vue實(shí)現(xiàn)圖片拖拽及鼠標(biāo)滾輪放大縮小的示例代碼

    本文主要給大家介紹如何vue實(shí)現(xiàn)圖片拖拽及鼠標(biāo)滾輪放大縮小,文中有詳細(xì)的代碼供大家參考,對(duì)我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-08-08
  • 為vue項(xiàng)目自動(dòng)設(shè)置請(qǐng)求狀態(tài)的配置方法

    為vue項(xiàng)目自動(dòng)設(shè)置請(qǐng)求狀態(tài)的配置方法

    這篇文章主要介紹了vue項(xiàng)目自動(dòng)設(shè)置請(qǐng)求狀態(tài)的配置方法,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06
  • Vue 搭建Vuex環(huán)境詳解

    Vue 搭建Vuex環(huán)境詳解

    這篇文章主要為大家介紹了Vue搭建Vuex環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • 解決vue3打包過(guò)后空白頁(yè)面的情況

    解決vue3打包過(guò)后空白頁(yè)面的情況

    這篇文章主要介紹了解決vue3打包過(guò)后空白頁(yè)面的情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法

    對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法

    這篇文章主要介紹了對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Vue通過(guò)封裝全局獲取焦點(diǎn)指令

    Vue通過(guò)封裝全局獲取焦點(diǎn)指令

    這篇文章主要為大家詳細(xì)介紹了Vue通過(guò)封裝全局獲取焦點(diǎn)指令的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下
    2023-12-12
  • Vue?Token過(guò)期問(wèn)題的2種解決方案小結(jié)

    Vue?Token過(guò)期問(wèn)題的2種解決方案小結(jié)

    在使用token進(jìn)行登錄的過(guò)程中,如果token過(guò)期了,需要重新輸入用戶名和密碼登錄,這種體驗(yàn)肯定是不好的,下面這篇文章主要給大家介紹了關(guān)于Vue?Token過(guò)期問(wèn)題的2種解決方案,需要的朋友可以參考下
    2023-02-02

最新評(píng)論