|
|
|
|
//app.js
|
|
|
|
|
//导入leancloud库,与后台交互
|
|
|
|
|
|
|
|
|
|
import {Session} from "./data/requests";
|
|
|
|
|
import {Client} from "./data/client";
|
|
|
|
|
import {Account, Course, Exercise, ExerciseQuestion} from "./data/eduapi"
|
|
|
|
|
const AV = require('./lib/av-live-query-weapp-min');
|
|
|
|
|
const Towxml = require('/towxml/main');
|
|
|
|
|
const login = require("./model/user");
|
|
|
|
|
|
|
|
|
|
//初始化
|
|
|
|
|
AV.init({
|
|
|
|
|
appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI',
|
|
|
|
|
appKey: 'waM3bwf1ftpsMLjRBqqVyJIQ',
|
|
|
|
|
});
|
|
|
|
|
// test Appid
|
|
|
|
|
// appId: 'fQCxN98zS5thYY3AceKdI8Pj-MdYXbMMI',
|
|
|
|
|
// appKey: 'Tdi1DcLlVYrTabFiBaA00pjj',
|
|
|
|
|
|
|
|
|
|
App({
|
|
|
|
|
towxml: new Towxml(),
|
|
|
|
|
client: new Client(),
|
|
|
|
|
string_format_init: function(){
|
|
|
|
|
//使String类实现format方法
|
|
|
|
|
//@todo: 待测试
|
|
|
|
|
String.prototype.format = function (kwargs) {
|
|
|
|
|
return this.replace(/\{(\w+)\}/g, function (k, v) {
|
|
|
|
|
return kwargs[v]
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
enter_login: function(){
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: "/pages/login/login"
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onLaunch: function () {
|
|
|
|
|
console.log("onLauch");
|
|
|
|
|
console.log(this.client.get_user_info({
|
|
|
|
|
success: res=>{
|
|
|
|
|
console.log("userinfo get success");
|
|
|
|
|
console.log(res);
|
|
|
|
|
console.log(this);
|
|
|
|
|
if(res.data.user_id == 2){
|
|
|
|
|
this.enter_login();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail:error=>{
|
|
|
|
|
console.log("get user info fail");
|
|
|
|
|
this.enter_login();
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
login();
|
|
|
|
|
//.then((user) => {
|
|
|
|
|
// //console.log(user);
|
|
|
|
|
// //console.log(AV.User.current());
|
|
|
|
|
// if (!user.get("name_setted")) {
|
|
|
|
|
// wx.navigateTo({
|
|
|
|
|
// url: '../user/user',
|
|
|
|
|
// });
|
|
|
|
|
// wx.showToast({
|
|
|
|
|
// title: '请修改你的姓名',
|
|
|
|
|
// duration: 5000,
|
|
|
|
|
// icon: "none"
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// wx.cloud.init({
|
|
|
|
|
// env: 'test-tkkvk'
|
|
|
|
|
// })
|
|
|
|
|
}
|
|
|
|
|
});
|