Browse Source

请求库、接口

master
lqq 6 years ago
parent
commit
2eb30c48fd
  1. 45
      models/artice.js
  2. 9
      models/billboard.js
  3. 2
      models/home.js
  4. 10
      models/topic.js
  5. 9
      models/user.js
  6. 4
      package.json
  7. 12
      pages/home/index.js
  8. 13
      utils/dayjs/index.js
  9. 1
      utils/dayjs/relativeTime.js
  10. 2
      utils/http.js

45
models/artice.js

@ -0,0 +1,45 @@
import { HTTP } from '../utils/http.js'
class ArticeModel extends HTTP {
constructor() {
super()
}
// 文章详情
getDetail(aId, success) {
let params = {
url: '',
sucess: success,
method: 'POST',
data: {
id: aId
}
}
this.request(params)
}
// 设置收藏还是取消
setCollect(aId, type, success) {
let params = {
url: '',
success: success,
method: 'POST',
data: {
}
}
this.request(params)
}
// 在线报名
onlineSign (aId, type, success) {
let params = {
url: '',
success: success,
method: 'POST',
data: {
}
}
this.request(params)
}
}
export { ArticeModel }

9
models/billboard.js

@ -0,0 +1,9 @@
import {HTTP} from '../utils/http.js'
class BillboardModel extends HTTP {
constructor () {
super()
}
}
export {BillboardModel}

2
models/home.js

@ -5,7 +5,7 @@ class HomeModel extends HTTP {
super()
}
// 首页列表
getHomeList (success) {
getHomeList = (success) => {
let params = {
url: 'oas-admin/screen/user/ageAndSex',
success: success

10
models/topic.js

@ -0,0 +1,10 @@
import {HTTP} from '../utils/http.js'
class TopicModel extends HTTP {
constructor () {
super()
}
}
export {TopicModel}

9
models/user.js

@ -0,0 +1,9 @@
import {HTTP} from '../utils/http.js'
class UserModel extends HTTP {
constructor () {
super()
}
}
export { UserModel }

4
package.json

@ -11,5 +11,7 @@
"url": "http://liqianqian@121.42.41.42:7070/r/shibeirencai_wechat.git"
},
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
}
}

12
pages/home/index.js

@ -1,4 +1,7 @@
//index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import { HomeModel} from '../../models/home.js'
let homeModel = new HomeModel()
Page({
@ -25,7 +28,14 @@ Page({
]
},
onLoad: function () {
homeModel.getHomeList((res) => {
console.log(dayjs().toNow())
console.log(dayjs().from(dayjs('1990')))
this.fetchHomeList()
},
// 获取首页列表
fetchHomeList () {
homeModel.getHomeList(res => {
console.log('啦啦啦')
console.log(res)
})
},

13
utils/dayjs/index.js

File diff suppressed because one or more lines are too long

1
utils/dayjs/relativeTime.js

@ -0,0 +1 @@
!function (r, t) { "object" == typeof exports && "undefined" != typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define(t) : r.dayjs_plugin_relativeTime = t() }(this, function () { "use strict"; return function (r, t, e) { var n = t.prototype; e.en.relativeTime = { future: "%s", past: "%s", s: "刚刚", m: "一分钟前", mm: "%d分钟前", h: "1小时前", hh: "%d小时前", d: "1天前", dd: "%d天前", M: "1个月前", MM:"%d月前",y:"1年前",yy:"%d年前"};var o=function(r,t,n,o){for(var d,i,u=n.$locale().relativeTime,a=[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],f=a.length,s=0;s<f;s+=1){var l=a[s];l.d&&(d=o?e(r).diff(n,l.d,!0):n.diff(r,l.d,!0));var h=Math.round(Math.abs(d));if(h<=l.r||!l.r){1===h&&s>0&&(l=a[s-1]),i=u[l.l].replace("%d",h);break}}return t?i:(d>0?u.future:u.past).replace("%s",i)};n.to=function(r,t){return o(r,t,this,!0)},n.from=function(r,t){return o(r,t,this)};var d=function(r){return r.$u?e.utc():e()};n.toNow=function(r){return this.to(d(this),r)},n.fromNow=function(r){return this.from(d(this),r)}}});

2
utils/http.js

@ -24,10 +24,12 @@ class HTTP {
if (startCode == '2') {
params.success && params.success(res.data)
} else {
console.log('请求错误')
params.error && params.error(res)
}
},
fail: function (res) {
console.log('服务器错误')
params.fail && params.fail(res)
},
})

Loading…
Cancel
Save