A 网络请求缓存

master
educoder_weapp 5 years ago
parent 03e67f288a
commit c30432d745

@ -154,12 +154,12 @@ Page({
let tmp = pos[action];
pos[action] = pos[this.data.action];
pos[this.data.action] = tmp;
if(Math.random()>0.5){
/*if(Math.random()>0.5){
for(var k in pos){
if(pos[k]!=1)
pos[k] = pos[k]==2?3:2;
}
}
}*/
this.setData({pos, action});
},
onLoad: function (options) {

@ -7,10 +7,16 @@ Page({
buttons:[{text:"删除",type:"warn"}]
},
onLoad: function (options) {
console.log("Load", Date.now());
this.refresh()
.then(res=>{
this.loaded = 1;
})
},
onShow(){
this.refresh();
console.log("show", Date.now());
if(this.loaded)
this.refresh();
},
navBack(){
wx.navigateBack({
@ -18,12 +24,13 @@ Page({
});
},
refresh(){
console.log("start", Date.now());
this.setData({loading:1});
app.syncUser()
return app.syncUser()
.then(res=>{
if (this.oldNum!=null && accountManager.getAccounts().length>this.oldNum && !this.data.currentAccountSaved && this.data.currentAccount) {
if (this.oldNum!=null && accountManager.getAccounts().length>this.oldNum && !this.data.currentAccountSaved && this.currentAccount) {
// 增加了新账号,将未保存的老账号信息保存
accountManager.addAccount(this.data.currentAccount);
accountManager.addAccount(this.currentAccount);
this.setData({ currentAccountSaved: 1 });
}
// 更新当前账号信息, 如果更改了信息,可以显示最新的信息 @todo 完善
@ -53,7 +60,17 @@ Page({
}else{
var accounts = addedAccounts;
}
this.setData({ accounts, user: res.user, currentAccountSaved, currentAccount,loading:0});
this.accounts = accounts;
accounts = accounts.map(i=>{
return {user_id:i.user_id,name: i.name,login: i.login, image_url:i.image_url};
})
this.currentAccount = currentAccount;
this.setData({ accounts, user: {user_id }, currentAccountSaved,loading:0},()=>{
console.log("渲染完成", Date.now());
});
console.log("end", Date.now());
}).catch(e=>{
})
},
deleteAccount({user_id}){
@ -88,11 +105,11 @@ Page({
switchAccount(e){
let { currentTarget: {dataset: {id: user_id}}} = e;
if (user_id==this.data.user.user_id) return;
if (accountManager.getAccounts().length<5&&!this.data.currentAccountSaved&&this.data.currentAccount){
accountManager.addAccount(this.data.currentAccount);
if (accountManager.getAccounts().length<5&&!this.data.currentAccountSaved&&this.currentAccount){
accountManager.addAccount(this.currentAccount);
this.setData({currentAccountSaved:1});
}
let account = this.data.accounts.filter(i=>i.user_id == user_id) [0];
let account = this.accounts.filter(i=>i.user_id == user_id) [0];
if(!account.save_password){
wx.navigateTo({ url: "../account/account?nostorage=1&error=账号过期,需重新登录; 密码将加密保存至本地&save_password=1&addaccount=1&login_disabled=1&login="+account.login});
}else{

@ -35,7 +35,7 @@
.info{
flex: auto;
}
.info>.login{
.login{
font-size: 12px;
color: dimgray;
}

@ -88,17 +88,14 @@ Page({
this.setData({technical_index: value});
},
onDepartmentChange(e){
;
let { detail: { value } } = e;
this.setData({department_index:value});
},
refreshDepartments({detail}){
;
this.setData({department_id: detail.id});
this.pullDepartments();
},
pullDepartments(){
;
let {school_id, department_id} = this.data;
app.api("schools.departments.for_option")({school_id})
.then(res=>{

@ -82,9 +82,9 @@ App({
duration
})
},
showMsg(res, duration = 1500) {
showMsg({message=""}, duration = 1500) {
wx.showToast({
title: res.message, duration
title: message, duration
})
},
getPageUrl(url, root = "/") {

@ -33,9 +33,10 @@
]
},
{
"root": "avatar",
"root": "setting",
"pages": [
"pages/image_crop/image_crop"
"pages/image_crop/image_crop",
"pages/setting/setting"
]
},
{
@ -109,7 +110,7 @@
"pages/home/home": {
"network": "all",
"packages": [
"avatar",
"setting",
"account"
]
},

@ -1,11 +1,11 @@
@font-face {
font-family: 'iconfont'; /* project id 1656783 */
src: url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.eot');
src: url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.eot?#iefix') format('embedded-opentype'),
url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.woff2') format('woff2'),
url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.woff') format('woff'),
url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.ttf') format('truetype'),
url('//at.alicdn.com/t/font_1656783_wkdlw1gdzod.svg#iconfont') format('svg');
src: url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.eot');
src: url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.eot?#iefix') format('embedded-opentype'),
url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.woff2') format('woff2'),
url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.woff') format('woff'),
url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.ttf') format('truetype'),
url('//at.alicdn.com/t/font_1656783_1qepxw56cybi.svg#iconfont') format('svg');
}
.iconfont {
display: inline-block;
@ -118,4 +118,7 @@
.icon-filter:before {
content: "\e6c7";
}
.icon-shezhi:before{
content: "\e625";
}

@ -92,17 +92,16 @@ Component({
}
})
},
cancel() {
this.setData({ hidden: true,invite_code:'', assistant_professor:"", student:"", assistant_professor:"" });
onCancel() {
this.setData({ hidden: true,invite_code:'', professor:"", student:"", assistant_professor:"" });
},
onTapButton({detail:{index}}){
if(index==0)
this.cancel();
this.onCancel();
else if(index==1)
this.join_course();
},
update_invite_code: function ({ detail: { value } }) {
;
this.setData({ invite_code: value });
},
update_identities: function ({ detail: { value } }) {
@ -129,7 +128,7 @@ Component({
},640);
}
this.triggerEvent("success");
this.cancel();
this.onCancel();
})
.catch(app.showError)

@ -1,4 +1,4 @@
<mp-dialog show="{{!hidden}}" title="加入课堂" bindbuttontap="onTapButton" buttons="{{buttons}}">
<mp-dialog show="{{!hidden}}" title="加入课堂" bindclose="onCancel" bindbuttontap="onTapButton" buttons="{{buttons}}">
<block wx:if="{{!hidden}}">
<view class="input-wrap {{show_code?'':'hidden'}}">
<input class="code-input" cursor-spacing="130" type='text' bindinput="update_invite_code" value="{{invite_code}}" placeholder="邀请码" auto-focus="1" />

@ -1,13 +1,15 @@
const cloudDir = "cloud://educoder.6564-educoder-1300855313/";
let { miniProgram:{ envVersion, version}={}} = {}//wx.getAccountInfoSync();
let { miniProgram:{ envVersion, version}={}} = wx.getAccountInfoSync();
const developUrl = "https://test-newweb.educoder.net";
const trialUrl = "https://pre-newweb.educoder.net";
const releaseUrl = "https://www.educoder.net";
let _version = "0.16.1";
let _version = "0.16.2";
var eduUrl = releaseUrl;
/**
* A 支持选用实践课程
* A 网络请求缓存
*/
export function switchEnv(env) {
@ -37,14 +39,13 @@ const config = global.config = {
cloudDir,
get eduUrl(){return eduUrl},
imgDir: cloudDir + "images/",
get eduImgDir(){return eduUrl + "/images/"},
get eduImgDir(){ return eduUrl + "/images/"},
switchEnv,
pages:[
"exercise/pages/exercise_setting/exercise_setting",
"common-homework/pages/common-homework/common-homework"
]
};
switchEnv("release");
//switchEnv(envVersion=="develop"?"trial":"release");

@ -56,4 +56,5 @@
width: 20px;
height: 20px;
margin: 0 12px;
background: #eee;
}

@ -2,6 +2,7 @@ page{
display: flex;
flex-direction: column;
height: 100%;
background: #56A9EF;
}
.body{
flex: 1 1 10px;

@ -2,22 +2,39 @@ const app = getApp();
Page({
data: {
apply_size:0
},
onLoad: function (options) {
let {course_id} = options;
this.setData({course_id});
this.refresh();
this.pullCourse();
},
switchToTeacher(){
let {course_id} = this.data;
app.api("courses.switch_to_teacher")({course_id})
.then(res=>{
console.log(res);
this.refresh();
this.pullCourse();
})
},
pullCourse(){
let {course_id} = this.data;
app.api("courses.top_banner")({course_id})
.then(res=>{
console.log(res);
this.setData({course: res});
})
},
refresh(){
let {course_id} = this.data;
app.api("courses.apply_teachers")({course_id})
.then(res=>{
;
this.setData(res);
}).catch(e=>{
app.showError(e);
app.showError(e, 2200);
})
},

@ -1,8 +1,22 @@
<navigator class="course-name" url="/course/pages/course/course?course_id={{course_id}}&module_type=teachers">
{{course.name}}
</navigator>
<view class="header">
待审批:<text class="count">{{apply_size}}人</text>
<view>
<block wx:if="{{!course.switch_to_teacher}}">
待审批:<text class="count">{{apply_size}}人</text>
</block>
<text class="tip" wx:else>您目前不是教师身份</text>
</view>
<view wx:if="{{course.switch_to_teacher}}">
<button class="switch" bindtap="switchToTeacher" type="main" size="mini">切换为教师</button>
</view>
</view>
<view class="apply-list">
<view class="applt-item-wrp" bindreview="refresh" wx:for="{{application_list}}">
<view class="applt-item-wrp" bindreview="refresh" wx:for="{{application_list}}" wx:key="application_id">
<apply-item data="{{item}}" course_id="{{course_id}}"/>
</view>
<view class="empty" wx:if="{{application_list.length==0}}">
暂无待审批
</view>
</view>

@ -1,14 +1,38 @@
page{
background: white;
}
.course-name{
text-align: center;
font-size: 20px;
line-height: 36px;
height: 36px;
padding: 0 12px;
width: 100%;
}
.switch{
transform: scale(0.85);
}
.header{
padding: 12px;
padding: 12px 8px;
background: white;
border-bottom: #dddddd 1.5px solid;
display: flex;
align-items: center;
justify-content: space-between;
}
.count{
font-size: 14px;
margin-left: 12px;
margin-left: 10px;
}
.empty,
.tip{
font-size: 12px;
color: dimgray;
}
.empty{
text-align: center;
padding-top: 26px;
}

@ -147,13 +147,12 @@ export default class Client{
success:res=>{
this.trigger("success",name,res);
success&&success(res);
}, fail:e=>{
this.trigger("fail",name,e);
fail&&fail(e);
}, complete:res=>{
global.realTimeLog.debug(name+" api was called");
complete&&complete(res);
},
}, fail:(e,res)=>{
this.trigger("fail", name, e);
fail&&fail(e, res);
// for trace error
global.realTimeLog.warn(`api [${name}] called fail: `, e.toString(), res, data);
},complete
});
}
load_user() {

@ -1,6 +1,6 @@
import apiConfig from "./apiConfig";
function handler({success, fail, resolve, reject}){
function handler({success, fail, complete, resolve, reject}){
return {
success: res => {
if (res.data.status && res.data.status > 100 || res.data.status<0) {
@ -15,20 +15,22 @@ function handler({success, fail, resolve, reject}){
}
let e = new Error(message);
e.code = code;
if (fail) fail(e);
return reject(e);
if (fail) fail(e, res.data);
reject(e, res.data);
return complete&&complete(e, res.data);
}
if (success) success(res.data);
success&&success(res.data);
resolve(res.data);
complete&&complete(res.data);
},
fail: e => {
global.realTimeLog.warn(e);
if ("errMsg" in e)
(e = new Error("(⋟﹏⋞)\n网络连接出错了呢")).code = -2;
(e = new Error("(⋟﹏⋞)\n网络连接失败了")).code = -2;
if (!("message" in e))
(e = new Error("(_)\n出现了未知错误")).code = -1;
if (fail) { fail(e); }
reject(e);
(e = new Error("哎呀,出错了\n(_)")).code = -1;
fail&& fail(e, {});
reject(e, {});
complete&&complete(e, {});
}
}
}
@ -87,10 +89,9 @@ export default function ({ name, data:_data = {}, session, success, fail, comple
_name = Object.keys(formData)[0];
var filePath = formData[_name];
delete formData[_name];
;
return new Promise((resolve, reject)=>{
session.uploadFile({
url, filePath, name:_name, header, timeout, formData,complete, ...handler({success, fail, resolve, reject})
url, filePath, name:_name, header, timeout, formData, ...handler({success, fail, complete, resolve, reject})
})
});
}else if(method=="downloadFile"){
@ -108,7 +109,7 @@ export default function ({ name, data:_data = {}, session, success, fail, comple
}else
return new Promise((resolve, reject) => {
session.request({
url, method, data, header,complete,...handler({success, fail, resolve, reject})
url, method, data, header,...handler({success, fail, complete, resolve, reject})
});
})
}

@ -231,7 +231,6 @@ export function parseUrl({url}){
export function navigateToUrl({url,open_type='navigateTo'}){
url = parseUrl({url});
;
const app = getApp();
if(url){
app.navigateTo({url});
@ -275,21 +274,25 @@ export function throttle(func, wait, options) {
export function RealTimeLogManager(){
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null;
return {
debug() {
debug(...args) {
console.debug.apply(null, arguments);
if (!log) return
log.debug.apply(log, arguments)
log.debug( "v"+ global.config.version ,...args)
},
info() {
info(...args) {
console.info.apply(null, arguments);
if (!log) return
log.info.apply(log, arguments)
log.info( "v"+ global.config.version ,...args)
},
warn() {
warn(...args) {
console.warn.apply(null, arguments);
if (!log) return
log.warn.apply(log, arguments)
log.warn( "v"+ global.config.version ,...args);
},
error() {
error(...args) {
console.error.apply(null, arguments);
if (!log) return
log.error.apply(log, arguments)
log.error( "v"+ global.config.version ,...args);
},
setFilterMsg(msg) { // 从基础库2.7.3开始支持
if (!log || !log.setFilterMsg) return

@ -38,7 +38,6 @@ Page({
this.switch({current});
},
switchTab({ detail: { current, source, value } }) {
;
if (source == "touch") {
this.switch({current});
}

@ -8,16 +8,37 @@ Component({
data: {
shixun_list:[]
},
pageLifetimes:{
show(){
/*
let {status} = this.data;
console.log("show",status);
if(status<0)
this.pullShixuns({refresh:2 ,showError:0});
//limit param somehow don't work!
*/
}
},
attached(){
this.options = {page:1, limit: 10};
this.pullShixuns({refresh:1});
let key = "cache-shixun_list"
let cache_shixun_list = wx.getStorageSync(key);
if(cache_shixun_list)
this.setData({shixun_list: cache_shixun_list});
else
wx.showLoading({title: '努力加载中'});
this.pullShixuns({refresh:1, showError: !cache_shixun_list})
.then(res=>{
if(res.shixun_list)
wx.setStorageSync(key, res.shixun_list);
})
this.selects = {};
},
methods: {
clear(){
this.setData({keyword:"", showClear:0});
this.options.keyword = "";
this.pullShixuns({refresh:1});
this.pullShixuns({refresh:1, showError: 0});
},
onInput(e){
let {detail:{value}} = e;
@ -26,7 +47,6 @@ Component({
}else if(!this.data.showClear&&value){
this.setData({showClear:1});
}
},
onSelect(e){
let {detail} = e;
@ -67,14 +87,11 @@ Component({
})
}else{
this.setData({shixun_ids});
console.info(shixun_ids);
this.setData({showSendDialog: true});
}
}
},
search(e){
search(e){
let {detail:{value}} = e;
if(this.options.keyword!=value){
this.options.keyword = value;
@ -85,24 +102,26 @@ Component({
this.pullShixuns({refresh:1});
},
onReachBottom(){
if(this.data.status==200)
let {status} = this.data;
if(status!=205&&status!=204)
this.pullShixuns();
},
pullShixuns({refresh=0}={}){
pullShixuns({refresh=0, showError=1}={}){
if(refresh){
if(refresh==1){
this.options.page = 1;
var { options } = this;
}else if(refresh==2){
var {page, per_page} = this.options;
var options = {...this.options,page:1, per_page: page*per_page};
var {page, limit} = this.options;
var options = {...this.options,page:1, limit: page*limit};
}
}else{
this.options.page++;
var {options} = this;
}
wx.showNavigationBarLoading();
return app.api("shixun_lists")(options).then(({shixun_list})=>{
return app.api("shixun_lists")(options).then(res=>{
let {shixun_list} = res;
let length = shixun_list.length;
if (!refresh){
shixun_list = this.data.shixun_list.concat(shixun_list);
@ -113,11 +132,15 @@ Component({
var status = length>0?200:205;
}
this.setData({ shixun_list, status}, wx.hideNavigationBarLoading);
wx.hideLoading();
return res;
}).catch(e=>{
if(refresh)
this.setData({ shixun_list:[], status:e.code}, wx.hideNavigationBarLoading);
else
this.setData({status:e.code}, wx.hideNavigationBarLoading);
console.log("error!!!!",e, showError)
this.setData({status:e.code}, wx.hideNavigationBarLoading);
wx.hideLoading();
if(showError)
app.showError(e);
return e;
})
}
}

@ -11,9 +11,6 @@ Page({
showModal: false,
auto_attendance: false
},
log(e){
;
},
enterPage({ target: { dataset: { path } } }) {
if (!path) return;
let { id } = this.data.user;
@ -86,7 +83,7 @@ Page({
break;
case 1:
wx.navigateTo({
url: '/avatar/pages/image_crop/image_crop'
url: '/setting/pages/image_crop/image_crop'
});
break;
}
@ -102,7 +99,7 @@ Page({
app.showMsg(res);
this.onShow();
},
fail: error => {
fail: e=> {
if (showToast)
app.showError(e);
}
@ -120,6 +117,13 @@ Page({
this.setData({ showModal: true });
},
onLoad() {
let user_id = app.user().user_id;
if(user_id!=2&&user_id){
let key = `cache-users.homepage_info-${app.user().user_id}`;
let cache_homepage = wx.getStorageSync(key);
if(cache_homepage)
this.setData({user: cache_homepage});
}
let data = wx.getStorageSync("auto-attendence");
if (data)
this.setData({ auto_attendance: true });
@ -138,9 +142,12 @@ Page({
let { name: show_name, avatar_url: image_url} = res;
if(show_name&&image_url)
app.updateUserInfo({ show_name, image_url});
;
this.setData({ user: res })
this.setData({ user: res });
let key = `cache-users.homepage_info-${app.user().user_id}`;
wx.setStorage({
data: res,
key
})
if (!res.attendance_signed && this.data.auto_attendance)
this.attendance({ show: 0 })
});
@ -179,6 +186,5 @@ Page({
app.navigateTo({url:"{user_info}"});
},
onShareAppMessage: function () {
;
}
})

@ -2,6 +2,7 @@
"navigationBarTitleText": "个人中心",
"enablePullDownRefresh": false,
"usingComponents": {
"iconfont":"/components/iconfont/iconfont"
"iconfont":"/components/iconfont/iconfont",
"mp-icon":"/weui-miniprogram/icon/icon"
}
}

@ -59,6 +59,10 @@
<iconfont class="icon" type="kefu" size="21" />小程序客服
<iconfont type="jinru" color="dimgrey" size="15" class="enter"></iconfont>
</button>
<navigator wx:if="{{false}}" class="nav" url="/setting/pages/setting/setting">
<iconfont type="shezhi" class="icon" size="21"/>设置
<iconfont type="jinru" color="dimgrey" size="15" class="enter"/>
</navigator>
<navigator url="/account/pages/about/about" class="nav about gap">
<iconfont class="icon" type="guanyu" size="21" />关于
<iconfont type="jinru" color="dimgrey" size="15" class="enter"></iconfont>

@ -12,7 +12,7 @@
background: white;
border-bottom: 1px solid #eee;
padding: 0 14px;
height: 42px;
height: 41px;
font-weight: normal;
display: flex;
align-items: center;
@ -149,6 +149,7 @@ navigator[hidden] {
border-radius: 50%;
width: 42px;
height: 42px;
background: #eee;
}
.auto-attendance{
transform: scale(0.60);

@ -10,7 +10,6 @@ const titleMap = {
shixun:"实训项目",
path:"实践课程"
}
Page({
data:{
statusBarHeight:20,
@ -48,7 +47,6 @@ Page({
this.switch({current});
},
switchTab({detail:{current, source, value}}){
;
if(source=="touch"){
this.switch({current});
}

@ -57,6 +57,7 @@
overflow: hidden;
flex: none;
margin: 0 16px 0 8px;
background: #eee; /*for out of network*/
}
.course-info{
flex: auto;

@ -3,16 +3,11 @@ const app = getApp();
statuses:[]
*/
const getDataForRender = class_ => ({
name: class_.get('name'),
objectId: class_.get('objectId')
});
const categories = [{ text: "我学习的", value: "study" }, { text: "我管理的", value: "manage" }];
Component({
data: {
imgDir: global.config.imgDir,
attachDir: global.config.attachDir,
categories,
categories: [{ text: "我学习的", value: "study" }, { text: "我管理的", value: "manage" }],
statuses: [{ text: "正在进行", value: "processing" }, { text: "已结束", value: "end" }],
courses: [],
status: 0,
@ -21,26 +16,38 @@ Component({
current_cate: -1
},
attached() {
let user = app.user();
let key = `cache-weapps.home-${user.user_id}-${user.is_teacher}`
let cache_courses = wx.getStorageSync(key);
if(cache_courses)
this.setData({courses:cache_courses}); // set local cache;
this.options = { page: 1, limit: 15 };
if (app.user().is_teacher)
if (user.is_teacher)
var current_cate = 1;
else
var current_cate = 0;
this.setData({ current_cate });
this.options["category"] = this.data.categories[current_cate].value;
this.pullCourses({refresh:1})
.then(res=>{
if(res.courses){
var user = app.user();
wx.setStorageSync(key, res.courses);
}
});
this.setData({current_cate});
},
pageLifetimes: {
show: function () {
if (this.data.current_cate >= 0) {
this.pullCourses({ refresh: 2 });
this.pullCourses({ refresh: 2, showError:0 });
}
}
},
methods: {
onCategoryChange: function ({ detail: { current, value } }) {
;
onCategoryChange: function ({ detail: { current, value, source } }) {
if(source!='touch') return;
this.options["category"] = value.value;
this.pullCourses({ refresh: 1 });
this.setData({ category: value.value });
},
onStatusChange: function ({ detail: { value } }) {
this.options["status"] = value.value;
@ -66,14 +73,12 @@ Component({
*/
},
enter_course: function (event) {
;
let { id, course_name } = event.currentTarget.dataset;
wx.navigateTo({
url: "/course/pages/course/course?course_id=" + id + "&course_name=" + course_name,
})
},
pullCourses: function ({ refresh = 0 } = {}) {
pullCourses: function ({ refresh = 0, showError=1} = {}) {
if (refresh) {
if (refresh == 1) {
this.options.page = 1;
@ -88,7 +93,7 @@ Component({
}
return app.callApi({
name: "weapps.home", data
})
})
.then(res => {
let { courses } = res;
if (data.status)
@ -98,15 +103,18 @@ Component({
if (!refresh)
courses = this.data.courses.concat(courses);
this.setData({ courses, loading: false });
return res;
}).catch(e => {
this.setData({ courses: [], loading: false });
if(showError)
app.showError(e);
this.setData({loading: false });
return e;
});
},
onReachBottom() {
this.pullCourses();
},
onPullDownRefresh: function () {
;
this.pullCourses({ refresh: 2 });
},
}

@ -10,7 +10,7 @@
<text class="none-content hint">空空如也!</text>
</view>
<view wx:for="{{courses}}" wx:key="id" class="course-wrap">
<course-item data="{{item}}" category="{{category}}"/>
<course-item data="{{item}}" category="{{categories[current_cate].value}}"/>
</view>
</scroll-view>
<!-- {{imgDir}}add.png -->

@ -22,32 +22,34 @@ Component({
},
attached(){
this.options = {page:1, per_page:16};
this.refresh();
this.refresh({showError: 1});
},
methods: {
onCateChange({detail:{value}}){
;
this.options.category = value.value
this.pullShixuns({refresh:1});
this.pullShixuns({refresh:1,showError:1});
},
refresh(){
refresh({showError=0}={}){
app.syncUser()
.then(res => {
if (res.user.user_id != this.user_id) {
if(res.user_id==2)
this.setData({shixuns:[]})
else
this.pullShixuns({ refresh: 1 })
this.pullShixuns({ refresh: 1, showError })
this.user_id = res.user.user_id;
}else if(this.data.status==200){
this.pullShixuns({refresh:2});
this.pullShixuns({refresh:2, showError});
}
}).catch(e=>{
if(showError)
app.showError(e);
})
},
setStatus(status){
this.setData({status});
},
pullShixuns({refresh=0}={}){
pullShixuns({refresh=0, showError= 0}={}){
if(refresh){
if(refresh==1){
this.options.page = 1;
@ -72,16 +74,17 @@ Component({
}
this.setData({ shixuns, status});
}).catch(e=>{
if(showError)
app.showError(e);
this.setData({shixuns:[], status:e.code});
})
},
onPullDownRefresh(){
this.pullShixuns({refresh:2});
this.pullShixuns({refresh:2, showError: 1});
},
onReachBottom(){
if(this.data.status==200)
this.pullShixuns({refresh:0});
this.pullShixuns({refresh:0, showError:1});
}
}
})

@ -37,10 +37,8 @@ Component({
let route = get(ROUTE,data.belong_container_type,{});
route = get(route, data.container_type,{});
route = get(route, data.homework_type);
;
if(!route) return;
let url = format(route, data);
;
app.navigateTo({url});
}
}

@ -2,8 +2,8 @@
<image class="avatar" mode="scaleToFill" src="{{eduImgDir}}{{data.trigger_user.image_url}}"></image>
<view class="tiding-info">
<view class="name">
{{data.trigger_user.name}} {{data.time}}
<view wx:if="{{data.new_tiding}}" class="red-dot"></view>
{{data.trigger_user.name}} {{data.time}}<text wx:if="{{data.tiding_type=='Apply'}}" class="todo-tip {{data.status?'finish':''}}">{{data.status?'已处理':'待审批'}}</text>
<view wx:elif="{{data.new_tiding}}" class="blue-dot"></view>
</view>
<view class="content">{{data.content}}</view>
</view>

@ -7,6 +7,7 @@
border-radius: 50px;
width: 50px;
height: 50px;
background: #eee;
}
.tiding-info{
margin-left: 12px;
@ -17,10 +18,23 @@
color: dimgray;
font-size: 14px;
}
.todo-tip{
border-radius: 5px;
padding: 3px;
border: #DD1717 1px solid;
color: #DD1717;
font-size: 10px;
margin-left: 8px;
white-space: nowrap;
}
.todo-tip.finish{
border-color: #29BD8B;
color: #29BD8B;
}
.content{
margin: 8px 0;
}
.red-dot{
.blue-dot{
display: inline-block;
height: 7px;
width: 7px;

@ -2,10 +2,35 @@ const app = getApp();
Page({
data: {
tidings:[],
current: 0,
list:[
{text:"全部", type:""},{text:"课堂提醒",type:"course"},{text:"互动提醒", type:"interaction"},{text:"审核",type:"apply"},{text:"通知", type:"notice"}
{text:"全部", type:""},
{text:"课堂提醒",type:"course"},
{text:"审核",type:"apply"},
{text:"通知", type:"notice"},
{text:"互动提醒", type:"interaction"},
]
},
onTapMessage(){
let tidings = this.data.tidings.filter(i=>{
return i.tiding_type =='Apply'&&i.status==0
});
if(this.data.course_apply_count==tidings.length){
var flag = true;
var course_id = tidings[0].belong_container_id;
for(var k=1;k<tidings.length;k++){
flag = flag&&(course_id == tidings[k].belong_container_id);
}
if(flag){
app.navigateTo({
url:`{teacher_apply}?course_id=${course_id}`
})
}
else
this.setData({current:2});
}else
this.setData({current: 2});
},
changeType({detail:{current, value}}){
this.options.type=value.type;
this.refresh({refresh:1})
@ -13,7 +38,7 @@ Page({
this.setData({scrollTop:0});
});
},
refresh({refresh=0}={}){
refresh({refresh=0, showError=1}={}){
if(refresh){
this.setData({ loading: 1 });
if(refresh==1){
@ -27,27 +52,39 @@ Page({
this.options.page++;
var {options} = this;
}
;
return app.api("users.tidings")(options).then(res => {
let {tidings} = res;
let {tidings, course_apply_count} = res;
if(!refresh)
tidings = this.data.tidings.concat(tidings);
this.setData({ tidings ,loading:0});
this.setData({ tidings,course_apply_count ,loading:0});
return res;
}).catch(e=>{
//app.showError(e);
if(showError)
app.showError(e);
this.setData({loading:0});
return e;
})
},
onLoad: function (options) {
let key = `cache-users.tidings-${app.user().user_id}`;
let cache_tidings = wx.getStorageSync(key);
if(cache_tidings)
this.setData({tidings: cache_tidings});
this.options = { page: 1, per_page: 10 };
;
this.refresh({refresh:1}).then(res=>{
console.log("pull", res);
this.loaded = 1;
if(res.tidings)
wx.setStorageSync(key, res.tidings);
})
},
_onReachBottom(){
this.refresh();
},
onShow: function () {
let index = 2;
this.refresh({refresh:2})
if(this.loaded)
this.refresh({refresh:2, showError:0})
wx.hideTabBarRedDot({index});
wx.removeTabBarBadge({index});
},

@ -1,8 +1,11 @@
<page-meta>
<navigation-bar loading="{{loading}}"/>
</page-meta>
<nav-bar bar-class="navbar" current="0" list="{{list}}" itemWidth="0" type="cap" bg="transparent" mg="8" bindchange="changeType"/>
<nav-bar bar-class="navbar" current="{{current}}" list="{{list}}" itemWidth="0" type="cap" bg="transparent" mg="8" bindchange="changeType"/>
<scroll-view class="tidings" refresher-enabled="1" scroll-y="1" bindrefresherrefresh="onPullDownRefresh" bindscrolltolower="_onReachBottom" lower-threshold="120" scroll-top="{{scrollTop}}">
<view class="message" wx:if="{{course_apply_count}}" bindtap="onTapMessage">
您有{{course_apply_count}}条课堂申请待审批
</view>
<view class="tiding-wrap" wx:for="{{tidings}}" wx:key="id">
<tiding-item data="{{item}}"/>
</view>

@ -3,7 +3,7 @@
flex: none;
}
.tiding-wrap{
margin-top: 6px;
margin-top: 3px;
}
page{
display: flex;
@ -13,4 +13,12 @@ page{
.tidings{
flex: 1 1 1px;
height: 1px;
}
.message{
background: #fa5151;
color: white;
padding: 6px 12px;
border-radius: 8px;
text-align: center;
margin: 4px 16px;
}

@ -104,4 +104,5 @@
}
.operations>button{
flex: 1;
border-radius: 0;
}

@ -0,0 +1,66 @@
// miniprogram/setting/pages/setting/setting.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "设置"
}

@ -0,0 +1,2 @@
<!--miniprogram/setting/pages/setting/setting.wxml-->
<text>miniprogram/setting/pages/setting/setting.wxml</text>

@ -0,0 +1 @@
/* miniprogram/setting/pages/setting/setting.wxss */

@ -78,6 +78,7 @@
justify-content: center;
align-content: center;
white-space: nowrap;
border-radius: 0;
}
button.collect, button.send{
background: white!important;

@ -55,7 +55,7 @@
font: 14px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
white-space: pre;
padding: 0px 10px;
height: calc(100vh - 43px);
height: calc(100vh - 42px);
flex: auto;
}
.operations{
@ -64,6 +64,7 @@
}
.operations>button{
flex: auto;
border-radius: 0;
}
.outcome-swiper{
display: flex;

@ -163,6 +163,40 @@
"pathName": "path/pages/path_send/path_send",
"query": "subject_id=475",
"scene": null
},
{
"id": -1,
"name": "pages/tidings/tidings",
"pathName": "pages/tidings/tidings",
"query": "",
"scene": null
},
{
"id": -1,
"name": "course/pages/teacher_apply/teacher_apply",
"pathName": "course/pages/teacher_apply/teacher_apply",
"query": "course_id=7582",
"scene": null
},
{
"id": -1,
"name": "pages/home/home",
"pathName": "pages/home/home",
"query": "",
"scene": null
},
{
"id": -1,
"name": "pages/tidings/tidings",
"pathName": "pages/tidings/tidings",
"query": "",
"scene": null
},
{
"id": -1,
"name": "account/pages/accounts/accounts",
"pathName": "account/pages/accounts/accounts",
"scene": null
}
]
}

Loading…
Cancel
Save