Commit 5b3ea80f authored by lalalala's avatar lalalala

源码

parent b6faa060
// app.js
App({
onLaunch() {
// 展示本地存储能力
const 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
}
})
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/news/news"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
\ No newline at end of file
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad() {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})
{
"usingComponents": {}
}
\ No newline at end of file
<!--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>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
.usermotto {
margin-top: 200px;
}
\ No newline at end of file
// logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: [],
bgUrl: '../../asset/images/runing.png', // 背景图片
diceUrl: '../../asset/images/marshalling.png',// 骰子图片
timeCount: 0, // 时间秒
bgImageObj: { // 切换图片对象
a0: '../../asset/images/runing.png',
a1: '../../asset/images/runing1.png',
a2: '../../asset/images/runing2.png',
a3: '../../asset/images/runing3.png',
a4: '../../asset/images/runing4.png',
},
currentState: 'a1',
timer: null, // 定时器
},
onLoad() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
},
handleLongPress(e) {
// let timeCount = this.data.timeCount;
// timeCount == 1 && this.setBgUrl('a1');
// timeCount > 1 && timeCount <= 4&& this.setBgUrl('a2');
// timeCount > 4 && timeCount <= 6&& this.setBgUrl('a3');
// timeCount > 6 && timeCount <= 9&& this.setBgUrl('a3');
// timeCount > 9 && timeCount <= 12&& this.setBgUrl('a1');
},
handleTouchStart(e) {
let _this = this;
let timeCount = _this.data.timeCount;
let timer = setInterval(() => {
timeCount += 1
timeCount == 1 && this.setBgUrl('a1');
timeCount > 1 && timeCount <= 4&& this.setBgUrl('a2');
timeCount > 4 && timeCount <= 6&& this.setBgUrl('a3');
timeCount > 6 && timeCount <= 9&& this.setBgUrl('a4');
timeCount > 9 && timeCount < 12 && this.setBgUrl('a1');
if(timeCount == 12) {
timeCount = 0
this.setData({
timeCount: 0
})
}
timeCount !== 12 && this.setData({
timeCount: _this.data.timeCount+1
})
}, 1000);
console.log(timer)
this.setData({
timer: timer
})
},
handleTouchEnd(e) {
let _this = this;
this.data.timer && clearInterval(this.data.timer)
this.setData({
timeCount: 0
})
this.setBgUrl('a0');
},
setBgUrl(state) {
let _this = this;
this.setData({
bgUrl: _this.data.bgImageObj[state]
})
}
})
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}
\ No newline at end of file
<!--logs.wxml-->
<view class="container log-list">
<view class="game-content">
<image class="game-content-bg" src="{{bgUrl}}"></image>
<image class="game-content-dice" src="{{diceUrl}}" bindlongpress="handleLongPress" bindtouchstart="handleTouchStart"
bindtouchend="handleTouchEnd" ></image>
</view>
</view>
.container {
display: flex;
justify-content: center;
align-content: center;
width: 100%;
height: 100%;
}
.game-content {
width: 500rpx;
height: 500rpx;
position: relative;
}
.game-content-bg{
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
}
.game-content-dice{
width: 40%;
height: 40%;
position: absolute;
z-index: 2;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
// pages/news/news.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/news/news.wxml-->
<text>pages/news/news.wxml</text>
/* pages/news/news.wxss */
\ No newline at end of file
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"useMultiFrameRuntime": false,
"useApiHook": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"bundle": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
},
"compileType": "miniprogram",
"libVersion": "2.14.1",
"appid": "wx156a5724ac06d014",
"projectname": "diceGame",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
\ No newline at end of file
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
\ 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
}
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