Skip to content

支持单元格权限

可以通过实现 ISupportUIPermission 接口支持单元格权限,支持单元格的 可编辑权限需要和 ISupportReadOnly 接口配合, 支持单元格的禁用权限需要和 ISupportDisable 配合。

C#示例代码如下

csharp
    public class MyPluginCellType : CellType, ISupportDisable, ISupportReadOnly, ISupportUIPermission
    {
        [DisplayName("只读")]
        public bool ReadOnly { get; set; }

        [DisplayName("禁用")]
        public bool IsDisabled { get; set; }

        [DisplayName("单元格权限")]
        [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)]
        public List<UIPermission> UIPermissions { get; set; } = GetDefaultPermission();

        public static List<UIPermission> GetDefaultPermission()
        {
            var defaultAllowRoles = new List<string>() { "FGC_Anonymous" };
            return new List<UIPermission>
            {
                new UIPermission(){ Scope = UIPermissionScope.Enable, AllowRoles = defaultAllowRoles },
                new UIPermission(){ Scope = UIPermissionScope.Editable, AllowRoles = defaultAllowRoles },
                new UIPermission(){ Scope = UIPermissionScope.Visible, AllowRoles = defaultAllowRoles },
            };
        }
    }

JavaScript 代码可分别参考 支持只读支持禁用 章节

WARNING

注意:UIPermission 属性必须添加
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)]
否则保存再打开后会出现权限内容重复问题

更新: 2024-06-12 17:59:20
原文: https://www.yuque.com/robert-bh51n/ea8l6c/ae0ggrf4fzh3p8s5