@ganwei-web/gw-base-components-plus 1.0.20 → 1.0.22

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.
@@ -0,0 +1,53 @@
1
+ import axios from 'axios'
2
+ let packageId,pluginName,routeName;
3
+ const permissionList = async function() {
4
+ try {
5
+ let params = getpermissionMap()
6
+ packageId = params.get("packageId")
7
+ pluginName = params.get("pluginName")
8
+ routeName = params.get("menuName")
9
+ if(packageId && pluginName && routeName) {
10
+ window[packageId] = {}
11
+ let objData = {packageId: packageId, routeName: '/Index/jumpIframe/' + pluginName + "/" + routeName}
12
+ axios.defaults.withCredentials = true; // 让ajax携带cookie
13
+ let result = axios({
14
+ method: 'get',
15
+ url: '/api/UserRole/getPageControlPermission',
16
+ params: objData,
17
+ data: objData,
18
+ headers: {
19
+ 'Content-Type': 'application/json;charset=UTF-8',
20
+ 'Accept-Language': window.sessionStorage.languageType || 'zh-CN'
21
+ }
22
+ })
23
+ await result.then(res => {
24
+ if(res && res.data) {
25
+ let dt = res.data.data
26
+ window[packageId][routeName] = (Array.isArray(dt) && dt.length > 0) ? dt : []
27
+ }
28
+
29
+ })
30
+ } else {
31
+ console.log('地址需要携带参数: packageId, pluginName, menuName');
32
+ }
33
+ } catch (error) {
34
+ console.error('获取权限列表时出错:', error);
35
+ }
36
+ };
37
+
38
+ function getpermissionMap() {
39
+ let map = new Map()
40
+ if(window.location.href.indexOf("?") == -1) return map;
41
+ let parameters = window.location.href.split("?")[1]
42
+ if (!parameters) return map
43
+ let data = parameters.indexOf("&") != -1 ? parameters.split("&") : [parameters]
44
+ for (let i = 0; i < data.length; i++) {
45
+ let arry = data[i].indexOf("=") != -1 ?data[i].split("="): [data[i],data[i]]
46
+ map.set(arry[0], arry[1])
47
+ }
48
+ return map;
49
+ }
50
+
51
+ export {permissionList ,packageId ,pluginName, routeName};
52
+
53
+
@@ -0,0 +1,15 @@
1
+ // index.ts
2
+
3
+ import { createPermissionDirective } from './permission';
4
+
5
+ const install = async function (app, packageId,routeName) {
6
+ try {
7
+ app.directive('permission', createPermissionDirective((packageId && routeName)?window[packageId][routeName]:[]));
8
+ } catch (error) {
9
+ console.error('Failed to initialize permissions:', error);
10
+ }
11
+ }
12
+
13
+ export default {
14
+ install
15
+ };
@@ -0,0 +1,10 @@
1
+ export interface auth {
2
+ add: number, edit: number, delete: number, view: number, export: number, import: number, print: number, other: number
3
+ }
4
+
5
+ export interface permission {
6
+ packageId: string,
7
+ pluginName: string,
8
+ menuName: string,
9
+ auth: string
10
+ }
@@ -0,0 +1,61 @@
1
+
2
+ /**
3
+ *
4
+ * 权限指令
5
+ * 使用: v-permission="'add'"
6
+ */
7
+
8
+ // 权限初始化
9
+ export function initHasPermission(options) {
10
+ const permissionList = options;
11
+ return (permission) => { // 内部返回function,用于判断权限
12
+ if(!Array.isArray(permissionList) || permissionList.length == 0) {
13
+ return false;
14
+ }
15
+ if (permission.auth) {
16
+ let value = permissionList.includes(permission.auth);
17
+ return value;
18
+ }
19
+ return false;
20
+ }
21
+ }
22
+
23
+ // 权限指令
24
+ export function createPermissionDirective(arry) {
25
+ return {
26
+ async mounted(el, binding) { // vue3
27
+ // 元素插入父节点时执行的逻辑
28
+ el.style.display = 'none';
29
+ const hasPermissions = initHasPermission(arry);
30
+ checkPermission(el, binding, hasPermissions);
31
+ },
32
+ // async update(el, binding) { // vue2
33
+ // // 元素插入父节点时执行的逻辑
34
+ // el.style.display = 'none';
35
+ // const hasPermissions = initHasPermission(arry);
36
+ // checkPermission(el, binding, hasPermissions);
37
+ // },
38
+ async bind(el, binding, vnode) { // vue2
39
+ // 元素插入父节点时执行的逻辑
40
+ el.style.display = 'none';
41
+ const hasPermissions = initHasPermission(arry);
42
+ checkPermission(el, binding, hasPermissions);
43
+ }
44
+ };
45
+ }
46
+
47
+ // 权限检查并执行相应操作
48
+ function checkPermission(el, binding, hasPermissions) {
49
+ setTimeout(()=>{
50
+ const {value} = binding;
51
+ if (value) {
52
+ el.style.display = '';
53
+ let options = {auth: value};
54
+ if (hasPermissions(options)) {
55
+ el.parentNode
56
+ } else {
57
+ el.parentNode && el.parentNode.removeChild(el)
58
+ }
59
+ }
60
+ },200)
61
+ }
@@ -632,12 +632,14 @@ const _sfc_main$k = /* @__PURE__ */ vue.defineComponent({
632
632
  const proxyElement = vue.ref();
633
633
  const expose = useExpose(proxyElement);
634
634
  __expose(expose);
635
+ const injectedLocale = vue.inject(elementPlus.localeContextKey, {});
636
+ const locale = vue.computed(() => attrs.locale || injectedLocale.value);
635
637
  const defaultAttrs = {
636
638
  pageSizes: [20, 50, 100],
637
639
  layout: "sizes,prev, pager, next,total"
638
640
  };
639
641
  return (_ctx, _cache) => {
640
- return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElPagination), vue.mergeProps({ ...defaultAttrs, ...vue.unref(attrs) }, {
642
+ return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElPagination), vue.mergeProps({ ...defaultAttrs, ...vue.unref(attrs), locale: locale.value }, {
641
643
  ref_key: "proxyElement",
642
644
  ref: proxyElement
643
645
  }), vue.createSlots({ _: 2 }, [