npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wii/user-permission

v2.12.2

Published

toolkit for wii-user permission

Downloads

6

Readme

UserPermission

React component for wii user permission

安装

npm i @wii/user-permission

使用

  • 组件
    • UserPermissionProvider
    • UserPermissionAuthorize
  • Hooks
    • useUserPermissions
  • 工具函数
    • definePermission
    • definePermissions
    • checkPermission

示例

import { Button } from '@wii/wau'
import { UserPermissionProvider, UserPermissionAuthorize } from '@wii/user-permission'

export default = () => {
  return (
    <UserPermissionProvider permissions={{}} defaultBehavior="hidden">
    <UserPermissionAuthorize id="add-permission" name="新增功能权限">
      <Button>新增</Button>
    </UserPermissionAuthorize>
    </UserPermissionProvider>
  )
}

或者

import { Button } from '@wii/wau'
import { UserPermissionProvider, UserPermissionAuthorize, definePermission } from '@wii/user-permission'

const addPermission = definePermission({
  id: 'add-permission',
  name: '新增功能权限'
})

export default = () => {
  return (
    <UserPermissionProvider permissions={{}} defaultBehavior="hidden">
    <UserPermissionAuthorize {...addPermission}>
      <Button>新增</Button>
    </UserPermissionAuthorize>
    </UserPermissionProvider>
  )
}

API

UserPermissionProvider

| 参数 | 类型 | 说明 | 默认值 | 是否必须 | | :---------------: | :---------------------------------------: | :----------------------------------------------------------: | :------: | -------- | | permissions | Record<string, string> | 从用户中台获取的权限信息 | - | 是 | | defaultBehavior | AuthorizeBehavior | 无权限时的全局默认行为,disabled:禁止点击,hidden: 隐藏 | hidden | 否 | | debug | boolean | 是否开启调试模式,调试模式下,权限将不会生效 | false | 否 |

UserPermissionAuthorize

| 参数 | 类型 | 说明 | 默认值 | 是否必须 | | :-----------: | :---------------------------------------: | :----------------------------------------------------------------: | :-------: | -------- | | id | string | 权限 id | - | 是 | | name | string | 权限名称,用于中台存储 | - | 是 | | type | PermissionType | 权限类型,用于中台存储。 | OPERATE | 否 | | parent | string | 父权限,用于中台存储 | - | 否 | | value | string | 权限值,用于中台存储 | - | 否 | | description | string | 权限描述,用于中台存储 | - | 否 | | behavior | AuthorizeBehavior | 无权限时行为,disabled:禁止点击,hidden: 隐藏,默认为全局配置 | hidden | 否 |

definePermission

权限定义工具函数,参数参考 UserPermissionAuthorize

const addBtnPermission = definePermission({
  id: 'add-permission',
  name: '新增功能权限',
});

definePermissions

权限定义工具函数

const permissions = definePermissions({
  addBtn: {
    id: 'add-permission',
    name: '新增功能权限',
  },
});

console.log(permissions.addBtn);

PermissionType

权限类型,默认为操作权限

  • MENU: 菜单权限
  • OPERATE: 操作权限

AuthorizeBehavior

无权限表现行为

  • disabled: 禁止操作。UserPermissionAuthorize 将会向子组件注入 disabled 属性
  • hidden: 隐藏。UserPermissionAuthorize 将会渲染空组件