import { isPassword } from "oak-domain/lib/utils/validator"; import { encryptPasswordSha1 } from "../../../../utils/password"; export default OakComponent({ isList: false, formData({ features, props }) { const { pwdAllowMobile, pwdAllowEmail, pwdAllowLoginName } = this.props; let tips = []; if (pwdAllowLoginName) { tips.push(this.t('placeholder.LoginName')); } if (pwdAllowMobile) { tips.push(this.t('placeholder.Mobile')); } if (pwdAllowEmail) { tips.push(this.t('placeholder.Email')); } const accountPlaceholder = tips.length > 0 ? this.t('placeholder.Account') + tips.join('/') : this.t('placeholder.Account'); return { accountPlaceholder, }; }, data: { counter: 0, loading: false, domain: undefined, account: '', password: '', validMobile: false, vaildEmail: false, vaildAccount: false, validPassword: false, allowSubmit: false, }, properties: { disabled: '', redirectUri: '', // 微信登录后的redirectUri,要指向wechatUser/login去处理 url: '', // 登录系统之后要返回的页面 callback: undefined, // 登录成功回调,排除微信登录方式 pwdAllowMobile: false, pwdAllowEmail: false, pwdAllowLoginName: false, allowSms: false, //小程序切换手机号验证码登录 allowEmail: false, //小程序切换邮箱登录 allowWechatMp: false, //小程序切换授权登录 setLoginMode: (value) => undefined, pwdMode: 'all', //密码明文密文存储模式 allowRegister: false, goRegister: () => undefined, }, 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 { allowMobile, allowEmail } = this.props; switch (type) { case 'account': // const validMobile = allowMobile && !!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); }, goRegisterMp() { const { goRegister } = this.props; goRegister && goRegister(); } }, });