activate-card.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="page">
  3. <div class="activate-container">
  4. <div class="activate-header">
  5. <h2>{{ t('activate-card.title') }}</h2>
  6. <p>{{ t('activate-card.desc') }}</p>
  7. </div>
  8. <div class="activate-form">
  9. <div class="form-item">
  10. <van-field
  11. v-model="form.cardNo"
  12. :placeholder="t('activate-card.cardNoPlaceholder')"
  13. :rules="[{ required: true, message: t('activate-card.cardNoPlaceholder') }]"
  14. >
  15. <template #left-icon>
  16. <van-icon name="credit-pay" />
  17. </template>
  18. </van-field>
  19. </div>
  20. <div class="form-item">
  21. <van-field
  22. v-model="form.expireDate"
  23. :placeholder="t('activate-card.expireDatePlaceholder')"
  24. :rules="[{ required: true, message: t('activate-card.expireDatePlaceholder') }]"
  25. >
  26. <template #left-icon>
  27. <van-icon name="clock-o" />
  28. </template>
  29. </van-field>
  30. </div>
  31. <div class="form-item">
  32. <van-field
  33. v-model="form.cvv"
  34. :placeholder="t('activate-card.cvvPlaceholder')"
  35. :rules="[{ required: true, message: t('activate-card.cvvPlaceholder') }]"
  36. >
  37. <template #left-icon>
  38. <van-icon name="shield-o" />
  39. </template>
  40. </van-field>
  41. </div>
  42. <div class="form-item">
  43. <van-field
  44. v-model="form.password"
  45. type="password"
  46. :placeholder="t('activate-card.passwordPlaceholder')"
  47. :rules="[
  48. { required: true, message: t('activate-card.passwordPlaceholder') },
  49. { pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,16}$/, message: t('activate-card.passwordPlaceholder') }
  50. ]"
  51. >
  52. <template #left-icon>
  53. <van-icon name="lock" />
  54. </template>
  55. </van-field>
  56. </div>
  57. <div class="activate-button">
  58. <van-button type="primary" block :loading="loading" @click="handleActivate">
  59. {{ t('activate-card.activate') }}
  60. </van-button>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script setup lang="ts">
  67. import { ref } from 'vue'
  68. import { showToast, showLoadingToast } from 'vant'
  69. import { useRouter } from 'vue-router'
  70. import { useI18n } from 'vue-i18n'
  71. const { t } = useI18n()
  72. defineOptions({
  73. name: 'ActivateCard',
  74. })
  75. const router = useRouter()
  76. const loading = ref(false)
  77. const form = ref({
  78. cardNo: '',
  79. expireDate: '',
  80. cvv: '',
  81. password: '',
  82. })
  83. const handleActivate = async () => {
  84. if (!form.value.cardNo || !form.value.expireDate || !form.value.cvv || !form.value.password) {
  85. showToast('请填写完整信息')
  86. return
  87. }
  88. loading.value = true
  89. const loadingToast = showLoadingToast({
  90. message: '激活中...',
  91. forbidClick: true,
  92. })
  93. try {
  94. // TODO: 调用激活API
  95. await new Promise(resolve => setTimeout(resolve, 1000))
  96. showToast('激活成功')
  97. router.push('/cards')
  98. } catch (error: any) {
  99. showToast(error.message || '激活失败')
  100. } finally {
  101. loading.value = false
  102. loadingToast.close()
  103. }
  104. }
  105. </script>
  106. <style scoped lang="scss">
  107. .activate-container {
  108. padding: 40px 20px;
  109. }
  110. .activate-header {
  111. text-align: center;
  112. margin-bottom: 40px;
  113. h2 {
  114. font-size: var(--font-size-24);
  115. color: var(--main-yellow);
  116. margin-bottom: 8px;
  117. }
  118. p {
  119. font-size: var(--font-size-14);
  120. color: var(--gray);
  121. }
  122. }
  123. .activate-form {
  124. .form-item {
  125. margin-bottom: 20px;
  126. .van-field {
  127. background: var(--action-bg);
  128. border-radius: 12px;
  129. padding: 12px 16px;
  130. :deep(.van-field__left-icon) {
  131. margin-right: 12px;
  132. color: var(--main-yellow);
  133. }
  134. :deep(.van-field__control) {
  135. color: var(--white);
  136. &::placeholder {
  137. color: var(--gray);
  138. }
  139. }
  140. }
  141. }
  142. }
  143. .activate-button {
  144. margin-top: 40px;
  145. .van-button {
  146. height: 44px;
  147. border-radius: 12px;
  148. background: var(--main-yellow);
  149. border: none;
  150. color: var(--black);
  151. font-size: var(--font-size-16);
  152. font-weight: bold;
  153. :deep(&--loading) {
  154. opacity: 0.8;
  155. }
  156. }
  157. }
  158. </style>