diff --git a/app.js b/app.js
index b545190..c6ba268 100644
--- a/app.js
+++ b/app.js
@@ -1,5 +1,15 @@
//app.js
+var restAjax = require('utils/restAjax.js');
+var dialog = require('utils/dialog.js');
App({
+ loginUrl: 'http://192.168.0.113:7001/usercenter',
+ usercenterUrl: 'http://192.168.0.113:7001/usesrcenter',
+ newsUrl: 'http://192.168.0.113:8082/news',
+ libraryUrl: 'http://192.168.0.113:8081/library',
+ activityUrl: '',
+ venueUrl: '',
+ restAjax: restAjax,
+ dialog: dialog,
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
diff --git a/app.json b/app.json
index f3ba107..6788cc1 100644
--- a/app.json
+++ b/app.json
@@ -1,5 +1,5 @@
{
- "pages":[
+ "pages": [
"pages/index/index",
"pages/volunteerRegister/volunteerRegister",
"pages/volunteer/volunteer",
@@ -18,13 +18,14 @@
"pages/activitySign/activitySign",
"pages/activityDetail/activityDetail",
"pages/activity/activity",
- "pages/newsDetail/newsDetail"
+ "pages/newsDetail/newsDetail",
+ "pages/newsList/newsList"
],
- "window":{
- "backgroundTextStyle":"light",
+ "window": {
+ "backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#9F1512",
"navigationBarTitleText": "日喀则数字文化馆",
- "navigationBarTextStyle":"white"
+ "navigationBarTextStyle": "white"
},
"tabBar": {
"color": "#BBBBBB",
@@ -65,4 +66,4 @@
},
"style": "v2",
"sitemapLocation": "sitemap.json"
-}
+}
\ No newline at end of file
diff --git a/pages/index/index.js b/pages/index/index.js
index 949f80c..f72822e 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -1,47 +1,100 @@
+var app = getApp();
Page({
-
/**
* 页面的初始数据
*/
data: {
indicatorDots: true,
autoplay: true,
- baseUrl: 'http://192.168.0.111:8888/volunteer/',
token: '',
- key: ''
+ library: {
+ libraryUrl: app.libraryUrl,
+ bannerLibrary: [],
+ },
+ news: {
+ newsUrl: app.newsUrl,
+ newsList: []
+ },
+ venue: {
+ venueUrl: app.venueUrl
+ },
+ activity: {
+ activityUrl: app.activityUrl
+ }
},
- doLogin: function() {
+ doLogin: function () {
var self = this;
wx.login({
success(res) {
- console.log(res)
- if(res.code) {
- var WechatMiniAppLoginVO = {jsCode: res.code};
- wx.request({
- url: self.data.baseUrl + 'wxminiapp/auth/login',
- method: 'post',
- data: WechatMiniAppLoginVO,
- success: function(res) {
- self.setData({
- token: res.data.data
- })
- wx.setStorage({
- data: res.data.data,
- key: 'token'
- })
- }
- })
- }else {
- console.log('登陆失败!' + res.errMsg);
+ if (res.code) {
+ app.restAjax.post(app.restAjax.path('{url}/wxminiapp/auth/login', [app.loginUrl]), {
+ jsCode: res.code
+ }, null, function (code, data) {
+ var tokenArray = data.data.split('_');
+ var token = tokenArray[0];
+ var isRandomUsername = tokenArray[1];
+ self.setData({
+ token: token
+ })
+ wx.setStorageSync('token', token);
+ wx.setStorageSync('isRandomUsername', isRandomUsername)
+ }, function (code, data) {
+ app.dialog.msg(data.msg);
+ });
+ } else {
+ app.dialog.msg('登录失败!'+ res.errMsg);
}
}
})
},
+ doGetLibrary: function() {
+ var self = this;
+ app.restAjax.get(app.restAjax.path('{libraryUrl}/app/intangiblelibrary/listpageintangiblelibraryrelease', [self.data.library.libraryUrl]), {
+ page: 1,
+ rows: 5
+ }, null, function(code, data) {
+ self.setData({
+ 'library.bannerLibrary': data.rows
+ });
+ }, function(code, data){
+ app.dialog.msg(data.msg);
+ });
+ },
+ doGetVenue: function() {
+ app.restAjax.get(app.restAjax.path('', []), {
+
+ }, null, function(code, data) {
+
+ }, function(code, data) {
+ app.dialog.msg(data.msg);
+ });
+ },
+ doGetActivity: function() {
+
+ },
+ doGetNewsList: function() {
+ var self = this;
+ app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
+ page: 1,
+ rows: 5
+ }, null, function(code, data) {
+ self.setData({
+ 'news.newsList': data.rows
+ })
+ }, function(code, data) {
+ app.dialog.msg(data.msg);
+ });
+ },
goNewsDetail: function () {
wx.navigateTo({
url: '../newsDetail/newsDetail',
})
},
+ goNewsList: function() {
+ wx.navigateTo({
+ url: '../newsList/newsList',
+ })
+ },
goVolunteer: function () {
wx.navigateTo({
url: '../volunteer/volunteer',
@@ -78,54 +131,56 @@ Page({
onLoad: function (options) {
var self = this;
self.doLogin();
+ self.doGetLibrary();
+ self.doGetNewsList();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
-
+
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
-
+
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
-
+
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
-
+
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
-
+
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
-
+
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
-
+
}
})
\ No newline at end of file
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index ab76d25..f589d84 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -1,13 +1,7 @@
-
-
-
-
-
-
-
-
+
+
@@ -61,54 +55,62 @@
-
+
新闻资讯
-
- 银保监会印发《关于加快推进意外险改革的意见》
-
- 来源:百度
- 10评论
- 2020-03-02
-
-
-
- 银保监会印发《关于加快推进意外险改革的意见》
-
-
-
-
- 来源:百度
- 10评论
- 2020-03-02
-
-
-
- 银保监会印发《关于加快推进意外险改革的意见》
-
-
-
-
-
-
- 来源:百度
- 10评论
- 2020-03-02
-
-
-
-
-
-
-
- 银保监会印发《关于加快推进意外险改革的意见》
+
+
+ {{item.newsContentTitle}}
+
+
+
- 来源:百度
- 10评论
- 2020-03-02
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+
+
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
diff --git a/pages/newsList/newsList.js b/pages/newsList/newsList.js
new file mode 100644
index 0000000..1e10070
--- /dev/null
+++ b/pages/newsList/newsList.js
@@ -0,0 +1,101 @@
+// pages/newsList/newsList.js
+var app = getApp();
+Page({
+
+ /**
+ * 页面的初始数据
+ */
+ data: {
+ news: {
+ newsUrl: app.newsUrl,
+ newsList: [],
+ },
+ currentPage: 1,
+ rows: 10
+ },
+ doGetNewsList: function(page) {
+ var self = this;
+ app.dialog.loading('正在加载');
+ app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), {
+ page: page,
+ rows: self.data.rows
+ }, null, function(code, data) {
+ if(data.rows.length == 0) {
+ app.dialog.msg('暂无数据');
+ return;
+ }
+ var newsArray;
+ if(page <= 1) {
+ newsArray = data.rows;
+ } else {
+ newsArray = self.data.news.newsList;
+ newsArray = newsArray.concat(data.rows);
+ }
+ self.setData({
+ currentPage: page,
+ 'news.newsList': newsArray
+ })
+ }, function(code, data) {
+ app.dialog.msg(data.msg);
+ }, function() {
+ wx.stopPullDownRefresh();
+ wx.hideLoading();
+ });
+ },
+ /**
+ * 生命周期函数--监听页面加载
+ */
+ onLoad: function (options) {
+ var self = this;
+ self.doGetNewsList(1);
+ },
+
+ /**
+ * 生命周期函数--监听页面初次渲染完成
+ */
+ onReady: function () {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow: function () {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面隐藏
+ */
+ onHide: function () {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面卸载
+ */
+ onUnload: function () {
+
+ },
+
+ /**
+ * 页面相关事件处理函数--监听用户下拉动作
+ */
+ onPullDownRefresh: function () {
+ this.doGetNewsList(1);
+ },
+
+ /**
+ * 页面上拉触底事件的处理函数
+ */
+ onReachBottom: function () {
+ this.doGetNewsList(this.data.currentPage + 1);
+ },
+
+ /**
+ * 用户点击右上角分享
+ */
+ onShareAppMessage: function () {
+
+ }
+})
\ No newline at end of file
diff --git a/pages/newsList/newsList.json b/pages/newsList/newsList.json
new file mode 100644
index 0000000..2a7b263
--- /dev/null
+++ b/pages/newsList/newsList.json
@@ -0,0 +1,5 @@
+{
+ "usingComponents": {},
+ "enablePullDownRefresh": true,
+ "onReachBottomDistance": 50
+}
\ No newline at end of file
diff --git a/pages/newsList/newsList.wxml b/pages/newsList/newsList.wxml
new file mode 100644
index 0000000..e6cbc7d
--- /dev/null
+++ b/pages/newsList/newsList.wxml
@@ -0,0 +1,55 @@
+
+
+
+ {{item.newsContentTitle}}
+
+
+
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
+
+
+
+ {{item.newsContentTitle}}
+
+
+
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+ {{item.newsContentTitle}}
+
+ 来源:{{item.newsContentResource}}
+ {{item.newsContentPublishTime}}
+
+
+
+
\ No newline at end of file
diff --git a/pages/newsList/newsList.wxss b/pages/newsList/newsList.wxss
new file mode 100644
index 0000000..7e0ade1
--- /dev/null
+++ b/pages/newsList/newsList.wxss
@@ -0,0 +1,34 @@
+.news{
+ padding: 30rpx;
+ border-bottom: 5px solid #FBFBFB;
+}
+.news-box{
+ padding: 30rpx 0;
+ border-bottom: 1px solid #EBEBEB;
+ display: flex;
+ flex-direction: column;
+}
+.news-title{
+ color: #242424;
+ font-size: 30rpx;
+ font-weight: bold;
+}
+.news-info{
+ color: #949494;
+ margin-top: 15rpx;
+ font-size: 24rpx;
+}
+.news-info text{
+ margin-right: 20rpx;
+}
+.news-big-pic, .news-small-pic{
+ margin-top: 10rpx;
+}
+.news-big-pic image{
+ width: 100%;
+}
+.news-small-pic image{
+ width: 30%;
+ height: 150rpx;
+ margin-right: 20rpx;
+}
\ No newline at end of file
diff --git a/project.config.json b/project.config.json
index 43b81a9..451ba67 100644
--- a/project.config.json
+++ b/project.config.json
@@ -5,35 +5,35 @@
},
"setting": {
"urlCheck": false,
- "scopeDataCheck": false,
- "coverView": true,
"es6": true,
+ "enhance": false,
"postcss": true,
- "compileHotReLoad": false,
"preloadBackgroundData": false,
"minified": true,
- "autoAudits": false,
"newFeature": true,
- "uglifyFileName": false,
- "uploadWithSourceMap": true,
- "useIsolateContext": true,
+ "coverView": true,
"nodeModules": false,
- "enhance": false,
- "useCompilerModule": true,
- "userConfirmedUseCompilerModuleSwitch": false,
+ "autoAudits": false,
"showShadowRootInWxmlPanel": true,
+ "scopeDataCheck": false,
+ "uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
+ "uploadWithSourceMap": true,
+ "compileHotReLoad": false,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
- }
+ },
+ "useIsolateContext": true,
+ "useCompilerModule": true,
+ "userConfirmedUseCompilerModuleSwitch": false
},
"compileType": "miniprogram",
"libVersion": "2.11.1",
- "appid": "wxe7f135356342a070",
- "projectname": "miniprogram-2",
+ "appid": "wxb9c87f3dcf05852f",
+ "projectname": "xz_mini",
"debugOptions": {
"hidedInDevtools": []
},
diff --git a/utils/dialog.js b/utils/dialog.js
new file mode 100644
index 0000000..ef95156
--- /dev/null
+++ b/utils/dialog.js
@@ -0,0 +1,15 @@
+function msg(text) {
+ wx.showToast({
+ title: text,
+ icon: 'none',
+ duration: 1000
+ })
+}
+function loading(msg) {
+ wx.showLoading({
+ title: msg,
+ mask: true
+ })
+}
+module.exports.msg = msg;
+module.exports.loading = loading;
\ No newline at end of file
diff --git a/utils/restAjax.js b/utils/restAjax.js
new file mode 100644
index 0000000..24ea122
--- /dev/null
+++ b/utils/restAjax.js
@@ -0,0 +1,226 @@
+var methods = {
+ POST_METHOD: 'POST',
+ DELETE_METHOD: 'DELETE',
+ PUT_METHOD: 'PUT',
+ GET_METHOD: 'GET'
+};
+
+/**
+ * 新增
+ * @param url
+ * @param dataObj
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param completeCallback
+ */
+function postJson(url, dataObj, args, successCallback, errorCallback, completeCallback) {
+ doAjax(url, methods.POST_METHOD, dataObj, args, successCallback, errorCallback, completeCallback);
+}
+
+/**
+ * 删除
+ * @param url
+ * @param dataObj
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param completeCallback
+ */
+function deleteForm(url, dataObj, args, successCallback, errorCallback, completeCallback) {
+ doAjax(url, methods.DELETE_METHOD, dataObj, args, successCallback, errorCallback, completeCallback);
+}
+
+/**
+ * 修改
+ * @param url
+ * @param dataObj
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param completeCallback
+ */
+function putJson(url, dataObj, args, successCallback, errorCallback, completeCallback) {
+ doAjax(url, methods.PUT_METHOD, dataObj, args, successCallback, errorCallback, completeCallback);
+}
+
+/**
+ * 查询
+ * @param url
+ * @param dataObj
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param completeCallback
+ */
+function getForm(url, dataObj, args, successCallback, errorCallback, completeCallback) {
+ doAjax(url, methods.GET_METHOD, dataObj, args, successCallback, errorCallback, completeCallback);
+}
+
+/**
+ * 执行上传
+ * @param url
+ * @param method
+ * @param dataObj
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param completeCallback
+ */
+function doAjax(url, method, dataObj, args, successCallback, errorCallback, completeCallback) {
+ var headers = {};
+ if (args != null && typeof (args.headers) != 'undefined' && args.headers != null) {
+ headers = args.headers;
+ }
+ wx.request({
+ url: url,
+ method: method,
+ data: dataObj,
+ header: headers,
+ dataType: 'json',
+ success: function (response) {
+ if (response.statusCode == 200) {
+ successCallback(response.statusCode, response.data, args);
+ } else {
+ if (errorCallback && typeof (errorCallback) == 'function') {
+ errorCallback(response.statusCode, response.data);
+ }
+ }
+ },
+ fail: function (response) {
+ console.log(response);
+ },
+ complete: function () {
+ if (completeCallback && typeof (completeCallback) == 'function') {
+ completeCallback();
+ }
+ }
+ })
+}
+
+/**
+ * 检测是路径参数有重复值
+ * @param pathArgArray
+ * @returns {boolean}
+ */
+function pathArgsHasSameValue(pathArgArray) {
+ var tempArgIndex = 0;
+ var tempArgs = pathArgArray[tempArgIndex];
+ for (var i = (tempArgIndex + 1), item; item = pathArgArray[i]; i++) {
+ if (tempArgs == item) {
+ throw new Error('参数' + item + '有重复值!!!');
+ }
+ if (i == pathArgArray.length - 1) {
+ tempArgs = pathArgArray[++tempArgIndex];
+ i = tempArgIndex;
+ continue;
+ }
+ }
+}
+
+/**
+ * 获取页面间传递的参数
+ * @param url
+ */
+function getParamsArg(url) {
+ var params = url.split('?')[1];
+ var paramsObj = {};
+ if (typeof (params) == 'undefined' || params == null) {
+ return paramsObj;
+ }
+ var paramsKVs = params.split('&');
+ for (var i = 0, item = null; item = paramsKVs[i++];) {
+ var kvs = item.split('=');
+ if (kvs.length == 1) {
+ paramsObj[kvs[0]] = null;
+ }
+ if (kvs.length == 2) {
+ paramsObj[kvs[0]] = decodeURI(kvs[1]);
+ }
+ }
+ return paramsObj;
+}
+
+/**
+ * 构建路径
+ * @param basePath 请求路径,{参数},
+ * @param pathArgs 替换的路径参数,不能重复
+ * @returns {*}
+ */
+function buildPath(basePath, pathArgs) {
+ var path = basePath;
+ if (!basePath || !(typeof (basePath) == 'string')) {
+ throw new Error('basePath必须为字符串!!!');
+ }
+ if (!pathArgs || !Array.isArray(pathArgs)) {
+ throw new Error('pathArgs必须为数组!!!');
+ }
+ var pathArgArray = basePath.match(/\{\w+\}/g);
+ if (!pathArgArray) {
+ return path;
+ }
+ pathArgsHasSameValue(pathArgArray);
+ for (var i = 0, item; item = pathArgArray[i]; i++) {
+ path = path.replace(item, pathArgs[i]);
+ }
+ return path;
+}
+
+/**
+ * 通过form对象上传文件
+ * @param url
+ * @param formData
+ * @param args
+ * @param successCallback
+ * @param errorCallback
+ * @param beforeCallback
+ * @param completeCallback
+ */
+function postFile(url, path, name, args, successCallback, errorCallback, completeCallback) {
+ var headers = {};
+ if (args != null && typeof (args.headers) != 'undefined' && args.headers != null) {
+ headers = args.headers;
+ }
+ wx.uploadFile({
+ filePath: path,
+ name: name,
+ url: url,
+ header: headers,
+ success: function (response) {
+ if (response.statusCode == 200) {
+ successCallback(response.statusCode, response.data, args);
+ } else {
+ if (errorCallback && typeof (errorCallback) == 'function') {
+ errorCallback(response.statusCode, response.data);
+ }
+ }
+ },
+ fail: function (response) {
+ console.log(response);
+ },
+ complete: function () {
+ if (completeCallback && typeof (completeCallback) == 'function') {
+ completeCallback();
+ }
+ }
+ })
+};
+
+/**
+ * xss 转义
+ * @param html
+ * @returns {string}
+ */
+function escape(html) {
+ return String(html || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
+ .replace(//g, '>')
+ .replace(/'/g, ''').replace(/"/g, '"');
+}
+
+module.exports.post = postJson;
+module.exports.delete = deleteForm;
+module.exports.put = putJson;
+module.exports.get = getForm;
+module.exports.params = getParamsArg;
+module.exports.path = buildPath;
+module.exports.escape = escape;
\ No newline at end of file