前端提交日志

2020-10-20 14:59:52 阅读:2 编辑
//app.js
App({
    onLaunch: function () {

    },
    onShow: function () {

    },
    getUser:function(){
        return {
            type:"openid",
            user:"12345678"
        };
    },
    getPage:function(){
        return {
            page:"index/index",
            page_param:"a=1"
        };
    },
    getEnv:function(){
        return {
            phone:"123456"
        };
    },
    addLog:function(content){

       var data = {};
       data.event_id = "10000";
       var user = this.getUser();
       data.type=user.type;
       data.user=user.user;
       data.project = "1";
       data.platform = "mp";
       var page = this.getPage();
       data.page=page.page;
       data.page_param=page.page_param;
       data.env = this.getEnv();
       var now = parseInt(Date.parse(new Date()) / 1000);
       data.created_at = now;   
       if(content != undefined){
        data.content = content;
        }
       console.log(data);  
       var w_system_log = wx.getStorageSync('w_system_log');
       if(!w_system_log){
        w_system_log = [];
       }
       w_system_log.push(data);
       if(w_system_log.length >= 0){
           //upload log
           wx.request({
            url: "http://s.test/api/add_log",
            method:"POST",
            header: {
                'content-type': 'application/json' // 默认值
            },
            data:w_system_log,
            success(res) {

            }
        })
            wx.removeStorageSync('w_system_log')
       }else{
            wx.setStorageSync('w_system_log', w_system_log);
       }
    },

    ajax: function (url,callback) {
        var test = true;
        var api_url =  "http://gf.test/api/yzbld";
        wx.request({
            url: api_url + url, //仅为示例,并非真实的接口地址
            header: {
                'content-type': 'application/json' // 默认值
            },
            success(res) {
                //console.log(res.data)

                if (res.data.errno == 0) {
                    callback(res.data.data)
                }else{
                   // wx.a
                }
            }
        })
    },
    post: function (url,data,callback) {
        var test = true;
        var api_url =  "http://gf.test/api/yzbld";

        wx.request({
            url: api_url + url, //仅为示例,并非真实的接口地址
            method:"POST",
            data:data,
            header: {
                'content-type': 'application/json' // 默认值
            },
            success(res) {
                //console.log(res.data)

                if (res.data.errcode == 0) {
                    callback(res.data.data)
                }else{
                    // wx.a
                }
            }
        })
    },
    globalData: {
        userInfo: null,
        showMaskFlag: true,
        isIpx: false,
        api_url:"http://91.test",

    }
})