exchange.uvue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. uni.showToast({
  27. title: err.message,
  28. icon: 'error'
  29. })
  30. }
  31. }
  32. </script>
  33. <template>
  34. <view class="content">
  35. <view class="text-[30px] font-bold">
  36. 兑换码
  37. </view>
  38. <cl-input v-model="code" :pt="{
  39. className: '!h-[40px] ',
  40. }" placeholder="请输入兑换码"></cl-input>
  41. <view class="text-[18px] w-[140px] rounded-full text-black text-center check
  42. to-pink-500 py-[5px] " @tap="handleExchange()">
  43. 兑换
  44. </view>
  45. </view>
  46. </template>
  47. <style lang="scss" scoped>
  48. .content {
  49. @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;
  50. }
  51. .check {
  52. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  53. }
  54. </style>