소스 검색

fix(ticket): 修复新建券权限判断逻辑

- 统一使用 type 权限控制新建代金券和优惠券按钮显示
- 修改权限判断条件,确保商家入驻状态正确校验
- 优化初始化参数默认值处理,避免空值异常
- 移除重复的权限获取逻辑,提升代码可读性
- 调整提示文案,统一为“新建券”操作指引
congxuesong 3 주 전
부모
커밋
b92ec58a3b
2개의 변경된 파일37개의 추가작업 그리고 33개의 파일을 삭제
  1. 32 28
      src/utils/permission.ts
  2. 5 5
      src/views/ticketManagement/index.vue

+ 32 - 28
src/utils/permission.ts

@@ -8,36 +8,40 @@ import { getUserByPhone, getDetail } from "@/api/modules/homeEntry";
  */
 export async function usePermission(tip?: string) {
   let type = true;
-  if (!localGet("createdId") && !localGet("geeker-user").userInfo.storeId) {
-    let params = {
-      phone: localGet("iphone") || localGet("geeker-user").userInfo.phone
-    };
-    const res: any = await getUserByPhone(params);
-    if (res.data && res.data.storeId) {
-      localSet("createdId", res.data.storeId);
-      const resD: any = await getDetail({
-        id: res.data.storeId
-      });
-      if (resD.data && resD.data.commissionRate) {
-        localSet("commissionRate", resD.data.commissionRate);
-      }
-      if (resD.data && resD.data.businessSection) {
-        localSet("businessSection", resD.data.businessSection);
-      }
-    } else {
-      type = false;
-      if (tip) {
-        ElMessage.warning(`请完成商家入驻后再进行${tip}`);
-      }
-      return type;
+  // if (localGet("createdId") || localGet("geeker-user").userInfo.storeId) {
+  //   //   return type;
+  //   // }
+  let params = {
+    phone: localGet("iphone") || localGet("geeker-user").userInfo.phone
+  };
+  const res: any = await getUserByPhone(params);
+  if (res.data && res.data.storeId) {
+    localSet("createdId", res.data.storeId);
+    const resD: any = await getDetail({
+      id: res.data.storeId
+    });
+    if (resD.data && resD.data.storeApplicationStatus != 1) {
+      return false;
     }
-    if (!localGet("businessSection") && !localGet("geeker-user").userInfo.businessSection) {
-      type = false;
-      if (tip) {
-        ElMessage.warning(`请完成商家入驻后重新登录再进行${tip}`);
-      }
-      return type;
+    if (resD.data && resD.data.commissionRate) {
+      localSet("commissionRate", resD.data.commissionRate);
     }
+    if (resD.data && resD.data.businessSection) {
+      localSet("businessSection", resD.data.businessSection);
+    }
+  } else {
+    type = false;
+    if (tip) {
+      ElMessage.warning(`请完成商家入驻后再进行${tip}`);
+    }
+    return type;
+  }
+  if (!localGet("businessSection") && !localGet("geeker-user").userInfo.businessSection) {
+    type = false;
+    if (tip) {
+      ElMessage.warning(`请完成商家入驻后重新登录再进行${tip}`);
+    }
+    return type;
   }
   return type;
 }

+ 5 - 5
src/views/ticketManagement/index.vue

@@ -21,7 +21,7 @@
       <template #tableHeaderRight="scope">
         <div class="action-buttons">
           <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying" v-if="type"> 新建代金券 </el-button>
-          <el-button :icon="Plus" class="button" type="primary" @click="newCoupon" v-if="typeCoupon"> 新建优惠券 </el-button>
+          <el-button :icon="Plus" class="button" type="primary" @click="newCoupon" v-if="type"> 新建优惠券 </el-button>
         </div>
       </template>
       <template #status="scope">
@@ -436,8 +436,8 @@ const getStatusLabel = (status: any) => {
 
 // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
 const initParam = reactive({
-  storeId: localGet("createdId"),
-  groupType: localGet("businessSection"),
+  storeId: localGet("createdId") || "",
+  groupType: localGet("businessSection") || "1",
   couponType: activeName
 });
 const type = ref(false);
@@ -454,8 +454,8 @@ const restoreActiveName = () => {
 
 // 页面加载时触发查询
 onMounted(async () => {
-  type.value = await usePermission("新建代金券");
-  typeCoupon.value = await usePermission("新建优惠券");
+  type.value = await usePermission("新建券");
+  // typeCoupon.value = await usePermission("新建优惠券");
   // 从 sessionStorage 恢复 activeName
   restoreActiveName();
   proTable.value?.getTableList();