Commit 64815f13 by daizhigang

Initial commit

parents
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
}
})
\ No newline at end of file
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
}
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
videoBackgroundUrl:'../../images/background.jpg',
displayBackground:true,
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
sendRedpacket(){
console.log('发发发发')
},
startVideo(){
this.setData({
displayBackground:false
})
this.videoContext.play()
},
onLoad: function () {
this.videoContext = wx.createVideoContext('myVideo')
wx.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#f6c173',
})
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})
{
"navigationStyle":"custom"
}
\ No newline at end of file
<!--index.wxml-->
<view class="container" bindtap="startVideo">
<view style="position:absolute;top:0;left:0;right:0;bottom:0;z-index:-10;max-height:100%;overflow:hidden">
<image mode="widthFix"src="../../images/background2.jpg" style="width:100%;"/>
</view>
<view style="width:100%;position:relative;text-align:center;padding:0 auto">
<view style="width: 656rpx;height: 369rpx;margin: 250rpx auto 200rpx;position:relative;box-shadow:rgba(0, 0, 0, 0.16) 0px 3px 10px, rgba(0, 0, 0, 0.23) 0px 3px 10px">
<view style="width:656rpx;height:369rpx;margin:0 auto" wx:if="{{displayBackground}}">
<view style="position:absolute;top:0;left:0;right:0;bottom:0;display:flex;justify-content:center;align-items:center">
<image src="../../images/start.png" style="width:50rpx;height:50rpx"/>
</view>
<image src="{{videoBackgroundUrl}}" style="width:656rpx;height:369rpx;"/>
</view>
<video wx:if="{{!displayBackground}}" id="myVideo" style="z-index:{{displayBackground?-1:1}};position:absolute;margin:0 auto;top:0;left:0;right:0;bottom:0;width:656rpx;height:369rpx" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" controls></video>
</view>
</view>
<view class="button" style="display:flex;" catchtap='sendRedpacket'>
<image src="../../images/packet.png" style="width:28rpx;height:36rpx;padding-right:16rpx"/>
<text>马上去发语音红包</text>
</view>
</view>
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
.usermotto {
margin-top: 200px;
}
.button{
padding: 32rpx 72rpx;
background: rgb(216,89,64);
color: #fff;
font-size: 36rpx;
line-height: 36rpx;
border-radius: 50rpx;
font-weight: 500;
}
.container{
margin-top:130rpx;
}
page{
overflow-y: hidden;
}
\ No newline at end of file
//logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})
{
"navigationBarTitleText": "查看启动日志"
}
\ No newline at end of file
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
{
"description": "项目配置文件。",
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true
},
"compileType": "miniprogram",
"libVersion": "1.9.93",
"appid": "wxc1846028e897c711",
"projectname": "%E5%8C%85%E4%BD%A0%E8%AF%B4%E5%8D%95%E9%A1%B5",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
\ No newline at end of file
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = {
formatTime: formatTime
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment