You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

5 years ago
//app.js
5 years ago
//导入leancloud库与后台交互
import {Session} from "./data/requests";
import {Client} from "./data/client";
import {Account, Course, Exercise, ExerciseQuestion} from "./data/eduapi"
5 years ago
const AV = require('./lib/av-live-query-weapp-min');
const Towxml = require('/towxml/main');
const login = require("./model/user");
5 years ago
AV.init({
appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI',
appKey: 'waM3bwf1ftpsMLjRBqqVyJIQ',
5 years ago
});
5 years ago
5 years ago
5 years ago
App({
towxml: new Towxml(),
client: new Client(),
logining: false,
string_format_init: function(){
//使String类实现format方法
//@todo: 待测试
String.prototype.format = function (kwargs) {
return this.replace(/\{(\w+)\}/g, function (k, v) {
return kwargs[v]
});
};
},
require_login(){
if (!this.logining) {
this.logining = true;
wx.navigateTo({
url: "/pages/login/login"
});
}
5 years ago
},
onLaunch: function () {
this.client.onRequireLogin(() => {
this.require_login();
});
console.log("onLauch");
this.client.get_user_info({
success: res=>{
console.log("app.js: userinfo get success");
console.log(res);
if(res.data.user_id == 2){
this.client.callback.require_login();
}
},
fail:error=>{
console.warn("app.js: get user info fail");
}
5 years ago
}).then(()=>{
5 years ago
login().then(localuser=>{
//save for autologin
localuser.addUnique("edu_account_real_names", this.client.current_user.real_name);
localuser.addUnique("edu_account_names", this.client.current_user.name);
localuser.addUnique("edu_account_logins", this.client.current_user.login);
localuser.set("cookies", this.client.session.cookies).save();
5 years ago
});
});
5 years ago
}
});