diff --git a/client/mp/app.js b/client/mp/app.js index 99e534f2..d426caff 100644 --- a/client/mp/app.js +++ b/client/mp/app.js @@ -9,6 +9,7 @@ App({ app.usercode(function() {app.request(cmd, data, cb)}) return } + msg.__proto__ = { 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("") || ""}, @@ -36,6 +37,7 @@ App({ } } msg._index = index + typeof cb == "function" && cb(msg) }}) }, @@ -59,8 +61,8 @@ App({ }) }, - modal: function(title, cb) {wx.showModal({title: title, success: cb})}, - toast: function(title) {wx.showToast({title: title})}, + modal: function(title, content, cb) {wx.showModal({title: title||"", content: content||"", success: cb})}, + toast: function(title, content) {wx.showToast({title: title, content: content||""})}, jumps: function(url, args, cb) {var next = "/pages/"+kit.Args(url, args) console.log("jump", next), wx.navigateTo({url: next, success: cb}) }, @@ -71,7 +73,7 @@ App({ switch (value.type) { case "active": app.userinfo(function(userInfo) { - app.modal("授权登录", function(res) { + app.modal("授权登录", value.name, function(res) { res.confirm && app.request("mp/login/auth", {auth: value.name}, function(msg) { app.toast("授权成功") }) diff --git a/client/mp/pages/action/action.js b/client/mp/pages/action/action.js index a2ff772b..60a0cfd1 100644 --- a/client/mp/pages/action/action.js +++ b/client/mp/pages/action/action.js @@ -1,4 +1,3 @@ -const utils = require("../../utils/util.js") const kit = require("../../utils/kit.js") const app = getApp() @@ -58,16 +57,109 @@ Page({ this.action[name](event, this, data) }, onfigure: { - key: {click: function(event, page, data, cmd, field) { - page.run(event, data.order, ["action", "input", data.item.name, data.item.value]) - }}, location: {click: function(event, page, data, cmd, field) { wx.chooseLocation({success: function(res) { - field.inputs[data.index].value = res.name - page.setData({res: page.data.res}) - page.run(event, data.order, ["action", "location", res.name, res.address, res.latitude*100000, res.longitude*100000]) + if (data.input._input != "button") { + field.inputs[data.index].value = res.name + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", "location", res.name, res.address, "latitude", res.latitude*100000, "longitude", res.longitude*100000]) }}) - }} + }}, + battery: {click: function(event, page, data, cmd, field) { + wx.getBatteryInfo({success: function(res) { + if (data.input._input != "button") { + field.inputs[data.index].value = res.level + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", "battery", res.level, res.isCharging]) + }}) + }}, + paste: {click: function(event, page, data, cmd, field) { + wx.getClipboardData({success: function(res) { + if (data.input._input != "button") { + field.inputs[data.index].value = res.data + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", "paste", res.data, res.data]) + }}) + }}, + scan: {click: function(event, page, data, cmd, field) { + app.scans(function(res) { + if (data.input._input != "button") { + field.inputs[data.index].value = res.text || res.name + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", res.type||"spide", res.name||"", res.text||"", JSON.stringify(res.extra||"")]) + }) + }}, + album: {click: function(event, page, data, cmd, field) { + wx.chooseImage({success: function(res) { + console.log(res) + const tempFilePaths = res.tempFilePaths + wx.uploadFile({ + url: app.conf.serve+"/mp/login/upload", + filePath: tempFilePaths[0], + name: 'upload', formData: {'user': 'test'}, + success: function(msg) { + console.log(msg) + if (data.input._input != "button") { + field.inputs[data.index].value = msg.data + page.setData({res: page.data.res}) + } + }, + fail: function(res) { + console.log(res) + }, + }) + }}) + }}, + finger: {click: function(event, page, data, cmd, field) { + wx.startSoterAuthentication({ + requestAuthModes: ['fingerPrint'], authContent: '请用指纹解锁', + challenge: '123456', success(res) { + console.log(res) + res = JSON.parse(res.resultJSON) + if (data.input._input != "button") { + field.inputs[data.index].value = res.cpu_id + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", "finger", res.uid, res.cpu_id, "counter", res.counter, "raw", res.raw]) + } + }) + }}, + wifi: {click: function(event, page, data, cmd, field) { + wx.getConnectedWifi({success: function(res) { + console.log(res) + if (data.input._input != "button") { + field.inputs[data.index].value = res.wifi.SSID + page.setData({res: page.data.res}) + } + page.run(event, data.order, ["action", "device", "wifi", res.wifi.SSID, res.wifi.signalStrength]) + }}) + }}, + wifiConn: {click: function(event, page, data, cmd, field) { + wx.connectWifi({ + SSID: data.SSID, password: data.password, + success: function(res) { + console.log(res) + }, + fail: function(res) { + console.log(res) + }, + }) + }}, + vibrate: {click: function(event, page, data, cmd, field) { + wx.vibrateShort() + }}, + key: {click: function(event, page, data, cmd, field) { + page.run(event, data.order, ["action", "input", data.input.name, data.input.value]) + }}, + share: {click: function(event, page, data, cmd, field) { + wx.showShareMenu({ + withShareTicket: true + }) + }}, }, run: function(event, order, cmd, cb) {var page = this, field = page.data.res[order] @@ -107,11 +199,10 @@ Page({ onClick: function(event) {var page = this, data = event.target.dataset var field = page.data.res[data.order] - if (data && data.item && data.item._input == "text") { // 输入补全 - var figure = page.onfigure[data.item.cb||data.item.figure||data.item.name] - figure && figure.click(event, page, data, "what", field) - return + var figure = data && data.input && page.onfigure[data.input.cb||data.input.figure||data.input.name] + if (figure) { + return figure.click(event, page, data, data.input.name, field) } switch (data.input.cb) { @@ -162,5 +253,14 @@ Page({ this.onaction({}, {}, "刷新") }, onReachBottom: function () {}, - onShareAppMessage: function () {} + onShareAppMessage: function (res) { + console.log(res) + return { + title: "some", + path: "pages/action/action?river="+this.data.river+"&storm="+this.data.storm, + success: function(res) { + console.log(res) + }, + } + } }) diff --git a/client/mp/pages/action/action.wxml b/client/mp/pages/action/action.wxml index ae5943fc..0dfc7bc5 100644 --- a/client/mp/pages/action/action.wxml +++ b/client/mp/pages/action/action.wxml @@ -10,7 +10,7 @@ + bindtap="onClick" bindinput="onInput" bindconfirm="onEnter" data-order="{{order}}" data-index="{{index}}" data-input="{{item}}"/>