Files
labelmain-demo/components/login/feishu/util.ts
2026-02-28 16:20:58 +08:00

52 lines
1.7 KiB
TypeScript

// 飞书脚本
export function qr_load() {
return new Promise<void>((resolve, reject) => {
const script = document.createElement("script")
script.type = "text/javascript"
script.src =
"https://sf3-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.2.js"
script.onerror = reject
script.onload = () => {
resolve()
}
document.head.appendChild(script)
})
}
export async function qr_login(
appId: string,
redirect_url: string,
state: string
) {
const gotoUrl = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${appId}&redirect_uri=${encodeURIComponent(
redirect_url
)}&response_type=code&state=${encodeURIComponent(state)}`
const QRLogin = (<any>window).QRLogin
const QRLoginObj = QRLogin({
id: "login_container",
goto: gotoUrl,
style: `width: 270px;height: 270px;border: 0;border-radius:12px;background-color: #E4F2FF;
background-image:
radial-gradient(at 47% 33%, hsl(212.37, 72%, 59%) 0, transparent 59%),
radial-gradient(at 82% 65%, hsl(198.00, 100%, 50%) 0, transparent 55%);`,
})
const handleMessage = function (event: any) {
const origin = event.origin
if (
QRLoginObj.matchOrigin(origin) &&
window.location.href.indexOf("login") > -1
) {
const loginTmpCode = event.data
window.location.href = `${gotoUrl}&tmp_code=${loginTmpCode}`
}
}
if (typeof window.addEventListener !== "undefined") {
window.addEventListener("message", handleMessage, false)
} else if (typeof (<any>window).attachEvent !== "undefined") {
;(<any>window).attachEvent("onmessage", handleMessage)
}
}
export const APP_ID = "cli_a56577acb2f3d00c"
export const APP_SECRECT = "168xtvkFLnVbZd1Ih5T5agKue3JxJ87V"