Skip to content

Commit

Permalink
版本更新,网络请求用框架自带的
Browse files Browse the repository at this point in the history
  • Loading branch information
huangang committed Jan 19, 2017
1 parent 7db99ac commit 173c654
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 273 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wepy-one",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "dist/app.js",
"scripts": {
Expand All @@ -18,7 +18,7 @@
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-1": "^6.16.0",
"babel-runtime": "^6.20.0",
"wepy": "^1.3.6",
"wepy": "^1.3.11",
"wepy-com-toast": "^1.0.0",
"wepy-compiler-babel": "^1.3.7",
"wepy-compiler-less": "^1.3.6"
Expand Down
46 changes: 13 additions & 33 deletions src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
const host = 'http://v3.wufazhuce.com:8000';
const wxRequest = (params, url) => {
wx.showToast({
title: '加载中',
icon: 'loading'
});
const wxRequest = async (params = {}, url) => {
wx.showToast({
title: '加载中',
icon: 'loading'
});
console.log(url);
wx.request_bak({
url: url,
method: params.method || 'GET',
data: params.data || {},
header: {
'Content-Type': 'application/json'
},
success: (res) => {
params.success && params.success(res)
console.log(res)
wx.hideToast()
},
fail: (res) => {
params.fail && params.fail(res)
},
complete: (res) => {
params.complete && params.complete(res)
}
});//不知道是哪里的问题,先用原来的方法,不用框架的方法

// .then(function (res) {
// if(res.statusCode === 200){
// wx.hideToast();
// params.success && params.success(res);
// }else {
// params.fail && params.fail(res)
// }
// })
let res = await wx.request({
url: url,
method: params.method || 'GET',
data: params.data || {},
header: {'Content-Type': 'application/json'},
});
wx.hideToast();
return res;
};

// Index
Expand Down
21 changes: 7 additions & 14 deletions src/pages/index/detail.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,13 @@

};
async onLoad(options) {
let that = this;
api.getVolDetailById({
query: {
id: options.id
},
success: (res) => {
if (res.data.res === 0) {
let detail = res.data.data;
detail.hp_makettime = util.formatMakettime(detail.hp_makettime);
that.detail = detail;
that.setData({ detail })
}
}
})
let res = await api.getVolDetailById({query: {id: options.id}});
if (res.data.res === 0) {
let detail = res.data.data;
detail.hp_makettime = util.formatMakettime(detail.hp_makettime);
this.detail = detail;
this.setData({ detail })
}
}
}
</script>
40 changes: 17 additions & 23 deletions src/pages/index/index.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@

};

getVols (idList) {
async getVols (idList) {
let vols = this.vols;
if (idList.length > 0) {
api.getVolById({
query: {
id: idList.shift()
},
success: (res) => {
if (res.data.res === 0) {
let vol = res.data.data;
vol.hp_makettime = util.formatMakettime(vol.hp_makettime);
vols.push(vol);
}
this.getVols(idList)
}
})
let res = await api.getVolById({query: {id: idList.shift()}});
if (res.data.res === 0) {
let vol = res.data.data;
vol.hp_makettime = util.formatMakettime(vol.hp_makettime);
vols.push(vol);
this.getVols(idList)
}

} else {
this.setData({ vols , '$volList$list': vols});
}
Expand Down Expand Up @@ -81,16 +76,15 @@
};
async onLoad() {
try {
await api.getVolIdList({
success: (res) => {
if (res.data.res === 0) {
let idList = res.data.data;
this.getVols(idList)
}
}
});
let res = await api.getVolIdList();
console.log(res);
if (res.data.res === 0) {
let idList = res.data.data;
console.log(idList);
await this.getVols(idList)
}
} catch (error) {
console.error(error.stack);
console.error(error);
}
}
}
Expand Down
28 changes: 12 additions & 16 deletions src/pages/index/monthly.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,21 @@

};
async onLoad(options) {
let that = this;
this.setData({
title: options.title
});
api.getVolsByMonth({
query: {
month: options.month
},
success: (res) => {
if (res.data.res === 0) {
let monthly = res.data.data;
monthly.map((vol) => {
vol.hp_makettime = util.formatMakettime(vol.hp_makettime)
});
that.monthly = monthly;
that.setData({ monthly })
}
}
})
let res = await api.getVolsByMonth({query: {month: options.month}});
if (res.data.res === 0) {
let monthly = res.data.data;
// monthly.map((vol) => {
// vol.hp_makettime = util.formatMakettime(vol.hp_makettime)
// });
monthly.forEach(function (vol) {
vol.hp_makettime = util.formatMakettime(vol.hp_makettime)
});
this.monthly = monthly;
this.setData({ monthly })
}
};
onReady () {
wx.setNavigationBarTitle({
Expand Down
42 changes: 14 additions & 28 deletions src/pages/movie/detail.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -117,35 +117,21 @@

};
async onLoad(options) {
let that = this;
let id = options.id;
api.getMovieDetailById({
query: {
id: id
},
success: (res) => {
if (res.data.res === 0) {
let detail = res.data.data;
that.detail = detail;
that.setData({ detail })
}
}
});

api.getMovieStoryById({
query: {
id: id
},
success: (res) => {
if (res.data.res === 0) {
let story = res.data.data.data[0];
story.content = util.filterContent(story.content);
story.input_date = util.formatMakettime(story.input_date);
that.story = story;
that.setData({ story })
}
}
})
let res = await api.getMovieDetailById({query: {id: id}});
if (res.data.res === 0) {
let detail = res.data.data;
this.detail = detail;
this.setData({ detail })
}
let ret = await api.getMovieStoryById({query: {id: id}});
if (ret.data.res === 0) {
let story = ret.data.data.data[0];
story.content = util.filterContent(story.content);
story.input_date = util.formatMakettime(story.input_date);
this.story = story;
this.setData({ story })
}
}
}
</script>
28 changes: 10 additions & 18 deletions src/pages/movie/index.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,19 @@
async onLoad() {
this.getMovies();
};
getMovies () {
let that = this;
async getMovies () {
let lastId = this.data.lastId;
if (lastId >= 0) {
api.getMovieListById({
query: {
id: lastId
},
success: (res) => {
if (res.data.res === 0) {
let moreMovies = res.data.data;
let length = moreMovies.length;
let lastId = length ? moreMovies[length - 1].id : -1;

let movies = this.data.movies.concat(moreMovies);
that.movies = movies;
that.lastId = lastId;
that.setData({ movies, lastId })
}
let res = await api.getMovieListById({query: {id: lastId}})
if (res.data.res === 0) {
let moreMovies = res.data.data;
let length = moreMovies.length;
let lastId = length ? moreMovies[length - 1].id : -1;
let movies = this.data.movies.concat(moreMovies);
this.movies = movies;
this.lastId = lastId;
this.setData({ movies, lastId })
}
})
}
};
getDetail (e) {
Expand Down
28 changes: 10 additions & 18 deletions src/pages/music/detail.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,16 @@

};
async onLoad(options) {
let that = this;
api.getMusicDetailById({
query: {
id: options.id
},
success: (res) => {
if (res.data.res === 0) {
let detail = res.data.data;

detail.playImg = MUSIC_PALY_IMG;
detail.contentType = 'story';
detail.story = util.filterContent(detail.story);
detail.maketime = util.formatMakettime(detail.maketime);
that.detail = detail;
that.setData({ detail })
}
}
})
let res = api.getMusicDetailById({query: {id: options.id}});
if (res.data.res === 0) {
let detail = res.data.data;
detail.playImg = MUSIC_PALY_IMG;
detail.contentType = 'story';
detail.story = util.filterContent(detail.story);
detail.maketime = util.formatMakettime(detail.maketime);
this.detail = detail;
this.setData({ detail })
}
};

togglePlay (e) {
Expand Down
45 changes: 16 additions & 29 deletions src/pages/music/index.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -178,38 +178,25 @@

};
async onLoad() {
let that = this;
api.getMusicIdList({
success: (res) => {
if (res.data.res === 0) {
let idList = res.data.data;
that.getMusics(idList)
}
}
})
let res = await api.getMusicIdList({});
if (res.data.res === 0) {
let idList = res.data.data;
this.getMusics(idList)
}
};

getMusics (idList) {
async getMusics (idList) {
let musics = this.data.musics;

if (idList.length > 0) {
api.getMusicDetailById({
query: {
id: idList.shift()
},
success: (res) => {
if (res.data.res === 0) {
let music = res.data.data;

music.playImg = MUSIC_PALY_IMG;
music.contentType = 'story';
music.story = util.filterContent(music.story);
music.maketime = util.formatMakettime(music.maketime);
musics.push(music)
}
this.getMusics(idList)
}
})
let res = await api.getMusicDetailById({query: {id: idList.shift()}});
if (res.data.res === 0) {
let music = res.data.data;
music.playImg = MUSIC_PALY_IMG;
music.contentType = 'story';
music.story = util.filterContent(music.story);
music.maketime = util.formatMakettime(music.maketime);
musics.push(music)
}
this.getMusics(idList)
} else {
this.musics = musics;
this.setData({ musics })
Expand Down
Loading

0 comments on commit 173c654

Please sign in to comment.