Jelajahi Sumber

解决waiting页面bug问题

wuzj 5 hari lalu
induk
melakukan
90d3dbb81d

+ 2 - 3
src/pages/room/waiting/index.vue

@@ -525,8 +525,7 @@ export default {
             description: theme.description,
             disabled: theme.isLocked, // 根据是否解锁决定是否可选
             locked: theme.isLocked,
-            price: theme.price || '5', // 添加价格,默认5元
-            unlockRequirement: theme.isLocked ? (theme.unlockRequirement || '购买解锁') : ''
+            price: theme.price ? String(theme.price) : '5' // 添加价格,默认5元
           }))
           console.log('已加载主题:', themeOptions.value)
         }
@@ -642,7 +641,7 @@ export default {
               // 调用解锁主题API
               const result = await turtleSoupStore.unlockTheme(theme.value)
               
-              if (result.success) {
+              if (result && result.success) {
                 Taro.showToast({
                   title: '解锁成功',
                   icon: 'success'

+ 34 - 0
src/services/games/turtlesoup.ts

@@ -291,6 +291,40 @@ export const turtleSoupService = {
       });
   },
   
+
+  /**
+   * 解锁主题
+   * @param themeId 主题ID
+   */
+  async unlockTheme(themeId: string): Promise<Result<TurtleSoupTheme>> {
+    // 如果在开发环境或非小程序环境,使用Mock数据 
+    if (USE_MOCK || process.env.TARO_ENV !== 'weapp') {
+      return new Promise(resolve => {
+        setTimeout(() => {
+          const theme = mockThemes.find(t => t.id === themeId);
+          if (!theme) {
+            resolve(createError('主题未找到'));
+          } else {
+            resolve(createSuccess(theme));
+          }
+        }, 300);
+      });
+    }
+    
+    // 使用cloudApi调用云函数
+    return cloudApi.call<{ theme: TurtleSoupTheme }>('unlockTurtleSoupTheme', { themeId })
+      .then(result => {
+        if (result.success && result.data?.theme) {
+          return createSuccess(result.data.theme);
+        }
+        return createError(result.message || '解锁主题失败');
+      })
+      .catch(error => {
+        console.error('解锁主题失败:', error);
+        return createError(error.message || '解锁主题失败');  
+      });
+  },
+  
   /**
    * 获取题目列表
    * @param themeId 主题ID

+ 9 - 0
src/stores/games/turtlesoup.ts

@@ -186,6 +186,14 @@ export const useTurtleSoupStore = defineStore('turtlesoup', () => {
       loading.value = false
     }
   }
+
+  async function unlockTheme(themeId: string) {
+    const result = await turtleSoupService.unlockTheme(themeId)
+    if (result.success) {
+      return result
+    }
+    return null
+  }
   
   // 加载可用的题目列表
   async function loadPuzzles(themeId: string, difficulty?: TurtleSoupDifficulty) {
@@ -646,6 +654,7 @@ export const useTurtleSoupStore = defineStore('turtlesoup', () => {
     setViewType,
     updateGameSettings,
     loadThemes,
+    unlockTheme,
     loadPuzzles,
     createGame,
     loadHostGame,