commit 6ede62fbb96b02a82e6c97c4cc7d0c3d5a0de594 Author: XuPeng Date: Mon Dec 7 09:48:09 2020 +0800 init diff --git a/app.js b/app.js new file mode 100644 index 0000000..b545190 --- /dev/null +++ b/app.js @@ -0,0 +1,39 @@ +//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 diff --git a/app.json b/app.json new file mode 100644 index 0000000..ff0aff4 --- /dev/null +++ b/app.json @@ -0,0 +1,34 @@ +{ + "pages":[ + "pages/component/index/index", + "pages/API/index/index" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "Weixin", + "navigationBarTextStyle":"black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json", + "tabBar": { + "color": "#7A7E83", + "selectedColor": "#3cc51f", + "borderStyle": "black", + "backgroundColor": "#F7F7F7", + "list": [ + { + "pagePath": "pages/component/index/index", + "iconPath": "image/icon_component.png", + "selectedIconPath": "image/icon_component_HL.png", + "text": "组件" + }, + { + "pagePath": "pages/API/index/index", + "iconPath": "image/icon_API.png", + "selectedIconPath": "image/icon_API_HL.png", + "text": "接口" + } + ] + } +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/app.wxss @@ -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; +} diff --git a/image/green_tri.png b/image/green_tri.png new file mode 100644 index 0000000..a83f974 Binary files /dev/null and b/image/green_tri.png differ diff --git a/image/icon64_appwx_logo.png b/image/icon64_appwx_logo.png new file mode 100644 index 0000000..91a38f9 Binary files /dev/null and b/image/icon64_appwx_logo.png differ diff --git a/image/icon_API.png b/image/icon_API.png new file mode 100644 index 0000000..76e6cb9 Binary files /dev/null and b/image/icon_API.png differ diff --git a/image/icon_API_HL.png b/image/icon_API_HL.png new file mode 100644 index 0000000..6fa3707 Binary files /dev/null and b/image/icon_API_HL.png differ diff --git a/image/icon_API_dark.png b/image/icon_API_dark.png new file mode 100644 index 0000000..7b8f2e2 Binary files /dev/null and b/image/icon_API_dark.png differ diff --git a/image/icon_cloud.png b/image/icon_cloud.png new file mode 100644 index 0000000..8530b16 Binary files /dev/null and b/image/icon_cloud.png differ diff --git a/image/icon_cloud_HL.png b/image/icon_cloud_HL.png new file mode 100644 index 0000000..7285cc8 Binary files /dev/null and b/image/icon_cloud_HL.png differ diff --git a/image/icon_cloud_dark.png b/image/icon_cloud_dark.png new file mode 100644 index 0000000..d30fc6f Binary files /dev/null and b/image/icon_cloud_dark.png differ diff --git a/image/icon_component.png b/image/icon_component.png new file mode 100644 index 0000000..301f579 Binary files /dev/null and b/image/icon_component.png differ diff --git a/image/icon_component_HL.png b/image/icon_component_HL.png new file mode 100644 index 0000000..65c3fcb Binary files /dev/null and b/image/icon_component_HL.png differ diff --git a/image/icon_component_dark.png b/image/icon_component_dark.png new file mode 100644 index 0000000..1228520 Binary files /dev/null and b/image/icon_component_dark.png differ diff --git a/image/icon_foot.png b/image/icon_foot.png new file mode 100644 index 0000000..3288ee1 Binary files /dev/null and b/image/icon_foot.png differ diff --git a/image/location.png b/image/location.png new file mode 100644 index 0000000..b9e731e Binary files /dev/null and b/image/location.png differ diff --git a/image/pause.png b/image/pause.png new file mode 100644 index 0000000..9acb73d Binary files /dev/null and b/image/pause.png differ diff --git a/image/play.png b/image/play.png new file mode 100644 index 0000000..982f2f2 Binary files /dev/null and b/image/play.png differ diff --git a/image/plus.png b/image/plus.png new file mode 100644 index 0000000..73ddfe3 Binary files /dev/null and b/image/plus.png differ diff --git a/image/plus_dark.png b/image/plus_dark.png new file mode 100644 index 0000000..b9bb683 Binary files /dev/null and b/image/plus_dark.png differ diff --git a/image/record.png b/image/record.png new file mode 100644 index 0000000..a62ef81 Binary files /dev/null and b/image/record.png differ diff --git a/image/share.png b/image/share.png new file mode 100644 index 0000000..baac7f9 Binary files /dev/null and b/image/share.png differ diff --git a/image/stop.png b/image/stop.png new file mode 100644 index 0000000..9e65f3e Binary files /dev/null and b/image/stop.png differ diff --git a/image/trash.png b/image/trash.png new file mode 100644 index 0000000..83d68f3 Binary files /dev/null and b/image/trash.png differ diff --git a/image/wechat.png b/image/wechat.png new file mode 100644 index 0000000..470931c Binary files /dev/null and b/image/wechat.png differ diff --git a/image/wechatHL.png b/image/wechatHL.png new file mode 100644 index 0000000..3c5e52b Binary files /dev/null and b/image/wechatHL.png differ diff --git a/pages/API/index/index.js b/pages/API/index/index.js new file mode 100644 index 0000000..608a282 --- /dev/null +++ b/pages/API/index/index.js @@ -0,0 +1,54 @@ +//index.js +//获取应用实例 +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + //事件处理函数 + bindViewTap: function() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onLoad: function () { + 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: function(e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/API/index/index.json b/pages/API/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/API/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/API/index/index.wxml b/pages/API/index/index.wxml new file mode 100644 index 0000000..0243bda --- /dev/null +++ b/pages/API/index/index.wxml @@ -0,0 +1,13 @@ + + + + + + + {{userInfo.nickName}} + + + + {{motto}} + + diff --git a/pages/API/index/index.wxss b/pages/API/index/index.wxss new file mode 100644 index 0000000..ce30de0 --- /dev/null +++ b/pages/API/index/index.wxss @@ -0,0 +1,21 @@ +/**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 diff --git a/pages/component/index/index.js b/pages/component/index/index.js new file mode 100644 index 0000000..608a282 --- /dev/null +++ b/pages/component/index/index.js @@ -0,0 +1,54 @@ +//index.js +//获取应用实例 +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + //事件处理函数 + bindViewTap: function() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onLoad: function () { + 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: function(e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/component/index/index.json b/pages/component/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/component/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/component/index/index.wxml b/pages/component/index/index.wxml new file mode 100644 index 0000000..0243bda --- /dev/null +++ b/pages/component/index/index.wxml @@ -0,0 +1,13 @@ + + + + + + + {{userInfo.nickName}} + + + + {{motto}} + + diff --git a/pages/component/index/index.wxss b/pages/component/index/index.wxss new file mode 100644 index 0000000..ce30de0 --- /dev/null +++ b/pages/component/index/index.wxss @@ -0,0 +1,21 @@ +/**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 diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..b108c7f --- /dev/null +++ b/project.config.json @@ -0,0 +1,72 @@ +{ + "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, + "useIsolateContext": true, + "useCompilerModule": true, + "userConfirmedUseCompilerModuleSwitch": false, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "bundle": false + }, + "compileType": "miniprogram", + "libVersion": "2.14.1", + "appid": "wx60509bbad6b495c2", + "projectname": "wx-api-v2", + "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 diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..dbadbb8 --- /dev/null +++ b/utils/util.js @@ -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: formatTime +}