Commit f4d7f1c7 by zhanghaozhe

ml小程序

parent ccd68731
......@@ -39,6 +39,7 @@ class InteractiveStudy extends Component {
page,
videoId: data.current_video_id,
})
document.title = data.current_video_name
this.getPageContent(data.current_video_id, () => {
this.updatePosition()
this.getPageContent(data.current_video_id)
......@@ -72,6 +73,10 @@ class InteractiveStudy extends Component {
}
getPageContent = (videoId, cb) => {
const {page, schedule} = this.state
if (page > schedule.page_info.total_pages) {
return
}
http.post(`${API.home}/m/it/study/syllabus?page=${this.state.isFirst ? 1 : this.state.page}`, {
course_id: getParam('id'),
video_id: videoId,
......@@ -80,17 +85,21 @@ class InteractiveStudy extends Component {
const {code, msg, data} = res.data
if (code === 200) {
this.setState(state => {
const totalPage = state.schedule.page_info.total_pages
const page = state.page < totalPage ? state.isFirst ? state.page : state.page + 1 : totalPage
const list = data.syllabus_list
const progress = state.processContent.length
? data.syllabus_list.findIndex(item => item.syllabus_id === state.processContent[state.processContent.length - 1].syllabus_id) + 1
? list.findIndex(item => item.syllabus_id === state.processContent[state.processContent.length - 1].syllabus_id) + 1
: 0
if (state.isFirst) {
return {
processContent: state.processContent.concat(list),
isFirst: false,
}
}
return {
processContent: state.isFirst ? (state.processContent.concat(data.syllabus_list)) : state.processContent,
isFirst: false,
page,
cachedList: state.cachedList.reverse().concat(list.slice(progress)).reverse(),
page: state.page + 1,
pageData: data,
progress: state.isFirst ? state.progress : progress,
progress: progress,
}
}, () => {
cb && cb()
......@@ -102,10 +111,11 @@ class InteractiveStudy extends Component {
}
saveSchedule = (syllabusId, unitInfoId) => {
http.post(`/m/it/user/saveSchedule`, {
syllabus_id: syllabusId,
unit_info_id: unitInfoId,
}).then(res => {
let data = {syllabus_id: syllabusId}
if (unitInfoId) {
data.unit_info_id = unitInfoId
}
http.post(`/m/it/user/saveSchedule`, data).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
......@@ -115,25 +125,49 @@ class InteractiveStudy extends Component {
})
}
savePractice = ({syllabusId, type, answer, result, lines}) => {
let data = {
syllabus_id: syllabusId,
type,
answer,
result,
}
if (type === 2 && lines) {
data.lines = lines
}
http.post(`${API.home}/m/it/user/savePractice`, data).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
} else {
Toast.fail(msg, 2)
}
})
}
process = () => {
const {processStatus} = this.state
if (processStatus === status.practicingProgram || processStatus === status.practicingSingle) {
this.showToast('有其他正在进行的练习')
return
}
if (processStatus === status.nextSection) {
console.log('下一关')
return
}
this.setState(state => {
let nextQuestion, progress, cachedList = state.cachedList
if (state.cachedList.length) {
let nextQuestion, cachedList = state.cachedList, pageData = state.pageData
const length = cachedList.length
if (length) {
nextQuestion = [cachedList.pop()]
progress = 0
} else {
nextQuestion = state.pageData.syllabus_list.slice(state.progress, state.progress + 1)
progress = state.progress + 1
if (length < 6) {
this.getPageContent(state.videoId)
}
}
if (!cachedList.length && state.progress === state.pageData.syllabus_list.length - 6) {
cachedList = state.pageData.syllabus_list.slice(state.progress + 1).reverse()
console.log(state.page)
this.getPageContent(state.videoId)
if (!cachedList.length) {
return {
processStatus: status.nextSection,
}
}
let processStatus = nextQuestion[0].type === questionType.singleAnswer
? status.practicingSingle
......@@ -142,14 +176,12 @@ class InteractiveStudy extends Component {
: status.resumePractice
return {
processContent: state.processContent.concat(nextQuestion),
progress,
processStatus,
isProgramShowed: processStatus === status.practicingProgram && (state.isProgramShowed + 1),
cachedList,
pageData,
}
}, () => {
// console.log(this.state.processContent)
// console.log(this.state.cachedList)
this.updatePosition()
})
}
......@@ -185,10 +217,12 @@ class InteractiveStudy extends Component {
}
})
}
{/*<Project user={this.singleIcon}/>*/}
{
processStatus === status.nextSection && <Project user={avatar}/>
}
<div className="status-bar" onClick={this.process}>
{processStatus && <span className={'status'}>{processStatus}</span>}
{/*<span className={'complete'}>已学完全部课时</span>*/}
<span className={'status'}>{processStatus}</span>
{/*<div className="free-trial-end">*/}
{/* <span>试学体验结束,389.1元学习全部课时</span>*/}
{/* <button className={'purchase'}>立即购买</button>*/}
......
......@@ -137,7 +137,7 @@ function ToolBar({isProgramShowed, userAnswer, isSuccessful, execute}) {
}
return <Finished/>
}
return isProgramShowed ? <Normal/> : <First execute={execute}/>
return isProgramShowed > 1 ? <Normal/> : <First execute={execute}/>
}
export default Program;
\ No newline at end of file
......@@ -44,7 +44,12 @@ class TerminalInterface extends Component {
}
getAuthenticationData = () => {
http.get(`${API.home}/sys/ws/auth`).then(res => {
http.post(`http://47.93.119.175:8888/auth`, {
username: '3guh394h3fhj0f4',
password: 'okqdw029j038hrv3890cv',
}, {
withCredentials: false
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.getLinkId(data.token)
......@@ -55,7 +60,11 @@ class TerminalInterface extends Component {
}
getLinkId = token => {
http.get(`${API.home}/sys/ws/connection/${token}`).then(res => {
http.post(`http://47.93.119.175:8888`, {}, {
headers: {
Token: token,
},
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.connectServer(data.id)
......@@ -77,11 +86,12 @@ class TerminalInterface extends Component {
console.log(event.message)
this.terminal.write(event.data)
}
this.socket.onerror = () => {
console.log('error')
this.socket.onerror = (event) => {
console.log(event)
}
this.socket.onclose = () => {
this.socket.onclose = (event) => {
console.log('closed')
console.log(event)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment