SetPassword.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="page-container">
  3. <!-- 导航栏 -->
  4. <div class="nav-bar">
  5. <div class="nav-left" @click="$router.back()">
  6. <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
  7. <path
  8. d="M15 18L9 12L15 6"
  9. stroke="#333"
  10. stroke-width="2"
  11. stroke-linecap="round"
  12. stroke-linejoin="round" />
  13. </svg>
  14. </div>
  15. <div class="nav-title">设置密码</div>
  16. <div class="nav-right"></div>
  17. </div>
  18. <div class="content">
  19. <!-- 表单区域 -->
  20. <div class="form-group">
  21. <label class="form-label">填写支付密码</label>
  22. <div class="input-wrapper">
  23. <input
  24. type="password"
  25. v-model="password"
  26. placeholder="请输入"
  27. class="custom-input"
  28. maxlength="6" />
  29. </div>
  30. </div>
  31. <div class="form-group">
  32. <label class="form-label">请确认支付密码</label>
  33. <!-- 这里的 class 用于演示截图中的选中状态效果,实际使用中浏览器自带 focus 样式 -->
  34. <div class="input-wrapper">
  35. <input
  36. type="password"
  37. v-model="confirmPassword"
  38. placeholder="请输入"
  39. class="custom-input"
  40. maxlength="6" />
  41. </div>
  42. </div>
  43. <!-- 提交按钮 -->
  44. <div class="footer-action">
  45. <button class="submit-btn" @click="handleSubmit">提交</button>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { ref } from "vue";
  52. import { useRouter } from "vue-router";
  53. import { showToast } from "vant";
  54. import { setPassword } from "@/api/user";
  55. const router = useRouter();
  56. const password = ref("");
  57. const confirmPassword = ref("");
  58. const handleSubmit = async () => {
  59. if (!password.value || !confirmPassword.value) {
  60. showToast("请输入密码");
  61. return;
  62. }
  63. if (!/^\d+$/.test(password.value) || !/^\d+$/.test(confirmPassword.value)) {
  64. showToast("密码只能为数字");
  65. return;
  66. }
  67. if (password.value !== confirmPassword.value) {
  68. showToast("两次输入的密码不一致");
  69. return;
  70. }
  71. if (password.value.length !== 6) {
  72. showToast("密码长度必须为6位");
  73. return;
  74. }
  75. const params = {
  76. password: password.value,
  77. };
  78. const data = await setPassword(params);
  79. if (data.code == "00000") {
  80. showToast("密码设置成功");
  81. router.back();
  82. }
  83. };
  84. </script>
  85. <style scoped>
  86. .page-container {
  87. min-height: 100vh;
  88. background-color: #fff;
  89. display: flex;
  90. flex-direction: column;
  91. }
  92. /* 导航栏 */
  93. .nav-bar {
  94. display: flex;
  95. justify-content: space-between;
  96. align-items: center;
  97. height: 44px;
  98. padding: 0 16px;
  99. background: #fff;
  100. position: sticky;
  101. top: 0;
  102. z-index: 10;
  103. }
  104. .nav-title {
  105. font-size: 18px;
  106. font-weight: 600;
  107. color: #333;
  108. }
  109. .nav-left,
  110. .nav-right {
  111. width: 40px;
  112. display: flex;
  113. align-items: center;
  114. }
  115. /* 内容区 */
  116. .content {
  117. padding: 20px;
  118. flex: 1;
  119. display: flex;
  120. flex-direction: column;
  121. }
  122. .form-group {
  123. margin-bottom: 24px;
  124. }
  125. .form-label {
  126. display: block;
  127. font-size: 16px;
  128. color: #333;
  129. font-weight: 500;
  130. margin-bottom: 12px;
  131. }
  132. /* 输入框样式 */
  133. .custom-input {
  134. width: 100%;
  135. height: 50px;
  136. background: #f7f8fa; /* 截图中的浅灰背景 */
  137. border: 1px solid transparent; /* 默认无边框 */
  138. border-radius: 8px;
  139. padding: 0 16px;
  140. font-size: 16px;
  141. color: #333;
  142. box-sizing: border-box;
  143. outline: none; /* 去掉浏览器默认的黑框 */
  144. transition: all 0.2s;
  145. }
  146. /* 占位符颜色 */
  147. .custom-input::placeholder {
  148. color: #c2c4cc;
  149. }
  150. /* 核心细节:输入框聚焦时变蓝 */
  151. .custom-input:focus {
  152. border-color: #2b6bff; /* 截图中的亮蓝色边框 */
  153. background: #fff; /* 聚焦时背景可能变白,视设计而定,这里保留灰底或变白均可 */
  154. }
  155. /* 底部按钮区域 */
  156. .footer-action {
  157. margin-top: auto; /* 把按钮推到最底部 */
  158. padding-bottom: 30px;
  159. }
  160. .submit-btn {
  161. width: 100%;
  162. height: 48px;
  163. background: #e02f44; /* 截图中的红色 */
  164. color: #fff;
  165. border: none;
  166. border-radius: 24px;
  167. font-size: 16px;
  168. font-weight: 600;
  169. cursor: pointer;
  170. }
  171. .submit-btn:active {
  172. opacity: 0.9;
  173. }
  174. </style>