Commit 4b2b59e7 by zhangxw

fix(venus-usedcar-livecode): 扫码加群修改

1 parent 13cd7140
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
长按识别二维码加入群{{ groupName }} 长按识别二维码加入群{{ groupName }}
</div> </div>
</div> </div>
<div v-else class="scan-message">
{{ message || "加载失败" }}
</div>
</div> </div>
</div> </div>
</template> </template>
...@@ -73,6 +76,16 @@ function removeQueryKeys(urlText: string, keys: string[]) { ...@@ -73,6 +76,16 @@ function removeQueryKeys(urlText: string, keys: string[]) {
return url.toString(); return url.toString();
} }
function replaceUrlQuery(next: (url: URL) => void) {
try {
const url = new URL(window.location.href);
next(url);
window.history.replaceState({}, document.title, url.toString());
} catch {
// ignore
}
}
function resolveWeChatAppId() { function resolveWeChatAppId() {
const cfg = getConfig() as Record<string, unknown>; const cfg = getConfig() as Record<string, unknown>;
const candidates = ((cfg.ssoApiEnv as undefined | { codeWechatAppId?: string })?.codeWechatAppId ?? "") as string; const candidates = ((cfg.ssoApiEnv as undefined | { codeWechatAppId?: string })?.codeWechatAppId ?? "") as string;
...@@ -170,6 +183,26 @@ async function loadQr() { ...@@ -170,6 +183,26 @@ async function loadQr() {
const saUserId = getFirstQueryValue(["saUserId", "sa_user_id"]); const saUserId = getFirstQueryValue(["saUserId", "sa_user_id"]);
const carConditionCode = getFirstQueryValue(["carConditionCode", "car_condition_code"]); const carConditionCode = getFirstQueryValue(["carConditionCode", "car_condition_code"]);
const code = getFirstQueryValue(["code"]); const code = getFirstQueryValue(["code"]);
const openIdFromUrl = getFirstQueryValue(["openId", "openid"]);
if (!liveCode || !signature || !exp || !nonce || !saUserId || !carConditionCode) {
phase.value = "error";
message.value = "链接参数不完整,请重新扫码进入";
return;
}
if (openIdFromUrl) {
await fetchQrByOpenId({
openId: openIdFromUrl,
liveCode,
signature,
exp,
nonce,
saUserId,
carConditionCode,
});
return;
}
if (!code) { if (!code) {
const backUrl = removeQueryKeys(window.location.href, ["openId", "openid", "code", "state"]); const backUrl = removeQueryKeys(window.location.href, ["openId", "openid", "code", "state"]);
...@@ -190,9 +223,14 @@ async function loadQr() { ...@@ -190,9 +223,14 @@ async function loadQr() {
const openId = await exchangeCodeToOpenId(code); const openId = await exchangeCodeToOpenId(code);
if (!openId) { if (!openId) {
phase.value = "error"; phase.value = "error";
message.value = "获取 openid 失败"; message.value = "获取 openid 失败,请重新扫码进入";
return; return;
} }
replaceUrlQuery((url) => {
url.searchParams.delete("code");
url.searchParams.delete("state");
url.searchParams.set("openId", openId);
});
await fetchQrByOpenId({ await fetchQrByOpenId({
openId, openId,
liveCode, liveCode,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!