UNPKG

4.04 kBMarkdownView Raw
1<h1 align="center">Buession Shiro</h1>
2<div align="center">
3 <p align="center">Typescript 或者 JavaScript 的权限验证库</p>
4 <a href="https://codecov.io/github/buession/buession-shirojs?branch=master">
5 <img src="https://img.shields.io/codecov/c/github/buession/buession-shirojs?token=tp73oo63nf" alt="Coverage Status" />
6 </a>
7 <a href="https://github.com/buession/buession-shirojs/actions/workflows/codecov.yml">
8 <img src="https://github.com/buession/buession-shirojs/actions/workflows/codecov.yml/badge.svg" alt="Codecov" />
9 </a>
10 <a href="https://github.com/buession/buession-shirojs/actions/workflows/codeql-analysis.yml">
11 <img src="https://github.com/buession/buession-shirojs/actions/workflows/codeql-analysis.yml/badge.svg" alt="CodeQL" />
12 </a>
13 <a href="https://www.npmjs.com/package/@buession/shiro">
14 <img src="https://img.shields.io/bundlephobia/minzip/@buession/shiro/latest" alt="Size" />
15 </a>
16 <a href="https://www.npmjs.com/package/@buession/shiro">
17 <img src="https://img.shields.io/npm/v/@buession/shiro" alt="Version" />
18 </a>
19 <a href="https://www.npmjs.com/package/@buession/shiro">
20 <img src="https://img.shields.io/github/languages/top/buession/buession-shirojs" alt="Languages" />
21 </a>
22 <a href="https://www.npmjs.com/package/@buession/shiro">
23 <img src="https://img.shields.io/npm/l/@buession/shiro" alt="License" />
24 </a>
25 <a href="https://github.com/buession/buession-shirojs/stargazers">
26 <img src="https://img.shields.io/github/stars/buession/buession-shirojs" alt="Star" />
27 </a>
28 <a href="https://www.npmjs.com/package/@buession/shiro">
29 <img src="https://img.shields.io/npm/dm/@buession/shiro" alt="Download" />
30 </a>
31 <a href="https://www.npmjs.com/package/@buession/shiro">
32 <img src="https://img.shields.io/snyk/vulnerabilities/npm/@buession/shiro" alt="Vulnerabilities" />
33 </a>
34</div>
35
36## 为什么选择 Buession Shiro
37
38在前后端分离项目中(如:Vue、Angular、React等),前端常常涉及到根据权限显示数据、操作等等重复的实现所困惑。每当开启一个新项目时,我们都得手动重复去编写这些代码,而且还难免代码逻辑不一致,质量参差不齐。
39
40Buession ShiroJs 旨在提供便捷的、统一的、可靠的权限前端权限验证功能。在业务开发中省去的那些“脏活累活”,专注于业务核心的开发。
41
42Buession ShiroJs 的核心思想参考 [Apache Shiro](http://shiro.apache.org/) 。
43
44## 安装
45
46您可以通过 [NPM](https://www.npmjs.com/)、[YARN](https://yarnpkg.com/) 或者通过 `<script>` 的方式引入 [unpkg.com](https://unpkg.com/) 上的包。
47
48### NPM
49
50```sh
51npm install @buession/shiro
52# or
53yarn add @buession/shiro
54```
55
56### CDN
57
58> 对于生产环境,我们推荐链接到一个明确的版本号和构建文件,以避免新版本造成的不可预期的破坏。
59
60```html
61最新版:<script src="https://unpkg.com/@buession/shiro/dist/shiro.min.js" type="text/javascript"></script>
62具体版本:<script src="https://unpkg.com/@buession/shiro@版本/dist/shiro.min.js" type="text/javascript"></script>
63```
64
65## 示例
66
67```vue
68<template>
69 <div>
70 <div v-if="shiro.hasRole('admin')">Admin</div>
71 <div v-if="shiro.hasPermission('user:edit')">Edit</div>
72 <div v-if="shiro.hasPermissions(['user:add', 'user:edit'])">Action</div>
73 </div>
74</template>
75
76<script lang="ts">
77import { defineComponent } from 'vue';
78export default defineComponent({
79 setup() {
80 }
81});
82</script>
83```
84
85
86```javascript
87<script type="text/javascript">
88 function Principal(){
89 this.id = '1';
90 }
91
92 Principal.prototype.getId = function(){
93 return this.id;
94 }
95
96 Principal.prototype.getRoles = function(){
97 return ["admin", "admin1"];
98 }
99
100 Principal.prototype.getPermissions = function(){
101 return ["user:add", "user:edit"];
102 }
103
104 var shiro = new Shiro(new Principal());
105 if (shiro.hasRole("admin")) {
106
107 }
108</script>
109```
110
111## License
112
113[MIT License](https://github.com/buession/buession-shirojs/blob/master/LICENSE) © 2020-2023
\No newline at end of file