refactor权限控制逻辑

- 移除全局方法getUserBtnRole
- 使用hasPermission函数替代checkBtnPermission
- 优化权限判断逻辑,减少冗余代码
- 统一权限控制的实现方式
This commit is contained in:
郑彪辉
2025-04-26 09:50:55 +08:00
parent 07ac63b5bb
commit 69af422128
28 changed files with 238 additions and 239 deletions

View File

@@ -8,7 +8,7 @@
</u-form-item>
</view>
</u-form>
<view class="w-full footer">
<view v-if="hasPermission('erp_product_unit_add')" class="w-full footer">
<view class="py-[var(--top-m)] px-[var(--sidebar-m)] footer w-full fixed bottom-0 left-0 right-0 box-border">
<button hover-class="none" class="!bg-[var(--primary-color)] text-[#fff] h-[80rpx] leading-[80rpx] rounded-[100rpx] text-[26rpx] font-500"
@click="handSave" :disabled="loading" :class="{'opacity-50': loading}">{{t('save')}}</button>
@@ -28,9 +28,9 @@
import { onLoad } from '@dcloudio/uni-app';
import { getProductUnitInfo, addProductUnit, editProductUnit } from '@/addon/erp/api/product';
import { redirect } from '@/utils/common';
import { checkBtnPermission } from '@/utils/auth';
import useMemberStore from '@/stores/member'
import usePermission from '@/utils/usePermission'
const { hasPermission } = usePermission()
const memberStore = useMemberStore()
const formRef: any = ref(null)
@@ -71,8 +71,6 @@
// 保存
const handSave = async() => {
const hasPermission = await checkBtnPermission(memberStore.btnPermission, 'erp_product_unit_add')
if (!hasPermission) return
formRef.value.validate().then(() => {
if (loading.value) return
loading.value = true