fix list style
This commit is contained in:
@@ -2,7 +2,8 @@ import { Toast } from "tdesign-mobile-vue";
|
||||
import { useUserStore } from "timi-web";
|
||||
import StoreAPI from "@/api/StoreAPI";
|
||||
import type { Store } from "@/types/Store";
|
||||
import { getCurrentStoreId, readStoredCurrentStoreId, setCurrentStoreId } from "@/utils/store";
|
||||
import { gaoRoleCodes } from "@/utils/permission";
|
||||
import { getCurrentStoreId, readStoredCurrentStoreId, setCurrentStoreId, setLoginStoreId } from "@/utils/store";
|
||||
|
||||
export const useCurrentStoreStore = defineStore("currentStore", () => {
|
||||
const userStore = useUserStore();
|
||||
@@ -11,7 +12,7 @@ export const useCurrentStoreStore = defineStore("currentStore", () => {
|
||||
const loginStore = ref<Store>();
|
||||
const loginStoreUserId = ref("");
|
||||
const isLoading = ref(false);
|
||||
let loginStoreRequest: Promise<Store> | undefined;
|
||||
let loginStoreRequest: Promise<Store | undefined> | undefined;
|
||||
let loginStoreRequestUserId = "";
|
||||
|
||||
const currentStore = computed(() => storeList.value.find(item => item.id === currentStoreId.value));
|
||||
@@ -44,9 +45,9 @@ export const useCurrentStoreStore = defineStore("currentStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLoginStore(): Promise<Store> {
|
||||
async function loadLoginStore(): Promise<Store | undefined> {
|
||||
const loginUserId = userStore.loginUser.user?.id || userStore.loginUser.id || "";
|
||||
if (loginStore.value?.id && loginStoreUserId.value === loginUserId) {
|
||||
if (loginStoreUserId.value === loginUserId && loginUserId) {
|
||||
return loginStore.value;
|
||||
}
|
||||
|
||||
@@ -64,16 +65,39 @@ export const useCurrentStoreStore = defineStore("currentStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLoginStoreRequest(loginUserId: string): Promise<Store> {
|
||||
async function loadLoginStoreRequest(loginUserId: string): Promise<Store | undefined> {
|
||||
const result = await StoreAPI.loginStore();
|
||||
loginStore.value = result;
|
||||
loginStoreUserId.value = loginUserId;
|
||||
if (!result?.id) {
|
||||
loginStore.value = undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
loginStore.value = result;
|
||||
if (result.id) {
|
||||
setLoginStoreId(result.id);
|
||||
selectStore(result.id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async function loadAfterLogin(): Promise<void> {
|
||||
const isGlobalManager = userStore.hasRoles(gaoRoleCodes.globalManager);
|
||||
const hasStoreRole = userStore.hasRoles([gaoRoleCodes.storeManager, gaoRoleCodes.employee], "or");
|
||||
if (!isGlobalManager && !hasStoreRole) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await loadLoginStore();
|
||||
} catch {
|
||||
Toast.error("登录门店加载失败");
|
||||
}
|
||||
if (isGlobalManager) {
|
||||
await loadStoreList();
|
||||
}
|
||||
}
|
||||
|
||||
function selectStore(storeId: string): void {
|
||||
if (!storeId) {
|
||||
return;
|
||||
@@ -105,6 +129,7 @@ export const useCurrentStoreStore = defineStore("currentStore", () => {
|
||||
isLoading,
|
||||
loadStoreList,
|
||||
loadLoginStore,
|
||||
loadAfterLogin,
|
||||
selectStore
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user