wyl 1 year ago
parent e8a2bc419d
commit 6417d1eb74

@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

@ -1,2 +1 @@
# Tim-1 ![](time.png)

@ -0,0 +1,19 @@
// 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
}
})
},
globalData: {
userInfo: null
}
})

@ -0,0 +1,14 @@
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}

@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}

@ -0,0 +1,136 @@
Page({
width: 0, //窗口宽度
height: 0, //窗口高度
onLoad: function () {
// 获取系统信息
wx.getSystemInfo({
// 获取系统信息成功,保存获取到的系统窗口的宽高
success: res => {
// console.log(res)
this.width = res.windowWidth
this.height = res.windowHeight
}
})
},
timer: null, //定时器
onReady: function(){
//创建ctx实例
var ctx = wx.createCanvasContext('myCanvas')
//将角度转换为弧度,方便在后面使用
//计算公式:弧度 = 角度*Math.PI / 180
const D6 = 6 * Math.PI / 180
const D30 = 30 * Math.PI / 180
const D90 = 90 * Math.PI / 180
// 获取宽和高值
var width = this.width, height = this.height
// 计算表盘半径,留出 30px 外边距
var radius = width / 2 -30
// 每秒绘制一次
draw()
this.timer = setInterval(draw, 1000)
// 绘制函数
function draw(){
// 设置坐标轴原点为窗口的中心点
ctx.translate(width / 2, height / 2)
// 绘制表盘
drawClock(ctx,radius)
// 绘制指针
drawHand(ctx, radius)
//执行绘制
ctx.draw()
}
// 绘制表盘部分
function drawClock(ctx, radius){
// 绘制大圆
// 大圆的半径 radius 线条粗细为2px
ctx.setLineWidth(2) //设置线条粗细
ctx.beginPath() //开始一个新路径
ctx.arc(0, 0, radius, 0, 2 * Math.PI, true)
ctx.stroke() //画线
// 绘制同心圆
// 中心圆的半径为8px 线条粗细为1px
ctx.setLineWidth(1) //设置线条粗细
ctx.beginPath() //开始一个新路径
ctx.arc(0, 0, 8, 0, 2 * Math.PI, true)
ctx.stroke() //画线
// 绘制大刻度盘 线条粗细为5px
ctx.setLineWidth(5)
for (var i = 0; i < 12; ++i){
// 以原点为中心顺时针(多次调用旋转的角度会叠加)
// 大刻度盘需要绘制12个线条表示12个小时每次旋转30度
ctx.rotate(D30) // 360 / 12 = 30
ctx.beginPath()
ctx.moveTo(radius, 0)
ctx.moveTo(radius - 15, 0) //大刻度长度15px
ctx.stroke()
}
// 绘制小刻度盘线条粗细为1px
ctx.setLineWidth(1)
for(var i = 0; i < 60; ++i){
// 小刻度盘需要绘制60个线条表示60分钟或60秒每次旋转6度
ctx.rotate(D6)
ctx.beginPath()
ctx.moveTo(radius, 0)
ctx.lineTo(radius - 10, 0) //小刻度盘长度10px
ctx.stroke()
}
//绘制文本
ctx.setFontSize(20) //字号
ctx.textBaseline = 'middle' // 文本垂直居中
// 计算文本距离表盘中心点的半径r
var r = radius - 30
for(var i = 1; i <= 12; ++i){
// 利用三角函数计算文本坐标
var x = r * Math.cos(D30 * i - D90)
var y = r * Math.sin(D30 * i - D90)
if(i > 10){ // 调整11 和12位置
// 在画布上绘制文本 fillText(文本左上角x坐标左上角y坐标)
ctx.fillText(i, x - 12, y)
} else {
ctx.fillText(i, x-6, y)
}
}
}
//绘制指针部分
function drawHand(ctx, radius){
var t = new Date() // 获取当前时间
var h = t.getHours() //小时
var m = t.getMinutes() //分
var s = t.getSeconds() // 秒
h = h > 12 ? h -12 :h //将24小时制转换为12小时制
//时间从三点开始逆时针旋转90度指向12点
ctx.rotate(-D90)
//绘制时针
ctx.save() //记录旋转状态
// 计算时针指向的刻度
// 通过 30度 * h 可以计算每个整点的旋转角度
// 如果时间不是整点需要使用h + m / 60 + s / 3600 计算准确的偏移度
ctx.rotate(D30 * (h + m / 60 + s / 3600))
ctx.setLineWidth(6)
ctx.beginPath()
ctx.moveTo(-20, 0)
ctx.lineTo(radius / 2.6, 0)
ctx.stroke()
ctx.restore()
// 绘制分针
ctx.save()
ctx.rotate(D6 * (m + s / 60))
ctx.setLineWidth(4)
ctx.beginPath()
ctx.moveTo(-20, 0)
ctx.lineTo(radius / 1.8, 0)
ctx.stroke()
ctx.restore()
//绘制秒针
ctx.save()
ctx.rotate(D6 * s)
ctx.setLineWidth(2)
ctx.beginPath()
ctx.moveTo(-20, 0)
ctx.lineTo(radius / 1.6, 0)
ctx.stroke()
ctx.restore()
}
}
})

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

@ -0,0 +1 @@
<canvas canvas-id="myCanvas" class="mycanvas"></canvas>

@ -0,0 +1,6 @@
/**index.wxss**/
.mycanvas {
width: 100%;
height: 100%;
position: fixed;
}

@ -0,0 +1,18 @@
// logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return {
date: util.formatTime(new Date(log)),
timeStamp: log
}
})
})
}
})

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}

@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log.date}}</text>
</block>
</view>

@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}

@ -0,0 +1,52 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false,
"minifyWXML": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"condition": false
},
"compileType": "miniprogram",
"libVersion": "2.19.4",
"appid": "wx04c517846836da71",
"projectname": "miniprogram-92",
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}

@ -0,0 +1,7 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "miniprogram-1",
"setting": {
"compileHotReLoad": true
}
}

@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

@ -0,0 +1,19 @@
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
}
Loading…
Cancel
Save