1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
shaoying 2020-03-17 13:21:54 +08:00
parent 06729dd4dd
commit 41b45db4d4
4 changed files with 45 additions and 13 deletions

View File

@ -1,4 +1,4 @@
const utils = require("utils/util.js") const kit = require("utils/kit.js")
App({ App({
data: {}, conf: {serve: "https://shylinux.com/chat"}, data: {}, conf: {serve: "https://shylinux.com/chat"},
@ -61,25 +61,27 @@ App({
modal: function(title, cb) {wx.showModal({title: title, success: cb})}, modal: function(title, cb) {wx.showModal({title: title, success: cb})},
toast: function(title) {wx.showToast({title: title})}, toast: function(title) {wx.showToast({title: title})},
jumps: function(url, args, cb) { jumps: function(url, args, cb) {var next = "/pages/"+kit.Args(url, args)
wx.navigateTo({url: "/pages/"+utils.Args(url, args), success: cb}) console.log("jump", next), wx.navigateTo({url: next, success: cb})
}, },
scans: function(cb) {var app = this scans: function(cb) {var app = this
wx.scanCode({success(res) { wx.scanCode({success(res) {console.log("scan", res)
try { try {
var value = JSON.parse(res.result) var value = JSON.parse(res.result)
switch (value.type) { switch (value.type) {
case "active": case "active":
app.userinfo(function(userInfo) { app.userinfo(function(userInfo) {
app.modal("授权登录", function(res) { app.modal("授权登录", function(res) {
res.confirm && app.request("mp/login/auth", {auth: value.name}) res.confirm && app.request("mp/login/auth", {auth: value.name}, function(msg) {
app.toast("授权成功")
})
}) })
}) })
default: default:
typeof cb == "function" && cb(res) typeof cb == "function" && cb(value)
} }
} catch(e) { } catch(e) {
typeof cb == "function" && cb(res) typeof cb == "function" && cb({type: "", text: res.result})
} }
}}) }})
}, },

View File

@ -1,4 +1,4 @@
const utils = require("../../utils/util.js") const kit = require("../../utils/kit.js")
const app = getApp() const app = getApp()
Page({ Page({
@ -10,6 +10,7 @@ Page({
action: { action: {
"扫码": function(event, page, data, name) { "扫码": function(event, page, data, name) {
app.scans(function(res) { app.scans(function(res) {
app.toast()
}) })
}, },
"刷新": function(event, page, data, name) { "刷新": function(event, page, data, name) {

30
client/mp/utils/kit.js Normal file
View File

@ -0,0 +1,30 @@
module.exports = {
Number: function(d, n) {var res = [];
while (d > 0) {res.push(d % 10); d = parseInt(d / 10); n--}
while (n > 0) {res.push("0"); n--}
return res.reverse(), res.join("");
},
Time: function(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
},
Args: function(url, args) {var list = []
for (var k in args) {
list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k]))
}
return url+"?"+list.join("&")
},
List: function(list, cb, cbs) {var res = [], val;
for (var i = 0; i < list.length; i++) {
typeof cb == "function"? (val = cb(list[i], i, list)) != undefined && res.push(val): res.push(list[i])
}
return typeof cbs == "function" && cbs(res), res
},
}

View File

@ -13,11 +13,10 @@ const formatNumber = n => {
n = n.toString() n = n.toString()
return n[1] ? n : '0' + n return n[1] ? n : '0' + n
} }
function Number(d, n) {var result = []; function Number(d, n) {var res = [];
while (d>0) {result.push(d % 10); d = parseInt(d / 10); n--} while (d > 0) {res.push(d % 10); d = parseInt(d / 10); n--}
while (n > 0) {result.push("0"); n--} while (n > 0) {res.push("0"); n--}
result.reverse(); return res.reverse(), res.join("");
return result.join("");
} }
function Time(t, fmt) {var now = t? new Date(t): new Date(); function Time(t, fmt) {var now = t? new Date(t): new Date();
fmt = fmt || "%y-%m-%d %H:%M:%S"; fmt = fmt || "%y-%m-%d %H:%M:%S";