shopro-auth-modal.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. <template>
  2. <view class="cu-modal bottom-modal" :class="{ show: showAuth }" @tap="closeAuthModal" style="z-index: 10080;">
  3. <view class="login-wrap cu-dialog form-wrap safe-area-inset-bottom" @tap.stop style="border-radius: 20rpx 20rpx 0 0;">
  4. <!-- 1.账号密码登录 -->
  5. <view v-if="authType === 'accountLogin'">
  6. <!-- 标题 -->
  7. <view class="head-box u-m-b-60 u-flex-col ">
  8. <view class="u-flex u-m-b-20">
  9. <view class="head-title u-m-r-40 head-title-animation">账号登录</view>
  10. <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">短信登录</view>
  11. </view>
  12. <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view>
  13. </view>
  14. <view class="form-item u-border-bottom ">
  15. <view class="item-content u-flex u-col-center">
  16. <view class="item-title">账号</view>
  17. <u-input
  18. class="u-m-r-10 u-flex-1"
  19. placeholder="请输入账号"
  20. @blur="checkValue($event, 'account')"
  21. @input="checkValue($event, 'account')"
  22. :placeholderStyle="placeholderStyle"
  23. v-model="form['accountLogin'].data.account"
  24. type="text"
  25. ></u-input>
  26. <button class="u-reset-button forgot-btn" @tap="showAuthModal('forgotPwd')">忘记密码</button>
  27. </view>
  28. <view class="message-error">{{ form['accountLogin'].error.account || '' }}</view>
  29. </view>
  30. <view class="form-item u-border-bottom">
  31. <view class="item-content u-flex u-col-center">
  32. <view class="item-title">密码</view>
  33. <u-input
  34. class="u-m-r-10 u-flex-1"
  35. placeholder="请输入密码"
  36. :placeholderStyle="placeholderStyle"
  37. v-model="form['accountLogin'].data.password"
  38. type="password"
  39. @blur="checkValue($event, 'password')"
  40. @input="checkValue($event, 'password')"
  41. ></u-input>
  42. <button class="u-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  43. </view>
  44. <view class="message-error">{{ form['accountLogin'].error.password || '' }}</view>
  45. </view>
  46. <button class="u-reset-button type-btn" @tap="showAuthModal('register')">立即注册</button>
  47. </view>
  48. <!-- 2.短信登录 -->
  49. <view v-if="authType === 'smsLogin'">
  50. <view class="head-box u-m-b-60">
  51. <view class="u-flex u-m-b-20">
  52. <view class="head-title-active u-m-r-40" @tap="showAuthModal('accountLogin')">账号登录</view>
  53. <view class="head-title head-title-line head-title-animation">短信登录</view>
  54. </view>
  55. <view class="head-subtitle">未注册手机号请先点击下方立即注册</view>
  56. </view>
  57. <view class="form-item u-border-bottom">
  58. <view class="item-content u-flex u-col-center">
  59. <view class="item-title">手机号</view>
  60. <u-input
  61. class="u-m-r-10 u-flex-1"
  62. placeholder="请输入手机号"
  63. @blur="checkValue($event, 'mobile')"
  64. @input="mobileInput($event, 'mobile')"
  65. :placeholderStyle="placeholderStyle"
  66. v-model="form['smsLogin'].data.mobile"
  67. type="number"
  68. ></u-input>
  69. <button
  70. class="u-reset-button code-btn code-btn-start"
  71. :disabled="!form['smsLogin'].data.isMobileEnd"
  72. :class="{ 'code-btn-end': form['smsLogin'].data.isMobileEnd }"
  73. @tap="getSmsCode('mobilelogin')"
  74. >
  75. {{ codeText }}
  76. </button>
  77. </view>
  78. <view class="message-error">{{ form['smsLogin'].error.mobile || '' }}</view>
  79. </view>
  80. <view class="form-item u-border-bottom">
  81. <view class="item-content u-flex u-col-center">
  82. <view class="item-title">验证码</view>
  83. <u-input
  84. class="u-m-r-10 u-flex-1"
  85. @blur="checkValue($event, 'code')"
  86. @input="checkValue($event, 'code')"
  87. placeholder="请输入验证码"
  88. :placeholderStyle="placeholderStyle"
  89. v-model="form['smsLogin'].data.code"
  90. type="number"
  91. ></u-input>
  92. <button class="u-reset-button login-btn-start" @tap="smsLoginSubmit">登录</button>
  93. </view>
  94. <view class="message-error">{{ form['smsLogin'].error.code || '' }}</view>
  95. </view>
  96. <button class="u-reset-button type-btn" @tap="showAuthModal('register')">立即注册</button>
  97. </view>
  98. <!-- 3.注册 -->
  99. <view v-if="authType === 'register'">
  100. <view class="head-box u-m-b-60">
  101. <view class="head-title u-m-b-20">注册</view>
  102. <view class="head-subtitle">请使用本人手机号完成注册</view>
  103. </view>
  104. <view class="form-item u-border-bottom">
  105. <view class="item-content u-flex u-col-center">
  106. <view class="item-title">手机号</view>
  107. <u-input
  108. class="u-m-r-10 u-flex-1"
  109. placeholder="请输入手机号"
  110. @blur="checkValue($event, 'mobile')"
  111. @input="mobileInput($event, 'mobile')"
  112. :placeholderStyle="placeholderStyle"
  113. v-model="form['register'].data.mobile"
  114. type="number"
  115. ></u-input>
  116. <button
  117. class="u-reset-button code-btn code-btn-start"
  118. :disabled="!form['register'].data.isMobileEnd"
  119. :class="{ 'code-btn-end': form['register'].data.isMobileEnd }"
  120. @tap="getSmsCode('register')"
  121. >
  122. {{ codeText }}
  123. </button>
  124. </view>
  125. <view class="message-error">{{ form['register'].error.mobile || '' }}</view>
  126. </view>
  127. <view class="form-item u-border-bottom">
  128. <view class="item-content u-flex u-col-center">
  129. <view class="item-title">密码</view>
  130. <u-input
  131. class="u-m-r-10 u-flex-1"
  132. @blur="checkValue($event, 'password')"
  133. @input="checkValue($event, 'password')"
  134. placeholder="请输入密码"
  135. :placeholderStyle="placeholderStyle"
  136. v-model="form['register'].data.password"
  137. type="password"
  138. ></u-input>
  139. </view>
  140. <view class="message-error">{{ form['register'].error.password || '' }}</view>
  141. </view>
  142. <view class="form-item u-border-bottom">
  143. <view class="item-content u-flex u-col-center">
  144. <view class="item-title">验证码</view>
  145. <u-input
  146. class="u-m-r-10 u-flex-1"
  147. @blur="checkValue($event, 'code')"
  148. @input="checkValue($event, 'code')"
  149. placeholder="请输入验证码"
  150. :placeholderStyle="placeholderStyle"
  151. v-model="form['register'].data.code"
  152. type="number"
  153. ></u-input>
  154. <button class="u-reset-button login-btn-start" @tap="registerSubmit">注册</button>
  155. </view>
  156. <view class="message-error">{{ form['register'].error.code || '' }}</view>
  157. </view>
  158. <button v-if="!isLogin" class="u-reset-button type-btn" @tap="showAuthModal('accountLogin')">返回登录</button>
  159. </view>
  160. <!-- 4.忘记密码 -->
  161. <view v-if="authType === 'forgotPwd'">
  162. <view class="head-box u-m-b-60">
  163. <view class="head-title u-m-b-20">忘记密码</view>
  164. <view class="head-subtitle">为了您的账号安全,修改密码前请先进行安全验证</view>
  165. </view>
  166. <view class="form-item u-border-bottom">
  167. <view class="item-content u-flex u-col-center">
  168. <view class="item-title">手机号</view>
  169. <u-input
  170. class="u-m-r-10 u-flex-1"
  171. @blur="checkValue($event, 'mobile')"
  172. @input="mobileInput($event, 'mobile')"
  173. :placeholderStyle="placeholderStyle"
  174. v-model="form['forgotPwd'].data.mobile"
  175. type="number"
  176. ></u-input>
  177. <button
  178. class="u-reset-button code-btn code-btn-start"
  179. :disabled="!form['forgotPwd'].data.isMobileEnd"
  180. :class="{ 'code-btn-end': form['forgotPwd'].data.isMobileEnd }"
  181. @tap="getSmsCode('resetpwd')"
  182. >
  183. {{ codeText }}
  184. </button>
  185. </view>
  186. <view class="message-error">{{ form['forgotPwd'].error.mobile || '' }}</view>
  187. </view>
  188. <view class="form-item u-border-bottom">
  189. <view class="item-content u-flex u-col-center">
  190. <view class="item-title">验证码</view>
  191. <u-input
  192. class="u-m-r-10 u-flex-1"
  193. @blur="checkValue($event, 'code')"
  194. @input="checkValue($event, 'code')"
  195. placeholder="请输入验证码"
  196. :placeholderStyle="placeholderStyle"
  197. v-model="form['forgotPwd'].data.code"
  198. type="number"
  199. ></u-input>
  200. </view>
  201. <view class="message-error">{{ form['forgotPwd'].error.code || '' }}</view>
  202. </view>
  203. <view class="form-item u-border-bottom">
  204. <view class="item-content u-flex u-col-center">
  205. <view class="item-title">密码</view>
  206. <u-input
  207. class="u-m-r-10 u-flex-1"
  208. @blur="checkValue($event, 'password')"
  209. @input="checkValue($event, 'password')"
  210. placeholder="请输入密码"
  211. :placeholderStyle="placeholderStyle"
  212. v-model="form['forgotPwd'].data.password"
  213. type="password"
  214. ></u-input>
  215. <button class="u-reset-button login-btn-start" @tap="forgotPwdSubmit">确认</button>
  216. </view>
  217. <view class="message-error">{{ form['forgotPwd'].error.password || '' }}</view>
  218. </view>
  219. <button v-if="!isLogin" class="u-reset-button type-btn" @tap="showAuthModal('accountLogin')">返回登录</button>
  220. </view>
  221. <!-- 5.绑定手机号 -->
  222. <view v-if="authType === 'bindMobile'">
  223. <view class="head-box u-m-b-60">
  224. <view class="head-title u-m-b-20">绑定手机号</view>
  225. <view class="head-subtitle">为了您的账号安全,请绑定手机号</view>
  226. </view>
  227. <view class="form-item u-border-bottom">
  228. <view class="item-content u-flex u-col-center">
  229. <view class="item-title">手机号</view>
  230. <u-input
  231. class="u-m-r-10 u-flex-1"
  232. @blur="checkValue($event, 'mobile')"
  233. @input="mobileInput($event, 'mobile')"
  234. placeholder="请输入手机号"
  235. :placeholderStyle="placeholderStyle"
  236. v-model="form['bindMobile'].data.mobile"
  237. type="number"
  238. ></u-input>
  239. <button
  240. class="u-reset-button code-btn code-btn-start"
  241. :disabled="!form['bindMobile'].data.isMobileEnd"
  242. :class="{ 'code-btn-end': form['bindMobile'].data.isMobileEnd }"
  243. @tap="getSmsCode('changemobile')"
  244. >
  245. {{ codeText }}
  246. </button>
  247. </view>
  248. <view class="message-error">{{ form['bindMobile'].error.mobile || '' }}</view>
  249. </view>
  250. <view class="form-item u-border-bottom">
  251. <view class="item-content u-flex u-col-center">
  252. <view class="item-title">验证码</view>
  253. <u-input
  254. class="u-m-r-10 u-flex-1"
  255. @blur="checkValue($event, 'code')"
  256. @input="checkValue($event, 'code')"
  257. placeholder="请输入验证码"
  258. :placeholderStyle="placeholderStyle"
  259. v-model="form['bindMobile'].data.code"
  260. type="number"
  261. ></u-input>
  262. <button class="u-reset-button login-btn-start" @tap="bindMobileSubmit">立即绑定</button>
  263. </view>
  264. <view class="message-error">{{ form['bindMobile'].error.code || '' }}</view>
  265. </view>
  266. </view>
  267. <!-- 6.修改密码 -->
  268. <view v-if="authType === 'changePwd'">
  269. <view class="head-box u-m-b-60">
  270. <view class="head-title u-m-b-20">修改密码</view>
  271. <view class="head-subtitle"></view>
  272. </view>
  273. <view class="form-item u-border-bottom">
  274. <view class="item-content u-flex u-col-center">
  275. <view class="item-title">旧密码</view>
  276. <u-input
  277. class="u-m-r-10 u-flex-1"
  278. @blur="checkValue($event, 'oldPassword')"
  279. @input="checkValue($event, 'oldPassword')"
  280. placeholder="请输入旧密码"
  281. :placeholderStyle="placeholderStyle"
  282. v-model="form['changePwd'].data.oldPassword"
  283. type="password"
  284. ></u-input>
  285. </view>
  286. <view class="message-error">{{ form['changePwd'].error.oldPassword || '' }}</view>
  287. </view>
  288. <view class="form-item u-border-bottom">
  289. <view class="item-content u-flex u-col-center">
  290. <view class="item-title">新密码</view>
  291. <u-input
  292. class="u-m-r-10 u-flex-1"
  293. @blur="checkValue($event, 'newPassword')"
  294. @input="checkValue($event, 'newPassword')"
  295. placeholder="请输入新密码"
  296. :placeholderStyle="placeholderStyle"
  297. v-model="form['changePwd'].data.newPassword"
  298. type="password"
  299. ></u-input>
  300. </view>
  301. <view class="message-error">{{ form['changePwd'].error.newPassword || '' }}</view>
  302. </view>
  303. <view class="form-item u-border-bottom">
  304. <view class="item-content u-flex u-col-center">
  305. <view class="item-title">确认密码</view>
  306. <u-input
  307. class="u-m-r-10 u-flex-1"
  308. @blur="checkValue($event, 'reNewPassword')"
  309. @input="checkValue($event, 'reNewPassword')"
  310. placeholder="再次输入新密码"
  311. :placeholderStyle="placeholderStyle"
  312. v-model="form['changePwd'].data.reNewPassword"
  313. type="password"
  314. ></u-input>
  315. </view>
  316. <view class="message-error">{{ form['changePwd'].error.reNewPassword || '' }}</view>
  317. </view>
  318. <view class="editPwd-btn-box u-m-t-80">
  319. <button class="u-reset-button save-btn" @tap="changePwdSubmit">保存</button>
  320. <button class="u-reset-button forgot-btn" @tap="showAuthModal('forgotPwd')">忘记密码</button>
  321. </view>
  322. </view>
  323. <!-- 第三方登录 -->
  324. <view v-if="authType === 'accountLogin' || authType === 'smsLogin'" class="auto-login-box u-flex u-row-center u-col-center">
  325. <!-- 微信 -->
  326. <image
  327. v-if="['App', 'wxOfficialAccount', 'wxMiniProgram'].includes(platform)"
  328. class="auto-login-img"
  329. @tap="thirdLogin('wechat')"
  330. :src="$IMG_URL + '/imgs/auto_login_wx.png'"
  331. ></image>
  332. <!-- 支付宝 -->
  333. <!-- <image
  334. v-if="['App', 'alipayMiniProgram', 'H5'].includes(platform)"
  335. class="auto-login-img"
  336. @tap="thirdLogin('alipay')"
  337. :src="$IMG_URL + '/imgs/auto_login_ali.png'"
  338. mode=""
  339. ></image> -->
  340. <!-- 苹果 -->
  341. <!-- #ifdef APP-PLUS -->
  342. <image v-if="device === 'ios'" class="auto-login-img" @tap="thirdLogin('apple')" :src="$IMG_URL + '/imgs/auto_login_iphone.png'"></image>
  343. <!-- #endif -->
  344. </view>
  345. <!-- 协议 -->
  346. <view v-if="['accountLogin', 'smsLogin', 'register'].includes(authType)" class="agreement-box u-flex u-row-center">
  347. <u-checkbox v-model="protocol" shape="circle" active-color="#E9B461">
  348. <view class="agreement-text tcp-text u-flex u-col-center">
  349. 我已阅读并遵守
  350. <view class="tcp-text u-flex u-col-center">
  351. <view @tap.stop="$Router.push({ path: '/pages/public/richtext', query: { id: initShop.user_protocol || 0 } })">《用户协议》</view>
  352. <view @tap.stop="$Router.push({ path: '/pages/public/richtext', query: { id: initShop.privacy_protocol || 0 } })">《隐私协议》</view>
  353. </view>
  354. </view>
  355. </u-checkbox>
  356. </view>
  357. </view>
  358. </view>
  359. </template>
  360. <script>
  361. /**
  362. * 登录提示页
  363. */
  364. import FormValidate from '@/shopro/validate/form';
  365. import schema from '@/uview-ui/libs/util/async-validator';
  366. import wechat from '@/shopro/wechat/wechat';
  367. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  368. // #ifdef APP-PLUS
  369. import apple from '@/shopro/apple';
  370. // #endif
  371. export default {
  372. name: 'shoproAuthModal',
  373. data() {
  374. return {
  375. platform: this.$platform.get(),
  376. device: this.$platform.device(),
  377. form: {
  378. // 1.账号密码登录
  379. accountLogin: {
  380. data: {
  381. account: '', // 账号
  382. password: '' // 密码
  383. },
  384. rules: {
  385. account: FormValidate.account,
  386. password: FormValidate.password
  387. },
  388. error: {
  389. account: '',
  390. password: ''
  391. }
  392. },
  393. // 2.短信登录
  394. smsLogin: {
  395. data: {
  396. mobile: '', // 手机号
  397. code: '', // 验证码
  398. isMobileEnd: false // 手机号输入完毕
  399. },
  400. rules: {
  401. code: FormValidate.code,
  402. mobile: FormValidate.mobile
  403. },
  404. error: {
  405. mobile: '', // 手机号
  406. code: '' // 验证码
  407. }
  408. },
  409. // 3.注册
  410. register: {
  411. data: {
  412. mobile: '', // 手机号
  413. code: '', // 验证码
  414. password: '', // 密码
  415. isMobileEnd: false // 手机号输入完毕
  416. },
  417. rules: {
  418. code: FormValidate.code,
  419. mobile: FormValidate.mobile,
  420. password: FormValidate.password
  421. },
  422. error: {
  423. mobile: '', // 手机号
  424. code: '', // 验证码
  425. password: '' // 密码
  426. }
  427. },
  428. // 4.忘记密码
  429. forgotPwd: {
  430. data: {
  431. mobile: '', //手机号
  432. code: '', //验证码
  433. password: '', //密码
  434. isMobileEnd: false // 手机号输入完毕
  435. },
  436. rules: {
  437. mobile: FormValidate.mobile,
  438. code: FormValidate.code,
  439. password: FormValidate.password
  440. },
  441. error: {
  442. mobile: '', //手机号
  443. code: '', //验证码
  444. password: '' //密码
  445. }
  446. },
  447. // 5.绑定手机号
  448. bindMobile: {
  449. data: {
  450. mobile: '', //手机号
  451. code: '', //验证码
  452. isMobileEnd: false // 手机号输入完毕
  453. },
  454. rules: {
  455. code: FormValidate.code,
  456. mobile: FormValidate.mobile
  457. },
  458. error: {
  459. mobile: '', //手机号
  460. code: '' //验证码
  461. }
  462. },
  463. // 6.修改密码
  464. changePwd: {
  465. data: {
  466. oldPassword: '', //旧密码
  467. newPassword: '', //新密码
  468. reNewPassword: '' //确认密码
  469. },
  470. rules: {
  471. oldPassword: FormValidate.password,
  472. newPassword: FormValidate.password,
  473. reNewPassword: [
  474. {
  475. required: true,
  476. message: '请重新输入密码',
  477. trigger: ['change', 'blur']
  478. },
  479. {
  480. validator: (rule, value, callback) => {
  481. return value === this.form.changePwd.data.newPassword;
  482. },
  483. message: '两次输入的密码不一致',
  484. trigger: ['change', 'blur']
  485. }
  486. ]
  487. },
  488. error: {
  489. oldPassword: '', //旧密码
  490. newPassword: '', //新密码
  491. reNewPassword: '' //确认密码
  492. }
  493. }
  494. },
  495. codeText: '获取验证码',
  496. disabledCode: false,
  497. protocol: false, //是否同意隐私协议
  498. placeholderStyle: 'font-size: 30rpx; font-weight: 500;color:#C2C7CF;'
  499. };
  500. },
  501. computed: {
  502. ...mapGetters(['initShop', 'isLogin', 'authType']),
  503. showAuth: {
  504. get() {
  505. return !!this.authType;
  506. },
  507. set(value) {
  508. value ? uni.hideTabBar() : uni.showTabBar();
  509. }
  510. }
  511. },
  512. mounted() {},
  513. methods: {
  514. ...mapActions(['getUserInfo', 'showAuthModal']),
  515. // 检测
  516. checkValue(e, key) {
  517. this.validation(key);
  518. },
  519. // 校验数据
  520. validation(key, callback = () => {}) {
  521. let that = this;
  522. //拿到需要校验的数据
  523. let fieldValue = this.form[this.authType].data[key];
  524. //拿到需要检验的规则
  525. let rules = this.form[this.authType].rules[key];
  526. // 判空
  527. if (!rules || rules.length === 0) {
  528. return callback('');
  529. }
  530. // 设置当前的装填,标识为校验中
  531. let validateState = 'validating';
  532. // 调用async-validator的方法
  533. let validator = new schema({
  534. [key]: rules
  535. });
  536. // 校验
  537. validator.validate(
  538. {
  539. [key]: fieldValue
  540. },
  541. {
  542. firstFields: true
  543. },
  544. (errors, fields) => {
  545. // 记录状态和报错信息
  546. validateState = !errors ? 'success' : 'error';
  547. let validateMessage = errors ? errors[0].message : '';
  548. that.form[that.authType].error[key] = validateMessage;
  549. callback(validateMessage);
  550. }
  551. );
  552. },
  553. // 校验全部数据
  554. validateAll(callback) {
  555. let that = this;
  556. return new Promise(resolve => {
  557. // 对当前所有表单检验
  558. let valid = true; // 默认通过
  559. let count = 0; // 用于标记是否检查完毕
  560. let errorArr = []; // 存放错误信息
  561. let curFormData = that.form[that.authType].data;
  562. Object.keys(curFormData).map(field => {
  563. that.validation(field, error => {
  564. // 如果回调有error
  565. if (error) {
  566. valid = false;
  567. errorArr.push(error);
  568. }
  569. if (++count === Object.keys(curFormData).length) {
  570. resolve(valid);
  571. if (errorArr.length) {
  572. this.$u.toast(errorArr[0]);
  573. }
  574. if (typeof callback == 'function') callback(valid);
  575. }
  576. });
  577. });
  578. });
  579. },
  580. // 手机号是否输入完毕
  581. mobileInput(e, key) {
  582. this.form[this.authType].data.isMobileEnd = this.$u.test.mobile(this.form[this.authType].data.mobile);
  583. this.validation(key);
  584. },
  585. closeAuthModal() {
  586. this.$store.dispatch('showAuthModal', '');
  587. },
  588. // 获取短信验证码
  589. getSmsCode(type) {
  590. const that = this;
  591. if (that.form[this.authType].data.isMobileEnd && !that.disabledCode) {
  592. that.$http(
  593. 'common.smsSend',
  594. {
  595. mobile: that.form[this.authType].data.mobile,
  596. event: type
  597. },
  598. '获取验证码中...'
  599. ).then(res => {
  600. if (res.code === 1) {
  601. that.codeChange();
  602. that.$u.toast('验证码已发送,请注意查收短信');
  603. } else {
  604. that.$u.toast(res.msg);
  605. }
  606. });
  607. } else {
  608. that.$u.toast('请稍后再试');
  609. }
  610. },
  611. // 倒计时
  612. codeChange() {
  613. if (this.disabledCode) return;
  614. this.disabledCode = true;
  615. let n = 10;
  616. this.codeText = n + 's';
  617. const run = setInterval(() => {
  618. n -= 1;
  619. if (n < 0) {
  620. clearInterval(run);
  621. }
  622. this.codeText = n + 's';
  623. if (this.codeText < 0 + 's') {
  624. this.disabledCode = false;
  625. this.codeText = '重新获取';
  626. }
  627. }, 1000);
  628. },
  629. // 规则校验
  630. validateSubmit() {
  631. if (['accountLogin', 'smsLogin', 'register'].includes(this.authType) && !this.protocol) {
  632. this.$u.toast('请同意用户协议');
  633. return false;
  634. }
  635. return this.validateAll();
  636. },
  637. // 第三方登录
  638. async thirdLogin(provider) {
  639. if (!this.protocol) {
  640. this.$u.toast('请同意用户协议');
  641. return false;
  642. }
  643. const that = this;
  644. let token = '';
  645. switch (provider) {
  646. case 'wechat':
  647. token = await wechat.login();
  648. break;
  649. case 'alipay':
  650. break;
  651. case 'apple':
  652. token = await apple.appleIdOauth();
  653. break;
  654. default:
  655. break;
  656. }
  657. if (token) {
  658. that.closeAuthModal();
  659. that.getUserInfo(token);
  660. }
  661. },
  662. // 1.账号登录
  663. async accountLoginSubmit() {
  664. let that = this;
  665. (await that.validateSubmit()) &&
  666. that
  667. .$http(
  668. 'user.accountLogin',
  669. {
  670. account: that.form['accountLogin'].data.account,
  671. password: that.form['accountLogin'].data.password
  672. },
  673. '登录中...'
  674. )
  675. .then(res => {
  676. if (res.code === 1) {
  677. that.closeAuthModal();
  678. that.getUserInfo(res.data.token);
  679. that.$u.toast(res.msg);
  680. }
  681. });
  682. },
  683. // 2.短信登录
  684. async smsLoginSubmit() {
  685. let that = this;
  686. (await that.validateSubmit()) &&
  687. that
  688. .$http(
  689. 'user.smsLogin',
  690. {
  691. mobile: that.form['smsLogin'].data.mobile,
  692. code: that.form['smsLogin'].data.code
  693. },
  694. '登录中...'
  695. )
  696. .then(res => {
  697. if (res.code === 1) {
  698. that.closeAuthModal();
  699. that.getUserInfo(res.data.token);
  700. that.$u.toast(res.msg);
  701. }
  702. });
  703. },
  704. // 3.注册
  705. async registerSubmit() {
  706. let that = this;
  707. (await that.validateSubmit()) &&
  708. that
  709. .$http(
  710. 'user.register',
  711. {
  712. mobile: that.form['register'].data.mobile,
  713. code: that.form['register'].data.code,
  714. password: that.form['register'].data.password
  715. },
  716. '注册中...'
  717. )
  718. .then(res => {
  719. if (res.code === 1) {
  720. that.$u.toast(res.msg);
  721. that.closeAuthModal();
  722. that.getUserInfo(res.data.token);
  723. }
  724. });
  725. },
  726. // 4.忘记密码
  727. async forgotPwdSubmit() {
  728. let that = this;
  729. (await that.validateSubmit()) &&
  730. that
  731. .$http(
  732. 'user.forgotPwd',
  733. {
  734. mobile: that.form['forgotPwd'].data.mobile,
  735. code: that.form['forgotPwd'].data.code,
  736. password: that.form['forgotPwd'].data.password
  737. },
  738. '修改中...'
  739. )
  740. .then(res => {
  741. if (res.code === 1) {
  742. that.$u.toast(res.msg);
  743. if (that.isLogin) {
  744. that.closeAuthModal();
  745. } else {
  746. that.showAuthModal('accountLogin');
  747. }
  748. }
  749. });
  750. },
  751. // 5.绑定手机
  752. async bindMobileSubmit() {
  753. let that = this;
  754. (await that.validateSubmit()) &&
  755. that
  756. .$http(
  757. 'user.bindMobile',
  758. {
  759. mobile: that.form['bindMobile'].data.mobile,
  760. code: that.form['bindMobile'].data.code,
  761. password: that.form['bindMobile'].data.password
  762. },
  763. '绑定中...'
  764. )
  765. .then(res => {
  766. if (res.code === 1) {
  767. that.$u.toast(res.msg);
  768. that.closeAuthModal();
  769. that.getUserInfo();
  770. }
  771. });
  772. },
  773. // 6.修改密码
  774. async changePwdSubmit() {
  775. let that = this;
  776. (await that.validateSubmit()) &&
  777. that
  778. .$http(
  779. 'user.changePwd',
  780. {
  781. oldpassword: that.form['changePwd'].data.oldPassword,
  782. newpassword: that.form['changePwd'].data.newPassword
  783. },
  784. '修改中...'
  785. )
  786. .then(res => {
  787. if (res.code === 1) {
  788. that.closeAuthModal();
  789. that.$u.toast(res.msg);
  790. that.getUserInfo(res.data.userinfo.token);
  791. }
  792. });
  793. }
  794. }
  795. };
  796. </script>
  797. <style lang="scss" scoped>
  798. @keyframes title-animation {
  799. 0% {
  800. font-size: 32rpx;
  801. }
  802. 100% {
  803. font-size: 36rpx;
  804. }
  805. }
  806. .form-wrap {
  807. .form-item {
  808. display: flex;
  809. flex-direction: column;
  810. font-size: 28rpx;
  811. padding: 20rpx 0;
  812. color: $u-main-color;
  813. box-sizing: border-box;
  814. line-height: $u-form-item-height;
  815. width: 100%;
  816. .item-title {
  817. width: 140rpx;
  818. font-size: 30rpx;
  819. color: #333;
  820. font-weight: 600;
  821. text-align: left;
  822. }
  823. .message-error {
  824. text-align: left;
  825. font-size: 24rpx;
  826. line-height: 24rpx;
  827. color: $u-type-error;
  828. margin-top: 12rpx;
  829. margin-left: 120rpx;
  830. }
  831. }
  832. }
  833. .login-wrap {
  834. padding: 50rpx 34rpx;
  835. min-height: 700rpx;
  836. background-color: #fff;
  837. .head-box {
  838. .head-title {
  839. min-width: 160rpx;
  840. font-size: 36rpx;
  841. font-weight: bold;
  842. color: #333333;
  843. line-height: 36rpx;
  844. }
  845. .head-title-active {
  846. width: 160rpx;
  847. font-size: 32rpx;
  848. font-weight: 600;
  849. color: #999;
  850. line-height: 36rpx;
  851. }
  852. .head-title-animation {
  853. animation-name: title-animation;
  854. animation-duration: 0.1s;
  855. animation-timing-function: ease-out;
  856. animation-fill-mode: forwards;
  857. }
  858. .head-title-line {
  859. position: relative;
  860. &::before {
  861. content: '';
  862. width: 1rpx;
  863. height: 34rpx;
  864. background-color: #e4e7ed;
  865. position: absolute;
  866. left: -30rpx;
  867. top: 50%;
  868. transform: translateY(-50%);
  869. }
  870. }
  871. .head-subtitle {
  872. font-size: 26rpx;
  873. font-weight: 400;
  874. color: #c2c7cf;
  875. text-align: left;
  876. display: flex;
  877. }
  878. }
  879. .code-btn[disabled] {
  880. background-color: #fff;
  881. }
  882. .code-btn-start {
  883. width: 160rpx;
  884. line-height: 56rpx;
  885. border: 1rpx solid #e9b766;
  886. border-radius: 28rpx;
  887. font-size: 26rpx;
  888. font-weight: 400;
  889. color: #e9b766;
  890. opacity: 0.5;
  891. }
  892. .forgot-btn {
  893. width: 160rpx;
  894. line-height: 56rpx;
  895. font-size: 30rpx;
  896. font-weight: 500;
  897. color: #999;
  898. }
  899. .code-btn-end {
  900. opacity: 1 !important;
  901. }
  902. .login-btn-start {
  903. width: 158rpx;
  904. line-height: 56rpx;
  905. background: linear-gradient(90deg, #e9b461, #eecc89);
  906. border-radius: 28rpx;
  907. font-size: 26rpx;
  908. font-weight: 500;
  909. color: #ffffff;
  910. }
  911. .type-btn {
  912. padding: 20rpx;
  913. margin: 40rpx auto;
  914. width: 200rpx;
  915. font-size: 30rpx;
  916. font-weight: 500;
  917. color: #999999;
  918. }
  919. .auto-login-box {
  920. width: 100%;
  921. .auto-login-img {
  922. width: 68rpx;
  923. height: 68rpx;
  924. border-radius: 50%;
  925. margin: 0 30rpx;
  926. }
  927. }
  928. .agreement-box {
  929. margin: 80rpx auto 0;
  930. .protocol-check {
  931. transform: scale(0.7);
  932. }
  933. .agreement-text {
  934. font-size: 26rpx;
  935. font-weight: 500;
  936. color: #999999;
  937. .tcp-text {
  938. color: #e9b562;
  939. }
  940. }
  941. }
  942. }
  943. // 修改密码
  944. .editPwd-btn-box {
  945. .save-btn {
  946. width: 690rpx;
  947. line-height: 70rpx;
  948. background: linear-gradient(90deg, #e9b461, #eecc89);
  949. border-radius: 35rpx;
  950. font-size: 28rpx;
  951. font-weight: 500;
  952. color: #ffffff;
  953. }
  954. .forgot-btn {
  955. width: 690rpx;
  956. line-height: 70rpx;
  957. font-size: 28rpx;
  958. font-weight: 500;
  959. color: #999999;
  960. }
  961. }
  962. </style>