matrix_components 2.0.462 → 2.0.464

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +98 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,9 +6,8 @@ Matrix Components 是一个功能丰富的 Vue 3 企业级组件库,提供办
6
6
 
7
7
  组件使用示例参考 `dist/ComponentDemo`
8
8
 
9
- ## 📸 组件预览
9
+ ## 📸 部分组件预览
10
10
 
11
- 以下是组件库的架构和功能概览图:
12
11
  ### NsVideo:
13
12
  ![组件库架构](https://tc-cdn.processon.com/po/605c2da663768970077b1422-695db61dbffe264705f9b033)
14
13
 
@@ -859,16 +858,109 @@ const scaleY = sacle_y()
859
858
  import { createApp } from 'vue'
860
859
 
861
860
  const app = createApp(App)
862
- const btnsPermission = {
863
- 'zuhu_list_add': true, // 有权限
864
- 'zuhu_list_edit': false // 无权限
865
- }
866
861
 
862
+ // 方式1:使用 provide/inject
863
+ const btnsPermission = ['zuhu_list_add', 'zuhu_list_edit', 'admin-btn']
867
864
  app.provide('btnsPermission', btnsPermission)
865
+
866
+ // 方式2:使用全局属性
867
+ app.config.globalProperties.$btnsPermission = ['zuhu_list_add', 'zuhu_list_edit']
868
+
869
+ // 方式3:使用 sessionStorage(适用于动态权限)(推荐)
870
+ sessionStorage.setItem('btnsPermission', JSON.stringify(['zuhu_list_add', 'zuhu_list_edit']))
871
+
872
+ // 方式4:使用 localStorage(持久化权限)
873
+ localStorage.setItem('btnsPermission', JSON.stringify(['zuhu_list_add', 'zuhu_list_edit']))
874
+
868
875
  app.use(NsComponents) // 引入组件库
869
876
  </script>
870
877
  ```
871
878
 
879
+ #### 权限控制优先级说明
880
+
881
+ 权限控制按以下优先级进行判断(从高到低):
882
+
883
+ 1. **sessionStorage** → `sessionStorage.getItem('btnsPermission')`
884
+ 2. **localStorage** → `localStorage.getItem('btnsPermission')`
885
+ 3. **全局属性** → `app.config.globalProperties.$btnsPermission`
886
+ 4. **provide/inject** → `app.provide('btnsPermission', btnsPermission)`
887
+
888
+ #### 指令修饰符说明
889
+
890
+ - **v-permission** - 默认模式,使用 `id` 选择器,无权限时设置 `visibility: hidden`
891
+ - **v-permission.id** - 显式指定使用 `id` 选择器
892
+ - **v-permission.class** - 使用 `class` 选择器
893
+ - **v-permission.id.display** - 使用 `id` 选择器,无权限时设置 `display: none`
894
+ - **v-permission.class.display** - 使用 `class` 选择器,无权限时设置 `display: none`
895
+
896
+ #### 动态权限切换示例
897
+
898
+ ```javascript
899
+ // 动态切换权限
900
+ function togglePermission() {
901
+ // 获取当前权限列表
902
+ let btnsPermission = JSON.parse(sessionStorage.getItem('btnsPermission')) || []
903
+
904
+ // 添加新权限
905
+ if (!btnsPermission.includes('delete_btn')) {
906
+ btnsPermission.push('delete_btn')
907
+ } else {
908
+ // 移除权限
909
+ btnsPermission = btnsPermission.filter(item => item !== 'delete_btn')
910
+ }
911
+
912
+ // 更新权限存储
913
+ sessionStorage.setItem('btnsPermission', JSON.stringify(btnsPermission))
914
+
915
+ // 刷新页面或重新渲染组件
916
+ location.reload() // 或使用响应式更新
917
+ }
918
+ ```
919
+
920
+ #### 实际应用场景
921
+
922
+ ```vue
923
+ <template>
924
+ <!-- 按钮组权限控制 -->
925
+ <div class="toolbar">
926
+ <el-button id="add_btn" v-permission type="primary">添加</el-button>
927
+ <el-button id="edit_btn" v-permission type="success">编辑</el-button>
928
+ <el-button id="delete_btn" v-permission type="danger">删除</el-button>
929
+ <el-button id="export_btn" v-permission.id.display type="warning">导出</el-button>
930
+ <el-button class="admin-btn" v-permission.class type="info">管理员</el-button>
931
+ </div>
932
+
933
+ <!-- 菜单权限控制 -->
934
+ <el-menu>
935
+ <el-menu-item index="1" id="dashboard_menu" v-permission>
936
+ <span>仪表盘</span>
937
+ </el-menu-item>
938
+ <el-menu-item index="2" class="user-menu" v-permission.class>
939
+ <span>用户管理</span>
940
+ </el-menu-item>
941
+ </el-menu>
942
+ </template>
943
+
944
+ <script setup>
945
+ // 权限配置示例
946
+ const app = createApp(App)
947
+
948
+ // 实际项目中,权限数据通常从后端获取
949
+ const userPermissions = {
950
+ // 普通用户权限
951
+ normal: ['add_btn', 'edit_btn', 'dashboard_menu'],
952
+ // 管理员权限
953
+ admin: ['add_btn', 'edit_btn', 'delete_btn', 'export_btn', 'admin-btn', 'user-menu']
954
+ }
955
+
956
+ // 根据用户角色设置权限
957
+ const userRole = 'admin' // 从登录信息获取
958
+ app.provide('btnsPermission', userPermissions[userRole])
959
+
960
+ app.use(NsComponents)
961
+ </script>
962
+ ```
963
+
872
964
  ### 2. v-length - 输入长度限制
873
965
 
874
966
  ```vue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matrix_components",
3
- "version": "2.0.462",
3
+ "version": "2.0.464",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [