mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
opt some
This commit is contained in:
parent
88e773d746
commit
587cc84830
@ -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})
|
||||
}})}})
|
||||
})}})
|
||||
|
@ -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()},
|
||||
})
|
||||
|
@ -1,15 +1,9 @@
|
||||
<!--index.wxml-->
|
||||
<view class="container">
|
||||
<view class="userinfo">
|
||||
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
|
||||
<block wx:else>
|
||||
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
|
||||
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
|
||||
</block>
|
||||
</view>
|
||||
<button bindtap="onscan">扫一扫</button>
|
||||
<view><text>{{qrcode}}</text></view>
|
||||
<view class="usermotto">
|
||||
<text class="user-motto">{{motto}}</text>
|
||||
<view>
|
||||
<view wx:for="{{list}}" class="output">
|
||||
<image src="{{item.path}}" bindtap="click" data-index="{{index}}" data-path="{{item.path}}"></image>
|
||||
<view><text>{{item.time}}</text></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -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;
|
||||
}
|
@ -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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user