exchange.uvue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <script setup lang='ts'>
  2. import { ref } from 'vue'
  3. import { exchangeCode } from '@/services/user'
  4. import { dict } from '@/.cool/store'
  5. import { user } from '@/.cool'
  6. const code = ref<string>('')
  7. async function handleExchange() {
  8. if (!code.value) {
  9. uni.showToast({
  10. title: '请输入兑换码',
  11. icon: 'none'
  12. })
  13. return
  14. }
  15. try {
  16. await exchangeCode({
  17. exchangeCode: code.value,
  18. subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
  19. })
  20. await user.get()
  21. uni.showToast({
  22. title: '兑换成功',
  23. icon: 'success'
  24. })
  25. } catch (err: any) {
  26. }
  27. }
  28. </script>
  29. <template>
  30. <view class="content">
  31. <view class="text-[30px] font-bold">
  32. 兑换码
  33. </view>
  34. <cl-input v-model="code" :pt="{
  35. className: '!h-[40px] ',
  36. }" placeholder="请输入兑换码"></cl-input>
  37. <view class="text-[18px] w-[140px] rounded-full text-black text-center check
  38. to-pink-500 py-[5px] " @tap="handleExchange()">
  39. 兑换
  40. </view>
  41. </view>
  42. </template>
  43. <style lang="scss" scoped>
  44. .content {
  45. @apply absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-black w-[120vh] border-[3px] border-[#fff] border-solid rounded-[30px] px-10 py-4 h-[44vh] flex items-center justify-center gap-4 bg-white;
  46. }
  47. .check {
  48. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  49. }
  50. </style>