Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
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
baiguangyao
mr-julyedu
Commits
1a4760a9
Commit
1a4760a9
authored
Jun 24, 2020
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
c156b663
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
68 deletions
+115
-68
src/App.js
+23
-20
src/components/Index/index.js
+19
-11
src/components/my/index.js
+56
-19
src/router/index.js
+4
-11
src/utils/index.js
+13
-7
No files found.
src/App.js
View file @
1a4760a9
...
...
@@ -29,7 +29,7 @@ class App extends Component {
super
(
props
)
this
.
state
=
{
isShowActivityEntry
:
0
,
isShowChannel
:
0
isShowChannel
:
0
,
}
this
.
globalEntry
=
null
}
...
...
@@ -66,11 +66,13 @@ class App extends Component {
sessionStorage
.
setItem
(
'enter_url'
,
window
.
location
.
href
)
}
this
.
getUser
()
this
.
utm
()
const
{
history
}
=
this
.
props
this
.
getUser
()
this
.
setNavigationRecord
(
this
.
props
.
location
,
this
.
props
.
history
.
action
)
this
.
setPreviousLocation
()
...
...
@@ -95,9 +97,9 @@ class App extends Component {
from
:
{
pathname
:
this
.
previousLocation
.
pathname
,
search
:
this
.
previousLocation
.
search
,
hash
:
this
.
previousLocation
.
hash
}
}
hash
:
this
.
previousLocation
.
hash
,
}
,
}
,
}
}
else
{
this
.
removeShareCodeCookie
()
...
...
@@ -114,7 +116,7 @@ class App extends Component {
// treasure_stage,宝箱阶段,0-不在活动时间,1-活动时间内
this
.
setState
({
isShowActivityEntry
:
data
.
treasure_stage
,
isShowChannel
:
data
.
is_show_site_window_by_channel
isShowChannel
:
data
.
is_show_site_window_by_channel
,
},
()
=>
{
data
.
treasure_stage
&&
this
.
bindGlobalEntry
()
})
...
...
@@ -171,7 +173,7 @@ class App extends Component {
if
(
zhihu_cb
)
{
let
data
=
{
'zhihu_cb'
:
zhihu_cb
'zhihu_cb'
:
zhihu_cb
,
}
http
.
post
(
`
${
API
[
'home'
]}
/sys/zhihu/firstRecord`
,
data
)
...
...
@@ -220,11 +222,12 @@ class App extends Component {
}
else
{
if
(
this
.
props
.
location
.
pathname
!==
'/my'
)
{
http
.
get
(
`
${
API
.
home
}
/m/user_info_sample/0`
).
then
(
res
=>
{
this
.
props
.
setCurrentUser
(
this
.
transformUser
(
res
))
})
}
}
}
componentDidUpdate
()
{
...
...
@@ -253,8 +256,8 @@ class App extends Component {
user_name
:
username
,
is_vip
:
isVIP
,
uid
,
code
}
code
,
}
,
}
=
res
.
data
payload
=
{
...
...
@@ -265,15 +268,15 @@ class App extends Component {
isVIP
,
avatar
,
uid
,
code
}
code
,
}
,
}
}
else
{
payload
=
{
hasError
:
true
,
msg
:
res
.
data
.
msg
,
code
:
res
.
data
.
code
,
data
:
{}
data
:
{}
,
}
}
return
payload
...
...
@@ -284,7 +287,7 @@ class App extends Component {
if
(
data
.
errno
==
200
)
{
//移除红包统计cookie
this
.
removeShareCodeCookie
()
let
{
uid
,
token
,
avatar_file
:
avatar
,
uname
:
username
,
}
=
data
.
data
let
{
uid
,
token
,
avatar_file
:
avatar
,
uname
:
username
}
=
data
.
data
return
{
hasError
:
false
,
...
...
@@ -292,9 +295,9 @@ class App extends Component {
uid
,
token
,
avatar
,
username
username
,
},
msg
:
data
.
msg
msg
:
data
.
msg
,
}
}
else
{
let
{
code
,
msg
}
=
data
.
data
...
...
@@ -302,7 +305,7 @@ class App extends Component {
code
,
msg
,
hasError
:
true
,
data
:
{}
data
:
{}
,
}
}
}
...
...
@@ -338,7 +341,7 @@ class App extends Component {
closeGlobalEntry
=
()
=>
{
localStorage
.
setItem
(
'globalEntryClosedTime'
,
Date
.
now
().
toString
())
this
.
setState
({
isShowActivityEntry
:
0
isShowActivityEntry
:
0
,
})
}
...
...
@@ -374,7 +377,7 @@ class App extends Component {
export
default
compose
(
connect
(
state
=>
({
user
:
state
.
user
}),
{
setCurrentUser
,
startFetchUser
}
{
setCurrentUser
,
startFetchUser
}
,
),
withRouter
withRouter
,
)(
App
)
src/components/Index/index.js
View file @
1a4760a9
...
...
@@ -5,7 +5,7 @@ import { WithTab } from '@/HOCs'
// import Swiper from 'react-mobile-swiper'
// import createStyle from './createStyle'
import
HomeCourseList
from
'./course-list'
import
{
http
}
from
'@/utils'
import
{
http
,
isValidUrl
}
from
'@/utils'
import
LiveRoom
from
'./liveRoom'
import
{
Link
}
from
"react-router-dom"
import
{
Toast
}
from
'antd-mobile'
...
...
@@ -17,7 +17,7 @@ import AllCourseNavigation from "./all-course"
// const animateTypes = Swiper.animateTypes
@
connect
(
state
=>
({
user
:
state
.
user
user
:
state
.
user
,
}))
class
Index
extends
Component
{
constructor
(
props
)
{
...
...
@@ -33,28 +33,28 @@ class Index extends Component {
{
'src'
:
require
(
'./image/freeclass_icon.png'
),
'name'
:
'公开课'
,
'href'
:
'/study/free-course'
'href'
:
'/study/free-course'
,
},
{
'src'
:
require
(
'./image/jingpin_icon.png'
),
'name'
:
'精品特惠'
,
'href'
:
'/preferential'
'href'
:
'/preferential'
,
},
{
'src'
:
require
(
'./image/zjxj_icon.png'
),
'name'
:
'赚奖学金'
,
'href'
:
'/scholarship'
'href'
:
'/scholarship'
,
},
{
'src'
:
require
(
'./image/mryt_icon.png'
),
'name'
:
'每日一题'
,
'href'
:
'/examination'
'href'
:
'/examination'
,
},
{
'src'
:
require
(
'./image/shequ_icon.png'
),
'name'
:
'社区'
,
'href'
:
'https://ask.julyedu.com'
}
'href'
:
'https://ask.julyedu.com'
,
}
,
],
}
}
...
...
@@ -72,7 +72,7 @@ class Index extends Component {
this
.
setState
({
banner
:
data
.
banner
,
lives
:
data
.
lives
,
modules
modules
,
})
}
else
{
Toast
.
info
(
res
.
data
.
msg
,
2
)
...
...
@@ -93,7 +93,7 @@ class Index extends Component {
this
.
setState
({
isShow
:
true
,
islive
:
true
,
roomMess
:
item
roomMess
:
item
,
})
}
else
{
window
.
location
.
href
=
`
${
window
.
location
.
href
.
includes
(
'pre'
)
?
'http://www-pre.julyedu.com'
:
'http://www.julyedu.com'
}
/live/m_room/
${
item
.
room_id
}
`
...
...
@@ -147,10 +147,18 @@ class Index extends Component {
this
.
state
.
tabdata
.
map
((
item
,
index
)
=>
{
return
(
<
li
key
=
{
index
}
>
<
a
href
=
{
item
.
href
}
>
{
isValidUrl
(
item
.
href
)
?
<
a
href
=
{
item
.
href
}
>
<
img
src
=
{
item
.
src
}
alt
=
""
/>
<
span
>
{
item
.
name
}
<
/span
>
<
/a
>
:
<
Link
to
=
{
item
.
href
}
>
<
img
src
=
{
item
.
src
}
alt
=
""
/>
<
span
>
{
item
.
name
}
<
/span
>
<
/Link
>
}
<
/li
>
)
})
...
...
src/components/my/index.js
View file @
1a4760a9
import
React
,
{
PureComponent
}
from
'react'
import
{
Flex
,
WhiteSpace
,
List
}
from
'antd-mobile'
import
React
,
{
PureComponent
}
from
'react'
import
{
Flex
,
WhiteSpace
,
List
}
from
'antd-mobile'
import
'./index.scss'
import
Avatar
from
'./image/avatar.png'
import
Vip
from
'./image/vip.png'
import
{
WithTab
}
from
'@/HOCs'
import
{
Link
}
from
"react-router-dom"
import
{
connect
}
from
"react-redux"
import
{
HeaderBar
}
from
"@/common"
import
{
WithTab
}
from
'@/HOCs'
import
{
Link
}
from
"react-router-dom"
import
{
connect
}
from
"react-redux"
import
{
HeaderBar
}
from
"@/common"
import
{
http
}
from
"@/utils"
import
{
getCourses
}
from
'./../detail/actions'
;
import
{
getCourses
}
from
'./../detail/actions'
;
import
{
setCurrentUser
,
startFetchUser
}
from
"@/store/userAction"
const
Item
=
List
.
Item
;
const
Brief
=
Item
.
Brief
;
@
connect
(
state
=>
({
user
:
state
.
user
}))
user
:
state
.
user
,
})
,
{
startFetchUser
,
setCurrentUser
}
)
class
My
extends
PureComponent
{
constructor
(
props
)
{
super
(
props
)
...
...
@@ -27,14 +29,49 @@ class My extends PureComponent {
componentDidMount
()
{
this
.
getUser
()
}
getUser
=
()
=>
{
this
.
props
.
startFetchUser
()
http
.
get
(
`
${
API
.
home
}
/m/user_info_sample/1`
).
then
(
res
=>
{
const
{
data
,
code
}
=
res
.
data
if
(
code
===
200
)
{
this
.
setState
({
isVip
:
data
.
is_vip
this
.
props
.
setCurrentUser
(
this
.
transformUser
(
res
))
})
}
})
transformUser
=
res
=>
{
let
payload
if
(
res
.
data
.
code
===
200
)
{
const
{
msg
,
data
:
{
avatar_file
:
avatar
,
user_name
:
username
,
is_vip
:
isVIP
,
uid
,
code
,
},
}
=
res
.
data
payload
=
{
hasError
:
false
,
msg
,
data
:
{
username
,
isVIP
,
avatar
,
uid
,
code
,
},
}
}
else
{
payload
=
{
hasError
:
true
,
msg
:
res
.
data
.
msg
,
code
:
res
.
data
.
code
,
data
:
{},
}
}
return
payload
}
// 去登录
...
...
@@ -43,7 +80,7 @@ class My extends PureComponent {
}
toCourseDetail
=
(
id
)
=>
{
const
{
dispatch
,
history
}
=
this
.
props
;
const
{
dispatch
,
history
}
=
this
.
props
;
// dispatch(getCourses(id, () => {
history
.
push
(
`/detail?id=
${
id
}
`
);
return
false
;
...
...
@@ -55,8 +92,8 @@ class My extends PureComponent {
const
uid
=
user
&&
user
.
data
&&
user
.
data
.
uid
const
username
=
user
&&
user
.
data
&&
user
.
data
.
username
const
avatar
=
user
&&
user
.
data
&&
user
.
data
.
avatar
//
const isVIP = user && user.data && user.data.isVIP
const
isVIP
=
this
.
state
.
isVip
const
isVIP
=
user
&&
user
.
data
&&
user
.
data
.
isVIP
//
const isVIP = this.state.isVip
let
list
if
(
!
uid
)
{
...
...
@@ -132,8 +169,8 @@ class My extends PureComponent {
<
Link
to
=
{{
pathname
:
'/coupons'
,
state
:
{
from
:
this
.
props
.
location
.
pathname
}
from
:
this
.
props
.
location
.
pathname
,
},
}}
>
<
Item
arrow
=
"horizontal"
className
=
"no-border"
>
<
i
className
=
"iconfont iconiconfront-52"
><
/i
>
...
...
src/router/index.js
View file @
1a4760a9
...
...
@@ -2,16 +2,6 @@ import React from 'react'
import
{
Switch
,
Route
}
from
'react-router-dom'
import
RouterConfig
from
'./router-config'
import
PrivateRoute
from
'./privateRoute'
// 动态改变title
// const RouteWithSubRoutes = route => {
// return (
// <Route
// exact
// {...route}
// onChange={document.title = route.name}
// />
// );
// };
export
default
function
()
{
return
(
...
...
@@ -21,8 +11,11 @@ export default function () {
if
(
isPrivate
)
{
return
<
PrivateRoute
{...
rest
}
key
=
{
index
}
/
>
}
else
{
const
{
component
:
Component
,
...
rest
}
=
item
return
(
<
Route
{...
rest
}
key
=
{
index
}
/
>
<
Route
{...
rest
}
key
=
{
index
}
render
=
{(
props
)
=>
{
return
<
Component
{...
props
}
/
>
}}
/
>
)
}
})}
...
...
src/utils/index.js
View file @
1a4760a9
...
...
@@ -3,7 +3,7 @@ import {
differenceInDays
,
differenceInHours
,
differenceInMinutes
,
differenceInSeconds
differenceInSeconds
,
}
from
'date-fns'
...
...
@@ -15,7 +15,7 @@ export const getParam = (key, str) => {
}
const
html
=
content
=>
({
__html
:
htmlDecode
(
content
)
__html
:
htmlDecode
(
content
)
,
})
const
htmlDecode
=
content
=>
{
...
...
@@ -102,7 +102,7 @@ const browser = (function () {
isIOS
:
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/i
.
test
(
ua
),
isIPad
:
/iPad/i
.
test
(
ua
),
isAndroidApp
:
/Android/i
.
test
(
ua
)
&&
getParam
(
'version'
),
isIOSApp
:
/iPhone/i
.
test
(
ua
)
&&
getParam
(
'version'
)
isIOSApp
:
/iPhone/i
.
test
(
ua
)
&&
getParam
(
'version'
)
,
}
})()
...
...
@@ -119,17 +119,21 @@ const dateCountDown = (later, earlier) => {
d
,
h
,
m
,
s
s
,
}
}
const
isValidUrl
=
(
str
)
=>
{
return
/https
?
:
\/\/(
www
\.)?[
-a-zA-Z0-9@:%._
\+
~#=
]{1,256}\.[
a-zA-Z0-9()
]{1,6}\b([
-a-zA-Z0-9()@:%_
\+
.~#?&
//
=
]
*
)
/
.
test
(
str
)
}
export
{
default
as
http
default
as
http
,
}
from
'./http'
export
{
default
as
wxShare
default
as
wxShare
,
}
from
'./wechat/share'
export
{
...
...
@@ -141,8 +145,9 @@ export {
browser
,
isLogin
,
dateCountDown
,
isValidUrl
}
export
{
default
as
SendMessageToApp
default
as
SendMessageToApp
,
}
from
'./app'
\ 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