exchange.uvue 1.7 KB

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