changePassword.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="app-container pb-20">
  3. <TopBar title="修改密码" show-back />
  4. <view class="px-4 py-4">
  5. <view class="card p-4">
  6. <view class="form-group">
  7. <text class="form-label">
  8. <text class="text-red-500">*</text>当前密码
  9. </text>
  10. <uni-easyinput class="form-input"type="password" v-model="currentPassword" placeholder="请输入当前密码" />
  11. </view>
  12. <view class="form-group">
  13. <text class="form-label">
  14. <text class="text-red-500">*</text>新密码
  15. </text>
  16. <uni-easyinput class="form-input"type="password" v-model="newPassword" placeholder="请输入新密码(6-20位)" />
  17. </view>
  18. <view class="form-group">
  19. <text class="form-label">
  20. <text class="text-red-500">*</text>确认新密码
  21. </text>
  22. <uni-easyinput class="form-input"type="password" v-model="confirmNewPassword" placeholder="请再次输入新密码" />
  23. </view>
  24. <view class="mt-4">
  25. <view class="bg-blue-50 rounded-lg p-3 mb-4">
  26. <text class="text-blue-600 text-sm block">ℹ️ 密码要求:</text>
  27. <view class="text-gray-500 text-xs mt-2 gap-y-1">
  28. <text class="block">• 长度6-20位</text>
  29. <text class="block">• 必须包含字母和数字</text>
  30. <text class="block">• 不能与当前密码相同</text>
  31. </view>
  32. </view>
  33. <button class="w-full py-3 bg-blue-500 text-white rounded-xl font-medium" @click="submitChangePassword">
  34. 确认修改
  35. </button>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script setup lang="ts">
  42. import { ref } from 'vue'
  43. import TopBar from '@/components/common/TopBar.vue'
  44. import { showToast } from '@/utils'
  45. const currentPassword = ref('')
  46. const newPassword = ref('')
  47. const confirmNewPassword = ref('')
  48. function validateForm(): boolean {
  49. if (!currentPassword.value.trim()) {
  50. showToast('请输入当前密码')
  51. return false
  52. }
  53. if (!newPassword.value.trim()) {
  54. showToast('请输入新密码')
  55. return false
  56. }
  57. if (newPassword.value.length < 6 || newPassword.value.length > 20) {
  58. showToast('密码长度需在6-20位之间')
  59. return false
  60. }
  61. if (!/[a-zA-Z]/.test(newPassword.value) || !/[0-9]/.test(newPassword.value)) {
  62. showToast('密码必须包含字母和数字')
  63. return false
  64. }
  65. if (newPassword.value === currentPassword.value) {
  66. showToast('新密码不能与当前密码相同')
  67. return false
  68. }
  69. if (newPassword.value !== confirmNewPassword.value) {
  70. showToast('两次输入的新密码不一致')
  71. return false
  72. }
  73. return true
  74. }
  75. function submitChangePassword() {
  76. if (!validateForm()) return
  77. showToast({ title: '密码修改成功', icon: 'success' })
  78. setTimeout(() => {
  79. uni.navigateBack()
  80. }, 1500)
  81. }
  82. </script>
  83. <style scoped>
  84. .form-group {
  85. margin-bottom: 16px;
  86. }
  87. </style>