Browse Source

topic.js 合并

master
fanp 6 years ago
parent
commit
164624d8a0
  1. 5
      app.js
  2. 2
      components/cell/index.js
  3. 21
      components/focus/index.js
  4. 2
      components/focus/index.wxml
  5. 15
      components/swiper/index.js
  6. 2
      components/swiper/index.wxml
  7. 3
      config.js
  8. 38
      models/artice.js
  9. 48
      models/auth.js
  10. 3
      models/billboard.js
  11. 46
      models/home.js
  12. 4
      models/user.js
  13. 96
      pages/home/index.js
  14. 1
      pages/home/index.json
  15. 7
      pages/home/index.wxml
  16. 17
      utils/http.js

5
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 => {

2
components/cell/index.js

@ -8,7 +8,7 @@ Component({
title: String,
readed: {
type:Boolean,
value: true,
value: false,
},
time: String,
showTop: {

21
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: '啦啦啦阿拉啦啦啦爱啦啦啦'
}
]
},
/**

2
components/focus/index.wxml

@ -11,7 +11,7 @@
vertical="{{true}}"
circular="{{true}}"
>
<block wx:for="{{items}}" wx:key="*this">
<block wx:for="{{items}}" wx:key="forcus-{{index}}">
<swiper-item>
<view bindtap="onTap" data-item="{{item}}" class="focus_swiper_item">{{item.title}}</view>
</swiper-item>

15
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'
}
]
},
/**

2
components/swiper/index.wxml

@ -8,7 +8,7 @@
indicator-active-color="#D50000"
indicator-color="#fff"
>
<block wx:for="{{images}}" wx:key="*this">
<block wx:for="{{images}}" wx:key="swiper-{{index}}">
<swiper-item bind:tap="onTapImage" data-item="{{item}}">
<image class="swiper_icon" src="{{item.image}}"></image>
</swiper-item>

3
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 }

38
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: {
}

48
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)
})

3
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}

46
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)

4
models/user.js

@ -1,5 +1,7 @@
import {HTTP} from '../utils/http.js'
const UserConst = {
user_info: '', // 个人信息
}
class UserModel extends HTTP {
constructor () {
super()

96
pages/home/index.js

@ -6,6 +6,9 @@ import { HomeModel} from '../../models/home.js'
let homeModel = new HomeModel()
Page({
data: {
currPage: 1,
banners: [],
hots: [],
list: [
{
id: '1',
@ -31,14 +34,105 @@ 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 => {
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
})
})
},
// Banner/Hot/List事件
tapSwiperItem(e) {
console.log(e.detail)
this.gotoArticePage(e.detail.id)

1
pages/home/index.json

@ -1,4 +1,5 @@
{
"enablePullDownRefresh": true,
"usingComponents": {
"e-swiper": "/components/swiper/index",
"e-focus": "/components/focus/index",

7
pages/home/index.wxml

@ -1,9 +1,10 @@
<!--index.wxml-->
<view class="container">
<e-swiper bind:tapSwiperItem="tapSwiperItem"/>
<e-focus bind:tapFocusItem="tapFocusItem"/>
<block wx:for="{{list}}" wx:key="*this">
<e-swiper bind:tapSwiperItem="tapSwiperItem" images="{{banners}}"/>
<e-focus bind:tapFocusItem="tapFocusItem" items="{{hots}}"/>
<block wx:for="{{list}}" wx:key="{{index}}">
<e-cell
read="{{item.readed}}"
cId="{{item.id}}"
title="{{item.title}}"
time="{{item.time}}"

17
utils/http.js

@ -3,28 +3,33 @@ const Method = {
GET: 'GET',
POST: 'POST'
}
// 定义一些通用常量
const HTTPConst = {
TokenStoreKey: 'ETokenKey'
}
class HTTP {
constructor() {
this.baseUrl = config.api_url
}
request = (params) => {
// 从缓存中读取 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 }

Loading…
Cancel
Save