forget.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view style="height: 100%;">
  3. <image mode="widthFix" src="/pages2/static/login_bg.jpg" class="full_img"></image>
  4. <u-navbar title="忘记密码" :border-bottom="false" background="{ background: '#ffffff',opacity:0.4; }" title-color="#ffffff" back-icon-color="#ffffff"></u-navbar>
  5. <view style="padding: 30rpx;">
  6. <view class="login_box">
  7. <u-form :model="form" ref="uForm" >
  8. <u-form-item prop="tel" ref="tel"><u-input v-model="form.tel" type="number" maxlength="11" placeholder-style="color:#999999" placeholder="手机号"/></u-form-item>
  9. <u-form-item prop="code">
  10. <u-input v-model="form.code" type="number" placeholder-style="color:#999999" placeholder="验证码"/>
  11. <u-button slot="right" size="mini" @click="getCode">{{codeTips}}</u-button>
  12. </u-form-item>
  13. <u-form-item prop="pwd"><u-input class="password" placeholder-style="color:#999999" v-model="form.pwd" type="password" placeholder="请输入新密码"/></u-form-item>
  14. <u-form-item prop="pwdAgain"><u-input class="password" placeholder-style="color:#999999" v-model="form.pwdAgain" type="password" placeholder="再次输入新密码"/></u-form-item>
  15. </u-form>
  16. </view>
  17. <button :disabled="isUse" class="loginBtn" :class="{able:canSubmit()}" @click="submit">
  18. 确定
  19. </button>
  20. </view>
  21. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. code: '',
  29. form:{
  30. code:'',
  31. tel:'',
  32. pwd:'',
  33. pwdAgain:''
  34. },
  35. rules: {
  36. tel: [
  37. {
  38. required: true,
  39. message: '请输入手机号',
  40. // 可以单个或者同时写两个触发验证方式
  41. trigger: ['change'],
  42. },
  43. {
  44. validator: (rule, value, callback) => {
  45. // 上面有说,返回true表示校验通过,返回false表示不通过
  46. // this.$u.test.mobile()就是返回true或者false的
  47. return this.$u.test.mobile(value);
  48. },
  49. message: '手机号码格式不正确',
  50. // 触发器可以同时用blur和change
  51. trigger: ['change'],
  52. }
  53. ],
  54. pwd: [
  55. {
  56. required: true,
  57. message: '请输入密码',
  58. // 可以单个或者同时写两个触发验证方式
  59. trigger: ['change'],
  60. }
  61. ],
  62. pwdAgain: [
  63. {
  64. required: true,
  65. message: '请输入密码',
  66. // 可以单个或者同时写两个触发验证方式
  67. trigger: ['change'],
  68. }
  69. ],
  70. code: [
  71. {
  72. required: true,
  73. message: '请输入验证码',
  74. // 可以单个或者同时写两个触发验证方式
  75. trigger: ['change'],
  76. }
  77. ],
  78. },
  79. codeTips: '',
  80. read:'',
  81. isUse:false
  82. };
  83. },
  84. methods: {
  85. canSubmit() {
  86. if(this.form.tel && this.form.code && this.form.pwd && this.form.pwdAgain) {
  87. return true;
  88. }
  89. return false;
  90. },
  91. submit(){
  92. let that = this
  93. if(!this.form.tel){
  94. this.$u.toast('请输入手机号码');
  95. return
  96. }
  97. if(!this.form.code){
  98. this.$u.toast('请输入验证码');
  99. return
  100. }
  101. if(!this.form.pwd){
  102. this.$u.toast('请输入新密码');
  103. return
  104. }
  105. if(!this.form.pwdAgain){
  106. this.$u.toast('请输入确定新密码');
  107. return
  108. }
  109. if(this.form.pwd!=this.form.pwdAgain){
  110. this.$u.toast('两次密码不一致');
  111. return
  112. }
  113. that.isUse = true
  114. let datas = {
  115. tel:this.form.tel,
  116. code:this.form.code,
  117. pwd:this.form.pwd
  118. }
  119. that.$api.forgetUser(datas).then(
  120. res => {
  121. that.isUse = false
  122. if (res.data.code == 200) {
  123. uni.showModal({
  124. title: '提示',
  125. content: '修改成功',
  126. showCancel:false,
  127. success: function(resst) {
  128. uni.navigateBack()
  129. }
  130. });
  131. } else {
  132. that.$u.toast(res.data.msg);
  133. }
  134. },
  135. err => {
  136. that.isUse = false
  137. console.log(err);
  138. }
  139. );
  140. },
  141. codeChange(text) {
  142. this.codeTips = text;
  143. },
  144. // 获取验证码
  145. getCode() {
  146. let that = this
  147. if(that.$refs.uCode.canGetCode) {
  148. if(that.$refs.tel.validateState == 'success') {
  149. let datas = {tel:this.form.tel}
  150. that.$api.forgetSms(datas).then(
  151. res => {
  152. if (res.data.code == 200) {
  153. that.$u.toast('验证码已发送');
  154. // 通知验证码组件内部开始倒计时
  155. that.$refs.uCode.start();
  156. } else {
  157. that.$u.toast(res.data.msg);
  158. }
  159. },
  160. err => {
  161. console.log(err);
  162. });
  163. } else {
  164. this.$refs.tel.onFieldChange()
  165. }
  166. }
  167. },
  168. },
  169. onLoad(option) {
  170. let that = this;
  171. // this.from = option.from; // 看页面没有用到
  172. uni.login({
  173. provider: 'weixin',
  174. success: function(loginRes) {
  175. that.code = loginRes.code;
  176. }
  177. });
  178. },
  179. onReady() {
  180. this.$refs.uForm.setRules(this.rules)
  181. },
  182. };
  183. </script>
  184. <style scoped lang="scss">
  185. .wxBtn{
  186. position: fixed;
  187. bottom: 10%;
  188. width: 100%;
  189. left: 0;
  190. }
  191. /deep/ .wxBtn button::after{
  192. border: none;
  193. }
  194. .loginBtn{
  195. width: 526rpx;
  196. height: 80rpx;
  197. background: linear-gradient(90deg, #015EEA, #00C0FA);
  198. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  199. opacity: 0.6;
  200. border-radius: 40rpx;
  201. color: #FFFFFF;
  202. text-align: center;
  203. line-height: 80rpx;
  204. margin: 40rpx auto;
  205. &.able {
  206. opacity: 1;
  207. }
  208. }
  209. .wxloginBtn{
  210. background: url("/static/loginBtn.png") no-repeat;
  211. background-size:100% 100%;
  212. border:none;
  213. width: 100rpx;
  214. height: 100rpx;
  215. }
  216. /deep/page {
  217. background-color: #FFFFFF;
  218. height: 100%;
  219. width: 100%;
  220. }
  221. .login_box{
  222. width: 100%;
  223. height: 566rpx;
  224. background: #FFFFFF;
  225. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  226. border-radius: 24rpx;
  227. margin-top: 30rpx;
  228. padding:40rpx 35rpx;
  229. .password {
  230. /deep/.uicon-eye-fill {
  231. &::before{
  232. color:#007AFF;
  233. content:"\e613";
  234. }
  235. }
  236. }
  237. }
  238. /deep/ .u-item-bg{
  239. border-radius: 32px !important;
  240. }
  241. /deep/ .u-subsection{
  242. border-radius: 32px !important;
  243. }
  244. .full_img {
  245. position: absolute;
  246. left: 0;
  247. display: block;
  248. width: 100%;
  249. z-index: -999;
  250. top: 0;
  251. }
  252. .head {
  253. height: 96rpx;
  254. width: 100%;
  255. line-height: 96rpx;
  256. margin-top: 40rpx;
  257. text-align: center;
  258. display: flex;
  259. position: relative;
  260. justify-content: center;
  261. }
  262. .icon {
  263. position: absolute;
  264. left: 30rpx;
  265. }
  266. </style>