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

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜

這篇具有很好參考價值的文章主要介紹了Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)?

菜單功能實現(xiàn)

菜單接口封裝

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

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

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

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

import axios from '../axios'

/* 
 * 菜單管理模塊
 */

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

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

菜單管理界面

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

Menu.vue

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

<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="圖標">
        <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)標識">
      </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)標識" 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="菜單圖標" 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="菜單圖標名稱(如: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('確認刪除選中記錄嗎?', '提示', {
                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
    },
    // 圖標選中
    iconActiveHandle (iconName) {
      this.dataForm.icon = iconName
    },
    // 表單提交
    submitForm () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
                    this.$confirm('確認提交嗎?', '提示', {}).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>

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

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

views/Core/TableTreeColumn.vue

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

<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>

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

測試效果

最終測試效果下圖所示。

Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜,vue.js,javascript,elementui

源碼下載

后端:kitty: 基于Spring Boot、Spring Cloud、Vue.js 、Element UI實現(xiàn),采用前后端分離架構(gòu)的權(quán)限管理系統(tǒng),JAVA快速開發(fā)平臺。

前端:kitty-ui: Kitty 前端,基于 Vue + Element 實現(xiàn)的權(quán)限管理系統(tǒng)。文章來源地址http://www.zghlxwxcb.cn/news/detail-695636.html

到了這里,關(guān)于Vue + Element UI 實現(xiàn)權(quán)限管理系統(tǒng) 前端篇(十四):菜單功能實現(xiàn)菜的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【VUE學習】權(quán)限管理系統(tǒng)前端vue實現(xiàn)4-自定義icon實現(xiàn)

    template 部分:定義了組件的模板內(nèi)容。在這里,使用了 svg 標簽來創(chuàng)建一個 SVG 圖標元素,并添加了一個 use 元素來引用具體的圖標。 :xlink:href 屬性使用了綁定語法,將 iconName 綁定為 use 元素的 xlink:href 屬性的值。 script setup 部分:使用了 Vue 3 的 script setup 語法,用于編寫組件

    2024年02月13日
    瀏覽(25)
  • [VUE學習]權(quán)限管理系統(tǒng)前端vue實現(xiàn)8-右上角用戶頭像顯示實現(xiàn)

    [VUE學習]權(quán)限管理系統(tǒng)前端vue實現(xiàn)8-右上角用戶頭像顯示實現(xiàn)

    ? ???????? next(‘/logon’) 、 next(to) 或者 next({ …to, replace: true }) ? ????????在路由守衛(wèi)中, 只有next()是放行 ,其他的諸如:next(‘/logon’) 、 next(to) 或者 next({ …to, replace: true })都不是放行, 而是:中斷當前導航,執(zhí)行新的導航 ? ? ? ? ? ? ? ? 他不是直接放行 二十

    2024年02月13日
    瀏覽(32)
  • Vue + Element-ui實現(xiàn)后臺管理系統(tǒng)---項目搭建 + ??布局實現(xiàn)

    Vue + Element-ui實現(xiàn)后臺管理系統(tǒng)---項目搭建 + ??布局實現(xiàn)

    目錄:導讀 項目搭建 + ??布局實現(xiàn) 一、項目搭建 1、環(huán)境搭建 2、項目初期搭建 二、Main.vue 三、左側(cè)欄部分(CommonAside.vue) 四、header部分(CommonHeader.vue) 五、Home.vue 寫在最后 這篇主要講解 項目搭建 + 后臺??布局實現(xiàn) : 整體效果 后臺首頁按布局一共包含3個部分: 1、左側(cè)欄

    2024年02月02日
    瀏覽(56)
  • 基于vue-cli創(chuàng)建后臺管理系統(tǒng)前端頁面——element-ui,axios,跨域配置,布局初步,導航欄

    基于vue-cli創(chuàng)建后臺管理系統(tǒng)前端頁面——element-ui,axios,跨域配置,布局初步,導航欄

    1.vue-cli創(chuàng)建前端工程,安裝element-ui,axios和配置; 2.前端跨域的配置,請求添加Jwt的設(shè)置; 3.進行初始化布局,引入新增頁面的方式; 4.home頁面導航欄的設(shè)置,一級目錄,二級目錄; 安裝成功 布局初步 1.vue-cli創(chuàng)建前端工程,安裝element-ui,axios和配置; 2.前端跨域的配置,請

    2024年02月09日
    瀏覽(34)
  • [VUE學習]權(quán)限管理系統(tǒng)前端vue實現(xiàn)9-動態(tài)路由,動態(tài)標簽頁,動態(tài)面包屑

    [VUE學習]權(quán)限管理系統(tǒng)前端vue實現(xiàn)9-動態(tài)路由,動態(tài)標簽頁,動態(tài)面包屑

    ? ? ? ? ? ? ? ? 在總體布局頁面添加router router-view 是 Vue Router 提供的組件,用于動態(tài)展示匹配到的路由組件內(nèi)容。 通過在合適的位置放置 router-view ,你可以根據(jù)路由路徑動態(tài)地渲染對應的組件內(nèi)容。 ? ? ? ? ? ? ? ? ? ? 因為我們是多級頁面 之后動態(tài)路由也是多級的 如

    2024年02月13日
    瀏覽(21)
  • 基于Vue+Element UI的文件管理系統(tǒng)-Demo

    基于Vue+Element UI的文件管理系統(tǒng)-Demo

    記錄一下之前寫過的一個文件管理系統(tǒng)demo。 功能包括文件夾的新增、刪除、重命名及移動,文件的上傳、刪除、移動及下載功能。 相關(guān)功能的操作直接和 后端 進行 請求 交互。 因為該demo集成在大的系統(tǒng)中,懶得提取建庫開源,所以算是只記錄思路。 右鍵文件夾時顯示操作

    2024年03月08日
    瀏覽(27)
  • 【vue后臺管理系統(tǒng)】基于Vue+Element-UI+ECharts開發(fā)通用管理后臺(中)

    【vue后臺管理系統(tǒng)】基于Vue+Element-UI+ECharts開發(fā)通用管理后臺(中)

    點擊菜單圖標之前: 點擊菜單圖標之后: 首先我們要知道菜單欄的收縮,由el-menu的collapse屬性控制: 我們通過分析可以知道: 菜單按鈕的點擊是在CommonHeader.vue組件中,而我們修改的collapse屬性卻在CommonAside.vue中,這是兩個不同的組件。很明顯這涉及到了組件間的通信問題,

    2024年02月03日
    瀏覽(62)
  • Vue2+element-ui后臺管理系統(tǒng)(靜態(tài)頁面)

    Vue2+element-ui后臺管理系統(tǒng)(靜態(tài)頁面)

    node:https://nodejs.org/en/ git:https://git-scm.com/ vue:https://v2.cn.vuejs.org/v2/guide/installation.html element-ui:https://element.eleme.cn/#/zh-CN/component/installation 項目所需:https://pan.baidu.com/s/1ua0jp9YCtPH6slE49HDUBw 提取碼:kkkk 在node和vue都調(diào)試、配置好的情況下使用vscode 在終端中輸入命令 npm i -g @vue

    2024年02月06日
    瀏覽(43)
  • Vue+Element UI 生鮮管理系統(tǒng)簡介及項目搭建,頁面布局(一)

    Vue+Element UI 生鮮管理系統(tǒng)簡介及項目搭建,頁面布局(一)

    自從入了這家公司,就沒分配過前端的工作了,在上一家還能前后端都寫寫,現(xiàn)在真是對vue的代碼真是望塵莫及哇,前幾天跟前端朋友交流前端知識的時候,發(fā)現(xiàn)自己腦子里面的前端代碼好像被偷了一樣,趕緊找個項目練練,雖然現(xiàn)在是java,以后還是想要做全棧呢( ▽ )(哈哈

    2024年02月11日
    瀏覽(25)
  • Spring Boot + Vue + Element UI的網(wǎng)上商城后臺管理之訂單管理系統(tǒng)

    以下是訂單管理系統(tǒng)的思維導圖,展示了系統(tǒng)的主要功能和模塊之間的關(guān)系。 根節(jié)點 訂單列表 查看訂單列表 搜索訂單 排序訂單 導出訂單列表 訂單詳情 查看訂單詳情 修改訂單信息 修改商品信息 修改價格 修改收貨地址 取消訂單 處理訂單 處理訂單操作 確認訂單 拒絕訂單

    2024年02月03日
    瀏覽(40)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包