fastadmin 如何通过权限组来控制列的显示与隐藏

方法1

以版本控制(application/admin/controller/Version.php)为例子

需求
就是在有时候,有些列不想让这个权限组的人看到,只给制定的权限组的人看

1.给权限组创建一个字段

ALTER TABLE lt_auth_group
ADD COLUMN isBoothView TINYINT(1) NOT NULL DEFAULT 0 AFTER status;

在这里插入图片描述

2.给对应的控制器初始化方法添加对应的权限

        $adminAuths = $this->auth->getGroups($this->auth->id);
        $authIds = '';
        if (!empty($adminAuths)){
            foreach ($adminAuths as $k=>$v){
                $authIds .= $v['id'].',';
            }
        }
        $authIds = rtrim($authIds,',');
        $authGroup = model('auth_group')->where('id','in',$authIds)->where('isBoothView',1)->find();
        if (!empty($authGroup)){
            $this->isBoothView = 1;
        }
        $this->assignconfig('isBoothView', $this->isBoothView);

在这里插入图片描述

3.给对应的js文件添加隐藏代码

table.bootstrapTable(‘hideColumn’, ‘oldversion’);
就是要隐藏的列。隐藏多列可以写多行,
这个js 需要写在 index: function () {…}里面,与table.bootstrapTable({})平行


            table.on('load-success.bs.table',function (e,data){
                console.log(Config.isBoothView);
                if (Config.isBoothView){
                    // caigoujia就是采购价的字段名根据实际修改,需要隐藏的字段
                    table.bootstrapTable('hideColumn', 'oldversion');
                    table.bootstrapTable('hideColumn', 'newversion');
                }
            });

在这里插入图片描述

查看效果

  1. 没有隐藏的列
    在这里插入图片描述

  2. 隐藏的列

在这里插入图片描述

相关推荐

  1. 微信小程序如何控制元素显示隐藏

    2024-07-14 01:02:01       42 阅读
  2. 微信小程序如何控制元素显示隐藏

    2024-07-14 01:02:01       49 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 01:02:01       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 01:02:01       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 01:02:01       62 阅读
  4. Python语言-面向对象

    2024-07-14 01:02:01       72 阅读

热门阅读

  1. COMX-P2020、COMX-P1022板卡

    2024-07-14 01:02:01       20 阅读
  2. C# Winform中ToolStripButton控件实战应用

    2024-07-14 01:02:01       25 阅读
  3. 【DDD】领域驱动设计概念深入探索

    2024-07-14 01:02:01       24 阅读
  4. MATLAB——运算符

    2024-07-14 01:02:01       20 阅读
  5. 2024.7.31 Spyglass lint tcl 使用总结

    2024-07-14 01:02:01       23 阅读
  6. Python解包语法

    2024-07-14 01:02:01       21 阅读
  7. Linux概述

    2024-07-14 01:02:01       21 阅读