diff --git a/client/mp/app.js b/client/mp/app.js index 3ba1dd6b..c57c5965 100644 --- a/client/mp/app.js +++ b/client/mp/app.js @@ -1,16 +1,21 @@ 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 + wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success(res) {var msg = res.data msg.__proto__ = { - Result: function() {return msg.result && msg.result.length > 0 && msg.result.join("") || ""}, + Result() {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) { + download(cmd, data, cb) {var app = this; data.sessid = app.conf.sessid + wx.downloadFile({url: app.conf.serve+"/"+cmd, data: data, success(res) { + typeof cb == "function" && cb(res) + }}) + }, + onLaunch() {var app = this + wx.login({success(res) {app.request("login", {code: res.code}, function(msg) {app.conf.sessid = msg.Result() + wx.getSetting({success(res) {res.authSetting['scope.userInfo'] && wx.getUserInfo({success(res) { app.request("login", res.userInfo, function(msg) {app.conf.userInfo = res.userInfo}) }})}}) })}}) diff --git a/client/mp/pages/index/index.js b/client/mp/pages/index/index.js index f20f9fb0..af0729bd 100644 --- a/client/mp/pages/index/index.js +++ b/client/mp/pages/index/index.js @@ -1,18 +1,32 @@ const app = getApp() +var utils = require("../../utils/util.js") Page({ data: { - motto: 'Hello World', - qrcode: 'Hello World', - userInfo: {}, - hasUserInfo: false, - canIUse: wx.canIUse('button.open-type.getUserInfo') + list: [], }, - 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}) + show() {var page = this + page.setData({list: (wx.getStorageSync("qrcode")||[]).reverse()}) + }, + click(event) {var page = this + wx.showActionSheet({itemList:["保存"], success(res) { + wx.saveImageToPhotosAlbum({filePath: event.target.dataset.path, success(res) { + wx.showToast({title: "success"}) + }}) + }}) + console.log(event) + }, + onscan(event) {var page = this + wx.scanCode({success(res) { + app.download("login?type="+encodeURIComponent(res.scanType)+"&scan="+encodeURIComponent(res.result), {}, function(res) { + wx.saveFile({tempFilePath: res.tempFilePath, success(res) { + var list = wx.getStorageSync("qrcode") || [] + list.push({path: res.savedFilePath, index: list.length, time: utils.Time()}) + wx.setStorageSync("qrcode", list) + page.show() + }}) + }) }}) }, - onLoad: function () {}, + onLoad() {this.show()}, }) diff --git a/client/mp/pages/index/index.wxml b/client/mp/pages/index/index.wxml index bc14c6da..1a33578a 100644 --- a/client/mp/pages/index/index.wxml +++ b/client/mp/pages/index/index.wxml @@ -1,15 +1,9 @@ - - - - - - {{userInfo.nickName}} - - - {{qrcode}} - - {{motto}} + + + + {{item.time}} + diff --git a/client/mp/pages/index/index.wxss b/client/mp/pages/index/index.wxss index ce30de01..24a860d0 100644 --- a/client/mp/pages/index/index.wxss +++ b/client/mp/pages/index/index.wxss @@ -1,21 +1,3 @@ -/**index.wxss**/ -.userinfo { - display: flex; - flex-direction: column; - align-items: center; +.output { + text-align: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/utils/util.js b/client/mp/utils/util.js index dbadbb81..c7ceea02 100644 --- a/client/mp/utils/util.js +++ b/client/mp/utils/util.js @@ -13,7 +13,24 @@ const formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } +function Number(d, n) {var result = []; + while (d>0) {result.push(d % 10); d = parseInt(d / 10); n--} + while (n > 0) {result.push("0"); n--} + result.reverse(); + return result.join(""); +} +function Time(t, fmt) {var now = t? new Date(t): new Date(); + fmt = fmt || "%y-%m-%d %H:%M:%S"; + fmt = fmt.replace("%y", now.getFullYear()) + fmt = fmt.replace("%m", Number(now.getMonth()+1, 2)) + fmt = fmt.replace("%d", Number(now.getDate(), 2)) + fmt = fmt.replace("%H", Number(now.getHours(), 2)) + fmt = fmt.replace("%M", Number(now.getMinutes(), 2)) + fmt = fmt.replace("%S", Number(now.getSeconds(), 2)) + return fmt +} module.exports = { - formatTime: formatTime + formatTime: formatTime, + Time: Time, }