对接后端接口
This commit is contained in:
parent
4dee28c5ab
commit
5d4f911643
13
app.js
13
app.js
|
@ -1,14 +1,17 @@
|
|||
const baseUrl = "http://localhost:8080"
|
||||
|
||||
App({
|
||||
onLaunch: function () {
|
||||
console.log('App Launch')
|
||||
console.log("App Launch")
|
||||
},
|
||||
onShow: function () {
|
||||
console.log('App Show')
|
||||
console.log("App Show")
|
||||
},
|
||||
onHide: function () {
|
||||
console.log('App Hide')
|
||||
console.log("App Hide")
|
||||
},
|
||||
globalData: {
|
||||
hasLogin: false
|
||||
}
|
||||
hasLogin: false,
|
||||
baseUrl: baseUrl,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,66 +1,67 @@
|
|||
const app = getApp()
|
||||
const baseUrl = app.globalData.baseUrl
|
||||
// page/component/new-pages/user/address/address.js
|
||||
Page({
|
||||
data:{
|
||||
address:{
|
||||
name:'',
|
||||
phone:'',
|
||||
detail:''
|
||||
}
|
||||
data: {
|
||||
address: {
|
||||
username: "",
|
||||
phone: "",
|
||||
address: "",
|
||||
},
|
||||
},
|
||||
onLoad(){
|
||||
var self = this;
|
||||
onLoad() {
|
||||
var self = this
|
||||
// 获取地址信息
|
||||
wx.request({
|
||||
url: 'http://localhost:8080/user/getById',
|
||||
method: 'GET',
|
||||
url: baseUrl + "/user/getById",
|
||||
method: "GET",
|
||||
data: {
|
||||
id:1
|
||||
id: 1,
|
||||
},
|
||||
success(res) {
|
||||
self.setData({
|
||||
address: res.data
|
||||
});
|
||||
}
|
||||
});
|
||||
wx.getStorage({
|
||||
key: 'address',
|
||||
success: function(res){
|
||||
self.setData({
|
||||
address : res.data
|
||||
address: res.data,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
wx.getStorage({
|
||||
key: "address",
|
||||
success: function (res) {
|
||||
self.setData({
|
||||
address: res.data,
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
formSubmit(e){
|
||||
const value = e.detail.value;
|
||||
if (value.name && value.phone && value.detail){
|
||||
formSubmit(e) {
|
||||
console.log(e, "e")
|
||||
const value = e.detail.value
|
||||
if (value.username && value.phone && value.address) {
|
||||
//保存地址
|
||||
wx.request({
|
||||
url: 'http://localhost:8080/user/addOrUpdate',
|
||||
method: 'POST',
|
||||
url: baseUrl + "/user/addOrUpdate",
|
||||
method: "POST",
|
||||
data: {
|
||||
id: value.id,
|
||||
name : value.name,
|
||||
phone: value.phone,
|
||||
address: value.detail
|
||||
...value,
|
||||
openId: "123123dasdas",
|
||||
},
|
||||
success(res) {
|
||||
console.log(res)
|
||||
}
|
||||
});
|
||||
wx.setStorage({
|
||||
key: 'address',
|
||||
data: value,
|
||||
success(){
|
||||
wx.navigateBack();
|
||||
}
|
||||
},
|
||||
})
|
||||
}else{
|
||||
wx.setStorage({
|
||||
key: "address",
|
||||
data: value,
|
||||
success() {
|
||||
wx.navigateBack()
|
||||
},
|
||||
})
|
||||
} else {
|
||||
wx.showModal({
|
||||
title:'提示',
|
||||
content:'请填写完整资料',
|
||||
showCancel:false
|
||||
title: "提示",
|
||||
content: "请填写完整资料",
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,39 +1,33 @@
|
|||
const app = getApp()
|
||||
Page({
|
||||
data: {
|
||||
imgUrls: [
|
||||
'/image/b1.jpg',
|
||||
'/image/b2.jpg',
|
||||
'/image/b3.jpg'
|
||||
],
|
||||
imgUrls: ["/image/b1.jpg", "/image/b2.jpg", "/image/b3.jpg"],
|
||||
indicatorDots: false,
|
||||
autoplay: false,
|
||||
interval: 3000,
|
||||
duration: 800,
|
||||
goods: {
|
||||
id: 1,
|
||||
image: [
|
||||
'/image/beizi1.jpg',
|
||||
'/image/beizi1.jpg'
|
||||
],
|
||||
title: '床上用品六件套',
|
||||
image: ["/image/beizi1.jpg", "/image/beizi1.jpg"],
|
||||
title: "床上用品六件套",
|
||||
price: 220,
|
||||
detail: '被子、褥子、枕头、三件套',
|
||||
detail: "被子、褥子、枕头、三件套",
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
var self = this;
|
||||
var self = this
|
||||
/**
|
||||
* 发起请求获取商品列表信息
|
||||
*/
|
||||
wx.request({
|
||||
// get请求
|
||||
url: 'http://localhost:8080/goods/loadData',
|
||||
url: app.globalData.baseUrl + "/goods/loadData",
|
||||
success(res) {
|
||||
self.setData({
|
||||
goods: res.data.data
|
||||
goods: res.data.data,
|
||||
})
|
||||
console.log(res,'res',res.data.data)
|
||||
}
|
||||
console.log(res, "res", res.data.data)
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const app = getApp()
|
||||
const baseUrl = app.globalData.baseUrl
|
||||
// page/component/orders/orders.js
|
||||
Page({
|
||||
// onLoad: function (options) {
|
||||
|
@ -10,40 +12,46 @@ Page({
|
|||
hasAddress: false,
|
||||
total: 0,
|
||||
orders: [
|
||||
{ id: 1, title: '新鲜芹菜 半斤', image: '/image/s5.png', num: 4, price: 0.01 },
|
||||
{
|
||||
id: 1,
|
||||
title: "新鲜芹菜 半斤",
|
||||
image: "/image/s5.png",
|
||||
num: 4,
|
||||
price: 0.01,
|
||||
},
|
||||
// {id:2,title:'素米 500g',image:'/image/s6.png',num:1,price:0.03}
|
||||
]
|
||||
],
|
||||
},
|
||||
onLoad() {
|
||||
var self = this;
|
||||
var self = this
|
||||
// 获取地址信息
|
||||
wx.request({
|
||||
url: 'http://localhost:8080/order/loadData',
|
||||
method: 'POST',
|
||||
url: baseUrl + "/order/loadData",
|
||||
method: "POST",
|
||||
data: {
|
||||
|
||||
userId: 1,
|
||||
},
|
||||
success(res) {
|
||||
self.setData({
|
||||
orders: res.data
|
||||
});
|
||||
}
|
||||
});
|
||||
orders: res.data,
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
onReady() {
|
||||
this.getTotalPrice();
|
||||
this.getTotalPrice()
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
const self = this;
|
||||
const self = this
|
||||
wx.getStorage({
|
||||
key: 'address',
|
||||
key: "address",
|
||||
success(res) {
|
||||
self.setData({
|
||||
address: res.data,
|
||||
hasAddress: true
|
||||
hasAddress: true,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -51,65 +59,65 @@ Page({
|
|||
* 计算总价
|
||||
*/
|
||||
getTotalPrice() {
|
||||
let orders = this.data.orders;
|
||||
let total = 0;
|
||||
let orders = this.data.orders
|
||||
let total = 0
|
||||
for (let i = 0; i < orders.length; i++) {
|
||||
total += orders[i].num * orders[i].price;
|
||||
total += orders[i].num * orders[i].price
|
||||
}
|
||||
this.setData({
|
||||
total: total
|
||||
total: total,
|
||||
})
|
||||
},
|
||||
|
||||
toPay() {
|
||||
const self = this;
|
||||
const self = this
|
||||
|
||||
// 假设订单信息在 this.data.orders 中
|
||||
const orderData = this.data.orders;
|
||||
const orderData = this.data.orders
|
||||
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '本系统只做演示,支付系统已屏蔽',
|
||||
text: 'center',
|
||||
title: "提示",
|
||||
content: "本系统只做演示,支付系统已屏蔽",
|
||||
text: "center",
|
||||
complete() {
|
||||
// 发送订单数据到后端
|
||||
wx.request({
|
||||
url: 'https://your-backend-api.com/orders', // 替换为你的后端API地址
|
||||
method: 'POST',
|
||||
url: baseUrl + "/order/addOrUpdate", // 替换为你的后端API地址
|
||||
method: "POST",
|
||||
data: {
|
||||
orders: orderData
|
||||
...orderData,
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json' // 设置请求头
|
||||
"Content-Type": "application/json", // 设置请求头
|
||||
},
|
||||
success(res) {
|
||||
if (res.statusCode === 200) {
|
||||
wx.showToast({
|
||||
title: '订单已提交',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
title: "订单已提交",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
})
|
||||
// 跳转到用户页面
|
||||
wx.switchTab({
|
||||
url: '/page/component/user/user'
|
||||
});
|
||||
url: "/page/component/user/user",
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '提交失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
title: "提交失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
wx.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
title: "请求失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const app = getApp()
|
||||
const baseUrl = app.globalData.baseUrl
|
||||
// page/component/orders/orders.js
|
||||
Page({
|
||||
onLoad: function (options) {
|
||||
|
@ -7,32 +9,32 @@ Page({
|
|||
price: options.price,
|
||||
num: options.num,
|
||||
image: options.image,
|
||||
};
|
||||
this.setData({ orders });
|
||||
}
|
||||
this.setData({ orders })
|
||||
},
|
||||
data: {
|
||||
address: {},
|
||||
hasAddress: false,
|
||||
total: 0,
|
||||
orders: {}
|
||||
// {id:1,title:'新鲜芹菜 半斤',image:'/image/s5.png',num:4,price:0.01},
|
||||
// {id:2,title:'素米 500g',image:'/image/s6.png',num:1,price:0.03}
|
||||
orders: {},
|
||||
// {id:1,title:'新鲜芹菜 半斤',image:'/image/s5.png',num:4,price:0.01},
|
||||
// {id:2,title:'素米 500g',image:'/image/s6.png',num:1,price:0.03}
|
||||
},
|
||||
|
||||
onReady() {
|
||||
this.getTotalPrice();
|
||||
this.getTotalPrice()
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
const self = this;
|
||||
const self = this
|
||||
wx.getStorage({
|
||||
key: 'address',
|
||||
key: "address",
|
||||
success(res) {
|
||||
self.setData({
|
||||
address: res.data,
|
||||
hasAddress: true
|
||||
hasAddress: true,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -40,65 +42,66 @@ Page({
|
|||
* 计算总价
|
||||
*/
|
||||
getTotalPrice() {
|
||||
let orders = this.data.orders;
|
||||
let total = 0;
|
||||
let orders = this.data.orders
|
||||
let total = 0
|
||||
for (let i = 0; i < orders.length; i++) {
|
||||
total += orders[i].num * orders[i].price;
|
||||
total += orders[i].num * orders[i].price
|
||||
}
|
||||
this.setData({
|
||||
total: total
|
||||
total: total,
|
||||
})
|
||||
},
|
||||
|
||||
toPay() {
|
||||
const self = this;
|
||||
const self = this
|
||||
|
||||
// 假设订单信息在 this.data.orders 中
|
||||
const orderData = this.data.orders;
|
||||
const orderData = this.data.orders
|
||||
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '本系统只做演示,支付系统已屏蔽',
|
||||
text: 'center',
|
||||
title: "提示",
|
||||
content: "本系统只做演示,支付系统已屏蔽",
|
||||
text: "center",
|
||||
complete() {
|
||||
// 发送订单数据到后端
|
||||
wx.request({
|
||||
url: 'https://your-backend-api.com/orders', // 替换为你的后端API地址
|
||||
method: 'POST',
|
||||
// TODO 未测试
|
||||
url: baseUrl + "/order/addOrUpdate", // 替换为你的后端API地址
|
||||
method: "POST",
|
||||
data: {
|
||||
orders: orderData
|
||||
...orderData,
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json' // 设置请求头
|
||||
"Content-Type": "application/json", // 设置请求头
|
||||
},
|
||||
success(res) {
|
||||
if (res.statusCode === 200) {
|
||||
wx.showToast({
|
||||
title: '订单已提交',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
title: "订单已提交",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
})
|
||||
// 跳转到用户页面
|
||||
wx.switchTab({
|
||||
url: '/page/component/user/user'
|
||||
});
|
||||
url: "/page/component/user/user",
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '提交失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
title: "提交失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
wx.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
title: "请求失败",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,77 +1,83 @@
|
|||
const app = getApp()
|
||||
const baseUrl = app.globalData.baseUrl
|
||||
// page/component/new-pages/user/user.js
|
||||
Page({
|
||||
data: {
|
||||
thumb: '',
|
||||
nickname: '',
|
||||
thumb: "",
|
||||
nickname: "",
|
||||
orders: [],
|
||||
hasAddress: false,
|
||||
address: {}
|
||||
address: {},
|
||||
},
|
||||
onLoad() {
|
||||
var self = this;
|
||||
var self = this
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善会员资料', // 这里必须声明用途
|
||||
desc: "用于完善会员资料", // 这里必须声明用途
|
||||
success: function (res) {
|
||||
self.setData({
|
||||
thumb: res.userInfo.avatarUrl,
|
||||
nickname: res.userInfo.nickName
|
||||
});
|
||||
nickname: res.userInfo.nickName,
|
||||
})
|
||||
// 你可以将用户信息发送到后端或缓存到本地
|
||||
},
|
||||
fail: function (err) {
|
||||
wx.showToast({
|
||||
title: '用户拒绝了授权',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
title: "用户拒绝了授权",
|
||||
icon: "none",
|
||||
})
|
||||
},
|
||||
})
|
||||
/**
|
||||
* 发起请求获取订单列表信息
|
||||
*/
|
||||
wx.request({
|
||||
url: 'http://www.gdfengshuo.com/api/wx/orders.txt',
|
||||
url: baseUrl + "/order/loadData",
|
||||
method: "POST",
|
||||
data: {
|
||||
userId: 1,
|
||||
},
|
||||
success(res) {
|
||||
self.setData({
|
||||
orders: res.data
|
||||
orders: res.data,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
* 获取用户信息
|
||||
*/
|
||||
getUserProfile() {
|
||||
var self = this;
|
||||
var self = this
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善会员资料', // 这里必须声明用途
|
||||
desc: "用于完善会员资料", // 这里必须声明用途
|
||||
success: function (res) {
|
||||
self.setData({
|
||||
thumb: res.userInfo.avatarUrl,
|
||||
nickname: res.userInfo.nickName
|
||||
});
|
||||
nickname: res.userInfo.nickName,
|
||||
})
|
||||
// 你可以将用户信息发送到后端或缓存到本地
|
||||
},
|
||||
fail: function (err) {
|
||||
wx.showToast({
|
||||
title: '用户拒绝了授权',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
title: "用户拒绝了授权",
|
||||
icon: "none",
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
onShow() {
|
||||
var self = this;
|
||||
var self = this
|
||||
/**
|
||||
* 获取本地缓存 地址信息
|
||||
*/
|
||||
wx.getStorage({
|
||||
key: 'address',
|
||||
key: "address",
|
||||
success: function (res) {
|
||||
self.setData({
|
||||
hasAddress: true,
|
||||
address: res.data
|
||||
address: res.data,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
/**
|
||||
|
@ -79,21 +85,21 @@ Page({
|
|||
*/
|
||||
payOrders() {
|
||||
wx.requestPayment({
|
||||
timeStamp: 'String1',
|
||||
nonceStr: 'String2',
|
||||
package: 'String3',
|
||||
signType: 'MD5',
|
||||
paySign: 'String4',
|
||||
timeStamp: "String1",
|
||||
nonceStr: "String2",
|
||||
package: "String3",
|
||||
signType: "MD5",
|
||||
paySign: "String4",
|
||||
success: function (res) {
|
||||
console.log(res)
|
||||
},
|
||||
fail: function (res) {
|
||||
wx.showModal({
|
||||
title: '支付提示',
|
||||
content: '<text>',
|
||||
showCancel: false
|
||||
title: "支付提示",
|
||||
content: "<text>",
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue