resetpass.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="修改密码"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. bgColor="#ED0000"
  9. :titleStyle="{color:'#fff'}"
  10. leftIconColor="#fff"
  11. >
  12. </u-navbar>
  13. <view class="form-wrap">
  14. <u--form labelPosition="left" labelWidth="70px" :model="form" :rules="rules" ref="uForm" >
  15. <u-form-item label="旧密码" prop="oldPassword" borderBottom ref="oldPassword" >
  16. <u--input
  17. v-model="form.oldPassword"
  18. border="none"
  19. placeholder="请输入旧密码"
  20. :customStyle="inputCustomStyle"
  21. ></u--input>
  22. </u-form-item>
  23. <u-form-item label="新密码" prop="password" borderBottom ref="password" >
  24. <u--input
  25. v-model="form.password"
  26. border="none"
  27. :password="true"
  28. placeholder="请输入新密码"
  29. :customStyle="inputCustomStyle"
  30. ></u--input>
  31. </u-form-item>
  32. <u-form-item label="确认密码" prop="comfpassword" :borderBottom="false" ref="comfpassword" >
  33. <u--input
  34. v-model="form.comfpassword"
  35. border="none"
  36. :password="true"
  37. placeholder="请确认新密码"
  38. :customStyle="inputCustomStyle"
  39. ></u--input>
  40. </u-form-item>
  41. </u--form>
  42. </view>
  43. <u-button
  44. @click="submit"
  45. text="确定"
  46. type="primary"
  47. shape="circle"
  48. :customStyle="{'margin':'60rpx 32rpx',height:'98rpx','box-sizing':'border-box',width:'auto'}"
  49. color="linear-gradient(90deg, #FF7979 0%, #ED0000 100%)">
  50. </u-button>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. form:{
  58. oldPassword:'',
  59. password:'',
  60. comfpassword:'',
  61. },
  62. rules: {
  63. oldPassword: {
  64. type: 'string',
  65. required: true,
  66. message: '请输入旧密码',
  67. trigger: ['blur', 'change']
  68. },
  69. password: [
  70. {
  71. type: 'string',
  72. required: true,
  73. message: '请输入新密码',
  74. trigger: ['blur', 'change']
  75. },
  76. {
  77. min: 6,
  78. max: 10,
  79. message: '长度在6-10个字符之间',
  80. trigger: 'blur',
  81. },
  82. ],
  83. comfpassword: [
  84. {
  85. type: 'string',
  86. required: true,
  87. message: '请确认密码',
  88. trigger: ['blur', 'change']
  89. },
  90. {
  91. validator: (rule, value, callback) => {
  92. if (value === '') {
  93. callback(new Error('请再次输入密码'));
  94. } else if (value !== this.form.password) {
  95. callback(new Error('两次输入密码不一致!'));
  96. } else {
  97. callback();
  98. }
  99. },
  100. trigger: 'blur',
  101. }
  102. ],
  103. },
  104. inputCustomStyle:{
  105. height:'98rpx',
  106. 'border-color':'#eee',
  107. 'padding-left':'30rpx',
  108. 'box-sizing':'border-box',
  109. }
  110. }
  111. },
  112. onShow() {
  113. },
  114. onReady() {
  115. this.$refs.uForm.setRules(this.rules)
  116. },
  117. onLoad() {
  118. },
  119. methods: {
  120. chekPass(){
  121. console.log('chekPass---',this.form);
  122. return new Promise((resolve, reject)=>{
  123. if(!password){
  124. reject('needAuth');
  125. }
  126. })
  127. },
  128. async submit(){
  129. let that = this;
  130. // console.log('form',this.form);
  131. this.$refs.uForm.validate().then(res => {
  132. // let chekPassResult = await this.chekPass();
  133. // return
  134. // uni.$u.toast('校验通过')
  135. const param = {
  136. oldPassword:this.form.oldPassword,
  137. newPassword:this.form.password
  138. }
  139. this.$u.api.updatePassword(param).then(res=>{
  140. // console.log('res',res.data);
  141. this.$u.vuex('vuex_user_info', res.data);
  142. uni.showToast({
  143. title:res.msg,
  144. icon:'success'
  145. })
  146. setTimeout(()=>{
  147. that.redirectToAuth();
  148. },2000)
  149. // uni.reLaunch({url: this.backUrl});
  150. }).catch(err=>{
  151. console.log('login',err);
  152. })
  153. }).catch(errors => {
  154. uni.$u.toast('请正确填写表单')
  155. })
  156. },
  157. redirectToAuth() {
  158. try{
  159. window.location.href = this.$commonConfig.authUrl;
  160. }catch(e){
  161. alert(`redirectToAuth e:${e}`)
  162. }
  163. },
  164. }
  165. }
  166. </script>
  167. <style>
  168. page{
  169. background-color: #F4F5F7;
  170. }
  171. </style>
  172. <style lang="scss" scoped>
  173. .form-wrap{
  174. margin: 40rpx 32rpx;
  175. padding: 20rpx 40rpx;
  176. background-color: #fff;
  177. box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(226,226,226,0.5);
  178. border-radius: 24rpx;
  179. }
  180. </style>