Compare commits

..

No commits in common. "9b5ab9fa9c5da5d53774dacef3c407cf30f6af7f" and "faf4284da96633a45e4eed3e4d825f9e2f482ab4" have entirely different histories.

7 changed files with 35 additions and 125 deletions

View File

@ -2,7 +2,7 @@
import dbStore from "@/store/db";
import accountStore from "@/store/account";
import { globalUnreadListenerManager } from "@/utils/global-unread-listener.js";
import { initApiContextFromAppOptions, normalizeCorpIdFields } from "@/utils/api-base-config";
import { initApiContextFromAppOptions } from "@/utils/api-base-config";
export default {
async onLaunch(options) {
@ -35,9 +35,7 @@ export default {
//
if (storedAccount) {
const normalizedAccount = normalizeCorpIdFields(storedAccount);
account.account = normalizedAccount;
uni.setStorageSync("account", normalizedAccount);
account.account = storedAccount;
}
// IM

View File

@ -31,8 +31,7 @@ import { onLoad, onShow, onShareAppMessage } from "@dcloudio/uni-app";
import useAccount from "@/store/account";
import api from "@/utils/api";
import { toast } from "@/utils/widget";
import { get, remove, set } from "@/utils/cache";
import { normalizeCorpId } from "@/utils/api-base-config";
import { get, remove } from "@/utils/cache";
import FullPage from "@/components/full-page.vue";
import articleList from "./article-list.vue";
@ -58,7 +57,6 @@ const consultRef = ref(null);
const archiveRef = ref(null);
const corpUserIds = ref({});
const referenceCustomerIds = ref({});
const HOME_CURRENT_TEAM_CACHE_KEY = "home-current-team-info";
const corpId = computed(() => team.value?.corpId);
@ -70,55 +68,23 @@ function handleCustomersUpdate(newCustomers) {
customers.value = newCustomers;
}
function getTeamIdentity(source = {}) {
return {
teamId: source.teamId || "",
corpId: normalizeCorpId(source.corpId || ""),
};
}
function cacheCurrentTeam(currentTeam) {
if (!currentTeam || !currentTeam.teamId) return;
set(HOME_CURRENT_TEAM_CACHE_KEY, getTeamIdentity(currentTeam));
}
function isSameTeam(candidate, target = {}) {
const targetTeamId = target.teamId || "";
if (!candidate || !candidate.teamId || candidate.teamId !== targetTeamId) return false;
const targetCorpId = normalizeCorpId(target.corpId || "");
if (!targetCorpId) return true;
const teamCorpId = normalizeCorpId(candidate.corpId || "");
return targetCorpId === teamCorpId;
}
async function changeTeam({ teamId, corpId, corpName }) {
loading.value = true;
const res = await api("getTeamData", { teamId, corpId });
loading.value = false;
if (res && res.data) {
team.value = {
...res.data,
corpId: normalizeCorpId(res.data.corpId || corpId),
};
team.value = res.data;
team.value.corpName = corpName;
cacheCurrentTeam(team.value);
} else {
toast(res?.message || "获取团队信息失败");
}
}
async function getMatchTeams(inviteTeam = null) {
async function getMatchTeams(inviteTeamId = '') {
loading.value = true;
teams.value = await getTeams();
const inviteIdentity = typeof inviteTeam === "string" ? { teamId: inviteTeam } : (inviteTeam || {});
const cachedIdentity = get(HOME_CURRENT_TEAM_CACHE_KEY) || {};
const targetIdentity = getTeamIdentity({
teamId: inviteIdentity.teamId || team.value?.teamId || cachedIdentity.teamId,
corpId: inviteIdentity.corpId || team.value?.corpId || cachedIdentity.corpId,
});
const validTeam = teams.value.find(i => isSameTeam(i, targetIdentity));
const matchTeamId = inviteTeamId || (team.value ? team.value.teamId : '');
const validTeam = teams.value.find(i => i.teamId && i.teamId === matchTeamId);
const firstTeam = teams.value[0]
if (validTeam || firstTeam) {
changeTeam(validTeam || firstTeam);
@ -149,7 +115,7 @@ onShow(async () => {
referenceCustomerIds.value[inviteTeam.teamId] = inviteTeam.referenceCustomerId;
}
if (account.value && account.value.openid) {
getMatchTeams(inviteTeam && inviteTeam.teamId ? inviteTeam : null);
getMatchTeams(inviteTeam && inviteTeam.teamId ? inviteTeam.teamId : '');
} else {
teams.value = [];
}

View File

@ -11,7 +11,6 @@ import api from "@/utils/api";
import { set } from "@/utils/cache";
import { toast } from "@/utils/widget";
import useAccountStore from "@/store/account";
import { normalizeCorpId, normalizeCorpIdFields } from "@/utils/api-base-config";
const env = __VITE_ENV__;
const appid = env.MP_WX_APP_ID;
@ -50,18 +49,17 @@ function parseInviteOptions(options = {}) {
return acc;
}, {});
return {
...normalizeCorpIdFields(options),
...normalizeCorpIdFields(data),
...options,
...data,
};
}
async function syncExternalUserRelation({ corpId, externalUserId, corpUserId }) {
const normalizedCorpId = normalizeCorpId(corpId);
const currentAccount = account.value || {};
if (!(normalizedCorpId && externalUserId && currentAccount.openid)) return;
if (!(corpId && externalUserId && currentAccount.openid)) return;
try {
const res = await api('syncWxappExternalUserRelation', {
corpId: normalizedCorpId,
corpId,
externalUserId,
unionid: currentAccount.unionid || '',
openid: currentAccount.openid,
@ -76,19 +74,14 @@ async function syncExternalUserRelation({ corpId, externalUserId, corpUserId })
}
async function changeTeam({ teamId, corpId, corpUserId, externalUserId, qrid, referenceCustomerId }) {
const normalizedCorpId = normalizeCorpId(corpId);
loading.value = true;
const res = await api("getTeamData", { teamId, corpId: normalizedCorpId, withCorpName: true });
const res = await api("getTeamData", { teamId, corpId, withCorpName: true });
loading.value = false;
if (res && res.data) {
team.value = normalizeCorpIdFields({
...res.data,
corpId: res.data.corpId || normalizedCorpId,
});
team.value = res.data;
team.value.corpName = res.data.corpName;
set('home-invite-team-info', {
teamId: team.value.teamId,
corpId: team.value.corpId,
corpUserId: corpUserId || '',
externalUserId: externalUserId || '',
qrid,

View File

@ -70,8 +70,6 @@ import useAccountStore from "@/store/account.js";
import { globalTimChatManager } from "@/utils/tim-chat.js";
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
import { globalUnreadListenerManager } from "@/utils/global-unread-listener.js";
import { get } from "@/utils/cache";
import { normalizeCorpId } from "@/utils/api-base-config";
import useGroupAvatars from "./hooks/use-group-avatars.js";
import GroupAvatar from "@/components/group-avatar.vue";
import {
@ -96,7 +94,6 @@ const loadingMore = ref(false);
const hasMore = ref(false);
const refreshing = ref(false);
const showSubscribeEntry = ref(false);
const HOME_CURRENT_TEAM_CACHE_KEY = "home-current-team-info";
//
const { loadGroupAvatars, getAvatarList } = useGroupAvatars();
@ -513,23 +510,11 @@ const cleanMessageText = (text) => {
return text.replace(/[\r\n]+/g, " ").trim();
};
function getCurrentTeamCorpId() {
const currentTeam = get(HOME_CURRENT_TEAM_CACHE_KEY) || {};
const currentCorpId = normalizeCorpId(currentTeam.corpId || "");
const hasCurrentCorpId = currentCorpId && teams.value.some((item) => {
return normalizeCorpId(item?.corpId || "") === currentCorpId;
});
if (hasCurrentCorpId) return currentCorpId;
const firstTeam = teams.value.find((item) => item?.corpId);
return normalizeCorpId(firstTeam?.corpId || "");
}
const handleSubscribeReminder = async () => {
await requestConversationSubscribeMessage({
role: SUBSCRIBE_MESSAGE_ROLE.PATIENT,
scene: SUBSCRIBE_MESSAGE_SCENE.LIST,
corpId: getCurrentTeamCorpId(),
corpId: teams.value.find((item) => item?.corpId)?.corpId || "",
userId: openid.value || account.value?.openid || "",
openid: openid.value || account.value?.openid || "",
unionid: account.value?.unionid || "",
@ -540,7 +525,7 @@ const handleSubscribeReminder = async () => {
};
const loadSubscribeEntryState = async () => {
const currentCorpId = getCurrentTeamCorpId();
const currentCorpId = teams.value.find((item) => item?.corpId)?.corpId || "";
showSubscribeEntry.value = await checkConversationSubscribeEntryVisible(
currentCorpId,
true

View File

@ -4,7 +4,6 @@ import api from '@/utils/api';
import { toast } from '@/utils/widget';
import { initGlobalTIM, globalTimChatManager } from "@/utils/tim-chat.js";
import { globalUnreadListenerManager } from "@/utils/global-unread-listener.js";
import { normalizeCorpId, normalizeCorpIdFields } from "@/utils/api-base-config";
const env = __VITE_ENV__;
export default defineStore("accountStore", () => {
@ -44,16 +43,15 @@ export default defineStore("accountStore", () => {
});
loading.value = false
if (res.success && res.data) {
const normalizedAccount = normalizeCorpIdFields(res.data);
account.value = normalizedAccount;
openid.value = normalizedAccount.openid;
account.value = res.data;
openid.value = res.data.openid;
// 保存账户信息和 openId 到本地存储
uni.setStorageSync('account', normalizedAccount);
uni.setStorageSync('openid', normalizedAccount.openid);
uni.setStorageSync('account', res.data);
uni.setStorageSync('openid', res.data.openid);
// initIMAfterLogin(openid.value)
return normalizedAccount
return res.data
}
}
toast('登录失败,请重新登录');
@ -136,7 +134,7 @@ export default defineStore("accountStore", () => {
async function searchTeams() {
const res = await api('getWxappRelateTeams', { openid: account.value.openid });
teams.value = res && Array.isArray(res.data) ? normalizeCorpIdFields(res.data) : [];
teams.value = res && Array.isArray(res.data) ? res.data : [];
return teams.value;
}
@ -150,14 +148,13 @@ export default defineStore("accountStore", () => {
}
async function getExternalUserId(corpId) {
const normalizedCorpId = normalizeCorpId(corpId);
const unionid = account.value?.unionid;
const openid = account.value?.openid;
if (!(normalizedCorpId && unionid && openid)) {
if (!(corpId && unionid && openid)) {
externalUserId.value = '';
return
};
const res = await api('getUnionidToExternalUserid', { unionid, openid, corpId: normalizedCorpId }, false);
const res = await api('getUnionidToExternalUserid', { unionid, openid, corpId }, false);
const id = res && res.success && typeof res.data === 'string' && res.data.trim() ? res.data.trim() : '';
externalUserId.value = id;
return id;

View File

@ -23,21 +23,6 @@ export function normalizeCorpId(corpId) {
return CORP_ID_ALIAS_MAP[normalizedCorpId] || normalizedCorpId;
}
export function normalizeCorpIdFields(value) {
if (Array.isArray(value)) {
return value.map((item) => normalizeCorpIdFields(item));
}
if (!value || typeof value !== "object") {
return value;
}
return Object.keys(value).reduce((acc, key) => {
acc[key] = key === "corpId"
? normalizeCorpId(value[key])
: normalizeCorpIdFields(value[key]);
return acc;
}, {});
}
function readCachedContext() {
if (typeof uni === "undefined" || typeof uni.getStorageSync !== "function") {
return null;
@ -45,14 +30,10 @@ function readCachedContext() {
try {
const cached = uni.getStorageSync(API_CONTEXT_CACHE_KEY);
if (!cached || typeof cached !== "object" || !cached.baseUrl) return null;
const context = {
corpId: normalizeCorpId(cached.corpId),
return {
corpId: cached.corpId || "",
baseUrl: normalizeBaseUrl(cached.baseUrl),
};
if (context.corpId !== (cached.corpId || "")) {
writeCachedContext(context);
}
return context;
} catch (error) {
return null;
}
@ -64,7 +45,7 @@ function writeCachedContext(context) {
}
try {
uni.setStorageSync(API_CONTEXT_CACHE_KEY, {
corpId: normalizeCorpId(context.corpId),
corpId: context.corpId || "",
baseUrl: normalizeBaseUrl(context.baseUrl),
});
} catch (error) {
@ -74,7 +55,7 @@ function writeCachedContext(context) {
function createContext(corpId, baseUrl) {
return {
corpId: normalizeCorpId(corpId),
corpId: corpId || "",
baseUrl: normalizeBaseUrl(baseUrl),
};
}

View File

@ -1,6 +1,5 @@
import { normalizeCorpIdFields } from './api-base-config'
const env = __VITE_ENV__;
const PREFIX = env.MP_CACHE_PREFIX
const EXPIRE_PREFIX = `${PREFIX}_expire_`
@ -44,15 +43,14 @@ function isExpired(key) {
*/
function set(key, value, expire = 0) {
try {
const normalizedValue = normalizeCorpIdFields(value)
// 序列化数据
let serializedValue
if (typeof normalizedValue === 'object' && normalizedValue !== null) {
if (typeof value === 'object' && value !== null) {
// 对象和数组需要JSON序列化
serializedValue = JSON.stringify(normalizedValue)
serializedValue = JSON.stringify(value)
} else {
// 基本类型直接存储
serializedValue = normalizedValue
serializedValue = value
}
uni.setStorageSync(getKey(key), serializedValue)
@ -92,22 +90,14 @@ function get(key, defaultValue = null) {
try {
// 尝试解析JSON
const parsed = JSON.parse(value)
const normalizedValue = normalizeCorpIdFields(parsed)
if (JSON.stringify(normalizedValue) !== JSON.stringify(parsed)) {
uni.setStorageSync(getKey(key), JSON.stringify(normalizedValue))
}
return normalizedValue
return parsed
} catch (e) {
// 如果解析失败,说明是普通字符串,直接返回
return value
}
}
const normalizedValue = normalizeCorpIdFields(value)
if (JSON.stringify(normalizedValue) !== JSON.stringify(value)) {
uni.setStorageSync(getKey(key), normalizedValue)
}
return normalizedValue
return value
} catch (e) {
console.error('缓存获取失败:', e)
return defaultValue