Giter Club home page Giter Club logo

gzteacher-auth's Introduction

简体中文 | English

logo.png

@gzteacher/auth

基于 @alifd/next 的权限相关组件

Version download Coverage Status PRs Welcome GitHub license

📚 在线文档

Features

  • 🐒 基本: 基本的权限逻辑组件
    • Provider: 定义权限组件上下文
    • Wrapper: 有权限时展示组件内容
    • DenyWrapper: 有权限时不展示组件内容
    • RouteGuard: 路由权限拦截
  • 🐯 组件: 对@alifd/next的常用组件扩展了基本权限逻辑
    • Button: 无权限时展示为文本
    • Select: 下拉框不展示无权限的选项
    • Tab: 标签页不展示无权限的标签
    • Table: 表格不展示无权限的列
    • Menu: 菜单不显示无权限的菜单项
    • Nav: 导航栏不显示无权限的导航项
  • 🤖️ 定制: 支持自定义权限验证器以实现更丰富的权限功能
    • Validator
  • 🦁 代理: 支持在上下文内将权限编码重定向到其他权限编码
    • Proxy
  • 🐌 工具: 权限业务逻辑相关的工具函数
    • useAuth: 返回权限信息和权限更新方法
    • useMatchAuth: 返回是否有对应权限
    • useAuthData: 根据传入集合返回有权限的集合数据
  • 🌲 树形: 权限功能支持树形结构
    • useAuthDataSelectTableRouteGuardMenuNav...

Install

Install with npm:

npm install --save @gzteacher/auth

Install with yarn:

yarn add @gzteacher/auth

Install with pnpm:

pnpm add @gzteacher/auth

Usage

使用 Auth.Provider 组件包裹以使用权限相关组件。

// index.tsx
import { useState, useEffect } from "react";
import { Auth } from "@gzteacher/auth";

function Layout() {
  const [auth, setAuth] = useState();

  const getAuth = async () => {
    const auth = await getAuth();
    console.log(auth);
    // {
    //    "user.watch": true,
    //    "user.edit": true,
    // }
    setAuth(auth);
  };

  useEffect(() => {
    getAuth();
  }, []);

  return (
    <Auth.Provider auth={auth}>
      <Auth.Wrapper authCode="user.watch">查看</Auth.Wrapper>
      <Auth.Button authCode="user.edit">编辑</Auth.Button>
    </Auth.Provider>
  );
}
ice2.js 中使用
// app.tsx
import { IAppConfig, runApp, useAuth } from "ice";
import { Auth } from "@gzteacher/auth";

const appConfig: IAppConfig = {
  // ...
  app: {
    // ...
    getInitialData: async () => {
      const auth = await getAuth();
      return {
        auth,
      };
    },
    addProvider: ({ children }) => {
      const [auth] = useAuth();
      return <Auth.Provider auth={auth}>{children}</Auth.Provider>;
    },
  },
};

runApp(appConfig);

LICENSE

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.