Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhqg-mini
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhqg
zhqg-mini
Commits
306fed17
Commit
306fed17
authored
Oct 19, 2020
by
wangyalan-git
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录流程修改/分享码上下级修改
parent
52207aa2
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
165 additions
and
137 deletions
+165
-137
app.js
app.js
+13
-10
index.js
pages/index/index.js
+41
-36
login.js
pages/login/login.js
+83
-5
login.json
pages/login/login.json
+3
-1
user.js
pages/user/user.js
+4
-1
user.wxml
pages/user/user.wxml
+4
-2
user.wxss
pages/user/user.wxss
+4
-1
config.js
utils/config.js
+1
-1
http.js
utils/http.js
+12
-80
No files found.
app.js
View file @
306fed17
...
@@ -2,18 +2,21 @@
...
@@ -2,18 +2,21 @@
var
http
=
require
(
"utils/http.js"
);
var
http
=
require
(
"utils/http.js"
);
App
({
App
({
onLaunch
:
function
()
{
onLaunch
:
function
()
{
http
.
getToken
();
wx
.
getSetting
({
success
(
res
)
{
if
(
!
res
.
authSetting
[
'scope.userInfo'
])
{
wx
.
navigateTo
({
url
:
'/pages/login/login'
,
})
}
}
})
this
.
overShare
()
this
.
overShare
()
},
},
onShow
()
{
const
token
=
wx
.
getStorageSync
(
'token'
)
if
(
token
)
{
let
user
=
wx
.
getStorageSync
(
'user'
)
this
.
globalData
.
userInfo
=
JSON
.
parse
(
user
)
}
},
goLogin
:
function
()
{
console
.
log
(
"登录"
)
wx
.
navigateTo
({
url
:
'/pages/login/login'
,
})
},
//重写分享方法
//重写分享方法
overShare
:
function
()
{
overShare
:
function
()
{
//监听路由切换
//监听路由切换
...
...
pages/index/index.js
View file @
306fed17
...
@@ -25,10 +25,43 @@ Page({
...
@@ -25,10 +25,43 @@ Page({
})
})
},
},
onLoad
:
function
()
{
onLoad
:
function
()
{
let
token
=
wx
.
getStorageSync
(
'token'
)
this
.
getAllData
();
this
.
getAllData
();
// 如果是点击转发跳转进来,分析参数page
if
(
options
.
shareCode
)
{
app
.
globalData
.
shareCode
=
options
.
shareCode
token
&&
this
.
boundParentByShareCode
(
options
.
shareCode
);
// 绑定内容获取
}
// 登录返回
app
.
globalData
.
shareCode
&&
token
&&
this
.
boundParentByShareCode
(
app
.
globalData
.
shareCode
);
// 扫码页面渲染完成
if
(
options
.
scene
)
{
let
scene
=
decodeURIComponent
(
options
.
scene
);
app
.
globalData
.
shareCode
=
scene
.
split
(
"="
)[
1
];
token
&&
this
.
boundParentByShareCode
(
app
.
globalData
.
shareCode
)
}
},
},
bound
()
{
var
token
=
wx
.
getStorageSync
(
'token'
);
if
(
token
)
{
app
.
globalData
.
shareCode
=
options
.
shareCode
}
},
boundParentByShareCode
(
code
)
{
var
params
=
{
url
:
"/p/user/boundParentByShareCode"
,
method
:
"POST"
,
data
:
{
shareCode
:
code
},
callBack
:
(
res
)
=>
{
app
.
globalData
.
shareCode
=
''
console
.
log
(
"绑定成功"
,
res
)
}
};
http
.
request
(
params
);
},
// 页面滚动到指定位置指定元素固定在顶部
// 页面滚动到指定位置指定元素固定在顶部
onPageScroll
:
function
(
e
)
{
//监听页面滚动
onPageScroll
:
function
(
e
)
{
//监听页面滚动
this
.
setData
({
this
.
setData
({
...
@@ -80,43 +113,15 @@ Page({
...
@@ -80,43 +113,15 @@ Page({
},
},
onShow
:
function
()
{
onShow
:
function
()
{
console
.
log
(
'页面参路径'
,
this
.
options
)
console
.
log
(
'页面参数路径'
,
this
.
options
)
var
that
=
this
wx
.
getSetting
({
success
(
res
)
{
if
(
!
res
.
authSetting
[
'scope.userInfo'
])
{
if
(
that
.
options
.
shareCode
)
{
wx
.
navigateTo
({
url
:
'/pages/login/login?shareCode='
+
that
.
options
.
shareCode
,
})
}
else
{
wx
.
navigateTo
({
url
:
'/pages/login/login'
,
})
}
}
else
{
if
(
that
.
options
.
shareCode
)
{
that
.
boundParentByShareCode
(
options
.
shareCode
);
// 绑定内容获取
}
}
}
})
},
boundParentByShareCode
(
code
)
{
var
params
=
{
url
:
"/p/user/boundParentByShareCode"
,
method
:
"POST"
,
data
:
{
shareCode
:
code
},
callBack
:
(
res
)
=>
{
console
.
log
(
"绑定成功"
,
res
)
}
};
http
.
request
(
params
);
},
},
getAllData
()
{
getAllData
()
{
http
.
getCartCount
();
//重新计算购物车总数量
let
user
=
app
.
globalData
.
userInfo
if
(
user
&&
user
.
id
)
{
http
.
getCartCount
();
//重新计算购物车总数量
}
this
.
getIndexImgs
();
this
.
getIndexImgs
();
this
.
getNoticeList
();
this
.
getNoticeList
();
this
.
getTag
();
this
.
getTag
();
...
...
pages/login/login.js
View file @
306fed17
...
@@ -8,10 +8,88 @@ Page({
...
@@ -8,10 +8,88 @@ Page({
},
},
onGotUserInfo
:
function
(
res
)
{
onGotUserInfo
:
function
(
data
)
{
http
.
updateUserInfo
();
const
that
=
this
,
userInfo
=
data
.
detail
.
userInfo
wx
.
navigateBack
({
this
.
data
.
wxUserInfo
=
data
.
detail
.
userInfo
delta
:
1
console
.
log
(
'info'
,
data
.
detail
.
userInfo
)
if
(
userInfo
)
{
this
.
getToken
()
}
},
//通过code获取token,并保存到缓存
getToken
:
function
()
{
console
.
log
(
'getToken'
)
wx
.
login
({
success
:
res
=>
{
console
.
log
(
'token1'
,
res
)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
http
.
request
({
login
:
true
,
url
:
'/login?grant_type=mini_app'
,
data
:
{
principal
:
res
.
code
},
callBack
:
result
=>
{
console
.
log
(
'token2'
,
result
)
// 没有获取到用户昵称,说明服务器没有保存用户的昵称,也就是用户授权的信息并没有传到服务器
if
(
!
result
.
nickName
)
{
updateUserInfo
();
}
if
(
result
.
userStutas
==
0
)
{
wx
.
showModal
({
showCancel
:
false
,
title
:
'提示'
,
content
:
'您已被禁用,不能购买,请联系客服'
})
wx
.
setStorageSync
(
'token'
,
''
);
}
else
{
wx
.
setStorageSync
(
'token'
,
'bearer'
+
result
.
access_token
);
//把token存入缓存,请求接口数据时要用
this
.
getUserInfo
()
}
var
globalData
=
getApp
().
globalData
;
globalData
.
isLanding
=
false
;
while
(
globalData
.
requestQueue
.
length
)
{
http
.
request
(
globalData
.
requestQueue
.
pop
());
}
}
},
true
)
}
})
},
// 用户信息
getUserInfo
()
{
var
params
=
{
url
:
"/p/user/getUserInfo"
,
method
:
"GET"
,
data
:
{},
callBack
:
(
res
)
=>
{
console
.
log
(
'用户信息'
,
res
.
result
)
var
app
=
getApp
();
wx
.
setStorageSync
(
"user"
,
JSON
.
stringify
(
res
.
result
))
app
.
globalData
.
userInfo
=
res
.
result
wx
.
switchTab
({
url
:
'/pages/index/index'
,
})
}
};
http
.
request
(
params
);
},
// 更新用户头像昵称
updateUserInfo
:
function
()
{
wx
.
getUserInfo
({
success
:
(
res
)
=>
{
var
userInfo
=
JSON
.
parse
(
res
.
rawData
)
http
.
request
({
url
:
"/p/user/setUserInfo"
,
method
:
"PUT"
,
data
:
{
avatarUrl
:
userInfo
.
avatarUrl
,
nickName
:
userInfo
.
nickName
}
});
}
})
})
},
},
boundParentByShareCode
(
code
)
{
boundParentByShareCode
(
code
)
{
...
@@ -22,7 +100,7 @@ Page({
...
@@ -22,7 +100,7 @@ Page({
shareCode
:
code
shareCode
:
code
},
},
callBack
:
(
res
)
=>
{
callBack
:
(
res
)
=>
{
console
.
log
(
"绑定成功"
,
res
)
console
.
log
(
"绑定成功"
,
res
)
}
}
};
};
http
.
request
(
params
);
http
.
request
(
params
);
...
...
pages/login/login.json
View file @
306fed17
{
{
"usingComponents"
:
{}
"usingComponents"
:
{},
"navigationBarTitleText"
:
"登录"
}
}
\ No newline at end of file
pages/user/user.js
View file @
306fed17
// pages/user/user.js
// pages/user/user.js
var
http
=
require
(
"../../utils/http.js"
);
var
http
=
require
(
"../../utils/http.js"
);
var
app
=
getApp
()
Page
({
Page
({
/**
/**
...
@@ -31,7 +32,9 @@ Page({
...
@@ -31,7 +32,9 @@ Page({
* 生命周期函数--监听页面显示
* 生命周期函数--监听页面显示
*/
*/
onShow
:
function
()
{
onShow
:
function
()
{
this
.
setData
({
userInfo
:
app
.
globalData
.
userInfo
})
//加载订单数字
//加载订单数字
var
ths
=
this
;
var
ths
=
this
;
// var status = ths.data.status
// var status = ths.data.status
...
...
pages/user/user.wxml
View file @
306fed17
...
@@ -3,10 +3,12 @@
...
@@ -3,10 +3,12 @@
<!-- 用户信息 -->
<!-- 用户信息 -->
<view class='userinfo'>
<view class='userinfo'>
<view class='userinfo-avatar'>
<view class='userinfo-avatar'>
<open-data type="userAvatarUrl"></open-data>
<!-- <open-data type="userAvatarUrl"></open-data> -->
<image class="user-icon" src="{{userInfo.pic}}"></image>
</view>
</view>
<view class='userinfo-name'>
<view class='userinfo-name'>
<open-data type="userNickName"></open-data>
<!-- <open-data type="userNickName"></open-data> -->
<view>{{userInfo.nickName || '未登录'}}</view>
</view>
</view>
</view>
</view>
<view class="prod-col" style="margin-top: 0;padding-top: 0;">
<view class="prod-col" style="margin-top: 0;padding-top: 0;">
...
...
pages/user/user.wxss
View file @
306fed17
...
@@ -24,7 +24,10 @@ page {
...
@@ -24,7 +24,10 @@ page {
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
margin: auto;
margin: auto;
}
}
.userinfo .userinfo-avatar .user-icon{
width: 100%;
height: 100%;
}
.userinfo .userinfo-name {
.userinfo .userinfo-name {
font-size: 30rpx;
font-size: 30rpx;
font-weight: bold;
font-weight: bold;
...
...
utils/config.js
View file @
306fed17
var
domain
=
"http://192.168.31.1
13
:8086/capi"
;
//统一接口域名,测试环境
var
domain
=
"http://192.168.31.1
08
:8086/capi"
;
//统一接口域名,测试环境
exports
.
domain
=
domain
;
exports
.
domain
=
domain
;
utils/http.js
View file @
306fed17
...
@@ -5,10 +5,11 @@ function request(params, isGetTonken) {
...
@@ -5,10 +5,11 @@ function request(params, isGetTonken) {
// 全局变量
// 全局变量
var
globalData
=
getApp
().
globalData
;
var
globalData
=
getApp
().
globalData
;
// 如果正在进行登陆,就将非登陆请求放在队列中等待登陆完毕后进行调用
// 如果正在进行登陆,就将非登陆请求放在队列中等待登陆完毕后进行调用
if
(
!
isGetTonken
&&
globalData
.
isLanding
)
{
// if (!isGetTonken && globalData.isLanding) {
globalData
.
requestQueue
.
push
(
params
);
// console.log('shibai')
return
;
// globalData.requestQueue.push(params);
}
// return;
// }
wx
.
request
({
wx
.
request
({
url
:
config
.
domain
+
params
.
url
,
//接口请求地址
url
:
config
.
domain
+
params
.
url
,
//接口请求地址
data
:
params
.
data
,
data
:
params
.
data
,
...
@@ -35,11 +36,11 @@ function request(params, isGetTonken) {
...
@@ -35,11 +36,11 @@ function request(params, isGetTonken) {
// 添加到请求队列
// 添加到请求队列
globalData
.
requestQueue
.
push
(
params
);
globalData
.
requestQueue
.
push
(
params
);
// 是否正在登陆
// 是否正在登陆
if
(
!
globalData
.
isLanding
)
{
//
if (!globalData.isLanding) {
globalData
.
isLanding
=
true
globalData
.
isLanding
=
true
//重新获取token,再次请求接口
//重新获取token,再次请求接口
getToken
();
getApp
().
goLogin
()
}
//
}
}
else
if
(
res
.
statusCode
==
400
)
{
}
else
if
(
res
.
statusCode
==
400
)
{
wx
.
showToast
({
wx
.
showToast
({
title
:
res
.
data
,
title
:
res
.
data
,
...
@@ -66,74 +67,7 @@ function request(params, isGetTonken) {
...
@@ -66,74 +67,7 @@ function request(params, isGetTonken) {
})
})
}
}
//通过code获取token,并保存到缓存
var
getToken
=
function
()
{
wx
.
login
({
success
:
res
=>
{
// 发送 res.code 到后台换取 openId, sessionKey, unionId
request
({
login
:
true
,
url
:
'/login?grant_type=mini_app'
,
data
:
{
principal
:
res
.
code
},
callBack
:
result
=>
{
// 没有获取到用户昵称,说明服务器没有保存用户的昵称,也就是用户授权的信息并没有传到服务器
if
(
!
result
.
nickName
)
{
updateUserInfo
();
}
if
(
result
.
userStutas
==
0
)
{
wx
.
showModal
({
showCancel
:
false
,
title
:
'提示'
,
content
:
'您已被禁用,不能购买,请联系客服'
})
wx
.
setStorageSync
(
'token'
,
''
);
}
else
{
wx
.
setStorageSync
(
'token'
,
'bearer'
+
result
.
access_token
);
//把token存入缓存,请求接口数据时要用
getUserInfo
()
}
var
globalData
=
getApp
().
globalData
;
globalData
.
isLanding
=
false
;
while
(
globalData
.
requestQueue
.
length
)
{
request
(
globalData
.
requestQueue
.
pop
());
}
}
},
true
)
}
})
}
// 用户信息
function
getUserInfo
()
{
var
params
=
{
url
:
"/p/user/getUserInfo"
,
method
:
"GET"
,
data
:
{},
callBack
:
(
res
)
=>
{
console
.
log
(
'用户信息'
,
res
.
result
)
var
app
=
getApp
();
app
.
globalData
.
userInfo
=
res
.
result
}
};
request
(
params
);
}
// 更新用户头像昵称
function
updateUserInfo
()
{
wx
.
getUserInfo
({
success
:
(
res
)
=>
{
var
userInfo
=
JSON
.
parse
(
res
.
rawData
)
request
({
url
:
"/p/user/setUserInfo"
,
method
:
"PUT"
,
data
:
{
avatarUrl
:
userInfo
.
avatarUrl
,
nickName
:
userInfo
.
nickName
}
});
}
})
}
//获取购物车商品数量
//获取购物车商品数量
function
getCartCount
()
{
function
getCartCount
()
{
...
@@ -162,7 +96,5 @@ function getCartCount() {
...
@@ -162,7 +96,5 @@ function getCartCount() {
}
}
exports
.
getToken
=
getToken
;
exports
.
request
=
request
;
exports
.
request
=
request
;
exports
.
getCartCount
=
getCartCount
;
exports
.
getCartCount
=
getCartCount
;
exports
.
updateUserInfo
=
updateUserInfo
;
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment