changepass.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. password: true,
  80. newPassword: true,
  81. repNewPassword: true,
  82. content: '登录错误',
  83. overlayShow: false,
  84. tipShow: false,
  85. userShow: false,
  86. content: '',
  87. form: {
  88. password: '',
  89. newPassword: '',
  90. repNewPassword: '',
  91. },
  92. rules: {
  93. 'password': [
  94. {
  95. type: 'string',
  96. required: true,
  97. message: '请填写密码',
  98. trigger: ['blur', 'change']
  99. },
  100. {
  101. min: 6,
  102. max: 12,
  103. message: '密码在6-12个字符之间'
  104. },
  105. ],
  106. 'newPassword': [
  107. {
  108. type: 'string',
  109. required: true,
  110. message: '请填写新密码',
  111. trigger: ['blur', 'change']
  112. },
  113. {
  114. min: 6,
  115. max: 12,
  116. message: '密码在6-12个字符之间'
  117. },
  118. ],
  119. 'repNewPassword': [
  120. {
  121. type: 'string',
  122. required: true,
  123. message: '请填写验证新密码',
  124. trigger: ['blur', 'change']
  125. },
  126. {
  127. min: 6,
  128. max: 12,
  129. message: '密码在6-12个字符之间'
  130. },
  131. {
  132. validator: (rule, value, callback) => {
  133. return this.form.newPassword === this.form.repNewPassword
  134. },
  135. message: '两次密码不一致'
  136. },
  137. ]
  138. },
  139. }
  140. },
  141. onReady() {
  142. // 设置表单校验规则
  143. this.$refs.uForm.setRules(this.rules);
  144. },
  145. methods:{
  146. // 返回事件
  147. leftClick() {
  148. let canNavBack = getCurrentPages();
  149. if(canNavBack && canNavBack.length>1) {
  150. uni.navigateBack({
  151. delta: 1
  152. });
  153. } else {
  154. history.back();
  155. }
  156. },
  157. // 密码查看事件
  158. passwordEven(type) {
  159. this[type] = !this[type]
  160. },
  161. // 登录表单提交验证
  162. submit() {
  163. this.$refs.uForm.validate(valid => {
  164. if (valid) {
  165. this.overlayShow = true
  166. this.updateLeaderPwd()
  167. } else {
  168. uni.$u.toast('校验失败')
  169. }
  170. });
  171. },
  172. confirm() {
  173. this.userShow = false
  174. },
  175. // 修改登录密码接口
  176. async updateLeaderPwd() {
  177. let passwordMap = {
  178. password: this.form.password,
  179. newPassword: this.form.newPassword
  180. }
  181. const {code, data, msg} = await this.$u.api.updateLeaderPwd(passwordMap)
  182. this.overlayShow = false
  183. if (code === 200) {
  184. uni.$u.toast('密码修改成功,3s后跳转登录页!')
  185. setTimeout(() => {
  186. uni.navigateTo({
  187. url: '/pages/login/login'
  188. });
  189. }, 3000)
  190. } else {
  191. this.userShow = true
  192. this.content = msg
  193. }
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .user-content{
  200. padding-top: 120rpx;
  201. .from-box{
  202. padding: 0 20rpx;
  203. .u-form-item{
  204. margin-top: 20rpx;
  205. }
  206. .u-form-item /deep/ .u-form-item__body{
  207. padding: 20rpx 15rpx;
  208. }
  209. .u-input{
  210. }
  211. .u-form-item /deep/ .u-form-item__body__right__message{
  212. margin-left: 54rpx !important;
  213. margin-top: 10rpx;
  214. }
  215. }
  216. .btn-box{
  217. width: 80%;
  218. margin: auto;
  219. margin-top: 120rpx;
  220. }
  221. .btn-box /deep/ .u-button--error{
  222. background-color: #E32F2F;
  223. border-radius: 0;
  224. border-radius: 10rpx;
  225. }
  226. .warp {
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. height: 100%;
  231. }
  232. .rect {
  233. width: 120rpx;
  234. height: 120rpx;
  235. }
  236. }
  237. </style>