permission.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { localGet, localSet } from "@/utils/index";
  2. import { ElMessage } from "element-plus";
  3. import { getUserByPhone, getDetail } from "@/api/modules/homeEntry";
  4. /**
  5. * @description 判断是否有操作权限
  6. * @returns {Boolean} 是否有权限
  7. */
  8. export async function usePermission(tip?: string) {
  9. let type = true;
  10. if (!localGet("createdId")) {
  11. let params = {
  12. phone: localGet("iphone") || "18641153170"
  13. };
  14. const res: any = await getUserByPhone(params);
  15. if (res.data && res.data.storeId) {
  16. localSet("createdId", res.data.storeId);
  17. const resD: any = await getDetail({
  18. id: res.data.storeId
  19. });
  20. if (resD.data && resD.data.commissionRate) {
  21. localSet("commissionRate", resD.data.commissionRate);
  22. }
  23. if (resD.data && resD.data.businessSection) {
  24. localSet("businessSection", resD.data.businessSection);
  25. }
  26. } else {
  27. type = false;
  28. if (tip) {
  29. ElMessage.warning(`请完成商家入驻后再进行${tip}`);
  30. }
  31. return type;
  32. }
  33. if (!localGet("businessSection")) {
  34. type = false;
  35. if (tip) {
  36. ElMessage.warning(`请完成商家入驻后重新登录再进行${tip}`);
  37. }
  38. return type;
  39. }
  40. }
  41. return type;
  42. }