Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit b64fd79

Browse files
committed
WIP: fastlogin
1 parent 3e63d0c commit b64fd79

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gitignore
2+
3+
node_module
4+
5+
src
6+
7+
tsconfig.json
8+
tslint.json
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@alicloud/console-toolkit-preset-wind-component',
5+
{
6+
useTypescript: true,
7+
moduleName: 'ConsoleFastLogin',
8+
},
9+
],
10+
],
11+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@alicloud/console-fastlogin",
3+
"version": "2.3.0",
4+
"main": "lib/index.js",
5+
"module": "es/index.js",
6+
"license": "MIT",
7+
"homepage": "https://github.com/aliyun/alibabacloud-console-design",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/aliyun/alibabacloud-console-design.git"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/aliyun/alibabacloud-console-design/issues"
14+
},
15+
"devDependencies": {
16+
"@alicloud/console-toolkit-cli": "^1.0.0",
17+
"@alicloud/console-toolkit-preset-wind-component": "^1.0.0",
18+
"prop-types": "^15.7.2",
19+
"react": "^16.8.6",
20+
"react-dom": "^16.8.6"
21+
},
22+
"scripts": {
23+
"prepublish": "npm run clean && npm run build && npm run babel && npm run babel:esm",
24+
"babel": "breezr build --engine babel",
25+
"babel:esm": "breezr build --engine babel --es-module",
26+
"build": "breezr build --engine webpack",
27+
"storybook": "breezr start-storybook",
28+
"clean": "rm -rf es build lib yarn.lock"
29+
},
30+
"dependencies": {
31+
"lodash": "^4.0.0"
32+
}
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ENV = {
2+
prod: '//g.alicdn.com/dawn/assets-loader/scripts/fast-login.js',
3+
prepub: '//g-assets.prepub.taobao.net/dawn/assets-loader/scripts/fast-login.js',
4+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { IFastLoginOptions } from './type';
2+
import { ENV } from './env';
3+
4+
let fastLoginClient: typeof window.FastLogin = null;
5+
6+
const loadFastLoginScripts = (options: IFastLoginOptions): Promise<typeof window.FastLogin> => {
7+
const env = options.env || 'prod';
8+
const fastLoginUrl = ENV[env] || ENV.prod;
9+
10+
/* eslint-disable no-undef */
11+
return new Promise((resolve, reject) => {
12+
if (fastLoginClient) {
13+
resolve(fastLoginClient);
14+
return;
15+
}
16+
17+
const script = document.createElement('script');
18+
19+
script.onload = () => {
20+
fastLoginClient = window.FastLogin;
21+
// 必填
22+
// @ts-ignore
23+
window.FastLoginContext = {
24+
tenantName: "console"
25+
};
26+
resolve(fastLoginClient)
27+
}
28+
29+
script.onerror = () => {
30+
reject(new Error('script load fail'))
31+
}
32+
33+
script.src = fastLoginUrl;
34+
35+
document.body.appendChild(script);
36+
});
37+
}
38+
39+
40+
const open = async (options: IFastLoginOptions) => {
41+
const fastLogin = await loadFastLoginScripts(options);
42+
43+
return new Promise<void>((resolve) => {
44+
fastLogin('show', [{
45+
loginCallback: () => {
46+
resolve();
47+
}
48+
}])
49+
})
50+
}
51+
52+
const render = async (options: IFastLoginOptions) => {
53+
const fastLogin = await loadFastLoginScripts(options);
54+
fastLogin('render', [{}])
55+
}
56+
57+
58+
export {
59+
open,
60+
render,
61+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export interface IFastLoginOptions {
2+
env?: 'prod' | 'prepub';
3+
}
4+
5+
export interface ILoginCallbackProps {
6+
success: string;
7+
type: "password" | "qr";
8+
uuid: string; // 创建出来 IFrame 对应的 uuid
9+
}
10+
11+
export interface IFastLoginProps {
12+
targetId?: string;
13+
loginCallback?: (data: ILoginCallbackProps) => void;
14+
}
15+
16+
declare global {
17+
interface Window {
18+
FastLogin: (method: 'render' | 'show', [props]: [IFastLoginProps]) => void;
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { storiesOf } from '@storybook/react';
4+
import { open } from '../src';
5+
6+
window.React = React;
7+
window.ReactDOM = ReactDOM;
8+
9+
storiesOf('FastLogin', module)
10+
.add('FastLogin', () => {
11+
const onClick = () => {
12+
open({env: 'prepub'})
13+
}
14+
15+
return (<div id="app-wrapper">
16+
<div id="app">
17+
<button onClick={onClick}>open fast login</button>
18+
</div>
19+
</div>);
20+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./lib",
4+
"jsx": "react",
5+
"module": "esnext",
6+
"target": "es5",
7+
"esModuleInterop": true,
8+
"lib": ["dom", "es2015", "scripthost"],
9+
"moduleResolution": "node",
10+
"skipLibCheck": true,
11+
"experimentalDecorators": true,
12+
"importHelpers": true,
13+
"downlevelIteration": true
14+
},
15+
"include": [
16+
"./src/*",
17+
],
18+
"exclude": [
19+
"node_modules"
20+
]
21+
}

0 commit comments

Comments
 (0)