Prechádzať zdrojové kódy

refactor(api):重构权限管理与API调用- 移除多个模块中重复的getUserByPhone和getDetail API定义
- 在homeEntry模块中统一实现用户和门店信息获取接口
- 新增权限判断工具函数usePermission
-优化各页面中的按钮显示逻辑,增加权限控制
- 调整表格初始化参数获取方式,支持从本地存储读取storeId和groupType- 更新ProTable组件空状态样式
- 完善商家入驻状态检查逻辑

congxuesong 1 mesiac pred
rodič
commit
044016060a

+ 0 - 6
src/api/modules/couponManagement.ts

@@ -17,12 +17,6 @@ export const updateNum = params => {
 export const saveDraft = params => {
   return http.post(PORT_NONE + `/PcGroupBuy/saveDraft`, params);
 };
-export const getUserByPhone = params => {
-  return http.get(PORT_NONE + `/store/user/getUserByPhone`, params);
-};
-export const getDetail = params => {
-  return http.get(PORT_NONE + `/store/info/getDetail`, params);
-};
 export const getMenuByStoreId = params => {
   return http.get(PORT_NONE + `/menuPlatform/getMenuByStoreId`, params);
 };

+ 0 - 6
src/api/modules/groupPackageManagement.ts

@@ -29,9 +29,3 @@ export const getHolidayList = (params: any) => {
 export const getThaliById = params => {
   return http.get(PORT_NONE + `/PcGroupBuy/getThaliById`, params);
 };
-export const getUserByPhone = params => {
-  return http.get(PORT_NONE + `/store/user/getUserByPhone`, params);
-};
-export const getDetail = params => {
-  return http.get(PORT_NONE + `/store/info/getDetail`, params);
-};

+ 6 - 0
src/api/modules/homeEntry.ts

@@ -21,3 +21,9 @@ export const getMerchantByPhone = params => {
 export const getNoticeList = params => {
   return http.get<StoreUser.ResStoreUserList>(PORT_NONE + `/notice/getNoticeList`, params);
 };
+export const getUserByPhone = params => {
+  return http.get(PORT_NONE + `/merchantUser/getMerchantByPhone`, params);
+};
+export const getDetail = params => {
+  return http.get(PORT_NONE + `/storeManage/getStoreDetail`, params);
+};

+ 0 - 6
src/api/modules/orderManagement.ts

@@ -20,12 +20,6 @@ export const xgkc = params => {
 export const saveDraft = params => {
   return http.post(PORT_NONE + `/PcGroupBuy/saveDraft`, params);
 };
-export const getUserByPhone = params => {
-  return http.get(PORT_NONE + `/store/user/getUserByPhone`, params);
-};
-export const getDetail = params => {
-  return http.get(PORT_NONE + `/store/info/getDetail`, params);
-};
 export const getMenuByStoreId = params => {
   return http.get(PORT_NONE + `/menuPlatform/getMenuByStoreId`, params);
 };

+ 0 - 3
src/api/modules/voucherManagement.ts

@@ -17,9 +17,6 @@ export const updateNum = params => {
 export const saveDraft = params => {
   return http.post(PORT_NONE + `/PcGroupBuy/saveDraft`, params);
 };
-export const getUserByPhone = params => {
-  return http.get(PORT_NONE + `/store/user/getUserByPhone`, params);
-};
 export const getVoucherDetail = params => {
   return http.get(PORT_NONE + `/store/info/getDetail`, params);
 };

BIN
src/assets/images/notData.png


+ 2 - 2
src/components/ProTable/index.vue

@@ -82,8 +82,8 @@
       <template #empty>
         <div class="table-empty">
           <slot name="empty">
-            <img src="@/assets/images/notData.png" alt="notData" />
-            <div>暂无数据</div>
+            <img src="@/assets/images/notData.png" alt="notData" style=" width: 180px;height: 180px" />
+            <div style=" font-size: 14px;font-weight: 500; color: #aaaaaa">暂无数据</div>
           </slot>
         </div>
       </template>

+ 3 - 0
src/utils/index.ts

@@ -340,3 +340,6 @@ export function findItemNested(enumData: any, callValue: any, value: string, chi
     if (current[children]) return findItemNested(current[children], callValue, value, children);
   }, null);
 }
+
+// 导出权限判断相关函数
+export { usePermission } from "./permission";

+ 39 - 0
src/utils/permission.ts

@@ -0,0 +1,39 @@
+import { localGet, localSet } from "@/utils/index";
+import { ElMessage } from "element-plus";
+import { getUserByPhone, getDetail } from "@/api/modules/homeEntry";
+
+/**
+ * @description 判断是否有操作权限
+ * @returns {Boolean} 是否有权限
+ */
+export async function usePermission(str) {
+  let type = true;
+  if (!localGet("createdId")) {
+    let params = {
+      phone: localGet("iphone") || "18641153170"
+    };
+    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;
+      ElMessage.warning(`请完成商家入驻后再进行${str}`);
+      return type;
+    }
+    if (!localGet("businessSection")) {
+      type = false;
+      ElMessage.warning(`请完成商家入驻后重新登录再进行${str}`);
+      return type;
+    }
+  }
+  return type;
+}

+ 7 - 6
src/views/couponManagement/index.vue

@@ -4,7 +4,7 @@
       <!-- 表格 header 按钮 -->
       <template #tableHeader="scope">
         <div class="table-header-btn">
-          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying"> 新建优惠券 </el-button>
+          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying" v-if="type"> 新建优惠券 </el-button>
           <el-tabs v-if="showTabs" v-model="activeName" class="tabs" @tab-click="handleClick">
             <el-tab-pane v-for="tab in filteredTabOptions" :key="tab.name" :label="tab.label" :name="tab.name" />
           </el-tabs>
@@ -94,7 +94,7 @@ import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
 import { Plus } from "@element-plus/icons-vue";
 import { getThaliList, updateStatus, updateNum, delThaliById } from "@/api/modules/couponManagement";
 import { ElMessageBox } from "element-plus/es";
-import { localGet } from "@/utils";
+import { localGet, usePermission } from "@/utils";
 
 const router = useRouter();
 const dialogFormVisible = ref(false);
@@ -240,13 +240,14 @@ watch(
 );
 // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
 const initParam = reactive({
-  storeId: "104",
-  groupType: "1",
+  storeId: localGet("createdId") || "",
+  groupType: localGet("businessSection") || "1",
   status: activeName
 });
-
+const type = ref(false);
 // 页面加载时触发查询
-onMounted(() => {
+onMounted(async () => {
+  type.value = await usePermission("新建优惠券");
   proTable.value?.getTableList();
 });
 

+ 0 - 25
src/views/couponManagement/newCoupon.vue

@@ -329,31 +329,6 @@ watch(
 onMounted(async () => {
   id.value = (route.query.id as string) || "";
   type.value = (route.query.type as string) || "";
-  // 不要删除-开始
-  // let param = {
-  //   // phone: localGet("iphone")
-  //   phone: "18641153170"
-  // };
-  // const resP: any = await getUserByPhone(param);
-  // if (resP.data && resP.data.storeId) {
-  //   localSet("createdId", resP.data.storeId);
-  //   const resD: any = await getDetail({
-  //     id: localGet("createdId")
-  //   });
-  //   if (resD.data && resD.data.commissionRate) {
-  //     localSet("commissionRate", resD.data.commissionRate);
-  //   }
-  //   if (resD.data && resD.data.businessSection) {
-  //     localSet("businessSection", resD.data.businessSection);
-  //   }
-  // } else {
-  //   ElMessage.warning("请完成商家入驻后再进行新建团购");
-  // }
-  // if (!getGroupCombination()) {
-  //   ElMessage.warning("请完成商家入驻后重新登录再进行新建团购");
-  //   return;
-  // }
-  // 不要删除-结束
   if (type.value != "add") {
     // TODO: 加载优惠券详情数据
     // let res: any = await getCouponDetail({ id: id.value });

+ 9 - 6
src/views/groupPackageManagement/index.vue

@@ -4,7 +4,7 @@
       <!-- 表格 header 按钮 -->
       <template #tableHeader="scope">
         <div class="table-header-btn">
-          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying"> 新建团购 </el-button>
+          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying" v-if="type"> 新建团购 </el-button>
           <el-tabs v-if="showTabs" v-model="activeName" class="tabs" @tab-click="handleClick">
             <el-tab-pane v-for="tab in filteredTabOptions" :key="tab.name" :label="tab.label" :name="tab.name" />
           </el-tabs>
@@ -149,8 +149,7 @@ import ProTable from "@/components/ProTable/index.vue";
 import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
 import { Plus } from "@element-plus/icons-vue";
 import { delThaliById, getThaliList, updateStatus, updateNum } from "@/api/modules/groupPackageManagement";
-import { localGet } from "@/utils";
-
+import { localGet, usePermission } from "@/utils";
 const router = useRouter();
 const dialogFormVisible = ref(false);
 const formInventory: any = ref({
@@ -359,12 +358,14 @@ watch(
 );
 // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
 const initParam = reactive({
-  storeId: localGet("createdId") || "104",
+  storeId: localGet("createdId") || "",
   groupType: localGet("businessSection") || "1",
   status: activeName
 });
+const type = ref(false);
 // 页面加载时触发查询
-onMounted(() => {
+onMounted(async () => {
+  type.value = await usePermission("新建团购");
   proTable.value?.getTableList();
 });
 
@@ -487,8 +488,10 @@ const closeRejectReasonDialog = () => {
   white-space: normal; // 允许自然换行
 }
 .table-header-btn {
+  .button {
+    margin-bottom: 10px;
+  }
   .tabs {
-    margin-top: 10px;
     :deep(.el-tabs__nav-wrap::after) {
       height: 0;
     }

+ 7 - 4
src/views/orderManagement/index.vue

@@ -37,6 +37,7 @@ import { useRouter } from "vue-router";
 import ProTable from "@/components/ProTable/index.vue";
 import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
 import { getThaliList, getCpList } from "@/api/modules/orderManagement";
+import { localGet, usePermission } from "@/utils";
 
 const router = useRouter();
 const proTable = ref<ProTableInstance>();
@@ -147,14 +148,16 @@ const columns = reactive<ColumnProps<any>[]>([
   { prop: "operation", label: "操作", fixed: "right", width: 200 }
 ]);
 
-// 初始化请求参数
+// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
 const initParam = reactive({
-  storeId: "104",
+  storeId: localGet("createdId") || "",
+  groupType: localGet("businessSection") || "1",
   status: activeName
 });
-
+const type = ref(false);
 // 页面加载时触发查询
-onMounted(() => {
+onMounted(async () => {
+  type.value = await usePermission("查看订单");
   proTable.value?.getTableList();
 });
 

+ 7 - 6
src/views/voucherManagement/index.vue

@@ -4,7 +4,7 @@
       <!-- 表格 header 按钮 -->
       <template #tableHeader="scope">
         <div class="table-header-btn">
-          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying"> 新建代金券 </el-button>
+          <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying" v-if="type"> 新建代金券 </el-button>
           <el-tabs v-if="showTabs" v-model="activeName" class="tabs" @tab-click="handleClick">
             <el-tab-pane v-for="tab in filteredTabOptions" :key="tab.name" :label="tab.label" :name="tab.name" />
           </el-tabs>
@@ -98,7 +98,7 @@ import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
 import { Plus } from "@element-plus/icons-vue";
 import { delThaliById, getThaliList, updateStatus, updateNum } from "@/api/modules/voucherManagement";
 import { ElMessageBox } from "element-plus/es";
-import { localGet } from "@/utils";
+import { localGet, usePermission } from "@/utils";
 
 const router = useRouter();
 const dialogFormVisible = ref(false);
@@ -272,13 +272,14 @@ watch(
 );
 // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
 const initParam = reactive({
-  storeId: "104",
-  groupType: "1",
+  storeId: localGet("createdId") || "",
+  groupType: localGet("businessSection") || "1",
   status: activeName
 });
-
+const type = ref(false);
 // 页面加载时触发查询
-onMounted(() => {
+onMounted(async () => {
+  type.value = await usePermission("新建代金券");
   proTable.value?.getTableList();
 });