55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
/**
|
|
* 调用云函数
|
|
* @param funcName
|
|
* @param options
|
|
* @param typeName
|
|
* @returns
|
|
*/
|
|
export default async function callCloud(
|
|
action: string,
|
|
options?: Record<string, any>,
|
|
// actionName?: string,
|
|
) {
|
|
try {
|
|
// const name = funcName
|
|
// const action = actionName || (options && options.action) || '';
|
|
// if (funcName.indexOf('.') > -1) {
|
|
// const nameArr = funcName.split('.') || [];
|
|
// name = nameArr[0];
|
|
// action = nameArr[1];
|
|
// }
|
|
const name = 'robotaxi';
|
|
|
|
const { errMsg, result } = await wx.cloud.callFunction({
|
|
name,
|
|
data: {
|
|
action,
|
|
...options,
|
|
},
|
|
});
|
|
if (!/ok/.test(errMsg)) {
|
|
wx.showToast({
|
|
title: '服务器错误',
|
|
icon: 'none',
|
|
duration: 2000,
|
|
});
|
|
return {
|
|
code: '500',
|
|
info: '服务器繁忙',
|
|
message: errMsg,
|
|
};
|
|
} else {
|
|
// const { code, info, data } = result;
|
|
// if (code === '401') {
|
|
// wx.showToast({
|
|
// title: info,
|
|
// duration: 2000,
|
|
// });
|
|
// }
|
|
return result;
|
|
}
|
|
} catch (e: any) {
|
|
return { code: '500', info: e.message || '服务器繁忙' };
|
|
}
|
|
}
|