Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
learn-online-pc
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
learn-online-pc
Commits
c5c5cc55
提交
c5c5cc55
authored
5月 19, 2020
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug fixes
上级
79ad72c7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
63 行删除
+69
-63
base_api.js
client/src/api/base_api.js
+66
-55
Before.js
client/src/components/beforeEnter/Before.js
+1
-6
course.vue
client/src/pages/learn/course.vue
+2
-2
没有找到文件。
client/src/api/base_api.js
浏览文件 @
c5c5cc55
...
@@ -4,7 +4,7 @@ import _ from 'lodash'
...
@@ -4,7 +4,7 @@ import _ from 'lodash'
import
{
MessageBox
,
Message
}
from
'element-ui'
import
{
MessageBox
,
Message
}
from
'element-ui'
export
default
class
API
{
export
default
class
API
{
constructor
(
config
)
{
constructor
(
config
)
{
/* 创建一个 自定义配置axios实例 */
/* 创建一个 自定义配置axios实例 */
// 让ajax携带cookie
// 让ajax携带cookie
axios
.
defaults
.
withCredentials
=
true
axios
.
defaults
.
withCredentials
=
true
...
@@ -24,14 +24,16 @@ export default class API {
...
@@ -24,14 +24,16 @@ export default class API {
}
}
/* 获取当前Vue创建实例 */
/* 获取当前Vue创建实例 */
getVueInstance
()
{
getVueInstance
()
{
return
window
.
G
.
$instance_vue
return
window
.
G
.
$instance_vue
}
}
/* 重新封装 请求时的执行函数 */
/* 重新封装 请求时的执行函数 */
_request
(
_config
=
{})
{
_request
(
_config
=
{})
{
/* 具体执行请求成功后业务逻辑前,先执行该方法 */
/* 具体执行请求成功后业务逻辑前,先执行该方法 */
const
beforeSuccess
=
_config
.
beforeSuccess
?
_config
.
beforeSuccess
:
this
.
_reqSuccess
const
beforeSuccess
=
_config
.
beforeSuccess
?
_config
.
beforeSuccess
:
this
.
_reqSuccess
/* 具体执行请求失败后业务逻辑前,先执行该方法 */
/* 具体执行请求失败后业务逻辑前,先执行该方法 */
const
beforeFail
=
_config
.
beforeFail
?
_config
.
beforeFail
:
this
.
_reqFail
const
beforeFail
=
_config
.
beforeFail
?
_config
.
beforeFail
:
this
.
_reqFail
const
headers
=
{
const
headers
=
{
...
@@ -40,7 +42,9 @@ export default class API {
...
@@ -40,7 +42,9 @@ export default class API {
}
}
_config
.
headers
=
_
.
assignIn
(
_config
.
headers
,
headers
)
_config
.
headers
=
_
.
assignIn
(
_config
.
headers
,
headers
)
/* 判别 传输方式 */
/* 判别 传输方式 */
if
(
_config
.
headers
[
'Content-Type'
]
===
'application/x-www-form-urlencoded'
)
{
if
(
_config
.
headers
[
'Content-Type'
]
===
'application/x-www-form-urlencoded'
)
{
let
str
=
''
let
str
=
''
const
_obj
=
_config
.
data
||
_config
.
params
const
_obj
=
_config
.
data
||
_config
.
params
for
(
const
key
in
_obj
)
{
for
(
const
key
in
_obj
)
{
...
@@ -62,11 +66,13 @@ export default class API {
...
@@ -62,11 +66,13 @@ export default class API {
_config
.
data
=
fr
_config
.
data
=
fr
}
}
/* 创建并根据参数发起请求 */
/* 创建并根据参数发起请求 */
return
this
.
_axios
(
_config
)
return
this
.
_axios
(
_config
).
then
(
.
then
(
beforeSuccess
.
bind
(
this
),
beforeFail
.
bind
(
this
))
beforeSuccess
.
bind
(
this
),
beforeFail
.
bind
(
this
)
)
}
}
setConfirm
(
titleStr
,
btnStr
,
msgStr
)
{
setConfirm
(
titleStr
,
btnStr
,
msgStr
)
{
return
MessageBox
.
confirm
(
msgStr
,
titleStr
,
{
return
MessageBox
.
confirm
(
msgStr
,
titleStr
,
{
confirmButtonText
:
btnStr
,
confirmButtonText
:
btnStr
,
type
:
'warning'
,
type
:
'warning'
,
...
@@ -77,12 +83,16 @@ export default class API {
...
@@ -77,12 +83,16 @@ export default class API {
})
})
}
}
goLoginIndex
(
_vIn
)
{
goLoginIndex
(
_vIn
)
{
const
href
=
window
.
location
.
href
const
href
=
window
.
location
.
href
if
(
/
\/
login
\/
index/gi
.
test
(
href
))
{
if
(
/
\/
login
\/
index/gi
.
test
(
href
))
{
_vIn
.
$router
.
go
(
0
)
_vIn
.
$router
.
go
(
0
)
}
else
{
}
else
{
_vIn
.
$router
.
push
({
path
:
'/login/index?rd='
+
encodeURIComponent
(
href
.
replace
(
/.*
?\/\/
.*
?\/
/gi
,
'/'
))
})
_vIn
.
$router
.
push
({
path
:
'/login/index?rd='
+
encodeURIComponent
(
href
.
replace
(
/.*
?\/\/
.*
?\/
/gi
,
'/'
))
})
}
}
}
}
...
@@ -91,35 +101,15 @@ export default class API {
...
@@ -91,35 +101,15 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 返回数据
* @param {[object]} res 返回数据
*/
*/
_reqSuccess
(
res
)
{
_reqSuccess
(
res
)
{
const
_vIn
=
this
.
getVueInstance
()
const
{
data
}
=
res
const
{
status
,
data
}
=
res
/* 带 code 参数,新接口模型 */
if
(
status
===
200
)
{
if
(
data
.
code
!==
undefined
)
{
if
(
/util
\/
kaosx/gi
.
test
(
res
.
config
.
url
))
{
if
(
data
.
code
!==
0
&&
!
/get-user-info$/gi
.
test
(
res
.
config
.
url
))
{
return
data
data
.
msg
&&
Message
({
type
:
'error'
,
message
:
data
.
msg
})
}
/* 针对 不同的 接口做一下 统一处理 */
/* 带 code 参数,新接口模型 */
if
(
data
&&
data
.
code
!==
undefined
)
{
if
(
data
.
code
!==
0
)
{
if
(
!
/account
\/
get-user-info/gi
.
test
(
res
.
config
.
url
))
{
data
.
msg
&&
Message
({
type
:
'error'
,
message
:
data
.
msg
})
}
}
}
}
return
data
}
else
if
(
status
===
403
&&
!
/
\/
getinfo$/gi
.
test
(
res
.
config
.
url
))
{
/* 不带 code 参数,老接口模型 */
this
.
setConfirm
(
'提示'
,
'确定'
,
'登录状态已过期, 请重新登录。'
).
then
(()
=>
{
this
.
goLoginIndex
(
_vIn
)
}).
catch
(()
=>
{
Message
({
type
:
'info'
,
message
:
'操作已取消,将不再记录任何数据操作,除非重新登录'
})
})
}
else
if
(
status
!==
200
&&
data
.
message
)
{
throw
new
Error
(
data
.
message
)
}
else
{
throw
new
Error
(
JSON
.
stringify
(
res
.
data
))
}
}
return
data
}
}
/**
/**
...
@@ -127,28 +117,32 @@ export default class API {
...
@@ -127,28 +117,32 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 如果未到达 response 阶段,则无res.response
* @param {[object]} res 如果未到达 response 阶段,则无res.response
*/
*/
_reqFail
(
res
)
{
_reqFail
(
res
)
{
const
_vIn
=
this
.
getVueInstance
()
const
_vIn
=
this
.
getVueInstance
()
let
err
=
null
let
err
=
null
if
(
res
.
code
===
'ECONNABORTED'
)
{
if
(
res
.
code
===
'ECONNABORTED'
)
{
err
=
new
Error
(
'网络超时,请稍后重试'
)
err
=
new
Error
(
'网络超时,请稍后重试'
)
}
else
if
(
res
.
response
)
{
}
else
if
(
res
.
response
)
{
const
{
status
,
data
}
=
res
.
response
/* 不带 code 参数,老接口模型 */
/* 不带 code 参数,老接口模型 */
if
(
res
.
response
.
data
)
{
if
(
data
)
{
if
(
!
/
\/
getinfo$/gi
.
test
(
res
.
config
.
url
)
&&
res
.
response
.
status
===
403
)
{
if
(
status
===
403
&&
!
/check-access$/gi
.
test
(
res
.
config
.
url
))
{
this
.
setConfirm
(
'提示'
,
'确定'
,
'登录状态已过期, 请重新登录。'
).
then
(()
=>
{
this
.
setConfirm
(
'提示'
,
'确定'
,
'登录状态已过期, 请重新登录。'
)
this
.
goLoginIndex
(
_vIn
)
.
then
(()
=>
{
}).
catch
(()
=>
{
this
.
goLoginIndex
(
_vIn
)
Message
({
type
:
'info'
,
message
:
'已取消,将不再记录任何数据操作,除非重新登录'
})
})
})
.
catch
(()
=>
{
Message
({
type
:
'info'
,
message
:
'已取消,将不再记录任何数据操作,除非重新登录'
})
})
}
else
if
(
status
===
401
)
{
this
.
setConfirm
(
'提示'
,
'关闭'
,
data
.
message
).
then
(()
=>
{})
}
}
}
else
if
(
res
.
response
.
status
===
401
)
{
this
.
setConfirm
(
'提示'
,
'关闭'
,
res
.
response
.
data
.
message
).
then
(()
=>
{
_vIn
.
$router
.
go
(
0
)
})
}
}
err
=
new
Error
(
res
.
response
.
data
.
message
||
JSON
.
stringify
(
res
.
response
.
data
))
err
=
new
Error
(
data
.
message
||
JSON
.
stringify
(
data
))
err
.
code
=
res
.
response
.
data
.
code
err
.
code
=
data
.
code
}
else
{
}
else
{
err
=
new
Error
(
'msg:'
+
res
.
message
+
'stack:'
+
res
.
stack
)
err
=
new
Error
(
'msg:'
+
res
.
message
+
'stack:'
+
res
.
stack
)
err
.
code
=
500
err
.
code
=
500
...
@@ -158,11 +152,28 @@ export default class API {
...
@@ -158,11 +152,28 @@ export default class API {
}
}
/* 重新实现 get请求 */
/* 重新实现 get请求 */
get
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'GET'
,
params
:
data
},
config
))
}
get
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'GET'
,
params
:
data
},
config
)
)
}
/* 重新实现 post请求 */
/* 重新实现 post请求 */
post
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'POST'
,
data
:
data
},
config
))
}
post
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'POST'
,
data
:
data
},
config
)
)
}
/* 重新实现 put请求 */
/* 重新实现 put请求 */
put
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'PUT'
,
data
:
data
},
config
))
}
put
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'PUT'
,
data
:
data
},
config
))
}
/* 重新实现 delete请求 */
/* 重新实现 delete请求 */
delete
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'DELETE'
,
params
:
data
},
config
))
}
delete
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'DELETE'
,
params
:
data
},
config
)
)
}
}
}
client/src/components/beforeEnter/Before.js
浏览文件 @
c5c5cc55
import
cAction
from
'@action'
import
cAction
from
'@action'
import
{
Message
}
from
'element-ui'
export
default
class
Before
{
export
default
class
Before
{
constructor
(
opt
)
{
constructor
(
opt
)
{
const
UA
=
navigator
.
userAgent
const
UA
=
navigator
.
userAgent
...
@@ -53,10 +51,7 @@ export default class Before {
...
@@ -53,10 +51,7 @@ export default class Before {
return
false
return
false
}
}
})
})
.
catch
((
res
)
=>
{
.
catch
(()
=>
{
if
(
res
.
code
!==
80201
)
{
Message
({
type
:
'error'
,
message
:
res
.
message
})
}
return
false
return
false
})
})
}
}
...
...
client/src/pages/learn/course.vue
浏览文件 @
c5c5cc55
...
@@ -120,7 +120,7 @@ export default {
...
@@ -120,7 +120,7 @@ export default {
if
(
json
.
status
===
200
)
{
if
(
json
.
status
===
200
)
{
this
.
newLiveMsg
=
json
.
data
this
.
newLiveMsg
=
json
.
data
}
}
})
.
catch
(
e
=>
{
this
.
$message
.
error
(
e
.
message
)
}).
finally
(()
=>
{
})
})
},
3000
)
},
3000
)
// const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
// const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
...
@@ -201,7 +201,7 @@ export default {
...
@@ -201,7 +201,7 @@ export default {
},
},
/* 直接进直播 */
/* 直接进直播 */
goLive
()
{
goLive
()
{
this
.
$router
.
push
({
path
:
`/player/
${
this
.
newLiveMsg
.
semester_id
}
/
${
this
.
newLiveMsg
.
course_id
}
/live/
${
this
.
newLiveMsg
.
live
.
id
}
`
})
this
.
$router
.
push
({
path
:
`/player/
${
this
.
newLiveMsg
.
course_id
}
/live/
${
this
.
newLiveMsg
.
live
.
id
}
`
})
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论