cloud.js 1.0 KB
Newer Older
J
junkunzhang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import response from "./response";
let CloudIDObject = {};
function fixWXCallFunctionData(data){
    for(var key in data){
        if(typeof data[key] == 'object'){
            fixWXCallFunctionData(data[key])
        }else if(typeof data[key] == 'string' && CloudIDObject[data[key]]){
            data[key] = CloudIDObject[data[key]];
        }
    }
}
export default {
    WXCallFunctionInit(conf){
        if(typeof conf === 'string'){
            conf = JSON.parse(conf);
        }
        wx.cloud.init(conf);
    },
    WXCallFunction(name,data,conf,s,f,c) {
        var d = JSON.parse(data);
        fixWXCallFunctionData(d);
        wx.cloud.callFunction({
            name: name,
            data: d,
            config: conf == "" ? null : JSON.parse(conf),
            ...response.handlecloudCallFunction(s,f,c)
        })
    },
    WXCloudID(cloudId){
        var res = wx.cloud.CloudID(cloudId);
        var r =  JSON.stringify(res);
        CloudIDObject[r] = res;
        return r;
    }
}