Commit f4d7f1c7 by zhanghaozhe

ml小程序

parent ccd68731
...@@ -39,6 +39,7 @@ class InteractiveStudy extends Component { ...@@ -39,6 +39,7 @@ class InteractiveStudy extends Component {
page, page,
videoId: data.current_video_id, videoId: data.current_video_id,
}) })
document.title = data.current_video_name
this.getPageContent(data.current_video_id, () => { this.getPageContent(data.current_video_id, () => {
this.updatePosition() this.updatePosition()
this.getPageContent(data.current_video_id) this.getPageContent(data.current_video_id)
...@@ -72,6 +73,10 @@ class InteractiveStudy extends Component { ...@@ -72,6 +73,10 @@ class InteractiveStudy extends Component {
} }
getPageContent = (videoId, cb) => { 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}`, { http.post(`${API.home}/m/it/study/syllabus?page=${this.state.isFirst ? 1 : this.state.page}`, {
course_id: getParam('id'), course_id: getParam('id'),
video_id: videoId, video_id: videoId,
...@@ -80,17 +85,21 @@ class InteractiveStudy extends Component { ...@@ -80,17 +85,21 @@ class InteractiveStudy extends Component {
const {code, msg, data} = res.data const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
this.setState(state => { this.setState(state => {
const totalPage = state.schedule.page_info.total_pages const list = data.syllabus_list
const page = state.page < totalPage ? state.isFirst ? state.page : state.page + 1 : totalPage
const progress = state.processContent.length 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 : 0
if (state.isFirst) {
return { return {
processContent: state.isFirst ? (state.processContent.concat(data.syllabus_list)) : state.processContent, processContent: state.processContent.concat(list),
isFirst: false, isFirst: false,
page, }
}
return {
cachedList: state.cachedList.reverse().concat(list.slice(progress)).reverse(),
page: state.page + 1,
pageData: data, pageData: data,
progress: state.isFirst ? state.progress : progress, progress: progress,
} }
}, () => { }, () => {
cb && cb() cb && cb()
...@@ -102,10 +111,11 @@ class InteractiveStudy extends Component { ...@@ -102,10 +111,11 @@ class InteractiveStudy extends Component {
} }
saveSchedule = (syllabusId, unitInfoId) => { saveSchedule = (syllabusId, unitInfoId) => {
http.post(`/m/it/user/saveSchedule`, { let data = {syllabus_id: syllabusId}
syllabus_id: syllabusId, if (unitInfoId) {
unit_info_id: unitInfoId, data.unit_info_id = unitInfoId
}).then(res => { }
http.post(`/m/it/user/saveSchedule`, data).then(res => {
const {code, msg, data} = res.data const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
...@@ -115,26 +125,50 @@ class InteractiveStudy extends Component { ...@@ -115,26 +125,50 @@ 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 = () => { process = () => {
const {processStatus} = this.state const {processStatus} = this.state
if (processStatus === status.practicingProgram || processStatus === status.practicingSingle) { if (processStatus === status.practicingProgram || processStatus === status.practicingSingle) {
this.showToast('有其他正在进行的练习') this.showToast('有其他正在进行的练习')
return return
} }
if (processStatus === status.nextSection) {
console.log('下一关')
return
}
this.setState(state => { this.setState(state => {
let nextQuestion, progress, cachedList = state.cachedList let nextQuestion, cachedList = state.cachedList, pageData = state.pageData
if (state.cachedList.length) { const length = cachedList.length
if (length) {
nextQuestion = [cachedList.pop()] nextQuestion = [cachedList.pop()]
progress = 0 if (length < 6) {
} else {
nextQuestion = state.pageData.syllabus_list.slice(state.progress, state.progress + 1)
progress = state.progress + 1
}
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) this.getPageContent(state.videoId)
} }
}
if (!cachedList.length) {
return {
processStatus: status.nextSection,
}
}
let processStatus = nextQuestion[0].type === questionType.singleAnswer let processStatus = nextQuestion[0].type === questionType.singleAnswer
? status.practicingSingle ? status.practicingSingle
: nextQuestion[0].type === questionType.program : nextQuestion[0].type === questionType.program
...@@ -142,14 +176,12 @@ class InteractiveStudy extends Component { ...@@ -142,14 +176,12 @@ class InteractiveStudy extends Component {
: status.resumePractice : status.resumePractice
return { return {
processContent: state.processContent.concat(nextQuestion), processContent: state.processContent.concat(nextQuestion),
progress,
processStatus, processStatus,
isProgramShowed: processStatus === status.practicingProgram && (state.isProgramShowed + 1), isProgramShowed: processStatus === status.practicingProgram && (state.isProgramShowed + 1),
cachedList, cachedList,
pageData,
} }
}, () => { }, () => {
// console.log(this.state.processContent)
// console.log(this.state.cachedList)
this.updatePosition() this.updatePosition()
}) })
} }
...@@ -185,10 +217,12 @@ class InteractiveStudy extends Component { ...@@ -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}> <div className="status-bar" onClick={this.process}>
{processStatus && <span className={'status'}>{processStatus}</span>}
{/*<span className={'complete'}>已学完全部课时</span>*/} {/*<span className={'complete'}>已学完全部课时</span>*/}
<span className={'status'}>{processStatus}</span>
{/*<div className="free-trial-end">*/} {/*<div className="free-trial-end">*/}
{/* <span>试学体验结束,389.1元学习全部课时</span>*/} {/* <span>试学体验结束,389.1元学习全部课时</span>*/}
{/* <button className={'purchase'}>立即购买</button>*/} {/* <button className={'purchase'}>立即购买</button>*/}
......
...@@ -137,7 +137,7 @@ function ToolBar({isProgramShowed, userAnswer, isSuccessful, execute}) { ...@@ -137,7 +137,7 @@ function ToolBar({isProgramShowed, userAnswer, isSuccessful, execute}) {
} }
return <Finished/> return <Finished/>
} }
return isProgramShowed ? <Normal/> : <First execute={execute}/> return isProgramShowed > 1 ? <Normal/> : <First execute={execute}/>
} }
export default Program; export default Program;
\ No newline at end of file
...@@ -44,7 +44,12 @@ class TerminalInterface extends Component { ...@@ -44,7 +44,12 @@ class TerminalInterface extends Component {
} }
getAuthenticationData = () => { 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 const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
this.getLinkId(data.token) this.getLinkId(data.token)
...@@ -55,7 +60,11 @@ class TerminalInterface extends Component { ...@@ -55,7 +60,11 @@ class TerminalInterface extends Component {
} }
getLinkId = token => { 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 const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
this.connectServer(data.id) this.connectServer(data.id)
...@@ -77,11 +86,12 @@ class TerminalInterface extends Component { ...@@ -77,11 +86,12 @@ class TerminalInterface extends Component {
console.log(event.message) console.log(event.message)
this.terminal.write(event.data) this.terminal.write(event.data)
} }
this.socket.onerror = () => { this.socket.onerror = (event) => {
console.log('error') console.log(event)
} }
this.socket.onclose = () => { this.socket.onclose = (event) => {
console.log('closed') 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