Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
learn-online
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
learn-online
Commits
eaa4f85e
提交
eaa4f85e
authored
6月 26, 2023
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: 登录优化
上级
118dd92d
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
61 行增加
和
25 行删除
+61
-25
base.js
learnOnline/api/base.js
+2
-2
app.js
learnOnline/app.js
+26
-3
home.js
learnOnline/pages/learnSystem/home/home.js
+0
-3
account.js
learnOnline/pages/login/account.js
+4
-2
index.js
learnOnline/pages/login/components/bindAccount/index.js
+5
-2
index.js
learnOnline/pages/login/components/bindPhone/index.js
+5
-2
index.js
learnOnline/pages/login/index.js
+8
-3
phone.js
learnOnline/pages/login/phone.js
+4
-2
request.js
learnOnline/utils/request.js
+7
-6
没有找到文件。
learnOnline/api/base.js
浏览文件 @
eaa4f85e
...
...
@@ -7,8 +7,8 @@ export function getPageShowStatus() {
}
// 获取用户信息
export
function
getUser
()
{
return
httpRequest
.
get
(
'/api/lms/user/getinfo'
)
export
function
getUser
(
params
)
{
return
httpRequest
.
get
(
'/api/lms/user/getinfo'
,
params
)
}
// 退出登录
...
...
learnOnline/app.js
浏览文件 @
eaa4f85e
...
...
@@ -2,10 +2,13 @@ import * as api from './api/base.js'
App
({
store
:
{
token
:
''
,
pageshow
:
false
,
user
:
{}
// 用户信息
},
onLaunch
:
function
()
{},
onLaunch
()
{
this
.
store
.
token
=
wx
.
getStorageSync
(
'token'
)
},
onPageNotFound
()
{
wx
.
redirectTo
({
url
:
'pages/login/index'
})
},
...
...
@@ -23,8 +26,8 @@ App({
})
},
// 获取用户信息
getUser
()
{
return
api
.
getUser
().
then
(
response
=>
{
getUser
(
params
)
{
return
api
.
getUser
(
params
).
then
(
response
=>
{
this
.
store
.
user
=
response
wx
.
setStorage
({
key
:
'uid'
,
data
:
response
.
id
})
wx
.
setStorage
({
key
:
'sid'
,
data
:
response
.
student_info
.
id
})
...
...
@@ -36,5 +39,25 @@ App({
return
api
.
logout
().
then
(
response
=>
{
wx
.
removeStorageSync
(
'token'
)
})
},
setToken
(
token
)
{
this
.
store
.
token
=
token
try
{
wx
.
setStorageSync
(
'token'
,
token
)
}
catch
(
e
)
{
wx
.
showToast
({
title
:
'Token 存储失败'
,
icon
:
'error'
})
console
.
log
(
e
)
}
},
// 检查权限
async
checkAccess
(
token
)
{
if
(
token
)
this
.
setToken
(
token
)
try
{
const
user
=
await
this
.
getUser
({
check
:
true
})
return
!!
user
?.
id
}
catch
(
error
)
{
console
.
log
(
error
)
return
false
}
}
})
learnOnline/pages/learnSystem/home/home.js
浏览文件 @
eaa4f85e
// pages/learnSystem/home/home.js
const
CourseApi
=
require
(
'../../../apiService/CourseApi.js'
)
const
app
=
getApp
()
Page
({
/**
...
...
@@ -53,8 +52,6 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
// 获取用户信息
app
.
getUser
()
wx
.
showLoading
({
title
:
'页面加载中...'
,
mask
:
true
})
CourseApi
.
getlearnFindList
((
_
)
=>
{
this
.
setData
({
'find[0].arrItem'
:
_
})
...
...
learnOnline/pages/login/account.js
浏览文件 @
eaa4f85e
import
*
as
api
from
'./api.js'
const
app
=
getApp
()
Page
({
data
:
{
...
...
@@ -34,8 +35,9 @@ Page({
},
// 登录成功
handleSuccess
(
data
)
{
wx
.
setStorage
({
key
:
'token'
,
data
:
data
.
TGC
})
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
app
.
checkAccess
(
data
.
TGC
).
then
(
isAuth
=>
{
if
(
isAuth
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
},
handlePassword
()
{
wx
.
navigateTo
({
url
:
'/pages/login/password'
})
...
...
learnOnline/pages/login/components/bindAccount/index.js
浏览文件 @
eaa4f85e
import
*
as
api
from
'../../api'
const
app
=
getApp
()
Component
({
/**
* 组件的属性列表
...
...
@@ -42,8 +44,9 @@ Component({
},
// 登录成功
handleSuccess
(
data
)
{
wx
.
setStorage
({
key
:
'token'
,
data
:
data
.
TGC
})
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
app
.
checkAccess
(
data
.
TGC
).
then
(
isAuth
=>
{
if
(
isAuth
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
}
}
})
learnOnline/pages/login/components/bindPhone/index.js
浏览文件 @
eaa4f85e
import
*
as
api
from
'../../api'
const
app
=
getApp
()
Component
({
/**
* 组件的属性列表
...
...
@@ -43,8 +45,9 @@ Component({
},
// 登录成功
handleSuccess
(
data
)
{
wx
.
setStorage
({
key
:
'token'
,
data
:
data
.
TGC
})
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
app
.
checkAccess
(
data
.
TGC
).
then
(
isAuth
=>
{
if
(
isAuth
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
},
// 发送验证码
handleSendCode
()
{
...
...
learnOnline/pages/login/index.js
浏览文件 @
eaa4f85e
import
*
as
api
from
'./api'
const
app
=
getApp
()
Page
({
/**
...
...
@@ -13,6 +14,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
app
.
checkAccess
().
then
(
isLogin
=>
{
if
(
isLogin
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
// 授权过的自动登录
// wx.getSetting({
// success: res => {
...
...
@@ -63,7 +67,7 @@ Page({
},
// 微信登录
wechatLogin
()
{
// 获取code
// 获取code
const
p1
=
this
.
getCode
()
// 获取用户信息
const
p2
=
this
.
getUserInfo
()
...
...
@@ -91,7 +95,8 @@ Page({
},
// 登录成功
handleSuccess
(
data
)
{
wx
.
setStorage
({
key
:
'token'
,
data
:
data
.
TGC
})
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
app
.
checkAccess
(
data
.
TGC
).
then
(
isAuth
=>
{
if
(
isAuth
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
}
})
learnOnline/pages/login/phone.js
浏览文件 @
eaa4f85e
import
*
as
api
from
'./api.js'
const
app
=
getApp
()
Page
({
data
:
{
...
...
@@ -35,8 +36,9 @@ Page({
},
// 登录成功
handleSuccess
(
data
)
{
wx
.
setStorage
({
key
:
'token'
,
data
:
data
.
TGC
})
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
app
.
checkAccess
(
data
.
TGC
).
then
(
isAuth
=>
{
if
(
isAuth
)
wx
.
switchTab
({
url
:
'/pages/learnSystem/home/home'
})
})
},
// 发送验证码
handleSendCode
()
{
...
...
learnOnline/utils/request.js
浏览文件 @
eaa4f85e
...
...
@@ -69,7 +69,8 @@ const httpRequest = new Request()
httpRequest
.
defaults
.
baseURL
=
apiBaseURL
httpRequest
.
defaults
.
headers
.
tenant
=
tenant
httpRequest
.
beforeRequest
=
function
(
config
)
{
config
.
headers
.
token
=
wx
.
getStorageSync
(
'token'
)
const
app
=
getApp
()
config
.
headers
.
token
=
app
?
app
.
store
.
token
:
wx
.
getStorageSync
(
'token'
)
return
config
}
// 成功处理
...
...
@@ -82,12 +83,12 @@ httpRequest.defaults.fail = (res, config) => {
wx
.
showToast
({
title
:
'接口请求失败,请检查网络设置'
,
icon
:
'none'
})
return
res
}
if
(
res
.
data
.
status
===
403
)
{
// 未登录
wx
.
redirectTo
({
url
:
'/pages/login/index'
})
return
// 未登录
if
(
!
config
.
data
.
check
&&
(
res
.
data
.
status
===
403
||
res
.
data
.
status
===
401
))
{
setTimeout
(()
=>
wx
.
redirectTo
({
url
:
'/pages/login/index'
}),
2000
)
}
wx
.
showToast
({
title
:
res
.
data
.
message
,
icon
:
'none'
})
return
res
.
data
}
// 导出
module
.
exports
=
httpRequest
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论