updatePassworf.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view style="position: relative;">
  3. <view class="bg"></view>
  4. <view class="bg1"></view>
  5. <view class="back" @click="$back">
  6. <u-icon name="arrow-left" size="50" color="#919191"></u-icon>
  7. </view>
  8. <view class="content">
  9. <view class="top">
  10. <view class="title">
  11. <text>修改登录密码</text>
  12. <text>输入手机号修改密码</text>
  13. </view>
  14. </view>
  15. <view style="width: 76%;margin-top: 80rpx;">
  16. <u-form ref="uForm" :model="form" :error-type="['message']">
  17. <u-form-item label="手机号" prop="phone" label-width="150">
  18. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  19. </u-form-item>
  20. <u-form-item label="验证码" prop="code" label-width="150">
  21. <view class="flex" >
  22. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
  23. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini" @click="getCode">{{codeTips}}</u-button>
  24. </view>
  25. </u-form-item>
  26. <u-form-item label="密码" label-width="150" prop="oldPassword">
  27. <u-input :border="false" placeholder="请输入旧密码" v-model="form.oldPassword"></u-input>
  28. </u-form-item>
  29. <u-form-item label="密码" prop="password" label-width="150">
  30. <u-input :border="false" placeholder="请设置新的登录密码" v-model="form.password"></u-input>
  31. </u-form-item>
  32. <u-form-item label="确认密码" prop="confirmPassword" label-width="150">
  33. <u-input :border="false" placeholder="请再次输入新密码" v-model="form.confirmPassword" ></u-input>
  34. </u-form-item>
  35. </u-form>
  36. </view>
  37. <view style="width: 86%;margin-top: 80rpx;">
  38. <view @click="update" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 34rpx;">
  39. 确定修改密码
  40. </view>
  41. </view>
  42. </view>
  43. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  44. </view>
  45. </template>
  46. <script>
  47. import md5Libs from "uview-ui/libs/function/md5";
  48. export default {
  49. data() {
  50. return {
  51. customStyle:{
  52. 'backgroundColor':'#d18c42',
  53. 'color':'#ffffff'
  54. },
  55. form:{
  56. code:'',
  57. phone:'',
  58. password:'',
  59. oldPassword:'',
  60. confirmPassword:'',
  61. },
  62. rules: {
  63. phone: [{
  64. required: true,
  65. message: '请输入手机号',
  66. trigger: ['change', 'blur'],
  67. }],
  68. code: [{
  69. required: true,
  70. message: '请输入验证码',
  71. trigger: ['change', 'blur'],
  72. }],
  73. password: [{
  74. required: true,
  75. message: '请设置新的登录密码',
  76. trigger: ['change', 'blur'],
  77. }],
  78. oldPassword: [{
  79. required: true,
  80. message: '请输入旧密码',
  81. trigger: ['change', 'blur'],
  82. }],
  83. confirmPassword: [{
  84. required: true,
  85. message: '请再次输入新密码',
  86. trigger: ['change', 'blur'],
  87. }],
  88. },
  89. codeTips: '',
  90. }
  91. },
  92. methods: {
  93. update() {
  94. this.$refs.uForm.validate(valid => {
  95. if (valid) {
  96. this.$dialog.showLoading('登录中..')
  97. setTimeout(()=>{
  98. this.doUpdate()
  99. },500)
  100. }
  101. });
  102. },
  103. async doUpdate(){
  104. let flag=await this.verifyCode()
  105. if (!flag) {
  106. return
  107. }
  108. if (this.form.password!=this.form.confirmPassword) {
  109. this.$u.toast('输入的两次新密码不一致')
  110. return
  111. }
  112. let params={
  113. type:1,
  114. phone:this.form.phone,
  115. password:md5Libs.md5(this.form.password),
  116. oldPassword:md5Libs.md5(this.form.oldPassword)
  117. }
  118. this.$api.appaccount.setPassword(params).then(res=>{
  119. console.log(res);
  120. })
  121. },
  122. codeChange(text) {
  123. this.codeTips = text;
  124. },
  125. async verifyCode(){
  126. let p=this.$u.queryParams(this.form)
  127. let res=await this.$api.sms.validCode(p)
  128. if (res.data == "success") {
  129. return true
  130. }else{
  131. this.$u.toast(res.data)
  132. return false
  133. }
  134. },
  135. // 获取验证码
  136. getCode() {
  137. if (this.$isEmpty(this.form.phone)) {
  138. this.$u.toast('请输入手机号')
  139. return
  140. }
  141. if (this.$refs.uCode.canGetCode) {
  142. // 模拟向后端请求验证码
  143. uni.showLoading({
  144. title: '正在获取验证码',
  145. mask: true
  146. })
  147. setTimeout(() => {
  148. uni.hideLoading();
  149. let params={
  150. phone:this.form.phone
  151. }
  152. let p=this.$u.queryParams(params)
  153. this.$api.sms.send(p).then(res=>{
  154. if (res.data=="success") {
  155. this.$u.toast('验证码已发送');
  156. // 通知验证码组件内部开始倒计时
  157. }else{
  158. this.$u.toast(res.data);
  159. }
  160. this.$refs.uCode.start();
  161. })
  162. }, 2000);
  163. } else {
  164. this.$u.toast('倒计时结束后再发送');
  165. }
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. $color:#d18c42;
  172. page{
  173. background-color: #FFFFFF;
  174. }
  175. .btn{
  176. background-color: $color;
  177. color:#FFFFFF;
  178. }
  179. .btn{
  180. background-color: $color;
  181. color:#FFFFFF;
  182. }
  183. .bg{
  184. z-index: 99;
  185. height: 440rpx;
  186. width: 440rpx;
  187. position: absolute;
  188. right: -240rpx;
  189. top: -240rpx;
  190. background-color: #d18c42;
  191. border-radius: 50%;
  192. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  193. }
  194. .bg1{
  195. height: 500rpx;
  196. width: 500rpx;
  197. position: absolute;
  198. right: -240rpx;
  199. top: -240rpx;
  200. background-color: #d18c42;
  201. border-radius: 50%;
  202. box-shadow: #c6813b;
  203. }
  204. .back{
  205. position: absolute;
  206. top: var(--status-bar-height);
  207. left: 20rpx;
  208. padding-top: var(--status-bar-height);
  209. }
  210. .content{
  211. height: 90vh;
  212. display: flex;
  213. flex-direction: column;
  214. justify-content: center;
  215. align-items: center;
  216. .top{
  217. width: 76%;
  218. display: flex;
  219. .title{
  220. margin-right: 20rpx;
  221. display: flex;
  222. flex-direction: column;
  223. justify-content: center;
  224. align-items: flex-start;
  225. text-align: left;
  226. text:first-child{
  227. font-weight: 800;
  228. font-size: 60rpx;
  229. color: #000;
  230. margin-bottom: 20rpx;
  231. }
  232. text:last-child{
  233. font-size: 28rpx;
  234. color: #7f7f7f;
  235. }
  236. }
  237. }
  238. }
  239. </style>