1 Star 0 Fork 9

飞行/答题小程序

forked from Mamba/答题小程序 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 4.20 KB
一键复制 编辑 原始数据 按行查看 历史
kesixin 提交于 2024-11-07 20:53 . 更新代码
// app.js
var Apis = require('utils/apis.js');
App({
onLaunch() {
this.initAPI();
wx.Apis = Apis;
//请求公告
wx.Apis.api.getConfigValue('notice',(code, data) => {
wx.setStorageSync('notice', data.value)
});
//请求配置
wx.Apis.api.getConfigValue('isWrite',(code, data) => {
wx.setStorageSync('isWrite', data.value)
});
wx.Apis.api.getConfigValue('checkUser',(code, data) => {
wx.setStorageSync('checkUser', data.value)
});
wx.Apis.api.getConfigValue('useLearn',(code, data) => {
wx.setStorageSync('useLearn', data.value)
});
var that = this;
var openid = wx.getStorageSync('openid')
if (openid == '' || openid == undefined) {
wx.showLoading({
title: '',
})
wx.login({
success(res) {
if (res.code) {
console.log(res.code)
wx.Apis.login.login(res.code, (code, data) => {
console.log(data);
wx.Apis.setUid(data.openid); //openid
wx.Apis.set('openid', data.openid);
wx.setStorageSync('userInfo', data);
wx.hideLoading({
success: (res) => {},
})
});
}
},fail(){
wx.hideLoading({
success: (res) => {},
})
}
});
}else {
Apis.login.index((code, data) => {
console.log(data);
Apis.setUid(data.openid); //openid
wx.setStorageSync('userInfo', data)
});
}
},
globalData: {
userInfo: null,
mainActiveIndex:0,
bgmUrl: 'https://mamba-blog-images.oss-cn-shanghai.aliyuncs.com/5c8a08dc4956424741.mp3'
},
initAPI() {
var cloudCaller = function (url,oper,params, callback) {
// console.log(url)
var header = {
'Content-Type': 'application/json'
};
wx.request({
url,
method: oper,
data: params,
header,
success: function (res) {
try {
wx.stopPullDownRefresh();
} catch (e) {}
callback(res.statusCode == 200 ? null : res, res.data);
},
fail: function (err) {
try {
wx.stopPullDownRefresh();
} catch (e) {}
callback(err);
}
});
};
Apis.init(cloudCaller);
},
saveInfo: function(e,t,n){
wx.getStorage({
key: e + "" + t,
success: function(e){
var t = e.data;
getApp().info = !1;
for (var i = 0; i < t.length; i++) if (t[i][Object.keys(t[i]).toString()].indexOf(n) > -1) return console.log(t[i][Object.keys(t[i]).toString()].indexOf(n) > -1),
void (getApp().info = !0);
}
});
},
setIdsStroage: function (e, t, n, i) {
wx.getStorage({
key: e + "" + t,
success: function (o) {
for (var s = o.data, r = [], c = 0; c < s.length; c++) r.push(Object.keys(s[c]).toString());
console.log(r)
if (r.indexOf(n.toString()) > -1)
for (c = 0; c < s.length; c++) Object.keys(s[c]).indexOf(n) > -1 && -1 == s[c][n].indexOf(i) && s[c][n].push(i);
else {
var a = {};
a[n] = [], a[n].push(i), s.push(a);
}
wx.setStorage({
key: e + "" + t,
data: s
});
}, fail: function () {
var o = [], s = {};
s[n] = [], s[n].push(i), o.push(s), wx.setStorage({
key: e + "" + t,
data: o
});
}
})
},
removeids: function(e,c,n) {
wx.getStorage({
key: e + "" + c,
success: function (t) {
for (var i = t.data, o = 0; o < i.length; o++) if (i[o][Object.keys(i[o]).toString()].indexOf(n) > -1) {
var s = i[o][Object.keys(i[o]).toString()].indexOf(n);
i[o][Object.keys(i[o]).toString()].splice(s, 1), 0 == i[o][Object.keys(i[o]).toString()].length && i.splice(o, 1);
}
wx.setStorage({
key: e + "" + c,
data: i
});
}
});
},
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhihuidati/QuestionWechatApp.git
git@gitee.com:zhihuidati/QuestionWechatApp.git
zhihuidati
QuestionWechatApp
答题小程序
master

搜索帮助