Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
c56dcfa0
Commit
c56dcfa0
authored
Jul 27, 2021
by
zhujian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
4f646be7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
25 deletions
+120
-25
src/core/routeHook.js
+62
-0
src/index.d.ts
+3
-0
src/index.tsx
+21
-7
src/modules/course-manage/AddLive.jsx
+6
-11
src/modules/root/Main.jsx
+28
-7
No files found.
src/core/routeHook.js
0 → 100644
View file @
c56dcfa0
import
Bus
from
'./bus'
;
class
routeHook
{
constructor
()
{
this
.
routeFun
=
[];
this
.
callBacks
=
[]
}
add
(
callback
)
{
//切换路由之前添加的函数
this
.
routeFun
=
[
callback
]
}
addJump
(
callback
)
{
this
.
callBacks
=
[
callback
]
}
pop
()
{
//去除回调
this
.
routeFun
.
pop
();
}
cancel
()
{
//取消跳转
this
.
routeFun
.
pop
()
}
break
()
{
//切换路由是执行的函数
const
enterFun
=
this
.
routeFun
[
0
];
enterFun
&&
enterFun
()
}
leave
()
{
//切换路由
const
callBacks
=
this
.
callBacks
.
pop
();
callBacks
&&
callBacks
()
this
.
routeFun
=
[];
}
//离开保存时的特例
// **
addSaveCase
()
{
//离开保存校验时将方法注入
this
.
add
(
this
.
saveBeforeLeave
.
bind
(
this
))
}
saveBeforeLeave
()
{
//离开保存时触发的方法
Bus
.
trigger
(
'showRouteChangeModal'
)
}
//** */
getCallbackNum
()
{
return
this
.
routeFun
.
length
}
}
export
default
new
routeHook
()
\ No newline at end of file
src/index.d.ts
View file @
c56dcfa0
declare
module
'jquery'
declare
module
'cropper'
declare
module
'ExamShareModal'
declare
module
'routeHooks'
// declare var this: any
\ No newline at end of file
src/index.tsx
View file @
c56dcfa0
...
...
@@ -23,6 +23,7 @@ import '@/core/xmTD';
import
User
from
'@/common/js/user'
;
import
Service
from
"@/common/js/service"
;
import
BaseService
from
'@/domains/basic-domain/baseService'
;
import
routeHook
from
'@/core/routeHook'
declare
var
getParameterByName
:
any
;
declare
var
window
:
any
;
...
...
@@ -31,7 +32,16 @@ const history = createHashHistory();
window
.
RCHistory
=
_
.
extend
({},
history
,
{
push
:
(
obj
:
any
)
=>
{
history
.
push
(
obj
)
console
.
log
(
routeHook
.
getCallbackNum
(),
'routeHook.getCallbackNum()'
)
if
(
routeHook
.
getCallbackNum
())
{
routeHook
.
break
();
routeHook
.
addJump
(()
=>
{
history
.
push
(
obj
)
})
}
else
{
history
.
push
(
obj
)
}
},
pushState
:
(
obj
:
any
)
=>
{
history
.
push
(
obj
)
...
...
@@ -39,7 +49,11 @@ window.RCHistory = _.extend({}, history, {
pushStateWithStatus
:
(
obj
:
any
)
=>
{
history
.
push
(
obj
)
},
goBack
:
history
.
goBack
,
goBack
:
()
=>
{
console
.
log
(
routeHook
.
getCallbackNum
(),
'routeHook.getCallbackNum()'
)
history
.
goBack
()
},
location
:
history
.
location
,
replace
:
(
obj
:
any
)
=>
{
history
.
replace
(
obj
)
...
...
@@ -73,19 +87,19 @@ if (getParameterByName('code') && isWeiXin()) {
window
.
currentStoreUserInfo
.
enterpriseId
=
res
.
result
.
enterpriseId
;
mount
()
})
}
else
if
(
getParameterByName
(
'from'
)
===
'customer'
&&
getParameterByName
(
'enterpriseId'
)
&&
getParameterByName
(
'userId'
))
{
}
else
if
(
getParameterByName
(
'from'
)
===
'customer'
&&
getParameterByName
(
'enterpriseId'
)
&&
getParameterByName
(
'userId'
))
{
User
.
setCustomerStoreId
(
getParameterByName
(
'storeId'
));
getWXWorkLoginNoCheck
(
getParameterByName
(
'enterpriseId'
),
getParameterByName
(
'userId'
));
//从C端跳转过来的学院自动执行免登录
}
else
{
getWXWorkLoginNoCheck
(
getParameterByName
(
'enterpriseId'
),
getParameterByName
(
'userId'
));
//从C端跳转过来的学院自动执行免登录
}
else
{
mount
()
}
function
getWXWorkLoginNoCheck
(
enterpriseId
:
string
,
userId
:
string
)
{
function
getWXWorkLoginNoCheck
(
enterpriseId
:
string
,
userId
:
string
)
{
const
params
=
{
appTermEnum
:
'XIAOMAI_CLOUD_CLASS_PC_WEB_ADMIN'
,
enterpriseId
,
userId
,
};
BaseService
.
getWXWorkLoginNoCheck
(
params
).
then
((
res
:
any
)
=>
{
BaseService
.
getWXWorkLoginNoCheck
(
params
).
then
((
res
:
any
)
=>
{
User
.
setUserId
(
res
.
result
.
loginInfo
.
userId
)
User
.
setToken
(
res
.
result
.
loginInfo
.
xmToken
)
User
.
setEnterpriseId
(
res
.
result
.
enterpriseId
)
...
...
src/modules/course-manage/AddLive.jsx
View file @
c56dcfa0
...
...
@@ -21,6 +21,7 @@ import { randomString } from '@/domains/basic-domain/utils';
import
Upload
from
'@/core/upload'
;
import
PreviewCourseModal
from
'./modal/PreviewCourseModal'
;
import
CourseService
from
'@/domains/course-domain/CourseService'
;
import
routeHook
from
'@/core/routeHook'
import
moment
from
'moment'
;
import
User
from
'@/common/js/user'
;
import
_
from
'underscore'
;
...
...
@@ -110,6 +111,7 @@ class AddLive extends React.Component {
}
componentDidMount
()
{
routeHook
.
addSaveCase
();
const
{
type
}
=
this
.
state
;
if
(
type
===
'edit'
)
{
this
.
getCourseDetail
();
...
...
@@ -515,19 +517,12 @@ class AddLive extends React.Component {
// 比较state的addLiveBasicInfo, addLiveClassInfo, addLiveIntroInfo和默认数据是否相等
const
{
addLiveBasicInfo
,
addLiveClassInfo
,
addLiveIntroInfo
}
=
this
.
state
;
if
(
!
_
.
isEqual
(
addLiveBasicInfo
,
defaultBasicInfo
)
||
!
_
.
isEqual
(
addLiveClassInfo
,
defaultClassInfo
)
||
!
_
.
isEqual
(
addLiveIntroInfo
,
defaultIntroInfo
))
{
Modal
.
confirm
({
title
:
'确定要返回吗?'
,
content
:
'返回后,本次编辑的内容将不被保存'
,
okText
:
'确认返回'
,
cancelText
:
'留在本页'
,
icon
:
<
span
className=
'icon iconfont default-confirm-icon'
>

</
span
>,
onOk
:
()
=>
{
window
.
RCHistory
.
push
({
pathname
:
`/live-course`
,
});
},
console
.
log
(
'ghjklkjh'
)
window
.
RCHistory
.
push
({
pathname
:
`/live-course`
,
});
}
else
{
routeHook
.
cancel
()
window
.
RCHistory
.
push
({
pathname
:
`/live-course`
,
});
...
...
src/modules/root/Main.jsx
View file @
c56dcfa0
import
React
,
{
useContext
,
useEffect
,
useState
}
from
'react'
import
React
,
{
useContext
,
useEffect
,
useState
}
from
'react'
import
'./Main.less'
;
import
{
MainRoutes
,
RedirectRoutes
}
from
'@/routes'
;
import
{
Modal
}
from
'antd'
;
import
{
MainRoutes
,
RedirectRoutes
}
from
'@/routes'
;
import
routeHook
from
'@/core/routeHook'
import
Bus
from
'@/core//bus'
;
function
Main
(
props
)
{
const
{
menuType
}
=
props
;
console
.
log
(
"menuType"
,
menuType
);
useEffect
(()
=>
{
Bus
.
bind
(
'showRouteChangeModal'
,
()
=>
{
Modal
.
confirm
({
title
:
'确定要返回吗?'
,
content
:
'返回后,本次编辑的内容将不被保存'
,
okText
:
'确认返回'
,
cancelText
:
'留在本页'
,
icon
:
<
span
className=
'icon iconfont default-confirm-icon'
>

</
span
>,
onOk
:
()
=>
{
routeHook
.
leave
()
},
});
})
},
[])
function
Main
(
props
){
const
{
menuType
}
=
props
;
console
.
log
(
"menuType"
,
menuType
);
return
(
<
div
className=
{
menuType
?
`right-container has-nav`
:
`right-container has-nav right-container-vertical`
}
id=
"rightContainer"
>
<
MainRoutes
/>
<
RedirectRoutes
/>
<
MainRoutes
/>
<
RedirectRoutes
/>
</
div
>
)
}
...
...
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