找回密码
 立即注册
查看: 21|回复: 0

uniapp微信小程序-项目实战实现修改密码功能

[复制链接]

19

主题

5

回帖

121

积分

管理员

积分
121

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老

发表于 2024-12-26 10:09:18 | 显示全部楼层 |阅读模式


  1. <template>
  2. <view>
  3. <!-- 密码三个 -->
  4. <view class="password" v-for="(item,index) in userList">
  5. <view class="contentuser">
  6. <view class="user">
  7. {{item.user}}
  8. </view>
  9. <view class="contentuserText">
  10. <!-- 两个框和两个眼睛 -->
  11. <input v-model="passwords[index]" maxlength=20 type="password" v-show="eyeVisible[index]" @blur="validatePassword" class="input" placeholder="请输入密码"/>
  12. <input v-model="passwords[index]" maxlength=20 type="text" v-show="!eyeVisible[index]" @blur="validatePassword" class="input" placeholder="请输入密码"/>
  13. <u-icon name="eye-fill" v-if="!eyeVisible[index]" size="28"
  14. @click="togglePasswordVisibility(index)"></u-icon>
  15. <u-icon name="eye-off" size="28" v-if="eyeVisible[index]"
  16. @click="togglePasswordVisibility(index)"></u-icon>
  17. </view>
  18. </view>
  19. <view class="border"></view>
  20. </view>
  21. <view class="signPut" @click="signPut">
  22. 更改密码
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapState
  29. } from 'vuex';
  30. import {putPassword}from "@/pages/utils/api.js"
  31. export default {
  32. data() {
  33. return {
  34. password:false,
  35. eyeVisible: [true, true, true], // 控制眼睛图标显示状态的数组
  36. eyefill: true,
  37. eyeoff: false,
  38. yuanmima: "12345",
  39. passwords: ["", '', ''], // 三个 input 的值分别保存在数组中,
  40. userList: [{
  41. user: "原密码",
  42. }, {
  43. user: "新密码",
  44. }, {
  45. user: "确认新密码",
  46. }]
  47. };
  48. },
  49. mounted() {

  50. },
  51. computed: {
  52. ...mapState(['userExt','userPwd']),
  53. },
  54. methods: {
  55. // 密码长度要求示例:6-20位
  56. validatePassword(event) {
  57. const password = event.detail.value;
  58. if (password.length < 6 || password.length > 20) {
  59. this.password = false
  60. uni.showToast({
  61. title: '密码长度应为6-20位',
  62. icon: 'none',
  63. duration: 2000
  64. });
  65. return;
  66. }
  67. this.password = true
  68. },
  69. togglePasswordVisibility(index) {
  70. // 使用 $set手动更新
  71. this.$set(this.eyeVisible, index, !this.eyeVisible[index]);
  72. },
  73. async signPut() {
  74. // 检查新密码和确认新密码是否匹配
  75. if (this.passwords[1] !== this.passwords[2]) {
  76. uni.showToast({
  77. title: "新密码和确认新密码不匹配",
  78. icon: "none",
  79. duration: 2000,
  80. });
  81. return;
  82. }
  83. else if(this.userPwd==this.passwords[1]){
  84. uni.showToast({
  85. title: '原密码和新密码相同无需修改',
  86. icon: 'none',
  87. duration: 2000
  88. });
  89. return
  90. }
  91. else if(this.passwords[1] == this.passwords[2]&&this.password){
  92. try{
  93. // 修改密码接口
  94. const passwordRes=await putPassword({
  95. action:"SetUpPassword",
  96. userId:this.userExt.code,
  97. OldPassword:this.passwords[0],
  98. newPassword:this.passwords[1]
  99. });
  100. if(passwordRes.Status==true){
  101. uni.showToast({
  102. title: passwordRes.Message,
  103. icon: "success",
  104. duration: 2000,
  105. });
  106. uni.reLaunch({
  107. url:"/pages/login/login"
  108. })
  109. }
  110. else{
  111. uni.showToast({
  112. title: passwordRes.Message,
  113. icon: "success",
  114. duration: 2000,
  115. });
  116. }
  117. }
  118. catch(err){
  119. console.log(err);
  120. }
  121. }
  122. else{
  123. uni.showToast({
  124. title: '密码长度应为6-20位',
  125. icon: 'none',
  126. duration: 2000
  127. });
  128. }

  129. },
  130. }

  131. }
  132. </script>

  133. <style lang="less">
  134. .input{
  135. // background-color: red;
  136. height: 100rpx;
  137. }
  138. .user {
  139. font-size: 32rpx;
  140. font-family: Inter, Inter;
  141. font-weight: 400;
  142. color: #333333;
  143. padding-left: 10rpx;
  144. }

  145. .contentuser {
  146. display: flex;
  147. // padding-right: 30rpx;
  148. box-sizing: border-box;
  149. justify-content: space-between;
  150. align-items: center;
  151. height: 116rpx;
  152. }

  153. .contentuserText {
  154. display: flex;
  155. width: 400rpx;
  156. // background-color: aqua;
  157. font-size: 28rpx;
  158. font-family: Inter, Inter;
  159. padding-right: 15rpx;
  160. font-weight: 400;
  161. color: #666666;
  162. }

  163. .border {
  164. width: 656rpx;
  165. height: 1rpx;
  166. opacity: 1;
  167. border-bottom: 0.5rpx solid #D2D2D2;

  168. }

  169. .password {
  170. box-sizing: border-box;
  171. padding-left: 40rpx;
  172. }

  173. .signPut {
  174. width: 90%;
  175. font-size: 32rpx;
  176. height: 80rpx;
  177. color: #FFFFFF;
  178. border-radius: 68rpx;
  179. margin-top: 82rpx;
  180. text-align: center;
  181. line-height: 80rpx;
  182. background-color: #F65A02;
  183. margin-left: auto;
  184. margin-right: auto;
  185. }
  186. </style>
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Gitbbs

GMT+8, 2025-1-11 15:49 , Processed in 0.140596 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表