diff --git a/weapp/images/noData.png b/weapp/images/noData.png new file mode 100644 index 0000000..a0db303 Binary files /dev/null and b/weapp/images/noData.png differ diff --git a/weapp/pages/index/index.js b/weapp/pages/index/index.js index f02309b..395167b 100644 --- a/weapp/pages/index/index.js +++ b/weapp/pages/index/index.js @@ -1,11 +1,71 @@ // pages/index/index.js +import { getProjectList } from "../../utils/getApiUrl"; +import { Request } from "../../common"; + Page({ /** * 页面的初始数据 */ data: { - dataList: [1, 2, 3, 4] + dataList: [], + limit: 10, //条数 + page: 0, //当前页 + count: '', //总条数 + keyName: '', //结构物名称 + hidden: true, + }, + + // 输入框 + formInp(e) { + let that = this; + that.setData({ + keyName: e.detail.value + }) + }, + + // 手机键盘点击完成按钮(回车事件) + bindconfirm() { + let that = this; + that.setData({ + page: 0, //当前页 + count: '', //总条数 + }) + that.getProjectList(); + }, + + // 搜索表单 + goSearch() { + let that = this; + that.setData({ + page: 0, //当前页 + count: '', //总条数 + }) + that.getProjectList(); + }, + + // 获取结构物列表 + getProjectList: function () { + let that = this; + let { page, limit, keyName } = that.data; + Request.get(getProjectList(), { limit, page, name: keyName }).then(res => { + console.log(res); + if (res.rows.length == 0) { + that.setData({ + dataList: res.rows, + hidden: false + }) + return; + } + var arr1 = that.data.dataList; //从data获取当前dataList数组 + var arr2 = res.rows; //从此次请求返回的数据中获取新数组 + arr1 = arr1.concat(arr2); //合并数组 + that.setData({ + dataList: arr1, + count: res.count, //总条数 + hidden: true + }) + }) }, /** @@ -36,6 +96,8 @@ Page({ wx.reLaunch({ url: '/pages/login/login' }); + } else { + this.getProjectList(); } }, @@ -57,14 +119,33 @@ Page({ * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { - + let that = this; + that.setData({ + dataList: [], + keyName: '', + page: 0, //当前页 + count: '', //总条数 + }) + that.getProjectList() + // 手动控制回弹 + wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { - + let _that = this; + let page = _that.data.page + 1; //获取当前页数并+1 + let { dataList, count } = _that.data; + if (dataList.length == count) { + showToast('没有更多数据了...'); + return; + } + _that.setData({ + page: page, //更新当前页数 + }) + _that.getProjectList() }, /** diff --git a/weapp/pages/index/index.json b/weapp/pages/index/index.json index 9b25508..2f631b8 100644 --- a/weapp/pages/index/index.json +++ b/weapp/pages/index/index.json @@ -2,5 +2,5 @@ "navigationBarBackgroundColor": "#1979ff", "navigationBarTextStyle": "white", "navigationBarTitleText": "巡检总览", - "enablePullDownRefresh": false + "enablePullDownRefresh": true } \ No newline at end of file diff --git a/weapp/pages/index/index.wxml b/weapp/pages/index/index.wxml index 13e3f48..ba653b9 100644 --- a/weapp/pages/index/index.wxml +++ b/weapp/pages/index/index.wxml @@ -7,7 +7,7 @@ - + @@ -23,4 +23,9 @@ + + \ No newline at end of file diff --git a/weapp/pages/index/index.wxss b/weapp/pages/index/index.wxss index 0a8eca4..2be3aac 100644 --- a/weapp/pages/index/index.wxss +++ b/weapp/pages/index/index.wxss @@ -52,4 +52,19 @@ page { overflow: hidden; line-height: 50rpx; background: #fff; +} + +/* 暂无数据 */ +.noData { + width: 254rpx; + height: 298rpx; + display: block; + margin: 450rpx auto 16rpx; +} + +.noTxt { + font-size: 30rpx; + color: #999; + font-weight: bold; + text-align: center; } \ No newline at end of file diff --git a/weapp/project.config.json b/weapp/project.config.json index a674783..faa4199 100644 --- a/weapp/project.config.json +++ b/weapp/project.config.json @@ -41,7 +41,7 @@ }, "compileType": "miniprogram", "libVersion": "2.19.4", - "appid": "wxe9595234589a0147", + "appid": "wxdd82ae635b22ccdb", "projectname": "miniprogram-92", "condition": {}, "editorSetting": { diff --git a/weapp/utils/getApiUrl.js b/weapp/utils/getApiUrl.js index c98a4d0..07b1d41 100644 --- a/weapp/utils/getApiUrl.js +++ b/weapp/utils/getApiUrl.js @@ -6,4 +6,9 @@ exports.loginUrl = () => { // 登出 exports.logoutUrl = () => { return `/logout` +} + +// 登出 +exports.getProjectList = () => { + return `/projectList` } \ No newline at end of file