diff --git a/miniprogram/app.json b/miniprogram/app.json index d5399e6..3d9dd1b 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,9 +1,9 @@ { "pages": [ - "pages/sign/index", - "pages/personal/personal", - "pages/user/login", "pages/index/index", + "pages/personal/personal", + "pages/sign/index", + "pages/user/login", "pages/logs/logs" ], "window": { @@ -16,10 +16,14 @@ "list": [ { "pagePath": "pages/index/index", + "iconPath":"assets/images/icon_home.png", + "selectedIconPath":"assets/images/icon_home_selected.png", "text": "首页" }, { "pagePath": "pages/personal/personal", + "iconPath":"assets/images/icon_user.png", + "selectedIconPath":"assets/images/icon_user_selected.png", "text": "个人中心" } ] diff --git a/miniprogram/app.less b/miniprogram/app.less index bc54259..0501f6d 100644 --- a/miniprogram/app.less +++ b/miniprogram/app.less @@ -1,13 +1,9 @@ -/**app.wxss**/ -.container { - height: 100%; - display: flex; - flex-direction: column; - align-items: center; - justify-content: space-between; - padding: 200rpx 0; - box-sizing: border-box; +/**global style**/ +image{ + max-width: 100%; + max-height: 100%; } +/**app.wxss**/ @content-widht:90%; .content-container{ width: @content-widht; diff --git a/miniprogram/assets/images/18005888-5c529143bfc58.jpg b/miniprogram/assets/images/18005888-5c529143bfc58.jpg new file mode 100644 index 0000000..2c4a320 Binary files /dev/null and b/miniprogram/assets/images/18005888-5c529143bfc58.jpg differ diff --git a/miniprogram/assets/images/icon_home.png b/miniprogram/assets/images/icon_home.png new file mode 100644 index 0000000..0964bbc Binary files /dev/null and b/miniprogram/assets/images/icon_home.png differ diff --git a/miniprogram/assets/images/icon_home_selected.png b/miniprogram/assets/images/icon_home_selected.png new file mode 100644 index 0000000..d4643fd Binary files /dev/null and b/miniprogram/assets/images/icon_home_selected.png differ diff --git a/miniprogram/assets/images/icon_user.png b/miniprogram/assets/images/icon_user.png new file mode 100644 index 0000000..53dcd44 Binary files /dev/null and b/miniprogram/assets/images/icon_user.png differ diff --git a/miniprogram/assets/images/icon_user_selected.png b/miniprogram/assets/images/icon_user_selected.png new file mode 100644 index 0000000..2adcbdc Binary files /dev/null and b/miniprogram/assets/images/icon_user_selected.png differ diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json index 8835af0..d121fff 100644 --- a/miniprogram/pages/index/index.json +++ b/miniprogram/pages/index/index.json @@ -1,3 +1,5 @@ { - "usingComponents": {} + "usingComponents": {}, + "navigationBarBackgroundColor": "#F96352", + "navigationBarTitleText": "积分商城" } \ No newline at end of file diff --git a/miniprogram/pages/index/index.less b/miniprogram/pages/index/index.less index eb64203..669233b 100644 --- a/miniprogram/pages/index/index.less +++ b/miniprogram/pages/index/index.less @@ -1,19 +1,110 @@ /**index.wxss**/ -.userinfo { - display: flex; - flex-direction: column; - align-items: center; - color: #aaa; +@box-shadow: 0 0 6px rgba(0, 0, 0, 0.25); + +image { + width: 100%; + height: 100%; } -.userinfo-avatar { +.box-border-radius { + border-radius: 10px; overflow: hidden; - width: 128rpx; - height: 128rpx; - margin: 20rpx; - border-radius: 50%; } -.usermotto { - margin-top: 200px; +.content-bg { + background: linear-gradient(to bottom, #F96352, #fff); + height: 120px; + width: 100%; + left: 0; + top: 0; + position: absolute; +} + +.content-wrapper { + position: relative; + z-index: 2; + width: 90vw; + margin: auto; + padding: 10px 0; +} + +// swiper +.top-swiper { + .box-border-radius; +} + +.swiper-item { + height: 150px; +} + +.index-act-1 { + width: 100%; + height: 110px; + .box-border-radius; + box-shadow: @box-shadow; + margin: 20px 0; +} + +.recommend-wrapper, +.hot-wrapper { + margin: 20px 0; +} + +.hot-title { + font-weight: bold; + font-size: 16px; + margin-bottom: 10px; +} + +// panel +.panel { + .box-border-radius; + box-shadow: @box-shadow; + + .panel-title { + font-weight: bold; + font-size: 16px; + padding: 20px 20px 0; + } + + .panel-body { + padding: 20px; + } +} + +.goods-list-row { + display: flex; + overflow: hidden; + + .goods-item { + flex: 1; + min-width: 20%; + margin-right: 10px; + text-align: center; + + &:last-child { + margin-right: 0px; + } + } + + .image { + width: 100%; + aspect-ratio: 1/1; + } + + .title { + word-break: break-all; + font-size: 12px; + line-height: 16px; + height: 32px; + overflow: hidden; + } + .price{ + color: #f00; + margin-top: 5px; + } +} + +.displex-flex { + display: flex; } \ No newline at end of file diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index 52d84cf..ca08a55 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -1,49 +1,59 @@ // index.ts // 获取应用实例 const app = getApp() - +const goodsItems = [ + { + cover: 'https://img10.360buyimg.com/mobilecms/s360x360_jfs/t1/103799/25/31581/57788/62e907f2E85845359/45e0568d42c9803d.jpg!q70.dpg.webp', + title: '轻奢高档女装 半身裙2022春秋女韩版中裙百褶中长款A字裙水兵舞防走光裙子跳舞裙子 酒红色 M', + price: 500, + stock: 20, + id: 1 + }, + { + cover: 'https://img10.360buyimg.com/mobilecms/s360x360_jfs/t1/354/20/1552/77109/5b939e1aE8318003c/b7d99e9173a51fa7.jpg!q70.dpg.webp', + title: '微星(MSI) 微星Cubi-B171N8GL-009BCN迷你静音电脑PC主机BN6000处理器 准系统(不含内存硬盘)', + price: 2000, + stock: 10, + id: 2 + }, + { + cover: 'https://img10.360buyimg.com/mobilecms/s360x360_jfs/t1/83150/10/23413/112462/63776142E6818d77c/2721b6f0420b15d2.jpg!q70.dpg.webp', + title: '爱普生(EPSON)L4268墨仓式品质款 彩色无线多功能一体机(打印复印扫描 wifi 自动双面)新旧包装随机发货', + price: 3000, + stock: 50, + id: 3 + }, + { + cover: 'https://img10.360buyimg.com/mobilecms/s360x360_jfs/t1/103799/25/31581/57788/62e907f2E85845359/45e0568d42c9803d.jpg!q70.dpg.webp', + title: '轻奢高档女装 半身裙2022春秋女韩版中裙百褶中长款A字裙水兵舞防走光裙子跳舞裙子 酒红色 M', + price: 500, + stock: 20, + id: 4 + }, +] 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', - }) + swiperList: [ + { + image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/160398/4/32302/103427/6374d1f3E5b1ecb32/a593b9982d8378cc.jpg!cr_1125x449_0_166!q70.jpg', + url: null, + }, + { + image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/203775/20/26428/95041/637fab4dEf6a4434d/3f8770efe691537b.jpg!cr_1053x420_4_0!q70.jpg', + url: null, + }, + { + image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/160398/4/32302/103427/6374d1f3E5b1ecb32/a593b9982d8378cc.jpg!cr_1125x449_0_166!q70.jpg', + url: null, + }, + { + image: 'https://m15.360buyimg.com/mobilecms/jfs/t1/203775/20/26428/95041/637fab4dEf6a4434d/3f8770efe691537b.jpg!cr_1053x420_4_0!q70.jpg', + url: null, + } + ], + goodsItems, + recommendItems: goodsItems.filter(s => s.id <= 3) }, 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) { - // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 - console.log(e) - this.setData({ - userInfo: e.detail.userInfo, - hasUserInfo: true - }) } }) diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index f00d294..710113c 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,23 +1,79 @@ - - - - + + + + + + + + + + + + + + + + + + + + 精选活动 + + + + + + + + + {{item.title}} + + + {{item.price}}积分 + + + + + + + - - - - - - 请使用1.4.4及以上版本基础库 - - - - {{userInfo.nickName}} - + + + + + + + + + + 热门超值兑换 + + + + + + + + + + {{item.title}} + + + + {{item.price}}积分 + + + + + + + + + + + - - {{motto}} - - + \ No newline at end of file diff --git a/miniprogram/pages/index/index.wxss b/miniprogram/pages/index/index.wxss deleted file mode 100644 index eb64203..0000000 --- a/miniprogram/pages/index/index.wxss +++ /dev/null @@ -1,19 +0,0 @@ -/**index.wxss**/ -.userinfo { - display: flex; - flex-direction: column; - align-items: center; - color: #aaa; -} - -.userinfo-avatar { - overflow: hidden; - width: 128rpx; - height: 128rpx; - margin: 20rpx; - border-radius: 50%; -} - -.usermotto { - margin-top: 200px; -} \ No newline at end of file diff --git a/miniprogram/pages/logs/logs.less b/miniprogram/pages/logs/logs.less new file mode 100644 index 0000000..92165d0 --- /dev/null +++ b/miniprogram/pages/logs/logs.less @@ -0,0 +1 @@ +/* pages/logs/logs.wxss */ \ No newline at end of file diff --git a/miniprogram/pages/personal/personal.json b/miniprogram/pages/personal/personal.json index aae18c3..41b3f5c 100644 --- a/miniprogram/pages/personal/personal.json +++ b/miniprogram/pages/personal/personal.json @@ -1,6 +1,5 @@ { "usingComponents": { }, - "document-url":"https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/page.html", "navigationBarTitleText": "个人中心", "navigationBarBackgroundColor": "#ceb17f", "navigationBarTextStyle": "white" diff --git a/miniprogram/pages/sign/index.ts b/miniprogram/pages/sign/index.ts index 6118e8b..7d0fa81 100644 --- a/miniprogram/pages/sign/index.ts +++ b/miniprogram/pages/sign/index.ts @@ -11,7 +11,13 @@ Page({ signToday: false, continuousDays: 0, dayTextArray:[ - '一','二','三','四','五','六','七' + {text:'一',value:5}, + {text:'二',value:10}, + {text:'三',value:15}, + {text:'四',value:20}, + {text:'五',value:25}, + {text:'六',value:30}, + {text:'七',value:35}, ] }, diff --git a/miniprogram/pages/sign/index.wxml b/miniprogram/pages/sign/index.wxml index 0290bf7..e5e03a1 100644 --- a/miniprogram/pages/sign/index.wxml +++ b/miniprogram/pages/sign/index.wxml @@ -31,15 +31,15 @@ 连续签到得积分 - + - {{(index +1 ) * 5}}积分 + {{item.value}}积分 - 第{{item}}天 + 第{{item.text}}天 diff --git a/miniprogram/pages/user/login.ts b/miniprogram/pages/user/login.ts index 5b7333d..79b4772 100644 --- a/miniprogram/pages/user/login.ts +++ b/miniprogram/pages/user/login.ts @@ -1,6 +1,9 @@ import message from "../../utils/message" import { getUserProfile, login } from "../../utils/promise-hooks" import request, { BizError } from "../../utils/request"; +type PageData = { + code: string +} // pages/user/login.ts Page({ @@ -9,39 +12,42 @@ Page({ * 页面的初始数据 */ data: { - + code:'' }, /** * 生命周期函数--监听页面加载 */ async onLoad() { + // 发起登录的授权 + const code = await login() + this.setData({ + code + }) }, + async onGetUserInfo() { - message.showLoading({}) + if(!this.data.code){ + this.onLoad() + message.toast('初始化错误,请重新登录') + return; + } + message.showLoading({ message: '登录中...' }) try { - // 发起登录的授权 const data = await getUserProfile() - const res = await request('/wechat/login', data) - - console.log(res) + data.code = this.data.code + const res = await request('/user/login', data) + // + console.log(res); } finally { message.hideLoading() } }, - async getCode() { - try { - const code = await login() - console.log(res) - } catch (e) { - message.toast(e) - } - }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { - + }, /** diff --git a/miniprogram/utils/promise-hooks.ts b/miniprogram/utils/promise-hooks.ts index edf90c6..e9391bd 100644 --- a/miniprogram/utils/promise-hooks.ts +++ b/miniprogram/utils/promise-hooks.ts @@ -35,31 +35,30 @@ type UserProfileData = { * 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 auth.code2Session, * 使用 code 换取 openid、unionid、session_key 等信息 */ - code: string + code?: string } -export function getUserProfile(timeout = 10000) { - return new Promise((resolve, reject) => { +export function getUserProfile() { + return new Promise(async (resolve, reject) => { + // wx.login 必须在获取用户数据之前 wx.getUserProfile({ - desc: '展示用户信息并参与相关活动', - success: (res) => { - if (res.errMsg == 'getUserProfile:ok' && res.encryptedData) { - login(timeout).then(code => { + desc: '展示用户信息并参与相关活动', + success: (res) => { + if (res.errMsg == 'getUserProfile:ok' && res.encryptedData) { resolve({ encryptedData: res.encryptedData, - iv: res.iv, - code + iv: res.iv }) - }).catch(reject) - } else { + } else { + message.toast('登录失败,请重新登录', 'error') + reject('登录失败,' + res.errMsg) + } + }, + fail: (e) => { message.toast('登录失败,请重新登录', 'error') - reject('登录失败,' + res.errMsg) + reject('登录失败,' + e.errMsg) } - }, - fail: (e) => { - message.toast('登录失败,请重新登录', 'error') - reject('登录失败,' + e.errMsg) - } - }) + }) + }); } \ No newline at end of file diff --git a/miniprogram/utils/request.ts b/miniprogram/utils/request.ts index 7958b41..44bb8e4 100644 --- a/miniprogram/utils/request.ts +++ b/miniprogram/utils/request.ts @@ -48,6 +48,12 @@ function request(api: string, data: any = null, method: HttpMethod = 'POST') const result = res.data // 验证接口是否正确 if (result.code !== 0) { + if(result.code === 403){ + wx.navigateTo({ + url:'/pages/user/login' + }) + return; + } reject(new BizError(result.message, result.code)) return; }