建档流程做优化

This commit is contained in:
wangdongbo 2026-06-02 10:36:41 +08:00
parent 6de95f5b47
commit 3e3b2a1fe8
3 changed files with 79 additions and 16 deletions

View File

@ -105,12 +105,33 @@ function toHome() {
});
}
async function syncExternalUserRelation() {
const currentTeam = team.value || {};
const currentAccount = account.value || {};
if (!(currentTeam.corpId && currentTeam.externalUserId && currentAccount.openid)) return;
try {
const res = await api('syncWxappExternalUserRelation', {
corpId: currentTeam.corpId,
externalUserId: currentTeam.externalUserId,
unionid: currentAccount.unionid || '',
openid: currentAccount.openid,
corpUserId: currentTeam.corpUserId || '',
}, false);
if (!res || !res.success) {
console.warn('关联 externalUserId 失败:', res && res.message);
}
} catch (error) {
console.warn('关联 externalUserId 异常:', error && error.message ? error.message : error);
}
}
async function bindTeam() {
const res = await api('bindWxappWithTeam', { appid, corpId: team.value.corpId, teamId: team.value.teamId, openid: account.value.openid });
if (!res || !res.success) {
return toast("关联团队失败");
}
await syncExternalUserRelation();
const res1 = await api('getWxAppCustomerCount', { miniAppId: account.value.openid, corpId: team.value.corpId, teamId: team.value.teamId });
if (res1 && res1.data > 0) {
toHome();
@ -126,7 +147,7 @@ async function getPhoneNumber(e) {
if (!res) return;
}
if (team.value) {
bindTeam(account.value)
bindTeam()
} else if (redirectUrl.value) {
await attempToPage(redirectUrl.value);
} else {

View File

@ -29,7 +29,51 @@ function copy() {
})
}
async function changeTeam({ teamId, corpId, corpUserId, qrid, referenceCustomerId }) {
function safeDecode(value) {
try {
return decodeURIComponent(value);
} catch (error) {
return value;
}
}
function parseInviteOptions(options = {}) {
const href =
typeof options.q === "string" ? safeDecode(options.q) : "";
const [, url = ""] = href.split("?");
const data = url.split("&").reduce((acc, cur) => {
if (!cur) return acc;
const [key, ...valueParts] = cur.split("=");
if (!key) return acc;
acc[key] = safeDecode(valueParts.join("=") || "");
return acc;
}, {});
return {
...options,
...data,
};
}
async function syncExternalUserRelation({ corpId, externalUserId, corpUserId }) {
const currentAccount = account.value || {};
if (!(corpId && externalUserId && currentAccount.openid)) return;
try {
const res = await api('syncWxappExternalUserRelation', {
corpId,
externalUserId,
unionid: currentAccount.unionid || '',
openid: currentAccount.openid,
corpUserId: corpUserId || '',
}, false);
if (!res || !res.success) {
console.warn('关联 externalUserId 失败:', res && res.message);
}
} catch (error) {
console.warn('关联 externalUserId 异常:', error && error.message ? error.message : error);
}
}
async function changeTeam({ teamId, corpId, corpUserId, externalUserId, qrid, referenceCustomerId }) {
loading.value = true;
const res = await api("getTeamData", { teamId, corpId, withCorpName: true });
loading.value = false;
@ -39,16 +83,17 @@ async function changeTeam({ teamId, corpId, corpUserId, qrid, referenceCustomerI
set('home-invite-team-info', {
teamId: team.value.teamId,
corpUserId: corpUserId || '',
corpUserId,
externalUserId: externalUserId || '',
qrid,
referenceCustomerId: referenceCustomerId || ''
});
await login()
if (account.value && account.value.mobile) {
bindTeam(corpUserId)
bindTeam({ corpUserId, externalUserId })
} else {
set("invite-team-info", {
corpUserId,
externalUserId,
qrid,
referenceCustomerId,
corpId: team.value.corpId,
@ -69,11 +114,16 @@ async function changeTeam({ teamId, corpId, corpUserId, qrid, referenceCustomerI
}
}
async function bindTeam(corpUserId) {
async function bindTeam({ corpUserId, externalUserId }) {
const res = await api('bindWxappWithTeam', { appid, corpId: team.value.corpId, teamId: team.value.teamId, openid: account.value.openid });
if (!res || !res.success) {
return toast("关联团队失败");
}
await syncExternalUserRelation({
corpId: team.value.corpId,
externalUserId,
corpUserId,
});
const res1 = await api('getWxAppCustomerCount', { miniAppId: account.value.openid, corpId: team.value.corpId, teamId: team.value.teamId });
if (res1 && res1.data > 0) {
uni.switchTab({
@ -89,15 +139,7 @@ async function bindTeam(corpUserId) {
onLoad((options) => {
if (options.q) {
opts.value = JSON.stringify(options)
const href =
typeof options.q === "string" ? decodeURIComponent(options.q) : "";
const [, url = ""] = href.split("?");
const data = url.split("&").reduce((acc, cur) => {
const [key, value] = cur.split("=");
acc[key] = value;
return acc;
}, {});
changeTeam(data);
changeTeam(parseInviteOptions(options));
} else if (options.type === 'archive') {
changeTeam(options);
}
@ -124,4 +166,4 @@ onLoad((options) => {
opacity: 1;
}
}
</style>
</style>

View File

@ -58,6 +58,7 @@ const urlsConfig = {
unbindMiniAppArchive: 'unbindMiniAppArchive',
updateMedicalRecord: 'updateMedicalRecord',
getUnionidToExternalUserid: 'getUnionidToExternalUserid',
syncWxappExternalUserRelation: 'syncWxappExternalUserRelation',
getWxAppCustomerCount: "getWxAppCustomerCount",
updateCustomer: 'update',
getRefrencePeople: 'getRefrencePeople',
@ -115,4 +116,3 @@ export default async function api(urlId, data = {}, loading = true) {
}
}, loading)
}