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

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng)之菜單功能實現(xiàn)代碼

 更新時間:2022年02月15日 11:50:01   作者:朝雨憶輕塵  
菜單管理是一個對菜單樹結(jié)構(gòu)的增刪改查操作,這篇文章主要介紹了Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng)之菜單功能實現(xiàn)代碼,需要的朋友可以參考下

菜單功能實現(xiàn)

菜單接口封裝

菜單管理是一個對菜單樹結(jié)構(gòu)的增刪改查操作。

提供一個菜單查詢接口,查詢整顆菜單樹形結(jié)構(gòu)。

http/modules/menu.js 添加findMenuTree 接口。

import axios from '../axios'

/* 
 * 菜單管理模塊
 */
 // 保存
export const save = (data) => {
    return axios({
        url: '/menu/save',
        method: 'post',
        data
    })
}
// 刪除
export const batchDelete = (data) => {
        url: '/menu/delete',
// 查找導(dǎo)航菜單樹
export const findNavTree = (params) => {
        url: '/menu/findNavTree',
        method: 'get',
        params
export const findMenuTree = () => {
        url: '/menu/findMenuTree',
        method: 'get'

菜單管理界面

菜單管理界面是使用封裝的表格樹組件顯示菜單結(jié)構(gòu),并提供增刪改查的功能。

Menu.vue

<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!--工具欄-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
        <el-form :inline="true" :model="filters" :size="size">
            <el-form-item>
                <el-input v-model="filters.name" placeholder="名稱"></el-input>
            </el-form-item>
            <el-form-item>
                <kt-button label="查詢" perms="sys:menu:view" type="primary" @click="findTreeData(null)"/>
            </el-form-item>
            <el-form-item>
                <kt-button label="新增" perms="sys:menu:add" type="primary" @click="handleAdd"/>
            </el-form-item>
        </el-form>
    </div>
    <!--表格樹內(nèi)容欄-->
    <el-table :data="tableTreeDdata" stripe size="mini" style="width: 100%;"
      v-loading="loading" element-loading-text="拼命加載中">
      <el-table-column
        prop="id" header-align="center" align="center" width="80" label="ID">
      </el-table-column>
      <table-tree-column 
        prop="name" header-align="center" treeKey="id" width="150" label="名稱">
      </table-tree-column>
      <el-table-column header-align="center" align="center" label="圖標(biāo)">
        <template slot-scope="scope">
          <i :class="scope.row.icon || ''"></i>
        </template>
      </el-table-column>
      <el-table-column prop="type" header-align="center" align="center" label="類型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.type === 0" size="small">目錄</el-tag>
          <el-tag v-else-if="scope.row.type === 1" size="small" type="success">菜單</el-tag>
          <el-tag v-else-if="scope.row.type === 2" size="small" type="info">按鈕</el-tag>
        </template>
      </el-table-column>
      <el-table-column 
        prop="parentName" header-align="center" align="center" width="120" label="上級菜單">
      </el-table-column>
      <el-table-column
        prop="url" header-align="center" align="center" width="150" 
        :show-overflow-tooltip="true" label="菜單URL">
      </el-table-column>
      <el-table-column
        prop="perms" header-align="center" align="center" width="150" 
        :show-overflow-tooltip="true" label="授權(quán)標(biāo)識">
      </el-table-column>
      <el-table-column
        prop="orderNum" header-align="center" align="center" label="排序">
      </el-table-column>
      <el-table-column
        fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <kt-button label="修改" perms="sys:menu:edit" @click="handleEdit(scope.row)"/>
          <kt-button label="刪除" perms="sys:menu:delete" type="danger" @click="handleDelete(scope.row)"/>
        </template>
      </el-table-column>
    </el-table>
    <!-- 新增修改界面 -->
    <el-dialog :title="!dataForm.id ? '新增' : '修改'" width="40%" :visible.sync="dialogVisible" :close-on-click-modal="false">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="submitForm()" 
        label-width="80px" :size="size" style="text-align:left;">
        <el-form-item label="菜單類型" prop="type">
          <el-radio-group v-model="dataForm.type">
            <el-radio v-for="(type, index) in menuTypeList" :label="index" :key="index">{{ type }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="menuTypeList[dataForm.type] + '名稱'" prop="name">
          <el-input v-model="dataForm.name" :placeholder="menuTypeList[dataForm.type] + '名稱'"></el-input>
        </el-form-item>
        <el-form-item label="上級菜單" prop="parentName">
            <popup-tree-input 
              :data="popupTreeData" :props="popupTreeProps" :prop="dataForm.parentName==null?'根節(jié)點':dataForm.parentName" 
              :nodeKey="''+dataForm.parentId" :currentChangeHandle="handleTreeSelectChange">
            </popup-tree-input>
        </el-form-item>
        <el-form-item v-if="dataForm.type === 1" label="菜單路由" prop="url">
          <el-input v-model="dataForm.url" placeholder="菜單路由"></el-input>
        </el-form-item>
        <el-form-item v-if="dataForm.type !== 0" label="授權(quán)標(biāo)識" prop="perms">
          <el-input v-model="dataForm.perms" placeholder="如: sys:user:add, sys:user:edit, sys:user:delete"></el-input>
        </el-form-item>
        <el-form-item v-if="dataForm.type !== 2" label="排序編號" prop="orderNum">
          <el-input-number v-model="dataForm.orderNum" controls-position="right" :min="0" label="排序編號"></el-input-number>
        </el-form-item>
        <el-form-item v-if="dataForm.type !== 2" label="菜單圖標(biāo)" prop="icon">
          <el-row>
            <el-col :span="22">
              <!-- <el-popover
                ref="iconListPopover"
                placement="bottom-start"
                trigger="click"
                popper-class="mod-menu__icon-popover">
                <div class="mod-menu__icon-list">
                  <el-button
                    v-for="(item, index) in dataForm.iconList"
                    :key="index"
                    @click="iconActiveHandle(item)"
                    :class="{ 'is-active': item === dataForm.icon }">
                    <icon-svg :name="item"></icon-svg>
                  </el-button>
                </div>
              </el-popover> -->
              <el-input v-model="dataForm.icon" v-popover:iconListPopover :readonly="true" placeholder="菜單圖標(biāo)名稱(如:fa fa-home fa-lg)" class="icon-list__input"></el-input>
            </el-col>
            <el-col :span="2" class="icon-list__tips">
              <fa-icon-tooltip />
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :size="size"  @click="dialogVisible = false">取消</el-button>
        <el-button :size="size"  type="primary" @click="submitForm()">確定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import KtButton from "@/views/Core/KtButton"
import TableTreeColumn from '@/views/Core/TableTreeColumn'
import PopupTreeInput from "@/components/PopupTreeInput"
import FaIconTooltip from "@/components/FaIconTooltip"
export default {
    components:{
    PopupTreeInput,
    KtButton,
    TableTreeColumn,
    FaIconTooltip
    },
    data() {
        return {
            size: 'small',
            loading: false,
            filters: {
                name: ''
      },
      tableTreeDdata: [],
      dialogVisible: false,
      menuTypeList: ['目錄', '菜單', '按鈕'],
      dataForm: {
        id: 0,
        type: 1,
        name: '',
        parentId: 0,
        parentName: '',
        url: '',
        perms: '',
        orderNum: 0,
        icon: '',
        iconList: []
      },
      dataRule: {
        name: [
          { required: true, message: '菜單名稱不能為空', trigger: 'blur' }
        ],
        parentName: [
          { required: true, message: '上級菜單不能為空', trigger: 'change' }
        ]
      },
      popupTreeData: [],
      popupTreeProps: {
                label: 'name',
                children: 'children'
            }
        }
    },
    methods: {
        // 獲取數(shù)據(jù)
    findTreeData: function () {
      this.loading = true
            this.$api.menu.findMenuTree().then((res) => {
        this.tableTreeDdata = res.data
        this.popupTreeData = this.getParentMenuTree(res.data)
        this.loading = false
            })
    },
        // 獲取上級菜單樹
    getParentMenuTree: function (tableTreeDdata) {
      let parent = {
        parentId: -1,
        name: '根節(jié)點',
        children: tableTreeDdata
      }
      return [parent]
    },
        // 顯示新增界面
        handleAdd: function () {
            this.dialogVisible = true
            this.dataForm = {
        id: 0,
        type: 1,
        typeList: ['目錄', '菜單', '按鈕'],
        name: '',
        parentId: 0,
        parentName: '',
        url: '',
        perms: '',
        orderNum: 0,
        icon: '',
        iconList: []
      }
        },
        // 顯示編輯界面
        handleEdit: function (row) {
      this.dialogVisible = true
      Object.assign(this.dataForm, row);
        },
    // 刪除
    handleDelete (row) {
      this.$confirm('確認(rèn)刪除選中記錄嗎?', '提示', {
                type: 'warning'
      }).then(() => {
        let params = this.getDeleteIds([], row)
        this.$api.menu.batchDelete(params).then( res => {
          this.findTreeData()
          this.$message({message: '刪除成功', type: 'success'})
        })
      })
    },
    // 獲取刪除的包含子菜單的id列表
    getDeleteIds (ids, row) {
      ids.push({id:row.id})
      if(row.children != null) {
        for(let i=0, len=row.children.length; i<len; i++) {
          this.getDeleteIds(ids, row.children[i])
        }
      }
      return ids
    },
      // 菜單樹選中
    handleTreeSelectChange (data, node) {
      this.dataForm.parentId = data.id
      this.dataForm.parentName = data.name
    },
    // 圖標(biāo)選中
    iconActiveHandle (iconName) {
      this.dataForm.icon = iconName
    },
    // 表單提交
    submitForm () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
                    this.$confirm('確認(rèn)提交嗎?', '提示', {}).then(() => {
                        this.editLoading = true
                        let params = Object.assign({}, this.dataForm)
                        this.$api.menu.save(params).then((res) => {
              if(res.code == 200) {
                                this.$message({ message: '操作成功', type: 'success' })
                            } else {
                                this.$message({message: '操作失敗, ' + res.msg, type: 'error'})
                            }
                            this.editLoading = false
                            this.$refs['dataForm'].resetFields()
                            this.dialogVisible = false
                            this.findTreeData()
                        })
                    })
                }
      })
    }
    },
    mounted() {
    this.findTreeData()
    }
}
</script>

<style scoped>

</style>

其中對表格樹組件進行了簡單的封裝。

views/Core/TableTreeColumn.vue

<template>
  <el-table-column :prop="prop" v-bind="$attrs">
    <template slot-scope="scope">
      <span @click.prevent="toggleHandle(scope.$index, scope.row)" :style="childStyles(scope.row)">
        <i :class="iconClasses(scope.row)" :style="iconStyles(scope.row)"></i>
        {{ scope.row[prop] }}
      </span>
    </template>
  </el-table-column>
</template>

<script>
  import isArray from 'lodash/isArray'
  export default {
    name: 'table-tree-column',
    props: {
      prop: {
        type: String
      },
      treeKey: {
        type: String,
        default: 'id'
      },
      parentKey: {
        type: String,
        default: 'parentId'
      },
      levelKey: {
        type: String,
        default: 'level'
      },
      childKey: {
        type: String,
        default: 'children'
      }
    },
    methods: {
      childStyles (row) {
        return { 'padding-left': (row[this.levelKey] * 25) + 'px' }
      },
      iconClasses (row) {
        return [ !row._expanded ? 'el-icon-caret-right' : 'el-icon-caret-bottom' ]
      },
      iconStyles (row) {
        return { 'visibility': this.hasChild(row) ? 'visible' : 'hidden' }
      },
      hasChild (row) {
        return (isArray(row[this.childKey]) && row[this.childKey].length >= 1) || false
      },
      // 切換處理
      toggleHandle (index, row) {
        if (this.hasChild(row)) {
          var data = this.$parent.store.states.data.slice(0)
          data[index]._expanded = !data[index]._expanded
          if (data[index]._expanded) {
            data = data.splice(0, index + 1).concat(row[this.childKey]).concat(data)
          } else {
            data = this.removeChildNode(data, row[this.treeKey])
          }
          this.$parent.store.commit('setData', data)
          this.$nextTick(() => {
            this.$parent.doLayout()
          })
        }
      },
      // 移除子節(jié)點
      removeChildNode (data, parentId) {
        var parentIds = isArray(parentId) ? parentId : [parentId]
        if (parentId.length <= 0) {
          return data
        }
        var ids = []
        for (var i = 0; i < data.length; i++) {
          if (parentIds.indexOf(data[i][this.parentKey]) !== -1 && parentIds.indexOf(data[i][this.treeKey]) === -1) {
            ids.push(data.splice(i, 1)[0][this.treeKey])
            i--
          }
        }
        return this.removeChildNode(data, ids)
      }
    }
  }
</script>

測試效果

最終測試效果下圖所示。

源碼下載

后端:https://gitee.com/liuge1988/kitty

前端:https://gitee.com/liuge1988/kitty-ui.git

到此這篇關(guān)于Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng)之菜單功能實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)Vue Element UI 權(quán)限管理系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue3 diff算法的簡單解刨

    Vue3 diff算法的簡單解刨

    如今Vue3的勢頭正盛,在diff算法方面也做了相應(yīng)的變化,利用到了最長遞增子序列把性能又提升了一個檔次。本文就來帶大家簡單解刨一下Vue3中的diff算法
    2023-02-02
  • 詳解vuex中mutation/action的傳參方式

    詳解vuex中mutation/action的傳參方式

    這篇文章主要介紹了詳解vuex中mutation/action的傳參方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • 淺談vue.js中v-for循環(huán)渲染

    淺談vue.js中v-for循環(huán)渲染

    本篇文章主要介紹了淺談vue.js中v-for循環(huán)渲染,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • 前端插件庫之vue3使用vue-codemirror插件的步驟和實例

    前端插件庫之vue3使用vue-codemirror插件的步驟和實例

    CodeMirror是一款基于JavaScript、面向語言的前端代碼編輯器,下面這篇文章主要給大家介紹了關(guān)于前端插件庫之vue3使用vue-codemirror插件的步驟和實例,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • Vue中的項目打包及部署全流程

    Vue中的項目打包及部署全流程

    這篇文章主要介紹了Vue中的項目打包及部署全流程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue頁面加載時的進度條功能(實例代碼)

    vue頁面加載時的進度條功能(實例代碼)

    這篇文章主要介紹了vue頁面加載時的進度條功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • vue3如何將html元素變成canvas(海報生成),進行圖片保存/截圖

    vue3如何將html元素變成canvas(海報生成),進行圖片保存/截圖

    這篇文章主要介紹了vue3實現(xiàn)將html元素變成canvas(海報生成),進行圖片保存/截圖,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue ajax 攔截原理與實現(xiàn)方法示例

    vue ajax 攔截原理與實現(xiàn)方法示例

    這篇文章主要介紹了vue ajax 攔截原理與實現(xiàn)方法,結(jié)合實例形式分析了vue.js基于ajax攔截實現(xiàn)無刷新登錄的相關(guān)原理與操作技巧,需要的朋友可以參考下
    2019-11-11
  • Vue+Element-ui日歷排班自定義實例代碼

    Vue+Element-ui日歷排班自定義實例代碼

    這篇文章主要給大家介紹了關(guān)于Vue+Element-ui日歷排班自定義的相關(guān)資料,有現(xiàn)成的日歷插件但是不符合需求,所以項目中使用vue+element的表格組件自己實現(xiàn)一個日歷組件,需要的朋友可以參考下
    2023-09-09
  • mpvue寫一個CPASS小程序的示例

    mpvue寫一個CPASS小程序的示例

    這篇文章主要介紹了mpvue寫一個CPASS小程序的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09

最新評論