Commit b8089100 by zhanghaozhe

智能选课

parent 877784fe
......@@ -3,6 +3,16 @@ import './index.scss'
import { Link } from "react-router-dom";
import { http } from "@/utils"
import { Toast } from "antd-mobile";
import { connect } from "react-redux";
import { WithFullSize } from "@/HOCs"
import { isEmpty } from "lodash";
import { addMessage, addResult, reselect } from './store'
const messageType = {
SYSTEM_MESSAGE: 1,
USER_MESSAGE: 2,
OPTIONS: 3,
}
class IntelligentRecommend extends Component {
......@@ -10,50 +20,85 @@ class IntelligentRecommend extends Component {
state = {
showAnalyzing: false,
systemAvatar: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/home/avatar_20191104.png',
options: [
{
id: 1,
text: '数据分析',
},
{
id: 2,
text: '人工智能',
options: {
data: [],
messageId: 0,
},
{
id: 3,
text: '无人驾驶',
next: {
oid: 0,
rid: 0,
},
],
processing: [],
}
componentDidMount() {
if (!this.props.intelligentRecommend.processing.length) {
this.getMessage()
}
handleSelect = () => {
}
next = () => {
handleSelect = (item) => {
this.props.addMessage({type: messageType.USER_MESSAGE, content: item.describe, id: item.id})
this.setState(state => ({
options: {data: [], messageId: 0},
next: {
...state.next,
oid: item.id,
},
}), () => {
this.getMessage()
})
}
getMessage = (oid = 0, rid = 0) => {
getMessage = () => {
const {oid, rid} = this.state.next
http.get(`${API.home}/sys/icc/communicate/${oid}/${rid}`)
.then(res => {
const {data, code, msg} = res.data
if (code === 200) {
if (data.answer_type === 1) {
this.setState({
showAnalyzing: true,
}, () => {
setTimeout(() => {
this.setState({showAnalyzing: false})
this.props.addResult({...data})
}, Math.random() * 1000 + 2000)
})
} else {
const message = {
type: messageType.SYSTEM_MESSAGE,
content: data.contents.find(item => item.is_question),
}
const optionsData = data.contents.filter(item => !item.is_question)
this.props.addMessage(message)
this.setState({
options: {
messageId: message.content.id,
data: optionsData,
},
next: {rid: data.rid},
})
}
} else {
Toast.fail(msg)
}
})
}
consult = (e) => {
e.preventDefault()
http.post(`${API.home}/sys/icc/consult`, {
rid: this.state.result.rid,
}).finally(() => {
window.location.href = e.target.getAttribute('href')
})
}
render() {
const {showAnalyzing, systemAvatar, processing, options} = this.state
const {showAnalyzing, systemAvatar, options} = this.state
const {user, intelligentRecommend: {result, processing}, reselect} = this.props
const recommends = result.contents
return (
<div id={'intelligent-recommend'}>
<div className="head">
......@@ -63,59 +108,106 @@ class IntelligentRecommend extends Component {
</div>
<div className={'title'}>七月在线智能选课</div>
</div>
<button>重新选课</button>
<button onClick={() => {
this.setState({
next: {oid: 0, rid: 0},
options: {messageId: 0, data: []},
}, () => {
reselect()
this.getMessage()
});
}}>重新选课
</button>
</div>
<div className="dialog-box">
<Message text={'请问你学习的目的是?'} avatar={systemAvatar} identity={'system'}/>
<Options options={options} handleSelect={this.handleSelect}/>
<Message text={'请问你学习的目的是?'} avatar={systemAvatar} identity={'user'}/>
{
!!processing.length && processing.map((item, index) => {
switch (item.type) {
case messageType.SYSTEM_MESSAGE:
return (
<React.Fragment key={index}>
<Message text={item.content.describe} identity={'system'} avatar={systemAvatar}/>
{
options.messageId === item.content.id &&
<Options options={options.data} handleSelect={this.handleSelect}/>
}
</React.Fragment>
)
case messageType.USER_MESSAGE:
return <Message text={item.content} identity={'user'} avatar={user.data.avatar} key={index + 2}/>
}
})
}
{
showAnalyzing && <div className="analyzing">努力分析中...</div>
}
</div>
<div className="result">
{
!isEmpty(recommends) && <div className="result">
<div className="title">根据您目前的情况,推荐结果如下</div>
<div className="obtained">
<div className={'subtitle'}>您将掌握的技能:</div>
<div className={'skill'}>技能描述、技能描述</div>
<div className={'subtitle'} dangerouslySetInnerHTML={{__html: recommends.skill_title}}></div>
<div className={'skill'} dangerouslySetInnerHTML={{__html: recommends.skill_desc}}></div>
</div>
<div className="obtained">
<div className={'subtitle'}>掌握后可以胜任以下工作及项目:</div>
<ul>
<li className={'skill'} style={{fontSize: '14px'}}>·技能描述、技能描述</li>
<li className={'skill'} style={{fontSize: '14px'}}>·工作及项目描述、工作及项目描述、项目描述</li>
</ul>
<div className={'subtitle'} dangerouslySetInnerHTML={{__html: recommends.project_title}}></div>
<div className={'skill project'} dangerouslySetInnerHTML={{__html: recommends.project_desc}}></div>
{/*<ul>
<li className={'skill project'}>·技能描述、技能描述</li>
<li className={'skill project'}>·工作及项目描述、工作及项目描述、项目描述</li>
</ul>*/}
</div>
<div className={'salary-section'}>
<div className={'subtitle'}>薪资范围:</div>
<div className={'salary'}>¥15k25K</div>
<div className={'subtitle'} dangerouslySetInnerHTML={{__html: recommends.salary_title}}></div>
<div className={'salary'} dangerouslySetInnerHTML={{__html: recommends.salary_desc}}></div>
</div>
<div className="recommends">
<div>想获得以上技能,向您推荐:</div>
<ul className={'courses'}>
<li className={'course'}>
{
!!recommends.courses.length && recommends.courses.map(item => {
return <li className={'course'} key={item.course_id} onClick={(e) => {
e.target.nodeName.toLowerCase() !== 'a' && this.props.history.push(`/detail?id=${item.course_id}`)
}}>
<div className="cover">
<img src="https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/1a3d88e90a.jpg" alt=""/>
<img src={item.img_url}
alt=""/>
</div>
<div className="info">
<div className={'title'}>课程名称</div>
<div className={'des'}>课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍课程介绍</div>
<div className={'title'}>{item.recmd_title}</div>
<div className={'des'}>{item.recmd_desc}</div>
<div className="bar">
{/*<div className="prices">
<span className={'price'}>¥3980</span>
<span className={'old-price'}>¥5680</span>
</div>*/}
{/*<a href="http://q.url.cn/s/Vbkup6m?_type=wpa" className={'contact'}>获取课程大纲</a>
<Link className={'register'}>立即报名</Link>*/}
<Link className={'study'}>开始学习</Link>
{
item.c_type === 1 && <React.Fragment key={item.course_id}>
<div className="prices">
<span className={'price'}>{item.price_sale}</span>
<span className={'old-price'}>{item.price_original}</span>
</div>
<Link className={'register'} to={`/detail?id=${item.course_id}`}>{item.second_btn}</Link>
</React.Fragment>
}
{
item.c_type === 2 && <React.Fragment key={item.course_id}>
<a href="http://q.url.cn/s/Vbkup6m?_type=wpa" className={'contact'}
onClick={this.consult.bind(this, item.rid)}>{item.consult}</a>
<Link className={'register'} to={`/detail?id=${item.course_id}`}>{item.second_btn}</Link>
</React.Fragment>
}
{
item.c_type === 0 &&
<Link className={'study'} to={`/play?id=${item.v_course_id}`}>{item.second_btn}</Link>
}
</div>
</div>
</li>
})
}
</ul>
</div>
</div>
}
</div>
);
}
......@@ -134,8 +226,8 @@ function Options({options, handleSelect}) {
return <ul className={'options'}>
{
!!options.length && options.map(item => {
return <li onClick={handleSelect} key={item.id}>
{item.text}
return <li onClick={() => handleSelect(item)} key={item.id}>
{item.describe}
</li>
})
}
......@@ -143,4 +235,7 @@ function Options({options, handleSelect}) {
}
export default IntelligentRecommend;
\ No newline at end of file
export default connect(
({user, intelligentRecommend}) => ({user, intelligentRecommend}),
{addMessage, addResult, reselect},
)(WithFullSize(IntelligentRecommend));
\ No newline at end of file
#intelligent-recommend {
background: linear-gradient(to right, #F1F0F6, #EBF4F9);
padding: 59px 10px 0;
padding: 59px 10px 18px;
height: 100%;
.clearfix {
&::after {
......@@ -172,9 +173,7 @@
}
.result {
width: 355px;
height: 614px;
padding: 0 15px;
padding: 0 15px 30px;
background: rgba(255, 255, 255, 1);
border: 1px solid rgba(0, 153, 255, 1);
border-radius: 8px;
......@@ -218,6 +217,10 @@
font-size: 18px;
line-height: 36px;
font-weight: 600;
&.project {
font-size: 14px;
}
}
.salary {
......@@ -257,9 +260,11 @@
.course {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
.info {
flex: 1 1 auto;
position: relative;
}
.title {
......@@ -282,9 +287,13 @@
}
.bar {
position: absolute;
left: 0;
bottom: 0;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 24px;
font-size: 0;
......@@ -321,7 +330,7 @@
text-decoration: line-through;
}
.study{
.study {
background-color: #09f;
color: #fff;
font-size: 12px;
......
export const ADD_MESSAGE = 'ADD_MESSAGE'
export const ADD_RESULT = 'ADD_RESULT'
export const RESELECT = 'RESELECT'
export const addMessage = payload => {
return {
type: ADD_MESSAGE,
payload,
}
}
export const addResult = payload => {
return {
type: ADD_RESULT,
payload,
}
}
export const reselect = () => {
return {
type: RESELECT
}
}
const initialState = {
processing: [],
result: {},
}
export default function intelligentRecommend(state = initialState, action) {
switch (action.type) {
case ADD_MESSAGE:
return {
processing: [...state.processing, action.payload],
result: state.result,
}
case ADD_RESULT:
return {
processing: state.processing,
result: action.payload,
}
case RESELECT:
return initialState
default:
return state
}
}
\ No newline at end of file
......@@ -3,13 +3,15 @@ import myCourses from '@/components/study/myCourses/reducers'
import courseInfo from '@/components/detail/reducers'
import user from './userReducer'
import country from '@/components/country/countryRedux'
import intelligentRecommend from "@components/intelligent-recommend/store"
const reducer = combineReducers({
myCourses,
courseInfo,
user,
country
country,
intelligentRecommend
});
export default reducer;
\ No newline at end of file
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