UNPKG

@forchange/aui

Version:

ai-boss 业务 ui 组件库

81 lines (66 loc) 1.98 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import * as React from 'react'; import { getPrefixCls } from '../style/config'; import { DING_CONFIG, createGotoURL } from './unit'; import "./style/index.css"; import classNames from 'classnames'; class DingAuth extends React.Component { constructor(props) { super(props); _defineProperty(this, "setScript", () => { const script = document.createElement('script'); script.src = DING_CONFIG.comomDingUrl; script.async = true; script.onload = () => this.onDingBinding(); document.body.appendChild(script); }); _defineProperty(this, "onDingBinding", () => { const { appId, redirectUri, width, height, style = 'border:none;background-color:#FFFFFF;margin-top:-12px;' } = this.props; DDLogin({ id: 'aui-dingauth-login-container', goto: createGotoURL(appId, redirectUri), style, width, height }); const onDingMessage = event => { const { origin, data } = event; if (origin === DING_CONFIG.origin) { // 扫码后生成tmp_code_data if (this.props.onSuccess) { this.props.onSuccess(data); } } }; window.addEventListener('message', onDingMessage, false); }); this.state = { displayName: 'ding-auth' }; } componentDidMount() { this.setScript(); } // 引入钉钉js render() { const { className } = this.props; const prefixCls = getPrefixCls(this.state.displayName); return React.createElement("div", { id: "aui-dingauth-login-container", className: classNames(prefixCls, { className }) }); } } export default DingAuth;