chore: 初始化仓库基线(AGENTS.md、git 规范、敏感文件排除)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
|
||||
const isWeapp = process.env.TARO_ENV === 'weapp'
|
||||
|
||||
export async function callFunction<T = any>(
|
||||
name: string,
|
||||
data?: Record<string, any>
|
||||
): Promise<T> {
|
||||
if (!isWeapp) {
|
||||
const mockModule = await import(`../data/${name}`)
|
||||
return mockModule.default(data) as T
|
||||
}
|
||||
const res = await Taro.cloud.callFunction({ name, data })
|
||||
const result = res.result as { code: number; message: string; data: T }
|
||||
if (result.code !== 0) {
|
||||
console.error(`[Cloud] ${name} failed:`, result.message)
|
||||
throw new Error(result.message || '请求失败')
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
export function getDatabase() {
|
||||
if (!isWeapp) {
|
||||
return null
|
||||
}
|
||||
return Taro.cloud.database()
|
||||
}
|
||||
Reference in New Issue
Block a user