فهرست منبع

feat(兑换码): 添加兑换码功能及相关组件

- 在user.ts中新增exchangeCode接口
- 在home.uvue中添加兑换码组件入口
- 新增exchange.uvue组件实现兑换码输入和兑换功能
whj 2 هفته پیش
والد
کامیت
a4c53f0e20
3فایلهای تغییر یافته به همراه61 افزوده شده و 0 حذف شده
  1. 56 0
      pages/index/components/exchange.uvue
  2. 2 0
      pages/index/home.uvue
  3. 3 0
      services/user.ts

+ 56 - 0
pages/index/components/exchange.uvue

@@ -0,0 +1,56 @@
+<script setup lang='ts'>
+import { ref } from 'vue'
+import { exchangeCode } from '@/services/user'
+import { dict } from '@/.cool/store'
+import { user } from '@/.cool'
+
+
+const code = ref<string>('')
+
+async function handleExchange() {
+  if (!code.value) {
+    uni.showToast({
+      title: '请输入兑换码',
+      icon: 'none'
+    })
+    return
+  }
+  try {
+    await exchangeCode({
+      exchangeCode: code.value,
+      subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
+    })
+    await user.get()
+    uni.showToast({
+      title: '兑换成功',
+      icon: 'success'
+    })
+  } catch (err: any) {
+
+  }
+}
+</script>
+<template>
+  <view class="content">
+    <view class="text-[30px] font-bold">
+      兑换码
+    </view>
+    <cl-input v-model="code" :pt="{
+      className: '!h-[40px] ',
+    }" placeholder="请输入兑换码"></cl-input>
+    <view class="text-[18px] w-[140px] rounded-full text-black  text-center check
+               to-pink-500 py-[5px] " @tap="handleExchange()">
+      兑换
+    </view>
+  </view>
+</template>
+<style lang="scss" scoped>
+.content {
+  @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;
+
+}
+
+.check {
+  background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
+}
+</style>

+ 2 - 0
pages/index/home.uvue

@@ -8,6 +8,7 @@ import Chinese from './components/chinese.uvue'
 import English from './components/english.uvue'
 import Mix from './components/mix.uvue'
 import Game from './components/game.uvue'
+import Exchange from './components/exchange.uvue'
 
 const menuList = computed(() => {
 	return [
@@ -64,6 +65,7 @@ const userInfo = computed(() => user.info.value?.userInfo)
 		<English v-else-if="selected === 'english'" />
 		<Mix v-else-if="selected === 'mix'" />
 		<Game v-else-if="selected === 'game'" />
+		<Exchange v-else-if="selected === 'exchange'" />
 	</cl-page>
 </template>
 <style lang="scss" scoped>

+ 3 - 0
services/user.ts

@@ -69,4 +69,7 @@ export function wechatPay(parameter: any) {
 }
 export function wechatPayRequest(parameter: any) {
   return useGet(`/wechat/pay/request/payment`, parameter) as Promise<any>
+}
+export function exchangeCode(params) {
+  return usePost(`/upms/users/exchange/code`, params) as Promise<any>
 }