index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="bg-gray-50 p-2">
  3. <!-- 移除了左右外边距,使用full宽度 -->
  4. <view class="bg-white rounded-xl shadow-sm p-8">
  5. <!-- 表单内容 -->
  6. <view class="space-y-6">
  7. <!-- 密码输入框 -->
  8. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  9. <text class="text-gray-700 text-sm w-1/3">密码:</text>
  10. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  11. <input
  12. :type="showPassword ? 'text' : 'password'"
  13. v-model="form.password"
  14. placeholder="请输入密码"
  15. class="flex-1 bg-transparent outline-none text-gray-900"
  16. />
  17. <view class="flex space-x-2">
  18. <view v-if="form.password" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="togglePasswordVisibility">
  19. <image :src="showPassword ? '/static/eye-close.png' : '/static/eye.png'" class="w-full h-full" />
  20. </view>
  21. <view v-if="form.password" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="clearPassword">
  22. <image src="/static/clear.png" class="w-full h-full" />
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 手机号输入框 -->
  28. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  29. <text class="text-gray-700 text-sm w-1/3">手机号:</text>
  30. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  31. <input
  32. type="number"
  33. v-model="form.phone"
  34. placeholder="请输入手机号"
  35. class="flex-1 bg-transparent outline-none text-gray-900"
  36. />
  37. <view v-if="form.phone" class="w-36 h-36 flex items-center justify-center text-gray-400" @click="clearPhone">
  38. <image src="/static/clear.png" class="w-full h-full" />
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 图形验证码 -->
  43. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  44. <text class="text-gray-700 text-sm w-1/3">图形验证码:</text>
  45. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  46. <input
  47. type="text"
  48. v-model="form.authCode"
  49. placeholder="请输入图形验证码"
  50. class="flex-1 bg-transparent outline-none text-gray-900"
  51. />
  52. <!-- 3个元素横向排列的色块验证码 -->
  53. <view class="flex space-x-1 px-2 py-1 bg-gray-100 rounded">
  54. <view class="w-10 h-10 bg-green-500 rounded-sm flex items-center justify-center text-white font-bold">3</view>
  55. <view class="w-10 h-10 bg-blue-500 rounded-sm flex items-center justify-center text-white font-bold">6</view>
  56. <view class="w-10 h-10 bg-purple-500 rounded-sm flex items-center justify-center text-white font-bold">1</view>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 短信验证码 -->
  61. <view class="flex items-center border-solid border-0 border-b-1 border-gray-200 pb-2">
  62. <text class="text-gray-700 text-sm w-1/3">短信验证码:</text>
  63. <view class="flex-1 flex items-center border-b border-gray-200 py-2">
  64. <input
  65. type="text"
  66. v-model="form.smsCode"
  67. placeholder="请输入短信验证码"
  68. class="flex-1 bg-transparent outline-none text-gray-900"
  69. />
  70. <view class="text-blue-500 text-sm border-0" @click="getSmsCode">
  71. 获取验证码
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 确认按钮在表单外部 - 蓝底白字+加深圆角 -->
  78. <view class="mt-6 px-8">
  79. <view
  80. class="w-full text-center bg-blue-600 text-white py-3 rounded-2xl font-medium shadow-sm hover:bg-blue-700 transition-colors"
  81. @click="submitForm"
  82. >
  83. <text>
  84. 确认
  85. </text>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script setup>
  91. import { ref } from 'vue'
  92. // 表单数据
  93. const form = ref({
  94. password: '',
  95. phone: '',
  96. authCode: '',
  97. smsCode: ''
  98. })
  99. // 密码可见性控制
  100. const showPassword = ref(false)
  101. // 验证手机号格式
  102. const validatePhone = (phone) => {
  103. const phoneRegex = /^1[3-9]\d{9}$/;
  104. return phoneRegex.test(phone);
  105. }
  106. // 获取短信验证码
  107. const getSmsCode = () => {
  108. // 首先检查手机号是否为空
  109. if (!form.value.phone) {
  110. uni.showToast({
  111. title: '请输入手机号',
  112. icon: 'none'
  113. })
  114. return
  115. }
  116. // 验证手机号格式
  117. if (!validatePhone(form.value.phone)) {
  118. uni.showToast({
  119. title: '请输入正确的手机号',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. // 实际项目中这里调用接口发送验证码
  125. uni.showToast({
  126. title: '验证码已发送',
  127. icon: 'none'
  128. })
  129. }
  130. // 清除密码
  131. const clearPassword = () => {
  132. form.value.password = ''
  133. }
  134. // 清除手机号
  135. const clearPhone = () => {
  136. form.value.phone = ''
  137. }
  138. // 切换密码可见性
  139. const togglePasswordVisibility = () => {
  140. showPassword.value = !showPassword.value
  141. }
  142. // 提交表单
  143. const submitForm = () => {
  144. console.log('表单提交数据:', form.value)
  145. uni.showToast({
  146. title: '表单已提交',
  147. icon: 'none'
  148. })
  149. }
  150. </script>