赞
踩
之前实现了一个功能VUE利用tree-transfer插件实现角色菜单动态设置
在这个功能的基础上,进一步完善
角色列表Uacter.vue页面,点击【菜单设置】按钮,弹出角色菜单MenuRole.vue页面,也就是说实现的是一个弹窗功能,只不过加载的vue页面
说来惭愧,这是我应用vue的第4天,好多东西都不知道,然后就是现学现用
首先肯定是找百度啊
主要参考的列子:vue编辑、新增弹框(引用外部页面)
但是按照上边这个方法,我的弹窗一直都没有显示出来,一个大的改动点是我Uacter.vue页面引用MenuRole时直接包裹在dialog里边
菜单权限按钮:
<el-button type="info" @click="handleClick3(scope.row.id)" size="mini">菜单权限</el-button>
引入MenuRole页面:
- <el-dialog :visible.sync="menuRoleVisible" append-to-body>
- <menu-role v-if="menuRoleVisible" ref="menuRole"></menu-role>
- </el-dialog>
编辑按钮触发方法:
- //设置菜单权限
- handleClick3(id){
- let roleId = id;
- this.menuRoleVisible = true;
- this.$nextTick(()=>{
- this.$refs.menuRole.dataInitialization(roleId);
- })
- }
MenuRole.vue完整代码:
- <template>
- <div class="widget-content">
- <tree-transfer :title="title"
- :from_data='fromData'
- :to_data='toData'
- :defaultProps="{label:'label',value:'id'}"
- @addBtn='add'
- @removeBtn='remove'
- @change="changeMode"
- :mode='mode' height='640px' filter openAll>
- </tree-transfer>
- <el-button type="primary" size="mini" @click="save" style="margin-left:30%;">保存</el-button>
- </div>
- </template>
- <script>
- import treeTransfer from 'el-tree-transfer' // 引入
- export default {
- components: {
- treeTransfer
- },
- data(){
- return{
- roleId:"",
- title:["已有菜单权限","可选菜单权限"],
- mode: "transfer", // transfer addressList
- fromData:[],
- toData:[]
- }
- },
- methods:{
- //初始化数据
- dataInitialization(id){
- let that = this;
- that.roleId = id;
- that.axios
- .get(
- "/qsmonitor/menu/getMenuByRole?roleId="+id
- )
- .then(res => {
- that.fromData = res.data.data.fromData;
- that.toData = res.data.data.toData;
- console.info("this id ");
- console.info(res);
- that.$notify({
- title: "成功",
- message: res.data.message,
- type: "success"
- });
- })
- .catch(err => {
- that.$notify.error({
- title: "错误",
- message: err
- });
- console.log(err);
- });
- },
- // 切换模式 现有树形穿梭框模式transfer 和通讯录模式addressList
- changeMode() {
- if (this.mode == "transfer") {
- this.mode = "addressList";
- } else {
- this.mode = "transfer";
- }
- },
- // 减少权限设置
- add(fromData,toData,obj){
- this.fromData = fromData;
- this.toData = toData;
- },
- // 增加权限设置
- remove(fromData,toData,obj){
- this.fromData = fromData;
- this.toData = toData;
- },
- save(){
- let addIds = "";
- this.fromData.forEach((item,i)=>{
- addIds += item.id+",";
- });
- this.axios
- .put(
- "/qsmonitor/menu/setMenu?roleId="+this.roleId+"&addIds="+addIds
- )
- .then(res => {
- if (res.data.data) {
- this.loading = false;
- }
- this.dataInitialization(this.roleId);
- this.$notify({
- title: "成功",
- message: res.data.message,
- type: "success"
- });
- })
- .catch(err => {
- console.info(err);
- this.$notify.error({
- title: "错误",
- message: "系统异常"
- });
- console.log(err);
- });
- }
- }
- }
- </script>
最终实现效果:
后记:用这个tree-transfer插件真的完美解决了我的问题,而且不需要再去给左移、右移按钮添加事件。看别人实现的代码好像很顺利,但真的做起来的时候总会遇到各种bug,我就一点一点去改去测,方法有些笨,毕竟刚开始接触vue呢,但是感觉以我现在混迹后端的水平,vue我也就只能实现基本的功能,做不出很酷炫的效果,慢慢来吧
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。