retrieve-by-email.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <!-- 找回密码页 -->
  2. <template>
  3. <view class="uni-content">
  4. <match-media :min-width="690">
  5. <view class="login-logo">
  6. <image :src="logo"></image>
  7. </view>
  8. <!-- 顶部文字 -->
  9. <text class="title title-box">通过邮箱验证码找回密码</text>
  10. </match-media>
  11. <uni-forms ref="form" :value="formData" err-show-type="toast">
  12. <uni-forms-item name="email">
  13. <uni-easyinput :focus="focusEmail" @blur="focusEmail = false" class="input-box" :disabled="lock" :inputBorder="false"
  14. v-model="formData.email" placeholder="请输入邮箱">
  15. </uni-easyinput>
  16. </uni-forms-item>
  17. <uni-forms-item name="code">
  18. <uni-id-pages-email-form ref="shortCode" :email="formData.email" type="reset-pwd-by-email" v-model="formData.code">
  19. </uni-id-pages-email-form>
  20. </uni-forms-item>
  21. <uni-forms-item name="password">
  22. <uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" type="password" :inputBorder="false" v-model="formData.password"
  23. placeholder="请输入新密码"></uni-easyinput>
  24. </uni-forms-item>
  25. <uni-forms-item name="password2">
  26. <uni-easyinput :focus="focusPassword2" @blur="focusPassword2 = false" class="input-box" type="password" :inputBorder="false" v-model="formData.password2"
  27. placeholder="请再次输入新密码"></uni-easyinput>
  28. </uni-forms-item>
  29. <button class="uni-btn send-btn-box" type="primary" @click="submit">提交</button>
  30. <match-media :min-width="690">
  31. <view class="link-box">
  32. <text class="link" @click="retrieveByPhone">通过手机验证码找回密码</text>
  33. <view></view>
  34. <text class="link" @click="backLogin">返回登录</text>
  35. </view>
  36. </match-media>
  37. </uni-forms>
  38. <uni-popup-captcha @confirm="submit" v-model="formData.captcha" scene="reset-pwd-by-sms" ref="popup"></uni-popup-captcha>
  39. </view>
  40. </template>
  41. <script>
  42. import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
  43. import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
  44. const uniIdCo = uniCloud.importObject("uni-id-co",{
  45. errorOptions:{
  46. type:'toast'
  47. }
  48. })
  49. export default {
  50. mixins: [mixin],
  51. data() {
  52. return {
  53. lock: false,
  54. focusEmail:true,
  55. focusPassword:false,
  56. focusPassword2:false,
  57. formData: {
  58. "email": "",
  59. "code": "",
  60. 'password': '',
  61. 'password2': '',
  62. "captcha": ""
  63. },
  64. rules: {
  65. email: {
  66. rules: [{
  67. required: true,
  68. errorMessage: '请输入邮箱',
  69. },
  70. {
  71. format:'email',
  72. errorMessage: '邮箱格式不正确',
  73. }
  74. ]
  75. },
  76. code: {
  77. rules: [{
  78. required: true,
  79. errorMessage: '请输入邮箱验证码',
  80. },
  81. {
  82. pattern: /^.{6}$/,
  83. errorMessage: '请输入6位验证码',
  84. }
  85. ]
  86. },
  87. ...passwordMod.getPwdRules()
  88. },
  89. logo: "/static/logo.png"
  90. }
  91. },
  92. computed: {
  93. isEmail() {
  94. let reg_email = /@/;
  95. let isEmail = reg_email.test(this.formData.email);
  96. return isEmail;
  97. },
  98. isPwd() {
  99. let reg_pwd = /^.{6,20}$/;
  100. let isPwd = reg_pwd.test(this.formData.password);
  101. return isPwd;
  102. },
  103. isCode() {
  104. let reg_code = /^\d{6}$/;
  105. let isCode = reg_code.test(this.formData.code);
  106. return isCode;
  107. }
  108. },
  109. onLoad(event) {
  110. if (event && event.emailNumber) {
  111. this.formData.email = event.emailNumber;
  112. if(event.lock){
  113. this.lock = event.lock //如果是已经登录的账号,点击找回密码就锁定指定的账号绑定的邮箱码
  114. this.focusEmail = true
  115. }
  116. }
  117. },
  118. onReady() {
  119. if (this.formData.email) {
  120. this.$refs.shortCode.start();
  121. }
  122. this.$refs.form.setRules(this.rules)
  123. },
  124. onShow() {
  125. // #ifdef H5
  126. document.onkeydown = event => {
  127. var e = event || window.event;
  128. if (e && e.keyCode == 13) { //回车键的键值为13
  129. this.submit()
  130. }
  131. };
  132. // #endif
  133. },
  134. methods: {
  135. /**
  136. * 完成并提交
  137. */
  138. submit() {
  139. console.log("formData", this.formData);
  140. console.log('rules', this.rules);
  141. this.$refs.form.validate()
  142. .then(res => {
  143. let {
  144. email,
  145. password: password,
  146. captcha,
  147. code
  148. } = this.formData
  149. uniIdCo.resetPwdByEmail({
  150. email,
  151. code,
  152. password,
  153. captcha
  154. }).then(e => {
  155. console.log(e);
  156. uni.navigateTo({
  157. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd',
  158. complete: (e) => {
  159. console.log(e);
  160. }
  161. })
  162. })
  163. .catch(e => {
  164. if (e.errCode == 'uni-id-captcha-required') {
  165. this.$refs.popup.open()
  166. }
  167. }).finally(e => {
  168. this.formData.captcha = ""
  169. })
  170. }).catch(errors=>{
  171. let key = errors[0].key
  172. if(key == 'code'){
  173. console.log(this.$refs.shortCode);
  174. return this.$refs.shortCode.focusSmsCodeInput = true
  175. }
  176. key = key.replace(key[0], key[0].toUpperCase())
  177. console.log(key,'focus'+key);
  178. this['focus'+key] = true
  179. })
  180. },
  181. retrieveByPhone() {
  182. uni.navigateTo({
  183. url: '/uni_modules/uni-id-pages/pages/retrieve/retrieve'
  184. })
  185. },
  186. backLogin () {
  187. uni.redirectTo({
  188. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss">
  195. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  196. @media screen and (max-width: 690px) {
  197. .uni-content{
  198. margin-top: 15px;
  199. }
  200. }
  201. @media screen and (min-width: 690px) {
  202. .uni-content{
  203. padding: 30px 40px 40px;
  204. }
  205. .link-box {
  206. /* #ifndef APP-NVUE */
  207. display: flex;
  208. /* #endif */
  209. flex-direction: row;
  210. justify-content: space-between;
  211. margin-top: 10px;
  212. }
  213. .link {
  214. font-size: 12px;
  215. }
  216. }
  217. </style>