This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add api/api.js, utils/constants.js and use es6
- Loading branch information
Showing
22 changed files
with
352 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const host = 'http://v3.wufazhuce.com:8000' | ||
const wxRequest = (params, url) => { | ||
wx.showToast({ | ||
title: '加载中', | ||
icon: 'loading' | ||
}) | ||
wx.request({ | ||
url: url, | ||
method: params.method || 'GET', | ||
data: params.data || {}, | ||
header: { | ||
'Content-Type': 'application/json' | ||
}, | ||
success: (res) => { | ||
params.success && params.success(res) | ||
wx.hideToast() | ||
}, | ||
fail: (res) => { | ||
params.fail && params.fail(res) | ||
}, | ||
complete: (res) => { | ||
params.complete && params.complete(res) | ||
} | ||
}) | ||
} | ||
|
||
// Index | ||
const getVolById = (params) => wxRequest(params, host + '/api/hp/detail/' + params.query.id) | ||
const getVolIdList = (params) => wxRequest(params, host + '/api/hp/idlist/0') | ||
const getVolsByMonth = (params) => wxRequest(params, host + '/api/hp/bymonth/' + params.query.month) | ||
const getVolDetailById = (params) => wxRequest(params, host + '/api/hp/detail/' + params.query.id) | ||
|
||
// Reading | ||
const getCarousel = (params) => wxRequest(params, host + '/api/reading/carousel') | ||
const getLastArticles = (params) => wxRequest(params, host + '/api/reading/index') | ||
const getEssayById = (params) => wxRequest(params, host + '/api/essay/' + params.query.id) | ||
const getSerialById = (params) => wxRequest(params, host + '/api/serialcontent/' + params.query.id) | ||
const getQuestionById = (params) => wxRequest(params, host + '/api/question/' + params.query.id) | ||
const getArticlesByMonth = (params) => { | ||
wxRequest(params, host + '/api/' + params.query.type + '/bymonth/' + params.query.month) | ||
} | ||
|
||
// Music | ||
const getMusicIdList = (params) => wxRequest(params, host + '/api/music/idlist/0') | ||
const getMusicsByMonth = (params) => wxRequest(params, host + '/api/music/bymonth/' + params.query.month) | ||
const getMusicDetailById = (params) => wxRequest(params, host + '/api/music/detail/' + params.query.id) | ||
|
||
module.exports = { | ||
getVolById, | ||
getVolIdList, | ||
getVolsByMonth, | ||
getVolDetailById, | ||
getCarousel, | ||
getLastArticles, | ||
getEssayById, | ||
getSerialById, | ||
getQuestionById, | ||
getArticlesByMonth, | ||
getMusicIdList, | ||
getMusicsByMonth, | ||
getMusicDetailById | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
App({ | ||
|
||
}) | ||
App({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,63 @@ | ||
var util = require('../../../utils/util.js') | ||
import { | ||
MUSIC_PALY_IMG, | ||
MUSIC_PAUSE_IMG | ||
} from '../../../utils/constants.js' | ||
import api from '../../../api/api.js' | ||
import util from '../../../utils/util.js' | ||
|
||
Page({ | ||
data: { | ||
item: [], | ||
playing: false, | ||
playImg: '../../../image/music_play.png', | ||
content: 'story' | ||
detail: [], | ||
playing: false | ||
}, | ||
onLoad: function (options) { | ||
var that = this | ||
|
||
wx.request({ | ||
url: 'http://v3.wufazhuce.com:8000/api/music/detail/' + options.id, | ||
header: { | ||
'Content-Type': 'application/json' | ||
api.getMusicDetailById({ | ||
query: { | ||
id: options.id | ||
}, | ||
success: function (res) { | ||
success: (res) => { | ||
if (res.data.res === 0) { | ||
var item = res.data.data | ||
let detail = res.data.data | ||
|
||
detail.playImg = MUSIC_PALY_IMG | ||
detail.contentType = 'story' | ||
detail.story = util.filterHTML(detail.story) | ||
detail.maketime = util.formatMakettime(detail.maketime) | ||
|
||
item.story = item.story.replace(/<br>/g,"") | ||
item.maketime = util.formatMakettime(item.maketime) | ||
that.setData({ | ||
item: item | ||
}) | ||
this.setData({ detail }) | ||
} | ||
} | ||
}) | ||
}, | ||
togglePlay: function (e) { | ||
var music = this.data.item | ||
var playing = this.data.playing | ||
let detail = this.data.detail | ||
let playing = this.data.playing | ||
|
||
if (!playing) { | ||
var playImg = '../../../image/music_pause.png' | ||
this.playMusic(music) | ||
detail.playImg = MUSIC_PAUSE_IMG | ||
this.playMusic(detail) | ||
} else { | ||
var playImg = '../../../image/music_play.png' | ||
detail.playImg = MUSIC_PALY_IMG | ||
this.pauseMusic() | ||
} | ||
playing = !playing | ||
|
||
this.setData({ | ||
playing: playing, | ||
playImg: playImg | ||
}) | ||
this.setData({ detail, playing }) | ||
}, | ||
playMusic: function (music) { | ||
wx.playBackgroundAudio({ | ||
dataUrl: music.music_id, | ||
title: music.title, | ||
fail: function () { | ||
wx.showToast({ title: '播放失败' }) | ||
} | ||
title: music.title | ||
}) | ||
}, | ||
pauseMusic: function () { | ||
wx.pauseBackgroundAudio() | ||
}, | ||
showStory: function () { | ||
this.setData({ | ||
content: 'story' | ||
}) | ||
}, | ||
showLyric: function () { | ||
this.setData({ | ||
content: 'lyric' | ||
}) | ||
}, | ||
showAbout: function () { | ||
this.setData({ | ||
content: 'about' | ||
}) | ||
switchContent: function (e) { | ||
let type = e.target.dataset.type | ||
let detail = this.data.detail | ||
|
||
detail.contentType = type | ||
this.setData({ detail }) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<view class="container"> | ||
<include src="../templates/musicItem.wxml"/> | ||
<import src="../templates/musicItem.wxml"/> | ||
<template is="music-item" data="{{item: detail}}"/> | ||
</view> |
6 changes: 3 additions & 3 deletions
6
pages/music/templates/about.wxml → pages/music/includes/about.wxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
pages/music/templates/lyric.wxml → pages/music/includes/lyric.wxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.