From 39429c43471b4a20e995fc1068462de63fd28088 Mon Sep 17 00:00:00 2001 From: callmeyan Date: Mon, 21 Nov 2022 08:24:09 +0800 Subject: [PATCH] init master --- miniprogram/app.json | 36 ++++--- miniprogram/app.ts | 12 +-- miniprogram/pages/index/index.ts | 120 +++++++++++++++-------- miniprogram/pages/index/index.wxml | 18 ++-- miniprogram/pages/personal/personal.json | 7 ++ miniprogram/pages/personal/personal.less | 37 +++++++ miniprogram/pages/personal/personal.ts | 66 +++++++++++++ miniprogram/pages/personal/personal.wxml | 48 +++++++++ project.private.config.json | 6 +- 9 files changed, 282 insertions(+), 68 deletions(-) create mode 100644 miniprogram/pages/personal/personal.json create mode 100644 miniprogram/pages/personal/personal.less create mode 100644 miniprogram/pages/personal/personal.ts create mode 100644 miniprogram/pages/personal/personal.wxml diff --git a/miniprogram/app.json b/miniprogram/app.json index 362db77..b754380 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,14 +1,26 @@ { - "pages": [ - "pages/index/index", - "pages/logs/logs" - ], - "window": { - "backgroundTextStyle": "light", - "navigationBarBackgroundColor": "#fff", - "navigationBarTitleText": "Weixin", - "navigationBarTextStyle": "black" - }, - "style": "v2", - "sitemapLocation": "sitemap.json" + "pages": [ + "pages/personal/personal", + "pages/index/index", + "pages/logs/logs" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "Weixin", + "navigationBarTextStyle": "black" + }, + "tabBar": { + "list": [{ + "pagePath": "pages/index/index", + "text": "首页" + }, + { + "pagePath": "pages/personal/personal", + "text": "个人中心" + } + ] + }, + "style": "v2", + "sitemapLocation": "sitemap.json" } \ No newline at end of file diff --git a/miniprogram/app.ts b/miniprogram/app.ts index 1af73a8..8759e49 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -8,11 +8,11 @@ App({ wx.setStorageSync('logs', logs) // 登录 - wx.login({ - success: res => { - console.log(res.code) - // 发送 res.code 到后台换取 openId, sessionKey, unionId - }, - }) + // wx.login({ + // success: res => { + // console.log(res.code) + // // 发送 res.code 到后台换取 openId, sessionKey, unionId + // }, + // }) }, }) \ No newline at end of file diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index 52d84cf..4f909c0 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -3,47 +3,83 @@ const app = getApp() Page({ - data: { - motto: 'Hello World', - userInfo: {}, - hasUserInfo: false, - canIUse: wx.canIUse('button.open-type.getUserInfo'), - canIUseGetUserProfile: false, - canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false - }, - // 事件处理函数 - bindViewTap() { - wx.navigateTo({ - url: '../logs/logs', - }) - }, - onLoad() { - // @ts-ignore - if (wx.getUserProfile) { - this.setData({ - canIUseGetUserProfile: true - }) - } - }, - getUserProfile() { - // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 - wx.getUserProfile({ - desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 - success: (res) => { - console.log(res) - this.setData({ - userInfo: res.userInfo, - hasUserInfo: true + data: { + motto: 'Hello World', + userInfo: {}, + open_id: '', + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo'), + canIUseGetUserProfile: false, + canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false + }, + // 事件处理函数 + bindViewTap() { + wx.navigateTo({ + url: '../logs/logs', }) - } - }) - }, - getUserInfo(e: any) { - // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 - console.log(e) - this.setData({ - userInfo: e.detail.userInfo, - hasUserInfo: true - }) - } + }, + onLoad() { + // @ts-ignore + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + }, + getUserProfile() { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + console.log(res) + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + }, + getUserInfo(e: any) { + // 用户授权操作后的回调 + // 并直接返回匿名的用户个人信息 + console.log(e) + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + }, + user_login() { + wx.login({ + success: ({ code }) => { + if (!code) { + wx.showToast({ + title: '获取授权数据失败' + }) + return; + } + // 发起请求 + wx.request({ + url: 'http://localhost:8080/wechat/login', + data: { code }, + method: 'GET', + success: (result) => { + if (result.statusCode != 200) { + wx.showToast({ + title: '登录失败' + }) + return; + } + this.setData({ + open_id: result.data.toString() + }) + } + }) + }, + fail: () => { + wx.showToast({ + title: '授权失败' + }) + } + }) + } }) diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index f00d294..e758b8f 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,21 +1,27 @@ - + + + + + {{open_id}} + {{motto}} diff --git a/miniprogram/pages/personal/personal.json b/miniprogram/pages/personal/personal.json new file mode 100644 index 0000000..aae18c3 --- /dev/null +++ b/miniprogram/pages/personal/personal.json @@ -0,0 +1,7 @@ +{ + "usingComponents": { }, + "document-url":"https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/page.html", + "navigationBarTitleText": "个人中心", + "navigationBarBackgroundColor": "#ceb17f", + "navigationBarTextStyle": "white" +} \ No newline at end of file diff --git a/miniprogram/pages/personal/personal.less b/miniprogram/pages/personal/personal.less new file mode 100644 index 0000000..feb84c2 --- /dev/null +++ b/miniprogram/pages/personal/personal.less @@ -0,0 +1,37 @@ +/* pages/personal.wxss */ +@content-widht:90%; +.content-container{ + width: @content-widht; + margin: auto; +} +.header{ + background-color: #ceb17f; + color:white; + width: 100%; + padding: 30px 0; + .content-container{ + display: flex; + justify-content: space-between; + align-items: center; + } + .user-info{ + display: flex; + align-items: center; + } + .user-avatar-wrapper{ + width: 60px; + height: 60px; + border-radius: 50%; + display: inline-block; + overflow: hidden; + } + .nickname{ + margin-left: 10px; + font-size: 20px; + } + .user-avatar{ + width: 100%; + height: 100%; + display: block; + } +} \ No newline at end of file diff --git a/miniprogram/pages/personal/personal.ts b/miniprogram/pages/personal/personal.ts new file mode 100644 index 0000000..ec311b1 --- /dev/null +++ b/miniprogram/pages/personal/personal.ts @@ -0,0 +1,66 @@ +// pages/personal.ts +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad() { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/personal/personal.wxml b/miniprogram/pages/personal/personal.wxml new file mode 100644 index 0000000..88d9c7c --- /dev/null +++ b/miniprogram/pages/personal/personal.wxml @@ -0,0 +1,48 @@ + + + +
+ + + 1,121 + +
+
+ + + + + + + 每次签到 + + + + + + + 兑换记录 + + + + + + + 积分游戏 + + + + + + + 我的收藏 + + + + +
\ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json index da04421..93eac2c 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -2,6 +2,8 @@ "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "projectname": "PointApp", "setting": { - "compileHotReLoad": true - } + "compileHotReLoad": true, + "urlCheck": false + }, + "libVersion": "2.23.0" } \ No newline at end of file