Skip to content

Commit

Permalink
微搭登陆cms,添加tam平台日志逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjduan committed Sep 29, 2021
1 parent b52eb6f commit ae3e84f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"lint:fix": "eslint --fix --cache --ext .ts,.tsx --format=pretty ./packages",
"lint:prettier": "prettier --check \"**/*.{ts,tsx,js,jsx,json}\" --end-of-line auto",
"deploy": "tcb framework deploy",
"preext:zip": "rm -rf build && mkdir build && npm run build",
"preext:zip-wx": "rm -rf build && mkdir build && npm run build:wx",
"preext:zip": "rm -rf build && mkdir build && yarn run build",
"preext:zip-wx": "rm -rf build && mkdir build && yarn run build:wx",
"ext:zip": "bash ./scripts/zip.sh",
"ext:zip-wx": "bash ./scripts/zip.sh"
},
Expand Down
37 changes: 33 additions & 4 deletions packages/admin/src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ const Login: React.FC<{}> = () => {

const { username, password } = values

let loginSuccess = false
try {
// 用户名密码登录
await loginWithPassword(username.trim(), password.trim())
message.success('登录成功')
loginSuccess = true
replaceGoto()
setTimeout(() => {
refresh()
Expand All @@ -101,6 +103,7 @@ const Login: React.FC<{}> = () => {
}

setSubmitting(false)
return Promise.resolve(loginSuccess)
}

// 从低码平台登录
Expand All @@ -111,9 +114,16 @@ const Login: React.FC<{}> = () => {

console.log('CMS 收到信息', event.data, event.origin)

const loginData: {
username?: string
password?: string
fromLowcode?: boolean
isSuccess?: boolean
} = {}
try {
const data = event?.data ? JSON.parse(event.data) : {}
if (data?.from !== 'lowcode') return
loginData.fromLowcode = true
window?.opener?.postMessage(
JSON.stringify({
from: 'cms',
Expand All @@ -123,30 +133,49 @@ const Login: React.FC<{}> = () => {
)

const { password, username } = data
await handleSubmit({
loginData.password = password || undefined
loginData.username = username || undefined
const loginSuccess = await handleSubmit({
password,
username,
})
loginData.isSuccess = !!loginSuccess

// 响应低码平台
window?.opener?.postMessage(
JSON.stringify({
from: 'cms',
status: 'success',
status: loginSuccess ? 'success' : 'fail',
}),
'*'
)
} catch (error) {
if (window.parent === window.self) return
// if (window.parent === window.self) return
// 响应低码平台
window?.opener?.postMessage(
JSON.stringify({
from: 'cms',
status: 'fail',
message: error.message,
message: error?.message,
}),
'*'
)
}

// 上报cms日志
if (loginData?.fromLowcode && window['Aegis']) {
try {
new window['Aegis']({
id: 'lXHFsBpTyYTEVwaNUr',
}).infoAll({
msg: `lowcode-login::${loginData?.isSuccess || false}`,
ext1: window?.TcbCmsConfig?.envId || '',
ext2: loginData?.username || '',
// password: loginData.password || "",
ext3: loginData?.isSuccess || false,
})
} catch (e) {}
}
}
window.addEventListener('message', messageListener, false)

Expand Down

0 comments on commit ae3e84f

Please sign in to comment.