diff --git a/app.js b/app.js index b545190..9e228ac 100644 --- a/app.js +++ b/app.js @@ -1,11 +1,6 @@ //app.js App({ onLaunch: function () { - // 展示本地存储能力 - var logs = wx.getStorageSync('logs') || [] - logs.unshift(Date.now()) - wx.setStorageSync('logs', logs) - // 登录 wx.login({ success: res => { diff --git a/components/cell/index.js b/components/cell/index.js index ee1b46a..071032c 100644 --- a/components/cell/index.js +++ b/components/cell/index.js @@ -8,7 +8,7 @@ Component({ title: String, readed: { type:Boolean, - value: true, + value: false, }, time: String, showTop: { diff --git a/components/focus/index.js b/components/focus/index.js index b9f1ef1..1af10f1 100644 --- a/components/focus/index.js +++ b/components/focus/index.js @@ -4,27 +4,16 @@ Component({ * 组件的属性列表 */ properties: { - + items: { + type: Array, + value:[] + } }, - /** * 组件的初始数据 */ data: { - items: [ - { - id: '1', - title: '啦啦啦阿拉啦啦啦爱啦啦啦' - }, - { - id: '2', - title: '啦啦啦阿拉啦啦啦爱啦啦啦啦啦啦阿拉啦啦啦爱啦啦啦' - }, - { - id: '3', - title: '啦啦啦阿拉啦啦啦爱啦啦啦' - } - ] + }, /** diff --git a/components/focus/index.wxml b/components/focus/index.wxml index a34f2f3..438d78c 100644 --- a/components/focus/index.wxml +++ b/components/focus/index.wxml @@ -11,7 +11,7 @@ vertical="{{true}}" circular="{{true}}" > - + {{item.title}} diff --git a/components/swiper/index.js b/components/swiper/index.js index 2763ccb..492405a 100644 --- a/components/swiper/index.js +++ b/components/swiper/index.js @@ -4,23 +4,16 @@ Component({ * 组件的属性列表 */ properties: { - + images: { + type: Array, + value: [] + } }, /** * 组件的初始数据 */ data: { - images: [ - { - id: '1', - image: "http://m.360buyimg.com/mobilecms/s700x280_jfs/t1/76190/38/9199/97616/5d6e380cEf6e9f6a7/71023fef24783257.jpg!cr_1125x445_0_171!q70.jpg.dpg" - }, - { - id: '2', - image: 'http://m.360buyimg.com/mobilecms/s700x280_jfs/t1/45210/40/7669/143615/5d53b19dEc9559d0a/cd9eade239533517.jpg!cr_1125x445_0_171!q70.jpg.dpg' - } - ] }, /** diff --git a/components/swiper/index.wxml b/components/swiper/index.wxml index 1de5256..0c1dbfe 100644 --- a/components/swiper/index.wxml +++ b/components/swiper/index.wxml @@ -8,7 +8,7 @@ indicator-active-color="#D50000" indicator-color="#fff" > - + diff --git a/config.js b/config.js index f4eb37b..893d040 100644 --- a/config.js +++ b/config.js @@ -1,4 +1,5 @@ const config = { - api_url: 'https://nei.netease.com/api/apimock/8290e3893033966572547b03f2ef3dbb/', // 服务器地址 + // api_url: 'https://nei.netease.com/api/apimock/8290e3893033966572547b03f2ef3dbb/', // 服务器地址 + api_url: 'http://121.42.41.42:8092/fqsb' } export { config } \ No newline at end of file diff --git a/models/artice.js b/models/artice.js index 2da2c74..f99467a 100644 --- a/models/artice.js +++ b/models/artice.js @@ -1,4 +1,12 @@ -import { HTTP } from '../utils/http.js' +import { HTTP, Method } from '../utils/http.js' + +// 请求url常量 +const ArticeConst = { + artice_url: '/api/content/queryById', + artice_add_collect_url: '/api/content/addCollection', + artice_remove_collect_url: '/api/content/removeCollection', + artice_online_url: '', +} class ArticeModel extends HTTP { constructor() { @@ -7,9 +15,9 @@ class ArticeModel extends HTTP { // 文章详情 getDetail(aId, success) { let params = { - url: '', + url: ArticeConst.artice_url, sucess: success, - method: 'POST', + method: Method.POST, data: { id: aId } @@ -17,13 +25,25 @@ class ArticeModel extends HTTP { this.request(params) } // 设置收藏还是取消 - setCollect(aId, type, success) { + // type: 0: 添加;1: 移除 + addCollect(aId, type, success) { let params = { - url: '', + url: artice_add_collect_url, success: success, - method: 'POST', + method: Method.POST, data: { - + id: aId + } + } + this.request(params) + } + removeCollect(aId, success) { + let params = { + url: artice_remove_collect_url, + success: success, + method: Method.POST, + data: { + id: aId } } this.request(params) @@ -31,9 +51,9 @@ class ArticeModel extends HTTP { // 在线报名 onlineSign (aId, type, success) { let params = { - url: '', + url: artice_online_url, success: success, - method: 'POST', + method: Method.POST, data: { } diff --git a/models/auth.js b/models/auth.js index 055aea7..40f06e7 100644 --- a/models/auth.js +++ b/models/auth.js @@ -1,4 +1,4 @@ -import { HTTP, Method } from '../utils/http.js' +import { HTTP, Method, HTTPConst } from '../utils/http.js' const token_url = 'oas-admin/screen/user/ageAndSex' @@ -6,6 +6,45 @@ class AuthModel extends HTTP { constructor() { super() } + // 获取短信验证码 + getMsgCode (phone) { + let params = { + url: '', + method: Method.POST, + data: { + + }, + success: (data)=> { + wx.showToast({ + title: '短信验证码已发送!', + icon: 'none' + }) + } + } + this.request(params) + } + // 验证和注册 + register (phone, name, vscode, success) { + let params = { + url: '', + method: Method.POST, + data: { + + }, + success: (data) => { + if (data) { + success(data) + } else { + wx.showToast({ + title: '注册失败', + icon: 'none' + }) + console.log('注册失败') + } + } + } + this.request(params) + } // 获取 Token fetchAuthToken(success) { // 获取token @@ -17,7 +56,12 @@ class AuthModel extends HTTP { data: { code: res }, - success: success, + success: (data) => { + // 将获取到的token存放起来 + let token = data + wx.setStorageSync(HTTPConst.TokenStoreKey, token) + success(token) + }, } this.request(params) }) diff --git a/models/billboard.js b/models/billboard.js index 9c0f935..ab353ef 100644 --- a/models/billboard.js +++ b/models/billboard.js @@ -1,9 +1,10 @@ -import {HTTP} from '../utils/http.js' +import {HTTP, Method} from '../utils/http.js' class BillboardModel extends HTTP { constructor () { super() } + } export {BillboardModel} \ No newline at end of file diff --git a/models/home.js b/models/home.js index 5d352fa..bfbe1a3 100644 --- a/models/home.js +++ b/models/home.js @@ -1,13 +1,53 @@ -import {HTTP} from '../utils/http.js' +import {HTTP, Method} from '../utils/http.js' + +const HOMEConst = { + home_banner_url: '/api/content/getListByCode', + home_hot_url: '/api/content/getListByCode', + home_list_url: '/api/content/getListByCode', +} class HomeModel extends HTTP { constructor () { super() } + // 获取 Banner 数据 + getHomeBanner(success) { + let params = { + url: HOMEConst.home_banner_url, + method: Method.POST, + data: { + typeCode: 'sc-banner', + page: 1, + pageSize: 20, + }, + success: success + } + this.request(params) + } + // 获取首页热点数据 + getHomeHot(success) { + let params = { + url: HOMEConst.home_hot_url, + method: Method.POST, + data: { + typeCode: 'sc-jdtz', + page: 1, + pageSize: 20, + }, + success: success + } + this.request(params) + } // 首页列表 - getHomeList = (success) => { + getHomeList(page, success){ let params = { - url: 'oas-admin/screen/user/ageAndSex', + url: HOMEConst.home_list_url, + method: Method.POST, + data: { + typeCode: 'sc-tzgg', + page: page, + pageSize: 20, + }, success: success } this.request(params) diff --git a/models/topic.js b/models/topic.js index dbc5f84..ec2fa9e 100644 --- a/models/topic.js +++ b/models/topic.js @@ -1,4 +1,4 @@ -import { HTTP, Method} from '../utils/http.js' +import {HTTP, Method} from '../utils/http.js' class TopicModel extends HTTP { constructor () { diff --git a/models/user.js b/models/user.js index ff9f9f7..a4177a0 100644 --- a/models/user.js +++ b/models/user.js @@ -1,5 +1,7 @@ import {HTTP} from '../utils/http.js' - +const UserConst = { + user_info: '', // 个人信息 +} class UserModel extends HTTP { constructor () { super() diff --git a/pages/home/index.js b/pages/home/index.js index c8b8c49..e032735 100644 --- a/pages/home/index.js +++ b/pages/home/index.js @@ -2,10 +2,13 @@ import dayjs from '../../utils/dayjs/index.js' import relativeTime from '../../utils/dayjs/relativeTime.js' dayjs.extend(relativeTime); -import { HomeModel} from '../../models/home.js' +import { HomeModel } from '../../models/home.js' let homeModel = new HomeModel() Page({ data: { + currPage: 1, + banners: [], + hots: [], list: [ { id: '1', @@ -31,30 +34,121 @@ Page({ console.log(dayjs().toNow()) console.log(dayjs().from(dayjs('1990'))) this.fetchHomeList() + this.fetchHomeBanner() + this.fetchHomeHot() + }, + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + this.setData({ + currPage: 1, + }) + this.fetchHomeList() + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + const page = this.data.currPage + 1 + this.setData({ + currPage: page + }) + this.fetchHomeList() }, // 获取首页列表 - fetchHomeList () { - homeModel.getHomeList(res => { + fetchHomeList() { + let page = this.data.currPage + homeModel.getHomeList(page, res => { console.log('啦啦啦') + const datas = res.result.records + let tempDatas = [] + datas.forEach(item => { + tempDatas.push({ + id: item.id, + title: item.title, + showTop: item.isTop == 1 ? true : false, + time: dayjs(item.createTime).toNow(), + }) + }) + if (page == 1) { + this.setData({ + list: tempDatas + }) + } else { + if (tempDatas.length > 0) { + const list = [...this.data.list, ...tempDatas] + this.setData({ + list: list + }) + } else { + const page = this.data.currPage - 1 + this.setData({ + currPage: page + }) + wx.showToast({ + title: '已加载全部', + icon: 'none' + }) + } + } + console.log(res) + wx.stopPullDownRefresh() + }) + }, + fetchHomeBanner() { + homeModel.getHomeBanner(res => { + console.log('Banner') + console.log(res) + const datas = res.result.records + let tempBanners = [] + datas.forEach(item => { + console.log(item) + tempBanners.push({ + id: item.id, + image: 'http://m.360buyimg.com/mobilecms/s700x280_jfs/t1/45210/40/7669/143615/5d53b19dEc9559d0a/cd9eade239533517.jpg!cr_1125x445_0_171!q70.jpg.dpg' + }) + }) + this.setData({ + banners: tempBanners + }) + }) + }, + fetchHomeHot() { + homeModel.getHomeHot(res => { + console.log('Hot') console.log(res) + const datas = res.result.records + let tempHots = [] + datas.forEach(item => { + tempHots.push({ + id: item.id, + title: item.title + }) + }) + this.setData({ + hots: tempHots + }) }) }, - tapSwiperItem (e) { + // Banner/Hot/List事件 + tapSwiperItem(e) { console.log(e.detail) this.gotoArticePage(e.detail.id) }, - tapFocusItem (e) { + tapFocusItem(e) { console.log(e.detail) this.gotoArticePage(e.detail.id) }, - clickListItem (e) { + clickListItem(e) { console.log(e.detail) this.gotoArticePage(e.detail.id) // wx.redirectTo({ // url: '/pages/register/index', // }) }, - gotoArticePage (id) { + gotoArticePage(id) { wx.navigateTo({ url: `/pages/article/index?id=${id}`, }) diff --git a/pages/home/index.json b/pages/home/index.json index 579d390..4721f9c 100644 --- a/pages/home/index.json +++ b/pages/home/index.json @@ -1,4 +1,5 @@ { + "enablePullDownRefresh": true, "usingComponents": { "e-swiper": "/components/swiper/index", "e-focus": "/components/focus/index", diff --git a/pages/home/index.wxml b/pages/home/index.wxml index 741c2ab..07e9f53 100644 --- a/pages/home/index.wxml +++ b/pages/home/index.wxml @@ -1,9 +1,10 @@ - - - + + + { + // 从缓存中读取 token + let token = wx.getStorageSync(HTTPConst.TokenStoreKey) || '' let url = this.baseUrl + params.url if (!params.method) { params.method = Method.GET } - console.log(params) + // token 拼接到 请求体中 + let data = Object.assign({ token: token }, params.data) wx.request({ url: url, - data: params.data, + data: data, header: { 'content-type': 'application/json', }, method: params.method, dataType: 'json', success: function (res) { - console.log(res) + // console.log(res) let code = res.statusCode.toString() let startCode = code.charAt(0) if (startCode == '2') { @@ -41,4 +46,4 @@ class HTTP { }) } } -export { HTTP, Method } +export { HTTP, Method, HTTPConst }