From 59a513ae2c89ce320a4312f5e28e8df367d69385 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 23 Feb 2020 06:36:55 +0800 Subject: [PATCH] opt mp --- client/mp/app.js | 45 ++++-- client/mp/app.wxml | 16 ++- client/mp/app.wxss | 68 ++++++--- client/mp/pages/action/action.js | 217 +++++++++++++++-------------- client/mp/pages/action/action.wxml | 63 +++++---- client/mp/pages/action/action.wxss | 29 ---- client/mp/pages/river/river.js | 46 ++++-- client/mp/pages/river/river.wxml | 5 +- client/mp/pages/storm/storm.js | 47 +++++-- client/mp/pages/storm/storm.wxml | 5 +- client/mp/project.config.json | 6 +- client/mp/utils/util.js | 8 ++ 12 files changed, 324 insertions(+), 231 deletions(-) diff --git a/client/mp/app.js b/client/mp/app.js index c9b44b46..dcbdbaba 100644 --- a/client/mp/app.js +++ b/client/mp/app.js @@ -1,8 +1,7 @@ const utils = require("utils/util.js") App({ - data: {}, - conf: {serve: "https://shylinux.com/chat"}, + data: {}, conf: {serve: "https://shylinux.com/chat"}, request: function(cmd, data, cb) {var app = this; data.sessid = app.conf.sessid wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success(res) {var msg = res.data console.log("POST", cmd, msg) @@ -11,9 +10,9 @@ App({ return } msg.__proto__ = { - nRow() {return msg.append && msg.append[0] && msg[msg.append[0]].length || 0}, - Result() {return msg.result && msg.result.length > 0 && msg.result.join("") || ""}, - Table(cb) {var row = 0 + nRow: function() {return msg.append && msg.append[0] && msg[msg.append[0]].length || 0}, + Result: function() {return msg.result && msg.result.length > 0 && msg.result.join("") || ""}, + Table: function(cb) {var row = 0 for (var i = 0; i < msg.append.length; i++) { row = msg[msg.append[i]].length > row? msg[msg.append[i]].length: row } @@ -41,12 +40,10 @@ App({ }}) }, download: function(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) - }}) + wx.downloadFile({url: app.conf.serve+"/"+cmd, data: data, success: cb}) }, usercode: function(cb) {var app = this - wx.login({success(res) {app.request("mp/login/code", {code: res.code}, function(msg) { + wx.login({success: function(res) {app.request("mp/login/code", {code: res.code}, function(msg) { wx.setStorage({key: "sessid", data: msg.Result()}) app.conf.sessid = msg.Result(), typeof cb == "function" && cb() })}}) @@ -54,15 +51,39 @@ App({ userinfo: function(cb) {var app = this if (app.conf.userInfo) {return typeof cb == "function" && cb(app.conf.userInfo)} app.usercode(function() { - wx.getSetting({success(res) {res.authSetting['scope.userInfo'] && wx.getUserInfo({success(res) { - app.request("mp/login/info", res.userInfo, function(msg) {app.conf.userInfo = res.userInfo, typeof cb == "function" && cb(res.userInfo)}) + wx.getSetting({success: function(res) {res.authSetting['scope.userInfo'] && wx.getUserInfo({success: function(res) { + app.request("mp/login/info", res.userInfo, function(msg) {app.conf.userInfo = res.userInfo + typeof cb == "function" && cb(res.userInfo) + }) }})}}) }) }, + + modal: function(title, cb) {wx.showModal({title: title, success: cb})}, + toast: function(title) {wx.showToast({title: title})}, jumps: function(url, args, cb) { wx.navigateTo({url: "/pages/"+utils.Args(url, args), success: cb}) }, - toast: function(title) {wx.showToast({title: title})}, + scans: function(cb) {var app = this + wx.scanCode({success(res) { + try { + var value = JSON.parse(res.result) + switch (value.type) { + case "active": + app.userinfo(function(userInfo) { + app.modal("授权登录", function(res) { + res.confirm && app.request("mp/login/auth", {auth: value.name}) + }) + }) + default: + typeof cb == "function" && cb(res) + } + } catch(e) { + typeof cb == "function" && cb(res) + } + }}) + }, + onLaunch: function() { this.conf.sessid = wx.getStorageSync("sessid") console.log("load", "sessid", this.conf.sessid) diff --git a/client/mp/app.wxml b/client/mp/app.wxml index 74147a28..16dd762e 100644 --- a/client/mp/app.wxml +++ b/client/mp/app.wxml @@ -1,5 +1,13 @@ -