Compare commits
No commits in common. "e3927b546ae44555df9dba8b82aec2d6da37eb4b" and "247a8eade9e2da0172215e1e7f9c87c4cec6e617" have entirely different histories.
e3927b546a
...
247a8eade9
@ -1,5 +1,3 @@
|
|||||||
import { info } from "./service/user-api";
|
|
||||||
|
|
||||||
// app.ts
|
// app.ts
|
||||||
App<IAppOption>({
|
App<IAppOption>({
|
||||||
globalData: {},
|
globalData: {},
|
||||||
@ -8,23 +6,6 @@ App<IAppOption>({
|
|||||||
const token = wx.getStorageSync('user-token')
|
const token = wx.getStorageSync('user-token')
|
||||||
if (token) {
|
if (token) {
|
||||||
this.globalData.token = token;
|
this.globalData.token = token;
|
||||||
info().then(userinfo => {
|
}
|
||||||
this.globalData.userInfo = userinfo;
|
},
|
||||||
})
|
|
||||||
}else{
|
|
||||||
wx.login({
|
|
||||||
success:(e)=>{
|
|
||||||
if(e.code){
|
|
||||||
console.log(e)
|
|
||||||
info(e.code).then(userinfo => {
|
|
||||||
if(userinfo.token){
|
|
||||||
wx.setStorageSync("user-token",userinfo.token)
|
|
||||||
}
|
|
||||||
this.globalData.userInfo = userinfo;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
@ -2,7 +2,5 @@
|
|||||||
"usingComponents": {},
|
"usingComponents": {},
|
||||||
"navigationBarBackgroundColor": "#ceb17f",
|
"navigationBarBackgroundColor": "#ceb17f",
|
||||||
"navigationBarTitleText": "积分商城",
|
"navigationBarTitleText": "积分商城",
|
||||||
"navigationBarTextStyle": "white",
|
"navigationBarTextStyle": "white"
|
||||||
"enablePullDownRefresh": true,
|
|
||||||
"backgroundTextStyle": "dark"
|
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
// index.ts
|
// index.ts
|
||||||
|
|
||||||
import { createOrder, Goods, queryGoodsList } from "../../service/shop-api"
|
import { queryGoodsList } from "../../service/shop-api"
|
||||||
import message from "../../utils/message";
|
|
||||||
|
|
||||||
// 获取应用实例
|
// 获取应用实例
|
||||||
const app = getApp<IAppOption>()
|
const app = getApp<IAppOption>()
|
||||||
@ -26,75 +25,22 @@ Page({
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
goodsItems: [],
|
goodsItems: [],
|
||||||
recommendItems: [],
|
recommendItems: []
|
||||||
page: 1,
|
|
||||||
hasMore: true,
|
|
||||||
pageSize: 10
|
|
||||||
},
|
|
||||||
onPullDownRefresh() {
|
|
||||||
this.setData({
|
|
||||||
page: 1
|
|
||||||
})
|
|
||||||
this.onLoad()
|
|
||||||
},
|
|
||||||
onReachBottom() {
|
|
||||||
if (!this.data.hasMore) return;
|
|
||||||
const page = this.data.page + 1;
|
|
||||||
this.setData({ page })
|
|
||||||
this.loadGoodsList(page)
|
|
||||||
},
|
|
||||||
loadGoodsList(page: number) {
|
|
||||||
|
|
||||||
// 所有其他的商品
|
|
||||||
queryGoodsList(1, page, this.data.pageSize).then((result) => {
|
|
||||||
//判断是否还有数据没有查询到
|
|
||||||
const count = page * this.data.pageSize;
|
|
||||||
if (count >= result.total) {
|
|
||||||
this.setData({
|
|
||||||
hasMore: false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const originList = page == 1 ? [] : this.data.goodsItems;
|
|
||||||
this.setData({
|
|
||||||
// @ts-ignore
|
|
||||||
goodsItems: [
|
|
||||||
...originList,
|
|
||||||
...result.records
|
|
||||||
]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
// 推荐商品
|
// 推荐商品
|
||||||
queryGoodsList(2, 1, 3).then((result) => {
|
queryGoodsList(2, 1, 3).then((result) => {
|
||||||
wx.stopPullDownRefresh();
|
|
||||||
this.setData({
|
this.setData({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
recommendItems: result.records
|
recommendItems: result.records
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// 所有其他的商品
|
// 所有其他的商品
|
||||||
this.loadGoodsList(this.data.page);
|
queryGoodsList(1, 1, 10).then((result) => {
|
||||||
},
|
this.setData({
|
||||||
createOrder(e) {
|
// @ts-ignore
|
||||||
if(!app.globalData.token){
|
goodsItems: result.records
|
||||||
// message.toast('请先完成登录','none',()=>{
|
|
||||||
// })
|
|
||||||
|
|
||||||
wx.switchTab({
|
|
||||||
url: '/pages/personal/personal'
|
|
||||||
})
|
})
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const goods = e.target.dataset.data as Goods;
|
|
||||||
message.showLoading({ message: '兑换中...' })
|
|
||||||
createOrder(goods.id).then(result => {
|
|
||||||
console.log(result)
|
|
||||||
message.toast('兑换成功')
|
|
||||||
}).catch(e => {
|
|
||||||
message.toast(e.message || '兑换失败')
|
|
||||||
}).finally(() => {
|
|
||||||
message.hideLoading()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<!--index.wxml-->
|
<!--index.wxml-->
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view class="content-bg"></view>
|
<view class="content-bg">
|
||||||
|
|
||||||
|
</view>
|
||||||
<view class="content-wrapper">
|
<view class="content-wrapper">
|
||||||
<view class="top-swiper">
|
<view class="top-swiper">
|
||||||
<swiper indicator-dots="{{true}}" indicator-color="#fff" autoplay="{{true}}">
|
<swiper indicator-dots="{{true}}" indicator-color="#fff" autoplay="{{true}}">
|
||||||
@ -68,7 +70,7 @@
|
|||||||
<text>{{item.price}}积分</text>
|
<text>{{item.price}}积分</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="actions">
|
<view class="actions">
|
||||||
<button data-data="{{item}}" bindtap="createOrder">立即兑换</button>
|
<button>立即兑换</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,30 +1,61 @@
|
|||||||
// pages/personal.ts
|
// pages/personal.ts
|
||||||
|
|
||||||
import message from "../../utils/message";
|
|
||||||
|
|
||||||
const app = getApp<IAppOption>();
|
|
||||||
Page({
|
Page({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 页面的初始数据
|
* 页面的初始数据
|
||||||
*/
|
*/
|
||||||
data: {
|
data: {
|
||||||
userinfo: app.globalData.userInfo
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生命周期函数--监听页面加载
|
* 生命周期函数--监听页面加载
|
||||||
*/
|
*/
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.setData({
|
|
||||||
userinfo: app.globalData.userInfo
|
},
|
||||||
})
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
|
*/
|
||||||
|
onReady() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面显示
|
||||||
|
*/
|
||||||
|
onShow() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面隐藏
|
||||||
|
*/
|
||||||
|
onHide() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面卸载
|
||||||
|
*/
|
||||||
|
onUnload() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||||||
|
*/
|
||||||
|
onPullDownRefresh() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面上拉触底事件的处理函数
|
||||||
|
*/
|
||||||
|
onReachBottom() {
|
||||||
|
|
||||||
},
|
},
|
||||||
onLogin() {
|
|
||||||
if(this.data.userinfo) return;
|
|
||||||
// TODO 完成登录
|
|
||||||
message.toast("开始登录")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户点击右上角分享
|
* 用户点击右上角分享
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
<view class="user-avatar-wrapper">
|
<view class="user-avatar-wrapper">
|
||||||
<open-data class="user-avatar" type="userAvatarUrl"></open-data>
|
<open-data class="user-avatar" type="userAvatarUrl"></open-data>
|
||||||
</view>
|
</view>
|
||||||
<text class="nickname" bindtap="onLogin">{{userinfo?userinfo.nickname:'请点击登录'}}</text>
|
<text class="nickname">张三</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="user-score">
|
<view class="user-score">
|
||||||
<text>{{userinfo?.pointInfo?.totalPoint}}</text>
|
<text>1,121</text>
|
||||||
</view>
|
</view>
|
||||||
</div>
|
</div>
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import message from "../../utils/message"
|
import message from "../../utils/message"
|
||||||
import { signInfo, sign } from "../../service/user-api"
|
import { info, sign } from "../../service/user-api"
|
||||||
|
|
||||||
// pages/sign/index.ts
|
// pages/sign/index.ts
|
||||||
Page({
|
Page({
|
||||||
@ -25,7 +25,7 @@ Page({
|
|||||||
* 生命周期函数--监听页面加载
|
* 生命周期函数--监听页面加载
|
||||||
*/
|
*/
|
||||||
onLoad() {
|
onLoad() {
|
||||||
signInfo().then(res=>{
|
info().then(res=>{
|
||||||
this.setData(res)
|
this.setData(res)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
27
miniprogram/pages/types.d.ts
vendored
27
miniprogram/pages/types.d.ts
vendored
@ -1,24 +1,5 @@
|
|||||||
interface PointInfo {
|
type UserInfo = {
|
||||||
uid: number;
|
id: number
|
||||||
totalPoint: number;
|
nickname: string
|
||||||
validPoint: number;
|
headImage: string
|
||||||
expirePoint: number;
|
|
||||||
expireTime?: any;
|
|
||||||
updateTime: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UserInfo {
|
|
||||||
id: number;
|
|
||||||
openId?: string;
|
|
||||||
nickname: string;
|
|
||||||
headImage: string;
|
|
||||||
gender: number;
|
|
||||||
province: string;
|
|
||||||
city: string;
|
|
||||||
parentId: number;
|
|
||||||
firstLoginTime: string;
|
|
||||||
updateTime?: any;
|
|
||||||
status: number;
|
|
||||||
token?: string
|
|
||||||
pointInfo: PointInfo;
|
|
||||||
}
|
}
|
@ -18,17 +18,6 @@ export type Goods = {
|
|||||||
updateTime: string;
|
updateTime: string;
|
||||||
status: number;
|
status: number;
|
||||||
}
|
}
|
||||||
export type OrderInfo = {
|
|
||||||
id: string;
|
|
||||||
gid: number;
|
|
||||||
price: number;
|
|
||||||
count: number;
|
|
||||||
uid: number;
|
|
||||||
data?: any;
|
|
||||||
createTime?: any;
|
|
||||||
updateTime?: any;
|
|
||||||
status: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function queryGoodsList(category: number, page = 1, pageSize = 10) {
|
export function queryGoodsList(category: number, page = 1, pageSize = 10) {
|
||||||
return request<DataList<Goods>>('/shop/goods/query', {
|
return request<DataList<Goods>>('/shop/goods/query', {
|
||||||
@ -37,8 +26,3 @@ export function queryGoodsList(category: number, page = 1, pageSize = 10) {
|
|||||||
pageSize
|
pageSize
|
||||||
}, 'GET');
|
}, 'GET');
|
||||||
}
|
}
|
||||||
export function createOrder(goodsId: number, buyCount = 1) {
|
|
||||||
return request<OrderInfo>('/shop/order/create', {
|
|
||||||
goodsId, buyCount
|
|
||||||
});
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ export type SignInfo = {
|
|||||||
/**
|
/**
|
||||||
* 签到信息
|
* 签到信息
|
||||||
*/
|
*/
|
||||||
export function signInfo() {
|
export function info(){
|
||||||
return request<SignInfo>('/sign/info');
|
return request<SignInfo>('/sign/info');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -17,9 +17,3 @@ export function signInfo() {
|
|||||||
export function sign(){
|
export function sign(){
|
||||||
return request<SignInfo>('/sign/today');
|
return request<SignInfo>('/sign/today');
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 用户信息
|
|
||||||
*/
|
|
||||||
export function info(code: string = '') {
|
|
||||||
return request<UserInfo>('/user/info', { code }, "GET");
|
|
||||||
}
|
|
@ -1,13 +1,10 @@
|
|||||||
import { BizError } from "./request";
|
import { BizError } from "./request";
|
||||||
|
|
||||||
type ToastIcon = 'success' | 'error' | 'none';
|
type ToastIcon = 'success' | 'error' | 'none';
|
||||||
export function toast(message: string | any, icon: ToastIcon = 'none', callback: (() => void) | null = null) {
|
export function toast(message: string|any, icon: ToastIcon = 'none') {
|
||||||
if(message instanceof BizError){
|
if(message instanceof BizError){
|
||||||
message = message.message
|
message = message.message
|
||||||
}
|
}
|
||||||
if (callback) {
|
|
||||||
setTimeout(callback, 2000);
|
|
||||||
}
|
|
||||||
return wx.showToast({
|
return wx.showToast({
|
||||||
title: message,
|
title: message,
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
|
@ -31,9 +31,8 @@ function request<T>(api: string, data: any = null, method: HttpMethod = 'POST')
|
|||||||
const header: {
|
const header: {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
} = {}
|
} = {}
|
||||||
const app = getApp();
|
|
||||||
// 判断是否有token
|
// 判断是否有token
|
||||||
const token = app ? app.globalData.token : wx.getStorageSync('user-token')
|
const token = getApp().globalData.token
|
||||||
if (token) { // 如果有token 添加token头
|
if (token) { // 如果有token 添加token头
|
||||||
header.token = token
|
header.token = token
|
||||||
}
|
}
|
||||||
@ -62,8 +61,8 @@ function request<T>(api: string, data: any = null, method: HttpMethod = 'POST')
|
|||||||
// 验证接口是否正确
|
// 验证接口是否正确
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
if (result.code === 403) {
|
if (result.code === 403) {
|
||||||
wx.switchTab({
|
wx.navigateTo({
|
||||||
url: '/pages/personal/personal'
|
url: '/pages/user/login'
|
||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
interface IAppOption {
|
interface IAppOption {
|
||||||
globalData: {
|
globalData: {
|
||||||
userInfo?: UserInfo,
|
userInfo?: WechatMiniprogram.UserInfo,
|
||||||
token?: string
|
token?: string
|
||||||
}
|
}
|
||||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user