index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="container">
  3. <view class="back-btn" @click="backToBefore()">
  4. <u-icon name="arrow-left" color="#fff" size="20" customStyle="margin:0 auto"></u-icon>
  5. <text class="back-text">密码修改</text>
  6. </view>
  7. <view class="change-content">
  8. <view class="pass-item">
  9. <view class="pass-item-name">账号</view>
  10. <input type="text" class="pass-item-content" v-model="loginName" />
  11. </view>
  12. <view class="pass-item">
  13. <view class="pass-item-name">验证码</view>
  14. <input type="text" class="pass-item-content" v-model="checkcode" />
  15. </view>
  16. <view class="pass-item">
  17. <view class="pass-item-name">新密码</view>
  18. <input :type="newPassType" class="pass-item-content" v-model="newPass" placeholder="含大小写数字与特殊符号" />
  19. <view class="pass-item-icon" :class="newPassType === 'text' ? 'pass-item-hide' :''">
  20. <image :src="newPassIcon" @click="changeInputType('new')"></image>
  21. </view>
  22. </view>
  23. <view class="pass-item">
  24. <view class="pass-item-name">确认密码</view>
  25. <input :type="checkPassType" class="pass-item-content" v-model="checkPass" placeholder="需与新密码一致" />
  26. <view class="pass-item-icon" :class="checkPassType === 'text' ? 'pass-item-hide' :''">
  27. <image :src="checkPassIcon" @click="changeInputType('check')"></image>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="confirm-btn" @click="confirmChange()">
  32. 确定修改
  33. </view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import {
  38. ref
  39. } from "vue";
  40. import {
  41. onLoad
  42. } from "@dcloudio/uni-app"
  43. import {
  44. verfiyChcekcodeWithName,
  45. changePass
  46. } from "@/api/login.js"
  47. import passSee from "@/static/pass-see.svg"
  48. import passHide from "@/static/pass-hide.svg"
  49. function backToBefore() {
  50. uni.navigateBack({})
  51. };
  52. let loginName = ref(null)
  53. let doneText = ref(null)
  54. let checkcode = ref(null)
  55. let newPassType = ref("password")
  56. let newPassIcon = ref(passHide)
  57. let newPass = ref('')
  58. let checkPassType = ref("password")
  59. let checkPassIcon = ref(passHide)
  60. let checkPass = ref('')
  61. function changeInputType(type) {
  62. if (type === "new") {
  63. newPassType.value = newPassType.value === "password" ? "text" : "password"
  64. newPassIcon.value = newPassType.value === "password" ? passHide : passSee
  65. } else {
  66. checkPassType.value = checkPassType.value === "password" ? "text" : "password"
  67. checkPassIcon.value = checkPassType.value === "password" ? passHide : passSee
  68. }
  69. }
  70. let emailAddress = null
  71. function confirmChange() {
  72. if (newPass.value !== checkPass.value) {
  73. return uni.showToast({
  74. title: "两次输入密码不一致",
  75. icon: "error",
  76. duration: 2000
  77. })
  78. }
  79. let reg = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[~!@#$%^&*)(_+}{|:?><]).{8,16}$/
  80. let isValid = reg.test(newPass.value)
  81. if (!isValid) {
  82. return uni.showToast({
  83. title: "密码强度过低。",
  84. icon: "error",
  85. duration: 2000
  86. })
  87. }
  88. let params = {
  89. login: loginName.value,
  90. email: emailAddress,
  91. code: checkcode.value
  92. }
  93. verfiyChcekcodeWithName(params).then(res => {
  94. if (res.code === 200 && res.data) {
  95. let passParams = {
  96. id: res.data.id,
  97. password: newPass.value,
  98. passwordCheck: checkPass.value
  99. }
  100. changePass(passParams).then(res => {
  101. if (res.code === 200) {
  102. uni.showToast({
  103. title: doneText.value,
  104. icon: "success",
  105. duration: 2000
  106. })
  107. setTimeout(() => {
  108. uni.reLaunch({
  109. url: '/pages/login/index'
  110. })
  111. }, 2000)
  112. }
  113. })
  114. }
  115. })
  116. }
  117. onLoad((option) => {
  118. emailAddress = option.email
  119. doneText.value = option.login === "done" ? "密码修改完成,请重新登录。" : "密码修改完成。"
  120. })
  121. </script>
  122. <style lang="scss" scoped>
  123. page {
  124. height: 100%;
  125. background-color: #EAF0FA;
  126. }
  127. .container {
  128. position: relative;
  129. width: 100%;
  130. height: 100%;
  131. background: linear-gradient(180deg, #1869F6 0%, #EAF0FA 64%, #EAF0FA 100%);
  132. .back-btn {
  133. position: absolute;
  134. top: 8%;
  135. left: 4%;
  136. display: flex;
  137. font-size: 40rpx;
  138. font-weight: 500;
  139. color: #FFF;
  140. .back-text {
  141. margin-left: 28rpx;
  142. }
  143. }
  144. .change-content {
  145. position: absolute;
  146. top: 226rpx;
  147. left: 4%;
  148. width: 92%;
  149. height: 358rpx;
  150. padding: 19rpx 28rpx;
  151. box-sizing: border-box;
  152. background-color: #fff;
  153. border-radius: 40rpx;
  154. .pass-item {
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. width: 100%;
  159. height: 80rpx;
  160. font-size: 32rpx;
  161. font-weight: 400;
  162. color: #9E9E9E;
  163. .pass-item-name {
  164. flex: 2;
  165. }
  166. .pass-item-content {
  167. flex: 6;
  168. text-align: right;
  169. font-size: 32rpx;
  170. color: #343437;
  171. }
  172. .pass-item-icon {
  173. flex: 1;
  174. height: 100%;
  175. line-height: 80rpx;
  176. text-align: right;
  177. image {
  178. width: 36rpx;
  179. height: 18rpx;
  180. }
  181. }
  182. .pass-item-hide {
  183. image {
  184. width: 36rpx;
  185. height: 28rpx;
  186. }
  187. }
  188. }
  189. }
  190. .confirm-btn {
  191. position: absolute;
  192. top: 640rpx;
  193. left: 4%;
  194. width: 92%;
  195. height: 84rpx;
  196. line-height: 84rpx;
  197. font-size: 36rpx;
  198. color: #fff;
  199. text-align: center;
  200. background: #1869F6;
  201. border-radius: 16rpx;
  202. }
  203. }
  204. </style>