From 55bf797dcc730b37bc691ebab2b51ff9db8ed245 Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周二, 06 5月 2025 17:37:23 +0800
Subject: [PATCH] 修改代码样式

---
 HIAWms/web/src/libs/Permission/Permission.ts |   77 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/HIAWms/web/src/libs/Permission/Permission.ts b/HIAWms/web/src/libs/Permission/Permission.ts
index 98ca98d..9417df6 100644
--- a/HIAWms/web/src/libs/Permission/Permission.ts
+++ b/HIAWms/web/src/libs/Permission/Permission.ts
@@ -10,6 +10,11 @@
 import { ElMessage } from 'element-plus'
 import sdk from 'sdk'
 import { Permission, UserInfo, Props } from './Permission.d'
+import { useGlobalState } from '../Store/Store'
+
+import { get } from 'lodash'
+import { editionMap } from '../enum'
+import { _t } from '../Language/Language'
 
 /**
  * 寮�鍙戠幆澧�
@@ -24,17 +29,19 @@
  */
 const permissionCodes = ref<string[]>([])
 
+const featureMap = ref<Record<string, any>>({})
+
 /**
  * 鏍¢獙鏉冮檺锛屽彂鍑鸿鍛�
  * @param code
  * @returns
  */
-const isPermission = (
+export const isPermission = (
   code: (typeof subsPermissions)[number]['id'],
   isHint = true
 ) => {
   if (!permissionCodes.value.includes(code)) {
-    isHint && ElMessage.warning('鐢ㄦ埛娌℃湁璇ユ潈闄愶紒')
+    isHint && ElMessage.warning(_t('鐢ㄦ埛娌℃湁璇ユ潈闄愶紒'))
     return false
   }
   return true
@@ -73,6 +80,52 @@
   })
 }
 
+export const vEditionShow: { [key: string]: Directive } = {
+  updated(el: HTMLElement, binding: DirectiveBinding<any>) {
+    if (el) {
+      const state: Record<string, any> = useGlobalState()
+      const l = Object.keys(state.featureMap.state.value)?.length
+      const featureKeys = binding.value
+        .split(',')
+        .filter((v) => v)
+        .map((v: string) => {
+          return editionMap[v]
+        })
+      if (!isEdition(featureKeys) && l) {
+        el.remove()
+      }
+    }
+  },
+}
+
+/**
+ * 鍒ゆ柇鏄惁鏈夎鍔熻兘
+ * @param feature
+ * @returns
+ */
+export const isEdition = (features: string[], condition = true) => {
+  const state: Record<string, any> = useGlobalState()
+  const l = Object.keys(state.featureMap.state.value)?.length
+  if (l) {
+    features = features.filter((v) => v)
+    if (features.length === 0) return true
+    let newFeatures = features
+    if (features[0].length < 3) {
+      newFeatures = features.map((v) => {
+        return editionMap[v]
+      })
+    }
+
+    if (!Object.keys(featureMap.value).length) {
+      featureMap.value = state.featureMap.state.value
+    }
+    const check = newFeatures.every((key: string) => {
+      return featureMap?.value?.[key]?.value
+    })
+    return check && condition
+  }
+}
+
 /**
  * 鍒濆鍖栨潈闄�
  * @param props
@@ -89,13 +142,17 @@
   permissionCodes.value = []
   setPermissions(permissionMap)
   const node = computed(() => props.node || {})
+  const children = get(
+    window.app.current.project?.current.page,
+    'body.children',
+    []
+  )
 
   const page = isDev
     ? {
         permissions: [],
       }
-    : // @ts-ignore
-      window.app.current.project?.current.page
+    : window.app.current.project?.current.page
   const permission = {
     id: node.value?.id,
     name: node.value?.name,
@@ -103,6 +160,10 @@
   }
 
   page.permissions = page.permissions || []
+  const childrenIds = children.map((item: any) => item.id)
+  page.permissions = page.permissions.filter((item: any) =>
+    childrenIds.includes(item.id)
+  )
 
   if (
     page.permissions.every(
@@ -111,6 +172,14 @@
   ) {
     page.permissions.push(permission)
   }
+
+  if (childrenIds.includes(permission.id)) {
+    const currentPermission = page.permissions.find(
+      (item: typeof permission) => item.id === permission.id
+    )
+    currentPermission && Object.assign(currentPermission, permission)
+  }
+
   const userInfo: UserInfo = isDev
     ? { permissions: { all: true, widgets: [] } }
     : sdk.userInfo

--
Gitblit v1.9.3