Commit 2c94d17f by FE

read api

parent 618d120f
...@@ -12,17 +12,21 @@ class PythonClass extends Component { ...@@ -12,17 +12,21 @@ class PythonClass extends Component {
this.state = { this.state = {
isWechat: browser.isWeixin, isWechat: browser.isWeixin,
isShare: true, isShare: true,
type: '1', // 1:课后习题,2:课堂习题
entryMode: 1, // 0:扫码页,1:落地页,2:直接进入 entryMode: 1, // 0:扫码页,1:落地页,2:直接进入
isExecute: false, isExecute: false,
isCopy: false, isCopy: false,
command: 'http://m.julyedu.com/python?from=python' command: 'http://m.julyedu.com/python?from=python',
data: {}
} }
} }
componentDidMount() { componentDidMount() {
this.handleFetchInfo(); this.handleFetchInfo();
this.initPageStatus();
}
initPageStatus = () => {
if(getParam('from') === 'barcode') { if(getParam('from') === 'barcode') {
this.setState({ this.setState({
entryMode: 0 entryMode: 0
...@@ -33,12 +37,31 @@ class PythonClass extends Component { ...@@ -33,12 +37,31 @@ class PythonClass extends Component {
entryMode: 2 entryMode: 2
}); });
} }
if(getParam('type') === '1') {
this.setState({
isShare: true
});
}
if(getParam('type') === '2') {
this.setState({
isShare: false
});
}
this.setState({
type: getParam('ques') || '1'
});
} }
handleFetchInfo = () => { handleFetchInfo = () => {
const id = getParam('id') || 10; const id = getParam('id') || 10;
http.get(`${API.home}/web/python/share/help/${id}`).then(res => { http.get(`${API.home}/web/python/share/help/${id}`).then(res => {
console.log(res); console.log(res);
const { code, data } = res.data;
if(code === 200) {
this.setState({
data,
});
}
}) })
} }
...@@ -48,7 +71,7 @@ class PythonClass extends Component { ...@@ -48,7 +71,7 @@ class PythonClass extends Component {
this.setState({ this.setState({
entryMode: 1 entryMode: 1
}); });
history.push(`/python?id=${getParam('id')}&from=python`); history.push(`/python?id=${getParam('id')}&type=${getParam('type')}&ques=${getParam('ques')}&from=python`);
} }
} }
...@@ -66,7 +89,7 @@ class PythonClass extends Component { ...@@ -66,7 +89,7 @@ class PythonClass extends Component {
} }
render() { render() {
const { isWechat, isShare, isExecute, entryMode, command, isCopy } = this.state; const { isWechat, isShare, isExecute, type, entryMode, command, isCopy, data } = this.state;
return ( return (
<> <>
<HeaderBar <HeaderBar
...@@ -74,14 +97,15 @@ class PythonClass extends Component { ...@@ -74,14 +97,15 @@ class PythonClass extends Component {
arrow={true} arrow={true}
home={true} home={true}
/> />
{entryMode}
<PythonContent <PythonContent
isWechat={isWechat} isWechat={isWechat}
isShare={isShare} isShare={isShare}
type={type}
isExecute={isExecute} isExecute={isExecute}
entryMode={entryMode} entryMode={entryMode}
isCopy={isCopy} isCopy={isCopy}
command={command} command={command}
data={data}
handleToExecute={this.handleToExecute} handleToExecute={this.handleToExecute}
handleToSend={this.handleToSend} handleToSend={this.handleToSend}
copyToSuccess={this.copyToSuccess} copyToSuccess={this.copyToSuccess}
...@@ -92,7 +116,27 @@ class PythonClass extends Component { ...@@ -92,7 +116,27 @@ class PythonClass extends Component {
} }
function PythonContent(props) { function PythonContent(props) {
const { isWechat, isShare, isExecute, entryMode, isCopy, command, handleToSend, copyToSuccess, handleToExecute } = props; const {
isWechat,
isShare,
isExecute,
type,
entryMode,
isCopy,
command,
data: { head_img, nickname, code_lines, code, result, ques_name, course_name, video_name },
handleToSend,
copyToSuccess,
handleToExecute
} = props;
let labelName = '';
if(type === '1') {
labelName = `练习-${ques_name}`;
}
if(type === '2') {
labelName = `课堂-${video_name}`;
}
return ( return (
<div className="python-container"> <div className="python-container">
...@@ -127,24 +171,24 @@ function PythonContent(props) { ...@@ -127,24 +171,24 @@ function PythonContent(props) {
<div className="python-content"> <div className="python-content">
<div className="python-user"> <div className="python-user">
<div className="python-user__portrait"> <div className="python-user__portrait">
<img src="" alt=""/> <img src={head_img} alt=""/>
</div> </div>
<h2 className="python-user__id">这里是用户ID</h2> <h2 className="python-user__id">{nickname}</h2>
{/* 分享 */} {/* 分享 */}
{ {
(entryMode === 0 && isShare) && (entryMode === 0 && isShare) &&
<p className="python-user__desc"> <p className="python-user__desc">
完成了 完成了
<span>练习-听见无脸男的声音</span> <span>{labelName}</span>
</p> </p>
} }
{ {
(entryMode !== 0 && isShare) && (entryMode !== 0 && isShare) &&
<p className="python-user__desc"> <p className="python-user__desc">
<span>练习-听见无脸男的声音</span>完成了<br /> <span>{course_name}</span>完成了<br />
练习-听见无脸男的声音 {labelName}
</p> </p>
} }
...@@ -153,7 +197,7 @@ function PythonContent(props) { ...@@ -153,7 +197,7 @@ function PythonContent(props) {
(entryMode === 0 && !isShare) && (entryMode === 0 && !isShare) &&
<p className="python-user__desc"> <p className="python-user__desc">
<span>练习-听见无脸男的声音</span> <span>{labelName}</span>
遇到了困难 遇到了困难
</p> </p>
} }
...@@ -161,26 +205,26 @@ function PythonContent(props) { ...@@ -161,26 +205,26 @@ function PythonContent(props) {
(entryMode !== 0 && !isShare) && (entryMode !== 0 && !isShare) &&
<p className="python-user__desc"> <p className="python-user__desc">
<span>练习-听见无脸男的声音</span>的<br /> <span>{course_name}</span>的<br />
课程-萌新的进化遇到了困难 <span>{labelName}</span>遇到了困
</p> </p>
} }
</div> </div>
<h4 className="python-code__title"> <h4 className="python-code__title">
{ entryMode !== 0 && isShare? '这是Ta的第723行代码' : '运行结果'} {entryMode !== 0 && isShare? `这是Ta的第${code_lines}行代码` : '运行结果'}
</h4> </h4>
<div className="python-code__content"> <div className="python-code__content">
code {entryMode !== 0 && isShare? code : result}
</div> </div>
<h4 className="python-code__title">代码</h4> <h4 className="python-code__title">{entryMode === 0? '代码' : '运行结果'}</h4>
<div className="python-code__content"> <div className="python-code__content">
{ {
entryMode === 0 && entryMode === 0 &&
<p>code</p> <p>{code}</p>
} }
{ {
entryMode !== 0 && entryMode !== 0 &&
<p>{isExecute? 'code' : ''}</p> <p>{isExecute? result : ''}</p>
} }
{ {
(entryMode !== 0 && isShare && !isExecute) && (entryMode !== 0 && isShare && !isExecute) &&
......
...@@ -110,9 +110,12 @@ ...@@ -110,9 +110,12 @@
position: relative; position: relative;
height: 171px; height: 171px;
margin: 0 16px; margin: 0 16px;
padding: 0 10px;
border-radius: 5px; border-radius: 5px;
border: 1px solid #67E4FF; border: 1px solid #67E4FF;
box-sizing: border-box; box-sizing: border-box;
font-size: 14px;
color: #fff;
background-color: #272822; background-color: #272822;
} }
......
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