activate-card.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 { showToast, showLoadingToast } from 'vant'
  68. import { useRouter } from 'vue-router'
  69. import { useI18n } from 'vue-i18n'
  70. const { t } = useI18n()
  71. defineOptions({
  72. name: 'ActivateCard',
  73. })
  74. const router = useRouter()
  75. const loading = ref(false)
  76. const form = ref({
  77. cardNo: '',
  78. expireDate: '',
  79. cvv: '',
  80. password: '',
  81. })
  82. const handleActivate = async () => {
  83. if (!form.value.cardNo || !form.value.expireDate || !form.value.cvv || !form.value.password) {
  84. showToast('请填写完整信息')
  85. return
  86. }
  87. loading.value = true
  88. const loadingToast = showLoadingToast({
  89. message: '激活中...',
  90. forbidClick: true,
  91. })
  92. try {
  93. // TODO: 调用激活API
  94. await new Promise(resolve => setTimeout(resolve, 1000))
  95. showToast('激活成功')
  96. router.push('/cards')
  97. } catch (error: any) {
  98. showToast(error.message || '激活失败')
  99. } finally {
  100. loading.value = false
  101. loadingToast.close()
  102. }
  103. }
  104. </script>
  105. <style scoped lang="scss">
  106. .activate-container {
  107. padding: 40px 20px;
  108. }
  109. .activate-header {
  110. text-align: center;
  111. margin-bottom: 40px;
  112. h2 {
  113. font-size: var(--font-size-24);
  114. color: var(--main-yellow);
  115. margin-bottom: 8px;
  116. }
  117. p {
  118. font-size: var(--font-size-14);
  119. color: var(--gray);
  120. }
  121. }
  122. .activate-form {
  123. .form-item {
  124. margin-bottom: 20px;
  125. .van-field {
  126. background: var(--action-bg);
  127. border-radius: 12px;
  128. padding: 12px 16px;
  129. :deep(.van-field__left-icon) {
  130. margin-right: 12px;
  131. color: var(--main-yellow);
  132. }
  133. :deep(.van-field__control) {
  134. color: var(--white);
  135. &::placeholder {
  136. color: var(--gray);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. .activate-button {
  143. margin-top: 40px;
  144. .van-button {
  145. height: 44px;
  146. border-radius: 12px;
  147. background: var(--main-yellow);
  148. border: none;
  149. color: var(--black);
  150. font-size: var(--font-size-16);
  151. font-weight: bold;
  152. :deep(&--loading) {
  153. opacity: 0.8;
  154. }
  155. }
  156. }
  157. </style>