Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
transport-show-h5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
transport-show-h5
Commits
5498f4b6
提交
5498f4b6
authored
7月 07, 2020
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug fixes
上级
f8994073
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
136 行增加
和
84 行删除
+136
-84
base_api.js
src/api/base_api.js
+42
-25
SearchBar.vue
src/components/SearchBar.vue
+22
-9
main.js
src/main.js
+1
-2
index.vue
src/pages/course/learn/index.vue
+8
-4
item.vue
src/pages/course/learn/item.vue
+12
-8
index.vue
src/pages/course/tag/index.vue
+16
-12
item.vue
src/pages/course/tag/item.vue
+9
-5
list.vue
src/pages/course/tag/list.vue
+9
-5
index.vue
src/pages/home/index.vue
+8
-4
index.js
src/router/index.js
+9
-10
没有找到文件。
src/api/base_api.js
浏览文件 @
5498f4b6
import
axios
from
'axios'
import
_
from
'lodash'
import
store
from
'../store'
import
router
from
'../router'
export
default
class
API
{
constructor
(
config
)
{
constructor
(
config
)
{
/* 创建一个 自定义配置axios实例 */
// 让ajax携带cookie
axios
.
defaults
.
withCredentials
=
true
...
...
@@ -23,14 +24,16 @@ export default class API {
}
/* 获取当前Vue创建实例 */
getVueInstance
()
{
getVueInstance
()
{
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
headers
=
{
...
...
@@ -38,7 +41,9 @@ export default class API {
}
_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
=
''
const
_obj
=
_config
.
data
||
_config
.
params
for
(
const
key
in
_obj
)
{
...
...
@@ -60,8 +65,10 @@ export default class API {
_config
.
data
=
fr
}
/* 创建并根据参数发起请求 */
return
this
.
_axios
(
_config
)
.
then
(
beforeSuccess
.
bind
(
this
),
beforeFail
.
bind
(
this
))
return
this
.
_axios
(
_config
).
then
(
beforeSuccess
.
bind
(
this
),
beforeFail
.
bind
(
this
)
)
}
/**
...
...
@@ -69,7 +76,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 返回数据
*/
_reqSuccess
(
res
)
{
_reqSuccess
(
res
)
{
const
{
status
,
data
}
=
res
let
err
=
null
if
(
status
===
200
)
{
...
...
@@ -85,7 +92,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 如果未到达 response 阶段,则无res.response
*/
_reqFail
(
res
)
{
_reqFail
(
res
)
{
// console.log(res.response, '========')
let
err
=
null
if
(
res
.
code
===
'ECONNABORTED'
)
{
...
...
@@ -93,17 +100,21 @@ export default class API {
}
else
if
(
res
.
response
)
{
const
{
status
,
data
}
=
res
.
response
if
(
data
)
{
if
(
status
===
40
2
)
{
if
(
window
.
G
.
$instance_vue
.
$
store
.
state
.
isWeapp
)
{
wx
.
miniProgram
.
navigateTo
({
url
:
`/pages/web/index?src=
${
window
.
location
.
origin
}
/pay`
})
if
(
status
===
40
3
)
{
if
(
store
.
state
.
isWeapp
)
{
wx
.
miniProgram
.
navigateTo
({
url
:
'/pages/login/index'
})
}
else
{
window
.
G
.
$instance_vue
.
$router
.
replace
({
path
:
'/pay'
router
.
push
(
'/login'
)
}
}
if
(
status
===
402
)
{
if
(
store
.
state
.
isWeapp
)
{
wx
.
miniProgram
.
navigateTo
({
url
:
`/pages/web/index?src=
${
window
.
location
.
origin
}
/pay`
})
}
else
{
router
.
replace
({
path
:
'/pay'
})
}
// window.G.$instance_vue.$router.replace({
// path: '/pay'
// })
}
}
err
=
new
Error
(
JSON
.
stringify
(
res
.
response
))
...
...
@@ -116,22 +127,28 @@ export default class API {
}
/* 重新实现 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
(
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
(
url
,
data
,
config
)
{
put
(
url
,
data
,
config
)
{
return
this
.
_request
(
_
.
assignIn
({
url
,
method
:
'PUT'
,
data
:
data
},
config
))
}
/* 重新实现 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
)
)
}
}
src/components/SearchBar.vue
浏览文件 @
5498f4b6
<
template
>
<div
class=
"search-bar"
>
<form
action
@
submit
.
prevent=
"onSearch"
>
<input
type=
"search"
class=
"search-input"
:placeholder=
"placeholder"
v-model=
"currentValue"
v-bind=
"$attrs"
@
input=
"onChange"
ref=
"formInput"
/>
<div
class=
"inner"
>
<input
type=
"search"
class=
"search-input"
:placeholder=
"placeholder"
v-model=
"currentValue"
v-bind=
"$attrs"
@
input=
"onChange"
ref=
"formInput"
/>
<input
type=
"button"
value=
"搜索"
class=
"search-button"
@
click=
"onSearch"
/>
</div>
</form>
</div>
</
template
>
...
...
@@ -73,4 +76,14 @@ export default {
border-radius
:
0
.1rem
;
outline
:
none
;
}
.search-button
{
margin-left
:
0
.2rem
;
color
:
#222
;
font-size
:
0
.3rem
;
appearance
:
none
;
background-color
:
transparent
;
}
.inner
{
display
:
flex
;
}
</
style
>
src/main.js
浏览文件 @
5498f4b6
import
Vue
from
'vue'
// 引入vue框架
import
VueRouter
from
'vue-router'
// 使用 vue-router
import
createR
outer
from
'./router'
// router定义
import
r
outer
from
'./router'
// router定义
import
store
from
'@/store'
import
VueI18n
from
'vue-i18n'
// 使用 国际化
import
createI18n
from
'./assets/languages'
// 国际化定义
...
...
@@ -24,7 +24,6 @@ require('promise.prototype.finally').shim()
/* 兼容处理 end */
Vue
.
use
(
VueRouter
)
const
router
=
createRouter
()
Vue
.
use
(
VueI18n
)
const
i18n
=
createI18n
()
...
...
src/pages/course/learn/index.vue
浏览文件 @
5498f4b6
...
...
@@ -26,10 +26,14 @@ export default {
message
:
'加载中...'
,
forbidClick
:
true
})
api
.
getCourseList
().
then
(
response
=>
{
this
.
courseList
=
response
this
.
$toast
.
clear
()
})
api
.
getCourseList
()
.
then
(
response
=>
{
this
.
courseList
=
response
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
}
},
beforeMount
()
{
...
...
src/pages/course/learn/item.vue
浏览文件 @
5498f4b6
...
...
@@ -62,15 +62,19 @@ export default {
forbidClick
:
true
})
this
.
loaded
=
false
api
.
getCourse
(
this
.
courseId
).
then
(
response
=>
{
this
.
loaded
=
true
response
.
chapters
=
response
.
chapters
.
filter
(
item
=>
{
item
.
children
=
item
.
children
.
filter
(
child
=>
child
.
type
===
2
)
return
item
.
children
.
length
api
.
getCourse
(
this
.
courseId
)
.
then
(
response
=>
{
this
.
loaded
=
true
response
.
chapters
=
response
.
chapters
.
filter
(
item
=>
{
item
.
children
=
item
.
children
.
filter
(
child
=>
child
.
type
===
2
)
return
item
.
children
.
length
})
this
.
detail
=
response
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
this
.
detail
=
response
this
.
$toast
.
clear
()
})
}
},
beforeMount
()
{
...
...
src/pages/course/tag/index.vue
浏览文件 @
5498f4b6
...
...
@@ -65,19 +65,23 @@ export default {
message
:
'加载中...'
,
forbidClick
:
true
})
api
.
getCourseTagList
(
this
.
courseId
).
then
(
response
=>
{
this
.
$emit
(
'ready'
,
response
)
this
.
detail
=
response
this
.
messageList
=
response
.
chapters
.
map
((
item
,
index
)
=>
{
return
{
id
:
this
.
genId
(
index
),
type
:
1
,
from
:
'system'
,
payload
:
item
}
api
.
getCourseTagList
(
this
.
courseId
)
.
then
(
response
=>
{
this
.
$emit
(
'ready'
,
response
)
this
.
detail
=
response
this
.
messageList
=
response
.
chapters
.
map
((
item
,
index
)
=>
{
return
{
id
:
this
.
genId
(
index
),
type
:
1
,
from
:
'system'
,
payload
:
item
}
})
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
this
.
$toast
.
clear
()
})
},
// 输入搜索
onSearch
()
{
...
...
src/pages/course/tag/item.vue
浏览文件 @
5498f4b6
...
...
@@ -50,11 +50,15 @@ export default {
forbidClick
:
true
})
this
.
loaded
=
false
api
.
getCourseTag
(
this
.
tagId
).
then
(
response
=>
{
this
.
loaded
=
true
this
.
detail
=
response
this
.
$toast
.
clear
()
})
api
.
getCourseTag
(
this
.
tagId
)
.
then
(
response
=>
{
this
.
loaded
=
true
this
.
detail
=
response
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
},
// 去知识点考试页面
toExamPage
()
{
...
...
src/pages/course/tag/list.vue
浏览文件 @
5498f4b6
...
...
@@ -60,11 +60,15 @@ export default {
forbidClick
:
true
})
this
.
loaded
=
false
api
.
getCourseTagList
(
this
.
courseId
).
then
(
response
=>
{
this
.
loaded
=
true
this
.
detail
=
response
this
.
$toast
.
clear
()
})
api
.
getCourseTagList
(
this
.
courseId
)
.
then
(
response
=>
{
this
.
loaded
=
true
this
.
detail
=
response
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
},
onClick
({
id
})
{
if
(
this
.
isTest
)
{
...
...
src/pages/home/index.vue
浏览文件 @
5498f4b6
...
...
@@ -56,10 +56,14 @@ export default {
message
:
'加载中...'
,
forbidClick
:
true
})
api
.
getFreeCourseList
().
then
(
response
=>
{
this
.
courseList
=
response
this
.
$toast
.
clear
()
})
api
.
getFreeCourseList
()
.
then
(
response
=>
{
this
.
courseList
=
response
})
.
finally
(()
=>
{
this
.
$toast
.
clear
()
})
},
// 搜索
toSearch
()
{
...
...
src/router/index.js
浏览文件 @
5498f4b6
import
Router
from
'vue-router'
import
routes
from
'./routes'
export
default
()
=>
{
return
new
Router
({
routes
,
mode
:
'history'
,
// 还有一个 hash 默认
fallback
:
true
,
// 浏览器不支持 history时,自动改成 hash方式
scrollBehavior
(
to
,
from
,
savedPosition
)
{
// 每次打开,滚动到 最顶端
return
{
x
:
0
,
y
:
0
}
}
})
}
export
default
new
Router
({
routes
,
mode
:
'history'
,
// 还有一个 hash 默认
fallback
:
true
,
// 浏览器不支持 history时,自动改成 hash方式
scrollBehavior
(
to
,
from
,
savedPosition
)
{
// 每次打开,滚动到 最顶端
return
{
x
:
0
,
y
:
0
}
}
})
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论