changepass.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="user-content">
  3. <!-- 自定义导航 -->
  4. <view class="navbar-box">
  5. <u-navbar
  6. title="修改密码"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. </view>
  12. <!-- 修改表单 -->
  13. <view class="from-box">
  14. <u-form
  15. labelPosition="left"
  16. :model="form"
  17. :rules="rules"
  18. ref="uForm">
  19. <!-- <u-form-item prop="password" leftIcon="lock-open" labelWidth="40rpx">
  20. <u-input
  21. v-model="form.password"
  22. type="text"
  23. placeholder="原密码"
  24. :border="true"
  25. clearable
  26. ></u-input>
  27. </u-form-item> -->
  28. <u-form-item prop="newPassword" leftIcon="lock-fill" labelWidth="40rpx">
  29. <u-input
  30. v-model="form.newPassword"
  31. type="password"
  32. placeholder="新密码"
  33. :border="true"
  34. :password="newPassword"
  35. clearable
  36. ></u-input>
  37. </u-form-item>
  38. <u-form-item prop="repNewPassword" leftIcon="lock-fill" labelWidth="40rpx">
  39. <u-input
  40. v-model="form.repNewPassword"
  41. type="password"
  42. placeholder="验证新密码"
  43. :border="true"
  44. :password="repNewPassword"
  45. clearable
  46. ></u-input>
  47. </u-form-item>
  48. </u-form>
  49. <view class="btn-box">
  50. <u-button @click="submit" type="error">修改</u-button>
  51. </view>
  52. </view>
  53. <!-- 请求加载框 -->
  54. <!-- <u-overlay :show="overlayShow">
  55. <view class="warp">
  56. <view class="rect">
  57. <u-loading-icon color="#fff"></u-loading-icon>
  58. </view>
  59. </view>
  60. </u-overlay> -->
  61. <u-mask :show="overlayShow">
  62. <view class="warp">
  63. <view class="rect">
  64. <u-loading mode="circle" size="120"></u-loading>
  65. </view>
  66. </view>
  67. </u-mask>
  68. <u-modal
  69. :show="userShow"
  70. title="错误提示"
  71. @confirm="confirm"
  72. :content='content' ></u-modal>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data () {
  78. return {
  79. useId:'',
  80. password: true,
  81. newPassword: true,
  82. repNewPassword: true,
  83. content: '登录错误',
  84. overlayShow: false,
  85. tipShow: false,
  86. userShow: false,
  87. content: '',
  88. form: {
  89. password: '',
  90. newPassword: '',
  91. repNewPassword: '',
  92. },
  93. rules: {
  94. 'password': [
  95. {
  96. type: 'string',
  97. required: true,
  98. message: '请填写密码',
  99. trigger: ['blur', 'change']
  100. },
  101. {
  102. min: 6,
  103. max: 12,
  104. message: '密码在6-12个字符之间'
  105. },
  106. ],
  107. 'newPassword': [
  108. {
  109. type: 'string',
  110. required: true,
  111. message: '请填写新密码',
  112. trigger: ['blur', 'change']
  113. },
  114. {
  115. min: 6,
  116. max: 12,
  117. message: '密码在6-12个字符之间'
  118. },
  119. ],
  120. 'repNewPassword': [
  121. {
  122. type: 'string',
  123. required: true,
  124. message: '请填写验证新密码',
  125. trigger: ['blur', 'change']
  126. },
  127. {
  128. min: 6,
  129. max: 12,
  130. message: '密码在6-12个字符之间'
  131. },
  132. {
  133. validator: (rule, value, callback) => {
  134. return this.form.newPassword === this.form.repNewPassword
  135. },
  136. message: '两次密码不一致'
  137. },
  138. ]
  139. },
  140. }
  141. },
  142. onReady() {
  143. // 设置表单校验规则
  144. this.$refs.uForm.setRules(this.rules);
  145. },
  146. methods:{
  147. // 返回事件
  148. leftClick() {
  149. let canNavBack = getCurrentPages();
  150. if(canNavBack && canNavBack.length>1) {
  151. uni.navigateBack({
  152. delta: 1
  153. });
  154. } else {
  155. history.back();
  156. }
  157. },
  158. // 密码查看事件
  159. passwordEven(type) {
  160. this[type] = !this[type]
  161. },
  162. // 登录表单提交验证
  163. submit() {
  164. this.$refs.uForm.validate(valid => {
  165. if (valid) {
  166. this.overlayShow = true
  167. this.resetPassWord()
  168. } else {
  169. uni.$u.toast('校验失败')
  170. }
  171. });
  172. },
  173. confirm() {
  174. this.userShow = false
  175. },
  176. // 修改登录密码接口
  177. async resetPassWord() {
  178. let passwordMap = {
  179. // password: this.form.password,
  180. id:this.user_info?.id,
  181. organPassword: this.form.newPassword
  182. }
  183. const {code, data, msg} = await this.$u.api.resetPassWord(passwordMap)
  184. this.overlayShow = false
  185. if (code === 200) {
  186. uni.$u.toast('密码修改成功,3s后跳转登录页!')
  187. setTimeout(() => {
  188. uni.navigateTo({
  189. url: '/pages/login/login'
  190. });
  191. }, 3000)
  192. } else {
  193. this.userShow = true
  194. this.content = msg
  195. }
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .user-content{
  202. padding-top: 120rpx;
  203. .from-box{
  204. padding: 0 20rpx;
  205. .u-form-item{
  206. margin-top: 20rpx;
  207. }
  208. .u-form-item /deep/ .u-form-item__body{
  209. padding: 20rpx 15rpx;
  210. }
  211. .u-input{
  212. }
  213. .u-form-item /deep/ .u-form-item__body__right__message{
  214. margin-left: 54rpx !important;
  215. margin-top: 10rpx;
  216. }
  217. }
  218. .btn-box{
  219. width: 80%;
  220. margin: auto;
  221. margin-top: 120rpx;
  222. }
  223. .btn-box /deep/ .u-button--error{
  224. background-color: #E32F2F;
  225. border-radius: 0;
  226. border-radius: 10rpx;
  227. }
  228. .warp {
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. height: 100%;
  233. }
  234. .rect {
  235. width: 120rpx;
  236. height: 120rpx;
  237. }
  238. }
  239. </style>