index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="bg-gray-50 p-2 min-h-screen">
  3. <view class="bg-white rounded-xl shadow-sm p-8">
  4. <!-- 表单内容 -->
  5. <view class="space-y-6">
  6. <!-- 旧密码输入框 -->
  7. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  8. <text class="text-gray-700 text-sm w-1/3">旧密码:</text>
  9. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  10. <input
  11. :type="showOldPassword ? 'text' : 'password'"
  12. v-model="form.oldPassword"
  13. placeholder="请输入旧密码"
  14. class="flex-1 bg-transparent outline-none text-gray-900"
  15. />
  16. <view class="flex space-x-2">
  17. <view v-if="form.oldPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="toggleOldPasswordVisibility">
  18. <image :src="showOldPassword ? '/static/eye-close.png' : '/static/eye.png'" class="w-full h-full" />
  19. </view>
  20. <view v-if="form.oldPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="clearOldPassword">
  21. <image src="/static/clear.png" class="w-full h-full" />
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 新密码输入框 -->
  27. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  28. <text class="text-gray-700 text-sm w-1/3">新密码:</text>
  29. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  30. <input
  31. :type="showNewPassword ? 'text' : 'password'"
  32. v-model="form.newPassword"
  33. placeholder="请输入8-16位新密码"
  34. class="flex-1 bg-transparent outline-none text-gray-900"
  35. />
  36. <view class="flex space-x-2">
  37. <view v-if="form.newPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="toggleNewPasswordVisibility">
  38. <image :src="showNewPassword ? '/static/eye-close.png' : '/static/eye.png'" class="w-full h-full" />
  39. </view>
  40. <view v-if="form.newPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="clearNewPassword">
  41. <image src="/static/clear.png" class="w-full h-full" />
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 确认密码输入框 -->
  47. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  48. <text class="text-gray-700 text-sm w-1/3">确认密码:</text>
  49. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  50. <input
  51. :type="showConfirmPassword ? 'text' : 'password'"
  52. v-model="form.confirmPassword"
  53. placeholder="请再次输入新密码"
  54. class="flex-1 bg-transparent outline-none text-gray-900"
  55. />
  56. <view class="flex space-x-2">
  57. <view v-if="form.confirmPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="toggleConfirmPasswordVisibility">
  58. <image :src="showConfirmPassword ? '/static/eye-close.png' : '/static/eye.png'" class="w-full h-full" />
  59. </view>
  60. <view v-if="form.confirmPassword" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="clearConfirmPassword">
  61. <image src="/static/clear.png" class="w-full h-full" />
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 确认按钮 -->
  69. <view class="mt-6 px-8">
  70. <view
  71. class="w-full text-center bg-blue-600 text-white py-3 rounded-2xl font-medium shadow-sm hover:bg-blue-700 transition-colors"
  72. @click="submitForm"
  73. >
  74. <text>确认</text>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script setup>
  80. import { ref } from 'vue'
  81. // 表单数据
  82. const form = ref({
  83. oldPassword: '',
  84. newPassword: '',
  85. confirmPassword: ''
  86. })
  87. // 密码可见性控制
  88. const showOldPassword = ref(false)
  89. const showNewPassword = ref(false)
  90. const showConfirmPassword = ref(false)
  91. // 验证密码长度
  92. const validatePasswordLength = (password) => {
  93. return password.length >= 8 && password.length <= 16
  94. }
  95. // 验证两次密码是否一致
  96. const validatePasswordMatch = () => {
  97. return form.value.newPassword === form.value.confirmPassword
  98. }
  99. // 清除旧密码
  100. const clearOldPassword = () => {
  101. form.value.oldPassword = ''
  102. }
  103. // 清除新密码
  104. const clearNewPassword = () => {
  105. form.value.newPassword = ''
  106. }
  107. // 清除确认密码
  108. const clearConfirmPassword = () => {
  109. form.value.confirmPassword = ''
  110. }
  111. // 切换旧密码可见性
  112. const toggleOldPasswordVisibility = () => {
  113. showOldPassword.value = !showOldPassword.value
  114. }
  115. // 切换新密码可见性
  116. const toggleNewPasswordVisibility = () => {
  117. showNewPassword.value = !showNewPassword.value
  118. }
  119. // 切换确认密码可见性
  120. const toggleConfirmPasswordVisibility = () => {
  121. showConfirmPassword.value = !showConfirmPassword.value
  122. }
  123. // 提交表单
  124. const submitForm = () => {
  125. // 验证旧密码
  126. if (!form.value.oldPassword) {
  127. uni.showToast({
  128. title: '请输入旧密码',
  129. icon: 'none'
  130. })
  131. return
  132. }
  133. // 验证新密码长度
  134. if (!validatePasswordLength(form.value.newPassword)) {
  135. uni.showToast({
  136. title: '新密码需为8-16位',
  137. icon: 'none'
  138. })
  139. return
  140. }
  141. // 验证确认密码
  142. if (!form.value.confirmPassword) {
  143. uni.showToast({
  144. title: '请输入确认密码',
  145. icon: 'none'
  146. })
  147. return
  148. }
  149. // 验证密码一致性
  150. if (!validatePasswordMatch()) {
  151. uni.showToast({
  152. title: '两次输入的密码不一致',
  153. icon: 'none'
  154. })
  155. return
  156. }
  157. // 所有验证通过,提交表单
  158. console.log('密码修改提交数据:', form.value)
  159. uni.showToast({
  160. title: '密码修改成功',
  161. icon: 'none'
  162. })
  163. // 实际项目中这里调用修改密码的接口
  164. }
  165. </script>