From e86d5067b159a82046b3ee091529292aade06c3a Mon Sep 17 00:00:00 2001 From: lqq Date: Tue, 8 Oct 2019 10:38:45 +0800 Subject: [PATCH] init --- app.js | 39 ++++++++++++++++++++++ app.json | 36 ++++++++++++++++++++ app.wxss | 10 ++++++ pages/billboards/index.js | 66 +++++++++++++++++++++++++++++++++++++ pages/billboards/index.json | 3 ++ pages/billboards/index.wxml | 2 ++ pages/billboards/index.wxss | 1 + pages/home/index.js | 54 ++++++++++++++++++++++++++++++ pages/home/index.json | 3 ++ pages/home/index.wxml | 13 ++++++++ pages/home/index.wxss | 21 ++++++++++++ pages/topics/index.js | 66 +++++++++++++++++++++++++++++++++++++ pages/topics/index.json | 3 ++ pages/topics/index.wxml | 2 ++ pages/topics/index.wxss | 1 + pages/user/index.js | 66 +++++++++++++++++++++++++++++++++++++ pages/user/index.json | 3 ++ pages/user/index.wxml | 2 ++ pages/user/index.wxss | 1 + project.config.json | 43 ++++++++++++++++++++++++ sitemap.json | 7 ++++ utils/util.js | 19 +++++++++++ 22 files changed, 461 insertions(+) create mode 100644 app.js create mode 100644 app.json create mode 100644 app.wxss create mode 100644 pages/billboards/index.js create mode 100644 pages/billboards/index.json create mode 100644 pages/billboards/index.wxml create mode 100644 pages/billboards/index.wxss create mode 100644 pages/home/index.js create mode 100644 pages/home/index.json create mode 100644 pages/home/index.wxml create mode 100644 pages/home/index.wxss create mode 100644 pages/topics/index.js create mode 100644 pages/topics/index.json create mode 100644 pages/topics/index.wxml create mode 100644 pages/topics/index.wxss create mode 100644 pages/user/index.js create mode 100644 pages/user/index.json create mode 100644 pages/user/index.wxml create mode 100644 pages/user/index.wxss create mode 100644 project.config.json create mode 100644 sitemap.json create mode 100644 utils/util.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..b545190 --- /dev/null +++ b/app.js @@ -0,0 +1,39 @@ +//app.js +App({ + onLaunch: function () { + // 展示本地存储能力 + var logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + // 获取用户信息 + wx.getSetting({ + success: res => { + if (res.authSetting['scope.userInfo']) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + this.globalData.userInfo = res.userInfo + + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + if (this.userInfoReadyCallback) { + this.userInfoReadyCallback(res) + } + } + }) + } + } + }) + }, + globalData: { + userInfo: null + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..cb385e5 --- /dev/null +++ b/app.json @@ -0,0 +1,36 @@ +{ + "pages": [ + "pages/home/index", + "pages/user/index", + "pages/billboards/index", + "pages/topics/index" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "凤栖市北", + "navigationBarTextStyle": "black" + }, + "tabBar": { + "list": [ + { + "pagePath": "pages/home/index", + "text": "首页" + }, + { + "pagePath": "pages/billboards/index", + "text": "宣传栏" + }, + { + "pagePath": "pages/topics/index", + "text": "议事厅" + }, + { + "pagePath": "pages/user/index", + "text": "我的" + } + ] + }, + "debug": true, + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/pages/billboards/index.js b/pages/billboards/index.js new file mode 100644 index 0000000..3704d83 --- /dev/null +++ b/pages/billboards/index.js @@ -0,0 +1,66 @@ +// pages/billboards/index.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/billboards/index.json b/pages/billboards/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/billboards/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/billboards/index.wxml b/pages/billboards/index.wxml new file mode 100644 index 0000000..cecdd04 --- /dev/null +++ b/pages/billboards/index.wxml @@ -0,0 +1,2 @@ + +pages/billboards/index.wxml diff --git a/pages/billboards/index.wxss b/pages/billboards/index.wxss new file mode 100644 index 0000000..f3b514b --- /dev/null +++ b/pages/billboards/index.wxss @@ -0,0 +1 @@ +/* pages/billboards/index.wxss */ \ No newline at end of file diff --git a/pages/home/index.js b/pages/home/index.js new file mode 100644 index 0000000..608a282 --- /dev/null +++ b/pages/home/index.js @@ -0,0 +1,54 @@ +//index.js +//获取应用实例 +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + //事件处理函数 + bindViewTap: function() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onLoad: function () { + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true + }) + } else if (this.data.canIUse){ + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo: function(e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/home/index.json b/pages/home/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/home/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/home/index.wxml b/pages/home/index.wxml new file mode 100644 index 0000000..0243bda --- /dev/null +++ b/pages/home/index.wxml @@ -0,0 +1,13 @@ + + + + + + + {{userInfo.nickName}} + + + + {{motto}} + + diff --git a/pages/home/index.wxss b/pages/home/index.wxss new file mode 100644 index 0000000..ce30de0 --- /dev/null +++ b/pages/home/index.wxss @@ -0,0 +1,21 @@ +/**index.wxss**/ +.userinfo { + display: flex; + flex-direction: column; + align-items: center; +} + +.userinfo-avatar { + width: 128rpx; + height: 128rpx; + margin: 20rpx; + border-radius: 50%; +} + +.userinfo-nickname { + color: #aaa; +} + +.usermotto { + margin-top: 200px; +} \ No newline at end of file diff --git a/pages/topics/index.js b/pages/topics/index.js new file mode 100644 index 0000000..ef6e5bb --- /dev/null +++ b/pages/topics/index.js @@ -0,0 +1,66 @@ +// pages/topics/index.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/topics/index.json b/pages/topics/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/topics/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/topics/index.wxml b/pages/topics/index.wxml new file mode 100644 index 0000000..b341ba3 --- /dev/null +++ b/pages/topics/index.wxml @@ -0,0 +1,2 @@ + +pages/topics/index.wxml diff --git a/pages/topics/index.wxss b/pages/topics/index.wxss new file mode 100644 index 0000000..a2216d8 --- /dev/null +++ b/pages/topics/index.wxss @@ -0,0 +1 @@ +/* pages/topics/index.wxss */ \ No newline at end of file diff --git a/pages/user/index.js b/pages/user/index.js new file mode 100644 index 0000000..c07393f --- /dev/null +++ b/pages/user/index.js @@ -0,0 +1,66 @@ +// pages/user/index.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/user/index.json b/pages/user/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/user/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/user/index.wxml b/pages/user/index.wxml new file mode 100644 index 0000000..753ccb2 --- /dev/null +++ b/pages/user/index.wxml @@ -0,0 +1,2 @@ + +pages/user/index.wxml diff --git a/pages/user/index.wxss b/pages/user/index.wxss new file mode 100644 index 0000000..ea787be --- /dev/null +++ b/pages/user/index.wxss @@ -0,0 +1 @@ +/* pages/user/index.wxss */ \ No newline at end of file diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..1f101bd --- /dev/null +++ b/project.config.json @@ -0,0 +1,43 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "postcss": true, + "minified": true, + "newFeature": true, + "autoAudits": false, + "coverView": true + }, + "compileType": "miniprogram", + "libVersion": "2.8.1", + "appid": "wx3bcb2b4ced1544f7", + "projectname": "fqsb_wx", + "debugOptions": { + "hidedInDevtools": [] + }, + "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "current": -1, + "list": [] + }, + "conversation": { + "current": -1, + "list": [] + }, + "game": { + "currentL": -1, + "list": [] + }, + "miniprogram": { + "current": -1, + "list": [] + } + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..dbadbb8 --- /dev/null +++ b/utils/util.js @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : '0' + n +} + +module.exports = { + formatTime: formatTime +}