• uniapp微信小程序-项目实战修改密码


     图标是使用uview里面的图标,icfont也可以

    以下是所有代码 

    1. <script>
    2. import {
    3. mapState
    4. } from 'vuex';
    5. import {putPassword}from "@/pages/utils/api.js"
    6. export default {
    7. data() {
    8. return {
    9. password:false,
    10. eyeVisible: [true, true, true], // 控制眼睛图标显示状态的数组
    11. eyefill: true,
    12. eyeoff: false,
    13. yuanmima: "12345",
    14. passwords: ["", '', ''], // 三个 input 的值分别保存在数组中,
    15. userList: [{
    16. user: "原密码",
    17. }, {
    18. user: "新密码",
    19. }, {
    20. user: "确认新密码",
    21. }]
    22. };
    23. },
    24. mounted() {
    25. },
    26. computed: {
    27. ...mapState(['userExt','userPwd']),
    28. },
    29. methods: {
    30. // 密码长度要求示例:6-20位
    31. validatePassword(event) {
    32. const password = event.detail.value;
    33. if (password.length < 6 || password.length > 20) {
    34. this.password = false
    35. uni.showToast({
    36. title: '密码长度应为6-20位',
    37. icon: 'none',
    38. duration: 2000
    39. });
    40. return;
    41. }
    42. this.password = true
    43. },
    44. togglePasswordVisibility(index) {
    45. // 使用 $set手动更新
    46. this.$set(this.eyeVisible, index, !this.eyeVisible[index]);
    47. },
    48. async signPut() {
    49. // 检查新密码和确认新密码是否匹配
    50. if (this.passwords[1] !== this.passwords[2]) {
    51. uni.showToast({
    52. title: "新密码和确认新密码不匹配",
    53. icon: "none",
    54. duration: 2000,
    55. });
    56. return;
    57. }
    58. else if(this.userPwd==this.passwords[1]){
    59. uni.showToast({
    60. title: '原密码和新密码相同无需修改',
    61. icon: 'none',
    62. duration: 2000
    63. });
    64. return
    65. }
    66. else if(this.passwords[1] == this.passwords[2]&&this.password){
    67. try{
    68. // 修改密码接口
    69. const passwordRes=await putPassword({
    70. action:"SetUpPassword",
    71. userId:this.userExt.code,
    72. OldPassword:this.passwords[0],
    73. newPassword:this.passwords[1]
    74. });
    75. if(passwordRes.Status==true){
    76. uni.showToast({
    77. title: passwordRes.Message,
    78. icon: "success",
    79. duration: 2000,
    80. });
    81. uni.reLaunch({
    82. url:"/pages/login/login"
    83. })
    84. }
    85. else{
    86. uni.showToast({
    87. title: passwordRes.Message,
    88. icon: "success",
    89. duration: 2000,
    90. });
    91. }
    92. }
    93. catch(err){
    94. console.log(err);
    95. }
    96. }
    97. else{
    98. uni.showToast({
    99. title: '密码长度应为6-20位',
    100. icon: 'none',
    101. duration: 2000
    102. });
    103. }
    104. },
    105. }
    106. }
    107. script>
    108. <style lang="less">
    109. .input{
    110. // background-color: red;
    111. height: 100rpx;
    112. }
    113. .user {
    114. font-size: 32rpx;
    115. font-family: Inter, Inter;
    116. font-weight: 400;
    117. color: #333333;
    118. padding-left: 10rpx;
    119. }
    120. .contentuser {
    121. display: flex;
    122. // padding-right: 30rpx;
    123. box-sizing: border-box;
    124. justify-content: space-between;
    125. align-items: center;
    126. height: 116rpx;
    127. }
    128. .contentuserText {
    129. display: flex;
    130. width: 400rpx;
    131. // background-color: aqua;
    132. font-size: 28rpx;
    133. font-family: Inter, Inter;
    134. padding-right: 15rpx;
    135. font-weight: 400;
    136. color: #666666;
    137. }
    138. .border {
    139. width: 656rpx;
    140. height: 1rpx;
    141. opacity: 1;
    142. border-bottom: 0.5rpx solid #D2D2D2;
    143. }
    144. .password {
    145. box-sizing: border-box;
    146. padding-left: 40rpx;
    147. }
    148. .signPut {
    149. width: 90%;
    150. font-size: 32rpx;
    151. height: 80rpx;
    152. color: #FFFFFF;
    153. border-radius: 68rpx;
    154. margin-top: 82rpx;
    155. text-align: center;
    156. line-height: 80rpx;
    157. background-color: #F65A02;
    158. margin-left: auto;
    159. margin-right: auto;
    160. }
    161. style>

  • 相关阅读:
    AI无处不在,科技改变生活:开放原子全球开源峰会参会感悟
    点击事件 事件委托的情况下实现阻止冒泡
    Springboot+ssm(Spring+SpringMVC+MyBatis)旧物置换网站
    Mybatis-Plus时间范围查询
    Selenium实现自动登录163邮箱和Locating Elements介绍
    场景应用:接口和抽象类有什么区别?你平时怎么用?
    解决Win10电脑无线网卡的移动热点无法开启问题
    【猿创征文】Vue3 企业级优雅实战 - 组件库框架 - 5 组件库通用工具包
    电阻电路的等效变化(Ⅱ)
    AIE荧光分子杂化介孔二氧化硅杂化纳米微球/聚合诱导微米级多孔SiO2微球
  • 原文地址:https://blog.csdn.net/apple_70049717/article/details/136213669