exchange.uvue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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, router } from '@/.cool'
  6. import { useUi } from "@/uni_modules/cool-ui";
  7. const ui = useUi();
  8. const code = ref<string>('')
  9. async function handleExchange() {
  10. if (user.token === 'Basic ZW5kOmVuZA==') {
  11. router.push({ path: '/pages/user/login' })
  12. return
  13. }
  14. if (!code.value) {
  15. uni.showToast({
  16. title: '请输入兑换码',
  17. icon: 'none'
  18. })
  19. return
  20. }
  21. try {
  22. await exchangeCode({
  23. exchangeCode: code.value,
  24. subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
  25. })
  26. await user.get()
  27. ui.showConfirm({
  28. title: "提示",
  29. message: "兑换成功",
  30. showCancel: false,
  31. callback(action) {
  32. console.log("用户已确认:", action);
  33. },
  34. });
  35. } catch (err: any) {
  36. uni.showToast({
  37. title: err.message,
  38. icon: 'error'
  39. })
  40. }
  41. }
  42. </script>
  43. <template>
  44. <view class="content">
  45. <view class="text-[30px] font-bold">
  46. 兑换码
  47. </view>
  48. <cl-input v-model="code" :pt="{
  49. className: '!h-[40px] ',
  50. }" placeholder="请输入兑换码"></cl-input>
  51. <view class="text-[18px] w-[140px] rounded-full text-black text-center check
  52. to-pink-500 py-[5px] " @tap="handleExchange()">
  53. 兑换
  54. </view>
  55. </view>
  56. </template>
  57. <style lang="scss" scoped>
  58. .content {
  59. @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;
  60. }
  61. .check {
  62. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  63. }
  64. </style>