From 65b3ca26f3a74dd4f5cdcc995da2b95c0ddf07e2 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 2 Jan 2020 21:16:06 +0800 Subject: [PATCH] add mp --- client/mp/app.js | 18 +++++++++++++ client/mp/app.json | 14 ++++++++++ client/mp/app.wxss | 10 +++++++ client/mp/pages/index/index.js | 18 +++++++++++++ client/mp/pages/index/index.json | 3 +++ client/mp/pages/index/index.wxml | 15 +++++++++++ client/mp/pages/index/index.wxss | 21 +++++++++++++++ client/mp/pages/logs/logs.js | 15 +++++++++++ client/mp/pages/logs/logs.json | 4 +++ client/mp/pages/logs/logs.wxml | 6 +++++ client/mp/pages/logs/logs.wxss | 8 ++++++ client/mp/project.config.json | 45 ++++++++++++++++++++++++++++++++ client/mp/sitemap.json | 7 +++++ client/mp/utils/util.js | 19 ++++++++++++++ 14 files changed, 203 insertions(+) create mode 100644 client/mp/app.js create mode 100644 client/mp/app.json create mode 100644 client/mp/app.wxss create mode 100644 client/mp/pages/index/index.js create mode 100644 client/mp/pages/index/index.json create mode 100644 client/mp/pages/index/index.wxml create mode 100644 client/mp/pages/index/index.wxss create mode 100644 client/mp/pages/logs/logs.js create mode 100644 client/mp/pages/logs/logs.json create mode 100644 client/mp/pages/logs/logs.wxml create mode 100644 client/mp/pages/logs/logs.wxss create mode 100644 client/mp/project.config.json create mode 100644 client/mp/sitemap.json create mode 100644 client/mp/utils/util.js diff --git a/client/mp/app.js b/client/mp/app.js new file mode 100644 index 00000000..3ba1dd6b --- /dev/null +++ b/client/mp/app.js @@ -0,0 +1,18 @@ +App({ + conf: {serve: "https://shylinux.com/chat/mp"}, + request(cmd, data, cb) {var app = this; data.sessid = app.conf.sessid + wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success: function(res) {var msg = res.data + msg.__proto__ = { + Result: function() {return msg.result && msg.result.length > 0 && msg.result.join("") || ""}, + } + typeof cb == "function" && cb(msg) + }}) + }, + onLaunch: function () {var app = this + wx.login({success: function(res) {app.request("login", {code: res.code}, function(msg) {app.conf.sessid = msg.Result() + wx.getSetting({success: function(res) {res.authSetting['scope.userInfo'] && wx.getUserInfo({success: function(res) { + app.request("login", res.userInfo, function(msg) {app.conf.userInfo = res.userInfo}) + }})}}) + })}}) + }, +}) diff --git a/client/mp/app.json b/client/mp/app.json new file mode 100644 index 00000000..34291890 --- /dev/null +++ b/client/mp/app.json @@ -0,0 +1,14 @@ +{ + "pages": [ + "pages/index/index", + "pages/logs/logs" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "WeChat", + "navigationBarTextStyle": "black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/client/mp/app.wxss b/client/mp/app.wxss new file mode 100644 index 00000000..06c6fc9c --- /dev/null +++ b/client/mp/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/client/mp/pages/index/index.js b/client/mp/pages/index/index.js new file mode 100644 index 00000000..f20f9fb0 --- /dev/null +++ b/client/mp/pages/index/index.js @@ -0,0 +1,18 @@ +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + qrcode: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + onscan: function(event) {var page = this + wx.scanCode({success: function(res) { + app.request("login", {scan: res.result, type: res.scanType}) + page.setData({qrcode: res.result}) + }}) + }, + onLoad: function () {}, +}) diff --git a/client/mp/pages/index/index.json b/client/mp/pages/index/index.json new file mode 100644 index 00000000..8835af06 --- /dev/null +++ b/client/mp/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/client/mp/pages/index/index.wxml b/client/mp/pages/index/index.wxml new file mode 100644 index 00000000..bc14c6da --- /dev/null +++ b/client/mp/pages/index/index.wxml @@ -0,0 +1,15 @@ + + + + + + + {{userInfo.nickName}} + + + + {{qrcode}} + + {{motto}} + + diff --git a/client/mp/pages/index/index.wxss b/client/mp/pages/index/index.wxss new file mode 100644 index 00000000..ce30de01 --- /dev/null +++ b/client/mp/pages/index/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/client/mp/pages/logs/logs.js b/client/mp/pages/logs/logs.js new file mode 100644 index 00000000..b2b967d8 --- /dev/null +++ b/client/mp/pages/logs/logs.js @@ -0,0 +1,15 @@ +//logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad: function () { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return util.formatTime(new Date(log)) + }) + }) + } +}) diff --git a/client/mp/pages/logs/logs.json b/client/mp/pages/logs/logs.json new file mode 100644 index 00000000..3ee76c18 --- /dev/null +++ b/client/mp/pages/logs/logs.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "查看启动日志", + "usingComponents": {} +} \ No newline at end of file diff --git a/client/mp/pages/logs/logs.wxml b/client/mp/pages/logs/logs.wxml new file mode 100644 index 00000000..b5a85ac6 --- /dev/null +++ b/client/mp/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log}} + + diff --git a/client/mp/pages/logs/logs.wxss b/client/mp/pages/logs/logs.wxss new file mode 100644 index 00000000..94d4b88a --- /dev/null +++ b/client/mp/pages/logs/logs.wxss @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git a/client/mp/project.config.json b/client/mp/project.config.json new file mode 100644 index 00000000..bcd03b75 --- /dev/null +++ b/client/mp/project.config.json @@ -0,0 +1,45 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "postcss": true, + "minified": true, + "newFeature": true, + "autoAudits": false, + "coverView": true, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false + }, + "compileType": "miniprogram", + "libVersion": "2.0.4", + "appid": "wxf4e5104d83476ed6", + "projectname": "%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7%E9%93%BE", + "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/client/mp/sitemap.json b/client/mp/sitemap.json new file mode 100644 index 00000000..ca02add2 --- /dev/null +++ b/client/mp/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/client/mp/utils/util.js b/client/mp/utils/util.js new file mode 100644 index 00000000..dbadbb81 --- /dev/null +++ b/client/mp/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 +}