From 2eb30c48fd8e4ec41b21909a2f213e1077313c43 Mon Sep 17 00:00:00 2001 From: lqq Date: Fri, 11 Oct 2019 11:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=BA=93=E3=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/artice.js | 45 +++++++++++++++++++++++++++++++++++++ models/billboard.js | 9 ++++++++ models/home.js | 2 +- models/topic.js | 10 +++++++++ models/user.js | 9 ++++++++ package.json | 4 +++- pages/home/index.js | 12 +++++++++- utils/dayjs/index.js | 13 +++++++++++ utils/dayjs/relativeTime.js | 1 + utils/http.js | 12 +++++----- 10 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 models/artice.js create mode 100644 models/billboard.js create mode 100644 models/topic.js create mode 100644 models/user.js create mode 100644 utils/dayjs/index.js create mode 100644 utils/dayjs/relativeTime.js diff --git a/models/artice.js b/models/artice.js new file mode 100644 index 0000000..2da2c74 --- /dev/null +++ b/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 } \ No newline at end of file diff --git a/models/billboard.js b/models/billboard.js new file mode 100644 index 0000000..9c0f935 --- /dev/null +++ b/models/billboard.js @@ -0,0 +1,9 @@ +import {HTTP} 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 d4865a1..5d352fa 100644 --- a/models/home.js +++ b/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 diff --git a/models/topic.js b/models/topic.js new file mode 100644 index 0000000..e54cfe4 --- /dev/null +++ b/models/topic.js @@ -0,0 +1,10 @@ +import {HTTP} from '../utils/http.js' + +class TopicModel extends HTTP { + constructor () { + super() + } +} + +export {TopicModel} + diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..ff9f9f7 --- /dev/null +++ b/models/user.js @@ -0,0 +1,9 @@ +import {HTTP} from '../utils/http.js' + +class UserModel extends HTTP { + constructor () { + super() + } +} + +export { UserModel } \ No newline at end of file diff --git a/package.json b/package.json index a3587e7..cef4c2d 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,7 @@ "url": "http://liqianqian@121.42.41.42:7070/r/shibeirencai_wechat.git" }, "author": "", - "license": "ISC" + "license": "ISC", + "dependencies": { + } } diff --git a/pages/home/index.js b/pages/home/index.js index 46c86d9..c8b8c49 100644 --- a/pages/home/index.js +++ b/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) }) }, diff --git a/utils/dayjs/index.js b/utils/dayjs/index.js new file mode 100644 index 0000000..66eaabc --- /dev/null +++ b/utils/dayjs/index.js @@ -0,0 +1,13 @@ +module.exports = (function() { +var __MODS__ = {}; +var __DEFINE__ = function(modId, func, req) { var m = { exports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; }; +var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = { exports: {} }; __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); if(typeof m.exports === "object") { __MODS__[modId].m.exports.__proto__ = m.exports.__proto__; Object.keys(m.exports).forEach(function(k) { __MODS__[modId].m.exports[k] = m.exports[k]; Object.defineProperty(m.exports, k, { set: function(val) { __MODS__[modId].m.exports[k] = val; }, get: function() { return __MODS__[modId].m.exports[k]; } }); }); if(m.exports.__esModule) Object.defineProperty(__MODS__[modId].m.exports, "__esModule", { value: true }); } else { __MODS__[modId].m.exports = m.exports; } } return __MODS__[modId].m.exports; }; +var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } }; +var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; }; +__DEFINE__(1570756320018, function(require, module, exports) { +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.dayjs=n()}(this,function(){var t="millisecond",n="second",e="minute",r="hour",i="day",s="week",u="month",a="quarter",o="year",h=/^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/,f=/\[([^\]]+)]|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=function(t,n,e){var r=String(t);return!r||r.length>=n?t:""+Array(n+1-r.length).join(e)+t},d={s:c,z:function(t){var n=-t.utcOffset(),e=Math.abs(n),r=Math.floor(e/60),i=e%60;return(n<=0?"+":"-")+c(r,2,"0")+":"+c(i,2,"0")},m:function(t,n){var e=12*(n.year()-t.year())+(n.month()-t.month()),r=t.clone().add(e,u),i=n-r<0,s=t.clone().add(e+(i?-1:1),u);return Number(-(e+(n-r)/(i?r-s:s-r))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return{M:u,y:o,w:s,d:i,h:r,m:e,s:n,ms:t,Q:a}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},$={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},l="en",m={};m[l]=$;var y=function(t){return t instanceof v},M=function(t,n,e){var r;if(!t)return l;if("string"==typeof t)m[t]&&(r=t),n&&(m[t]=n,r=t);else{var i=t.name;m[i]=t,r=i}return e||(l=r),r},g=function(t,n,e){if(y(t))return t.clone();var r=n?"string"==typeof n?{format:n,pl:e}:n:{};return r.date=t,new v(r)},D=d;D.l=M,D.i=y,D.w=function(t,n){return g(t,{locale:n.$L,utc:n.$u})};var v=function(){function c(t){this.$L=this.$L||M(t.locale,null,!0),this.parse(t)}var d=c.prototype;return d.parse=function(t){this.$d=function(t){var n=t.date,e=t.utc;if(null===n)return new Date(NaN);if(D.u(n))return new Date;if(n instanceof Date)return new Date(n);if("string"==typeof n&&!/Z$/i.test(n)){var r=n.match(h);if(r)return e?new Date(Date.UTC(r[1],r[2]-1,r[3]||1,r[4]||0,r[5]||0,r[6]||0,r[7]||0)):new Date(r[1],r[2]-1,r[3]||1,r[4]||0,r[5]||0,r[6]||0,r[7]||0)}return new Date(n)}(t),this.init()},d.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},d.$utils=function(){return D},d.isValid=function(){return!("Invalid Date"===this.$d.toString())},d.isSame=function(t,n){var e=g(t);return this.startOf(n)<=e&&e<=this.endOf(n)},d.isAfter=function(t,n){return g(t)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)}}}); diff --git a/utils/http.js b/utils/http.js index 5617375..cfee5fd 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,7 +1,7 @@ -import {config} from '../config.js' +import { config } from '../config.js' class HTTP { - constructor () { + constructor() { this.baseUrl = config.api_url } request = (params) => { @@ -17,20 +17,22 @@ class HTTP { }, method: params.method, dataType: 'json', - success: function(res) { + success: function (res) { console.log(res) let code = res.statusCode.toString() let startCode = code.charAt(0) if (startCode == '2') { params.success && params.success(res.data) } else { + console.log('请求错误') params.error && params.error(res) } }, - fail: function(res) { + fail: function (res) { + console.log('服务器错误') params.fail && params.fail(res) }, }) } } -export {HTTP} +export { HTTP }