Files
pixelheros/assets/Scripts/wx_clound_client_api/WxCloudApi.ts
panFD 31f5340866 refactor: 移除多余的新手引导2、3、4相关代码和资源
1. 删除Guide2、Guide3、Guide4的UIID配置和对应弹窗资源
2. 移除MissionCardComp中关闭guide3、guide4的逻辑代码
3. 移除GuideComp中对应guide2、3、4的UIID判断逻辑
4. 简化云函数代码中冗余的get请求分支
5. 调整按钮抖动动画的时长参数优化视觉效果
6. 新增微信云开发客户端API封装代码
2026-08-06 23:09:47 +08:00

84 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type CloudReturnType<T = any> = {
code: number,// 200成功
msg?:string,
data?:T
}
export class WxCloudApi{
/**
* @en init the cloud
* @zh 初始化云客户端(只调用一次即可)
* @param {string} env 云环境名称
*/
public static init(env:string){
wx?.cloud.init({
env: env
});
}
/**
* @en Login to the cloud
* @zh 登录云
* @return 返回结果
* 参考:
* result.result = {
* code: number, // 200成功其他都是失败
* msg: string, // 如果失败,这里是失败原因等信息
* data: { // 成功才有
* openid: string, // 用户微信平台openid
* regist_time: number, // 时间戳,用户注册时间
* game_data: object, // 开发者自己保存的数据
* }
* }
* 如果这个泛型令你报错一般是因为你删了wx.api.d.ts导致请使用以下签名
* login():Promise<{result: CloudReturnType<{openid: string, regist_time: number, game_data: object}>}>
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
* login():Promise<any>
*/
public static async login(): Promise<CloudCallFunctionResult<CloudReturnType<{
openid:string,
regist_time:number,
game_data:any
}>>>{
return await wx?.cloud.callFunction({
name: 'cocos_cloud',
data: {
cmd: "login"
}
});
}
/**
* @en Save game data to the cloud
* @zh 把客户端数据写入云,此为全覆盖写入,请自行管理完整数据
* @return 返回结果
* 参考:
* result.result = {
* code: number, // 200成功其他都是失败
* msg: string, // 如果失败,这里是失败原因等信息
* data: {
* errMsg: "document.update:ok", // 数据库返回结果
* stats: {
* updated: number, // 更新了几条数据正常是1
* }
* }
* 如果这个泛型令你报错一般是因为你删了wx.api.d.ts导致请使用以下签名
* save(gameData: any): Promise<{resoult:CloudReturnType}>
* 或者你是个“不拘小节”的老哥,可以用以下简洁版签名(参考上方的数据结构例子使用即可)
* login():Promise<any>
*/
public static async save(gameData: any): Promise<CloudCallFunctionResult<CloudReturnType<{
errMsg: string,
status:{
updated: number
}
}>>> {
return await wx?.cloud.callFunction({
name: 'cocos_cloud',
data: {
cmd: 'save',
data: gameData
}
});
}
}