retrieve.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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="phone">
  13. <uni-easyinput :focus="focusPhone" @blur="focusPhone = false" class="input-box" :disabled="lock" type="number" :inputBorder="false"
  14. v-model="formData.phone" maxlength="11" placeholder="请输入手机号">
  15. </uni-easyinput>
  16. </uni-forms-item>
  17. <uni-forms-item name="code">
  18. <uni-id-pages-sms-form ref="shortCode" :phone="formData.phone" type="reset-pwd-by-sms" v-model="formData.code">
  19. </uni-id-pages-sms-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="retrieveByEmail">通过邮箱验证码找回密码</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. const uniIdCo = uniCloud.importObject("uni-id-co",{
  44. errorOptions:{
  45. type:'toast'
  46. }
  47. })
  48. export default {
  49. mixins: [mixin],
  50. data() {
  51. return {
  52. lock: false,
  53. focusPhone:true,
  54. focusPassword:false,
  55. focusPassword2:false,
  56. formData: {
  57. "phone": "",
  58. "code": "",
  59. 'password': '',
  60. 'password2': '',
  61. "captcha": ""
  62. },
  63. rules: {
  64. phone: {
  65. rules: [{
  66. required: true,
  67. errorMessage: '请输入手机号',
  68. },
  69. {
  70. pattern: /^1\d{10}$/,
  71. errorMessage: '手机号码格式不正确',
  72. }
  73. ]
  74. },
  75. code: {
  76. rules: [{
  77. required: true,
  78. errorMessage: '请输入短信验证码',
  79. },
  80. {
  81. pattern: /^.{6}$/,
  82. errorMessage: '请输入6位验证码',
  83. }
  84. ]
  85. },
  86. password: {
  87. rules: [{
  88. required: true,
  89. errorMessage: '请输入新密码',
  90. },
  91. {
  92. pattern: /^.{6,20}$/,
  93. errorMessage: '密码为6 - 20位',
  94. }
  95. ]
  96. },
  97. password2: {
  98. rules: [{
  99. required: true,
  100. errorMessage: '请确认密码',
  101. },
  102. {
  103. pattern: /^.{6,20}$/,
  104. errorMessage: '密码为6 - 20位',
  105. },
  106. {
  107. validateFunction: function(rule, value, data, callback) {
  108. // console.log(value);
  109. if (value != data.password) {
  110. callback('两次输入密码不一致')
  111. };
  112. return true
  113. }
  114. }
  115. ]
  116. }
  117. },
  118. logo: "/static/logo.png"
  119. }
  120. },
  121. computed: {
  122. isPhone() {
  123. let reg_phone = /^1\d{10}$/;
  124. let isPhone = reg_phone.test(this.formData.phone);
  125. return isPhone;
  126. },
  127. isPwd() {
  128. let reg_pwd = /^.{6,20}$/;
  129. let isPwd = reg_pwd.test(this.formData.password);
  130. return isPwd;
  131. },
  132. isCode() {
  133. let reg_code = /^\d{6}$/;
  134. let isCode = reg_code.test(this.formData.code);
  135. return isCode;
  136. }
  137. },
  138. onLoad(event) {
  139. if (event && event.phoneNumber) {
  140. this.formData.phone = event.phoneNumber;
  141. if(event.lock){
  142. this.lock = event.lock //如果是已经登录的账号,点击找回密码就锁定指定的账号绑定的手机号码
  143. this.focusPhone = true
  144. }
  145. }
  146. },
  147. onReady() {
  148. if (this.formData.phone) {
  149. this.$refs.shortCode.start();
  150. }
  151. this.$refs.form.setRules(this.rules)
  152. },
  153. onShow() {
  154. // #ifdef H5
  155. document.onkeydown = event => {
  156. var e = event || window.event;
  157. if (e && e.keyCode == 13) { //回车键的键值为13
  158. this.submit()
  159. }
  160. };
  161. // #endif
  162. },
  163. methods: {
  164. /**
  165. * 完成并提交
  166. */
  167. submit() {
  168. console.log("formData", this.formData);
  169. console.log('rules', this.rules);
  170. this.$refs.form.validate()
  171. .then(res => {
  172. let {
  173. "phone": mobile,
  174. "password": password,
  175. captcha,
  176. code
  177. } = this.formData
  178. uniIdCo.resetPwdBySms({
  179. mobile,
  180. code,
  181. password,
  182. captcha
  183. }).then(e => {
  184. console.log(e);
  185. uni.navigateBack()
  186. })
  187. .catch(e => {
  188. if (e.errCode == 'uni-id-captcha-required') {
  189. this.$refs.popup.open()
  190. }
  191. }).finally(e => {
  192. this.formData.captcha = ""
  193. })
  194. }).catch(errors=>{
  195. let key = errors[0].key
  196. if(key == 'code'){
  197. console.log(this.$refs.shortCode);
  198. return this.$refs.shortCode.focusSmsCodeInput = true
  199. }
  200. key = key.replace(key[0], key[0].toUpperCase())
  201. console.log(key,'focus'+key);
  202. this['focus'+key] = true
  203. })
  204. },
  205. retrieveByEmail() {
  206. uni.navigateTo({
  207. url: '/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email'
  208. })
  209. },
  210. backLogin () {
  211. uni.redirectTo({
  212. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss">
  219. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  220. @media screen and (max-width: 690px) {
  221. .uni-content{
  222. margin-top: 15px;
  223. }
  224. }
  225. @media screen and (min-width: 690px) {
  226. .uni-content{
  227. padding: 30px 40px 40px;
  228. }
  229. .link-box {
  230. /* #ifndef APP-NVUE */
  231. display: flex;
  232. /* #endif */
  233. flex-direction: row;
  234. justify-content: space-between;
  235. margin-top: 10px;
  236. }
  237. .link {
  238. font-size: 12px;
  239. }
  240. }
  241. </style>