Merge branch 'pplok' of pplokijuhyg/deguodaigou into master

This commit is contained in:
pplokijuhyg 2019-12-19 14:31:12 +08:00
commit 3924510d78
4 changed files with 81 additions and 7 deletions

View File

@ -7,9 +7,41 @@ Page({
*/ */
data: { data: {
},
getinfo(a){
request({
url:"User/validateOpenid"
}).then((res)=>{
if(res.data.code == 400){
request({
url:"User/register",
data:{
country:"",
gender:0,
nick_name:a.detail.userInfo.nickName,
province:"",
city:"",
head_pic:a.detail.userInfo.avatarUrl,
open_id: wx.getStorageSync("openid"),
}
}).then((res)=>{
if(res.data.code == 200){
wx.switchTab({
url:"/pages/index/index"
})
}
})
}else{
wx.switchTab({
url:"/pages/index/index"
})
}
})
}, },
login(a){ login(a){
console.log(a) console.log(a)
let i = this
wx.login({ wx.login({
success (res) { success (res) {
if (res.code) { if (res.code) {
@ -21,6 +53,11 @@ Page({
} }
}).then((res)=>{ }).then((res)=>{
console.log(res) console.log(res)
wx.setStorageSync("openid",res.data.openid)
i.getinfo(a)
wx.switchTab({
url:"/pages/index/index"
})
}) })
} else { } else {
console.log('登录失败!' + res.errMsg) console.log('登录失败!' + res.errMsg)

View File

@ -1,4 +1,5 @@
// pages/personal/personal.js // pages/personal/personal.js.
import {request} from "../../utils/bin"
Page({ Page({
/** /**
@ -13,9 +14,7 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function(options) { onLoad: function(options) {
this.setData({
openid:wx.getStorageSync("openid")
})
}, },
toorder() { toorder() {
wx.navigateTo({ wx.navigateTo({
@ -57,6 +56,13 @@ Page({
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
login(){
if(this.data.openid == ""){
wx.navigateTo({
url:"/pages/login/login"
})
}
},
onReady: function() { onReady: function() {
}, },
@ -65,7 +71,14 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function() { onShow: function() {
this.setData({
openid:wx.getStorageSync("openid")
})
request({
url:"User/validateOpenid"
}).then((res)=>{
console.log(res)
})
}, },
/** /**

View File

@ -1,18 +1,38 @@
// pages/shopping/shopping.js // pages/shopping/shopping.js
import {request} from "../../utils/bin"
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
list:[1,1,1] list:[1,1,1],
userid:0
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
getlist(){
request({
url:"Cart/cartList/session_id/" + wx.getStorageSync('openid'),
data:{
user_id:this.data.userid
}
}).then((res)=>{
console.log(res)
})
},
onLoad: function(options) { onLoad: function(options) {
request({
url:"User/validateOpenid"
}).then((res)=>{
console.log(res)
this.setData({
userid:res.data.data.user_id
})
this.getlist()
})
}, },
sub() { sub() {
wx.navigateTo({ wx.navigateTo({

View File

@ -16,6 +16,10 @@ let request = function (obj){
} }
header['content-type'] = "application/x-www-form-urlencoded" header['content-type'] = "application/x-www-form-urlencoded"
} }
if(data == undefined){
data = {}
}
data.openid = wx.getStorageSync("openid")
return new Promise((res,rej)=>{ return new Promise((res,rej)=>{
wx.request({ wx.request({
url, url,