index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="change-password-page">
  3. <view class="form-container">
  4. <uni-forms ref="formRef" :model="formData" :rules="rules">
  5. <view class="form-group">
  6. <uni-forms-item label="旧密码" name="oldPassword" required label-width="160rpx">
  7. <uni-easyinput type="password" v-model="formData.oldPassword" placeholder="请输入当前密码"
  8. :inputBorder="false" />
  9. </uni-forms-item>
  10. <view class="line"></view>
  11. <uni-forms-item label="新密码" name="newPassword" required label-width="160rpx">
  12. <uni-easyinput type="password" v-model="formData.newPassword" placeholder="6-20位新密码"
  13. :inputBorder="false" />
  14. </uni-forms-item>
  15. <view class="line"></view>
  16. <uni-forms-item label="确认密码" name="confirmPassword" required label-width="160rpx">
  17. <uni-easyinput type="password" v-model="formData.confirmPassword" placeholder="请再次输入新密码"
  18. :inputBorder="false" />
  19. </uni-forms-item>
  20. </view>
  21. </uni-forms>
  22. <view class="btn-group">
  23. <button class="submit-btn" @click="submit">提交修改</button>
  24. </view>
  25. <view class="tip-text">
  26. <uni-icons type="info" size="14" color="#999"></uni-icons>
  27. <text>密码修改成功后,系统将自动安全退出,需重新登录。</text>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script setup>
  33. import { ref, reactive } from 'vue'
  34. const formRef = ref(null)
  35. const formData = reactive({
  36. oldPassword: '',
  37. newPassword: '',
  38. confirmPassword: ''
  39. })
  40. const rules = {
  41. oldPassword: {
  42. rules: [{ required: true, errorMessage: '请输入旧密码' }]
  43. },
  44. newPassword: {
  45. rules: [
  46. { required: true, errorMessage: '请输入新密码' },
  47. { minLength: 6, maxLength: 20, errorMessage: '密码长度在 6-20 位之间' }
  48. ]
  49. },
  50. confirmPassword: {
  51. rules: [
  52. { required: true, errorMessage: '请确认新密码' },
  53. {
  54. validateFunction: function (rule, value, data, callback) {
  55. if (value !== data.newPassword) {
  56. callback('两次输入的密码不一致')
  57. }
  58. return true
  59. }
  60. }
  61. ]
  62. }
  63. }
  64. const submit = async () => {
  65. try {
  66. await formRef.value.validate()
  67. uni.showLoading({ title: '修改中...' })
  68. // 模拟接口请求
  69. setTimeout(() => {
  70. uni.hideLoading()
  71. uni.showToast({ title: '密码修改成功', icon: 'success' })
  72. setTimeout(() => {
  73. uni.reLaunch({ url: '/pages/login/index' })
  74. }, 1500)
  75. }, 1000)
  76. } catch (err) {
  77. console.log('表单校验失败', err)
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .change-password-page {
  83. min-height: 100vh;
  84. background-color: #f7f8fa;
  85. padding-top: 20rpx;
  86. }
  87. .form-group {
  88. background: #fff;
  89. margin: 0 24rpx;
  90. border-radius: 20rpx;
  91. padding: 0 32rpx;
  92. }
  93. .line {
  94. height: 1rpx;
  95. background: #f5f5f5;
  96. margin: 0;
  97. }
  98. .btn-group {
  99. margin: 60rpx 32rpx 32rpx;
  100. }
  101. .submit-btn {
  102. height: 88rpx;
  103. line-height: 88rpx;
  104. background: linear-gradient(90deg, #ffd53f, #ff9500);
  105. color: #333;
  106. border: none;
  107. border-radius: 44rpx;
  108. font-size: 30rpx;
  109. font-weight: bold;
  110. }
  111. .tip-text {
  112. padding: 0 40rpx;
  113. display: flex;
  114. align-items: center;
  115. gap: 12rpx;
  116. font-size: 24rpx;
  117. color: #999;
  118. }
  119. :deep(.uni-forms-item) {
  120. border: none !important;
  121. padding: 10rpx 0;
  122. }
  123. </style>