import { isPassword } from "oak-domain/lib/utils/validator"; import { encryptPasswordSha1 } from "../../../../utils/password"; export default OakComponent({ isList: false, formData({ features, props }) { return {}; }, data: { counter: 0, loading: false, domain: undefined, account: '', password: '', validMobile: false, vaildEmail: false, vaildAccount: false, validPassword: false, allowSubmit: false, }, properties: { disabled: '', redirectUri: '', url: '', callback: undefined, allowSms: false, allowEmail: false, allowWechatMp: false, setLoginMode: (value) => undefined, pwdMode: 'all', //密码明文密文存储模式 }, lifetimes: {}, listeners: { 'vaildAccount,validPassword'(prev, next) { const { allowSubmit } = this.state; if (allowSubmit) { if (!(next.vaildAccount && next.validPassword)) { this.setState({ allowSubmit: false, }); } } else { if (next.vaildAccount && next.validPassword) { this.setState({ allowSubmit: true, }); } } } }, methods: { async loginByAccount() { const { url, callback, pwdMode } = this.props; const { account, password } = this.state; let pwd = password; if (pwdMode === 'sha1') { pwd = encryptPasswordSha1(password); } try { this.setState({ loading: true, }); await this.features.token.loginByAccount(account, pwd); this.setState({ loading: false, }); if (callback) { callback(); return; } if (url) { this.redirectTo({ url, }); return; } } catch (err) { this.setState({ loading: false, }); this.setMessage({ type: 'error', content: err.message, }); } }, inputChange(type, value) { const { allowSms, allowEmail } = this.props; switch (type) { case 'account': // const validMobile = allowSms && !!isMobile(value); // const vaildEmail = allowEmail && !!isEmail(value); const vaildAccount = !!(value && value.trim() && value.trim() !== ''); this.setState({ account: value, // validMobile, // vaildEmail, vaildAccount, }); break; case 'password': const validPassword = !!isPassword(value); this.setState({ password: value, validPassword }); break; default: break; } }, inputChangeMp(event) { const { detail, target: { dataset }, } = event; const { attr } = dataset; const { value } = detail; this.inputChange(attr, value); }, changeLoginMp(e) { const { setLoginMode } = this.props; const { value } = e.currentTarget.dataset; setLoginMode && setLoginMode(value); } }, });