|
@@ -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
|