123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- import React from 'react';
- import { Link } from 'react-router-dom';
- import './index.less';
- import Page from '@src/containers/Page';
- import Assets from '@src/components/Assets';
- import { getMap, formatPercent, formatDate } from '@src/services/Tools';
- import Footer from '../../../components/Footer';
- import { FaqModal, CommentModal, FinishModal, CourseNoteModal, AskCourseModal } from '../../../components/OtherModal';
- import { Contact, AnswerCarousel, Comment } from '../../../components/Other';
- import Tabs from '../../../components/Tabs';
- import { Icon as GIcon } from '../../../components/Icon';
- import Button from '../../../components/Button';
- import IconButton from '../../../components/IconButton';
- import UserTable from '../../../components/UserTable';
- import ProgressText from '../../../components/ProgressText';
- import { OpenText } from '../../../components/Open';
- import Video from '../../../components/Video';
- import { Main } from '../../../stores/main';
- import { Course } from '../../../stores/course';
- import { User } from '../../../stores/user';
- import { Order } from '../../../stores/order';
- import { Question } from '../../../stores/question';
- import { My } from '../../../stores/my';
- import { QrCodeAssets } from '../../../../Constant';
- export default class extends Page {
- initState() {
- this.columns = [
- {
- title: '学习内容',
- key: 'title',
- render: (text, record) => {
- const { no } = this.state;
- if (no === record.no) {
- // 当前正在
- }
- return `课时 ${record.no}: ${text}`;
- },
- },
- {
- title: '预习作业',
- key: 'paper',
- render: (text, record) => {
- const { paper = {} } = record;
- const progress = paper.report ? formatPercent(paper.report.userNumber, paper.report.questionNumber) : 0;
- const times = paper.paper ? paper.paper.resetTimes : 0;
- return (
- <div>
- <div className="v-a-m d-i-b">
- <ProgressText width={50} size="small" times={times} progress={progress} unit="次" />
- </div>
- {!paper.report && (
- <IconButton
- className="m-l-2"
- type="start"
- tip="Start"
- onClick={() => {
- User.needLogin().then(() => {
- Question.startLink('preview', paper);
- });
- }}
- />
- )}
- {paper.report && !paper.report.isFinish && (
- <IconButton
- className="m-l-2"
- type="continue"
- tip="Continue"
- onClick={() => {
- User.needLogin().then(() => {
- Question.continueLink('preview', paper);
- });
- }}
- />
- )}
- {paper.report && (
- <IconButton
- className="m-l-2"
- type="restart"
- tip="Restart"
- onClick={() => {
- User.needLogin().then(() => {
- Question.restart('preview', paper.id);
- });
- }}
- />
- )}
- {paper.report && !!paper.report.isFinish && (
- <IconButton
- className="m-l-5"
- type="report"
- tip="Report"
- onClick={() => {
- User.needLogin().then(() => {
- Question.reportLink('preview', paper);
- });
- }}
- />
- )}
- </div>
- );
- },
- },
- {
- title: '进度',
- key: 'progress',
- render: (text, record) => {
- const { progress } = record;
- return `${progress && progress.times > 0 ? `${progress.times}次+` : ''}${
- progress ? `${progress.progress}%` : '0%'}`;
- },
- },
- {
- title: '最近学习',
- key: 'lastTime',
- render: (text, rr) => {
- const { record } = rr;
- return record && formatDate(record.createTime, 'YYYY-MM-DD HH:mm:ss');
- },
- },
- {
- title: '笔记',
- key: 'note',
- render: (text, record) => {
- return <GIcon name="note" active={record.note} onClick={() => {
- this.setState({ showNote: true, note: this.noteMap ? this.noteMap[record.id] || { courseNoId: record.id } : { courseNoId: record.id } });
- }} />;
- },
- },
- {
- title: '问答',
- key: 'ask',
- render: (text, record) => {
- return (
- <Link to={`/course/answer/${record.courseId}?tab=my&courseNoId=${record.id}`}>{`${record.answerNumber ||
- 0}/${record.askNumber || 0}`}</Link>
- );
- },
- },
- ];
- return {
- tab: '1',
- rightTab: '1',
- key: '1',
- add: false,
- list: [{ key: '1' }, { key: '2' }, { key: '3' }],
- data: {},
- position: 0,
- };
- }
- init() {
- Main.dataStruct().then(result => {
- const dataStructSelect = result.map(row => {
- return {
- title: `${row.titleZh}${row.titleEn}`,
- key: row.id,
- };
- });
- const dataStructMap = getMap(dataStructSelect, 'key');
- this.setState({ dataStructSelect, dataStructMap });
- });
- Main.getBase().then(result => {
- this.setState({ base: result });
- });
- }
- formatRecord(row) {
- row.paperMap = {};
- if (row.papers) {
- row.papers.forEach(paper => {
- if (paper.courseNo) row.paperMap[paper.courseNo] = paper;
- });
- }
- row.progressMap = {};
- if (row.progress) {
- row.progress.forEach(progress => {
- row.progressMap[progress.courseNoId] = progress;
- });
- }
- row.recordMap = {};
- if (row.records) {
- row.records.forEach(record => {
- row.recordMap[record.courseNoId] = record;
- });
- }
- row.courseNoMap = {};
- row.courseTime = 0;
- if (row.courseNos) {
- row.courseNos.forEach(no => {
- row.courseNoMap[no.id] = no;
- row.courseTime += no.time;
- no.paper = row.paperMap[no.no];
- no.progress = row.progressMap[no.id];
- no.record = row.recordMap[no.id];
- });
- }
- if (row.currentNo) {
- row.currentCourseNo = row.courseNoMap[row.currentNo];
- } else {
- row.currentNo = 0;
- }
- return row;
- }
- initData() {
- const { id } = this.params;
- Course.detail(id).then(result => {
- result = this.formatRecord(result);
- // result.have = true;
- // result.waters = ['高*', '152****4895'];
- this.setState({ data: result });
- // 选择课时
- if (this.state.search.no) {
- this.onChangeItem(Number(this.state.search.no));
- } else {
- this.onChangeItem(1);
- }
- if (!result.have) {
- Course.trailView(id);
- }
- this.refreshNote();
- });
- Main.listComment({ page: 1, size: 100, channel: 'course-video', position: id }).then(result => {
- this.comments = result.list;
- this.setState({ comments: result.list });
- });
- }
- refreshAsk(position) {
- const { id } = this.params;
- const { item = {} } = this.state;
- Course.listAsk(Object.assign({ page: 1, size: 1000, courseId: id, courseNoId: item.id, position })).then(result => {
- this.setState({ asks: result.list });
- });
- }
- refreshNote() {
- const { id } = this.params;
- const { data } = this.state;
- if (!data.have) return;
- My.listCourseNote({ courseId: id, page: 1, size: data.courseNos.length })
- .then((result) => {
- this.noteMap = getMap(result.list, 'courseNoId');
- data.courseNos.forEach((row) => {
- const note = this.noteMap[row.id];
- if (note) row.note = true;
- });
- this.setState({ data });
- });
- }
- onChangeRightTab(rightTab) {
- this.setState({ rightTab });
- }
- onChangeTab(tab) {
- this.setState({ tab });
- }
- onChangeItem(key) {
- key = Number(key);
- this.changeQuery({ no: key });
- this.setState({ no: key });
- const { data, item } = this.state;
- const index = key - 1;
- const timelineSelect = [];
- const current = data.courseNos[index];
- if (current) {
- const max = current.time / 60;
- let start = 0;
- let end = start + 5;
- while (start < max) {
- timelineSelect.push({
- title: `${start} - ${end}min`,
- key: `${start}`,
- });
- start += 5;
- end = Math.min(start + 5, max);
- }
- }
- // 切换播放,记录进度
- if (item) {
- this.updateProgress(item.id, this.lastSecond, item.time, true);
- }
- this.setState({ item: current, timelineSelect });
- }
- onTimeUpdate(second) {
- const { position, item = {}, data } = this.state;
- if (!data.have) {
- // 如果是试用,则按秒数增加
- second += (item.startTrail || 0) * 60;
- }
- const minute = parseInt(second / 60, 10);
- const nowPosition = parseInt(minute / 5, 10) * 5;
- if (nowPosition !== position) {
- this.refreshAsk(position);
- this.setState({ position: nowPosition });
- // 定时更新进度
- this.updateProgress(item.id, second, item.time);
- }
- this.lastSecond = second;
- this.showWater(second);
- }
- playVideo(second) {
- // 开始计时
- this.lastTime = new Date();
- this.showWater(second);
- }
- showWater(second, extend) {
- const { data, water = {} } = this.state;
- let { waters = [] } = data;
- waters = waters || [];
- if (!this.lastTime && water.show) {
- water.show = false;
- second -= 1;
- water.transition = '';
- } else if (!water.show) {
- water.show = true;
- water.transition = 'transform 1s linear 0s';
- }
- if (water.show) {
- water.opacity = 1;
- } else {
- water.opacity = 0;
- }
- if (extend) {
- Object.assign(water, extend);
- }
- const time = 15;
- const stop = 0;
- const times = (second / (time + stop));
- const index = parseInt(times % waters.length, 10);
- const current = (second % (time + stop));
- water.style = [2, 0, 2, 1][parseInt((times % 4), 10)] + 1;
- water.text = waters[[0, 1][index]];
- // console.log(water.show, current, current / 4, (current / 4) % 2);
- if (water.show) {
- water.opacity = (current / 4) % 2 > 1 ? 0 : 1;
- }
- // if (water.style % 2) {
- // water.transform = `translateX(${current * 100 / time}%)`;
- // } else {
- water.transform = `translateX(${100 - ((current - stop / 2) * 100 / time)}%)`;
- // }
- this.setState({ water });
- }
- onChangeProgress(second) {
- this.showWater(second - 1, this.lastTime ? { transition: '', opacity: 0 } : { transition: '', opacity: 0 });
- setTimeout(() => {
- this.showWater(second, this.lastTime ? { transition: 'transform 1s linear 0s', opacity: 1 } : { transition: '', opacity: 0 });
- }, 1);
- }
- pauseVideo(second) {
- // 停止计时
- const now = new Date();
- if (this.lastTime != null) {
- this.time += (now.getTime() - this.lastTime.getTime()) / 1000;
- }
- this.lastTime = null;
- this.showWater(second);
- }
- next() {
- const { data, item } = this.state;
- if (data.courseNos.length === item.no) {
- return;
- }
- this.onChangeItem(item.no + 1);
- }
- onVideoAction(key) {
- const { rightTab, showTab, showAsk, showNote, item = {} } = this.state;
- switch (key) {
- case 'ask':
- return this.setState({ showAsk: !showAsk });
- case 'note':
- return this.setState({ showNote: !showNote, note: this.noteMap ? this.noteMap[item.id] || {} : {} });
- case 'answer':
- return this.setState({ showTab: rightTab === '1' ? !showTab : true, rightTab: '1' });
- case 'list':
- return this.setState({ showTab: rightTab === '2' ? !showTab : true, rightTab: '2' });
- default:
- return '';
- }
- }
- updateProgress(courseNoId, currentTime, totalTime, record) {
- if (!this.lastTime) return;
- const { id } = this.params;
- const now = new Date();
- this.time += (now.getTime() - this.lastTime.getTime()) / 1000;
- this.lastTime = now;
- const progress = formatPercent(currentTime, totalTime);
- if (record || this.time > 600) {
- // 最长5分钟记录一次
- Course.noProgress(id, courseNoId, progress, this.time, courseNoId);
- this.time = 0;
- } else {
- Course.noProgress(id, courseNoId, progress, null, null);
- }
- }
- buy() {
- const { data } = this.state;
- User.needLogin().then(() => {
- Order.speedPay({ productType: 'course', productId: data.id }).then(result => {
- User.needPay(result).then(() => {
- this.refresh();
- });
- });
- });
- }
- add() {
- const { data } = this.state;
- User.needLogin().then(() => {
- Order.addCheckout({ productType: 'course', productId: data.id }).then(() => {
- this.setState({ add: true });
- });
- });
- }
- viewAsk(id) {
- Course.askView(id);
- }
- setVideo(video) {
- this.video = video;
- }
- renderView() {
- const { base = {}, data = {}, item = {}, add, rightTab, showTab, showAsk, showNote, dataStructMap = {}, showComment, comment = {}, showFaq, faq = {}, showFinish, note = {}, ask = {}, timelineSelect = [], water = {} } = this.state;
- const { courseNos = [] } = data;
- const { paper = {} } = item;
- return (
- <div>
- <div className="top content t-8">
- <Link to="/course">千行课堂</Link> > <Link to="/course/online?tab=single">全部课程</Link> > {data.parentStructId > 0 ? <Link to={`/course/online?tab=single&parentStructId=${(dataStructMap[data.parentStructId] || {}).key}`}>{(dataStructMap[data.parentStructId] || {}).title}</Link> : null}{data.parentStructId > 0 ? '> ' : ''}
- <Link to={`/course/online?tab=single&parentStructId=${(dataStructMap[data.parentStructId] || {}).key}&structId=${(dataStructMap[data.structId] || {}).key}`}>{(dataStructMap[data.structId] || {}).title}</Link> > <Link to={`/course/detail/${data.id}`}>{data.title}</Link> > <span className="t-1">课程详情</span>
- </div>
- <div className="center content">
- <div className="t-1 t-s-20">
- {data.title}
- <div className="action f-r">
- {!data.have && <Button className="m-r-1" radius size="lager" onClick={() => this.buy()}>
- 立即购买
- </Button>}
- {!data.have && <Button theme="default" radius size="lager" disabled={data.add || add} onClick={() => this.add()}>
- <Assets name="add" />
- </Button>}
- {data.have && <Button className="m-r-1" radius size="lager" onClick={() => linkTo('/my/course')}>
- 我的课程
- </Button>}
- </div>
- </div>
- <div className="t-2 m-b-1">授课老师:{data.teacher}</div>
- <div className={'detail'}>
- <div className="left">
- {data.have && <div hidden={(paper.paper && paper.paper.finishTimes > 0)} className="left-top">
- <span className="d-i-b m-r-1">预习作业</span>
- <span className="d-i-b m-r-2">
- <ProgressText width={480} size="small" progress={paper.report ? formatPercent(paper.report.userNumber, paper.report.questionNumber) : 0} />
- </span>
- <Button className="f-r" radius onClick={() => (paper.report ? Question.continueLink('preview', paper) : Question.startLink('preview', paper))}>
- 做题
- </Button>
- </div>}
- <div className="video-layout">
- {item.resource && <Video
- key={item.id}
- src={item.resource}
- width={750}
- height={467}
- ref={ref => this.setVideo(ref)}
- water={<div key={water.style} className={`video-water style-${water.style}`} style={{ ...water }}>{water.text}</div>}
- btnList={[
- { title: '提问', key: 'ask', show: data.have, active: showAsk, pause: true },
- {
- key: 'answer',
- render(active) {
- return <Assets name={active ? 'question_on' : 'question_off'} />;
- },
- full: true,
- show: true,
- active: showTab && rightTab === '1',
- },
- { title: '笔记', key: 'note', show: data.have, active: showNote, pause: true },
- { title: '课表', key: 'list', show: true, full: true, active: showTab && rightTab === '2' },
- ]}
- onPlay={(second) => this.playVideo(second)}
- onPause={(second) => this.pauseVideo(second)}
- onChangeProgress={(second) => this.onChangeProgress(second)}
- onNext={() => this.next()}
- onAction={key => this.onVideoAction(key)}
- onTimeUpdate={time => this.onTimeUpdate(time)}
- onFullChange={() => this.setState({ showTab: true, rightTab: '1' })}
- >
- <div hidden={!showTab} className="video-fixed tab-warpper">
- <Tabs
- type="division"
- theme="gray"
- space={2.5}
- active={rightTab}
- tabs={[{ title: '精选问答', key: '1' }, { title: '课时列表', key: '2' }]}
- onChange={key => this.onChangeRightTab(key)}
- />
- <div className="tab-body">{this[`renderRightTab${rightTab}`]()}</div>
- </div>
- </Video>}
- </div>
- </div>
- <div className={`detail-right ${data.have && !(item.paper && item.paper.finishTimes > 0) ? 'have' : ''} tab-warpper`}>
- <Tabs
- type="division"
- theme="gray"
- space={2.5}
- active={rightTab}
- tabs={[{ title: '精选问答', key: '1' }, { title: '课时列表', key: '2' }]}
- onChange={key => this.onChangeRightTab(key)}
- />
- <div className="tab-body">{this[`renderRightTab${rightTab}`]()}</div>
- </div>
- </div>
- {data.have && <UserTable columns={this.columns} data={courseNos} />}
- </div>
- <div hidden={data.have} className="bottom">
- <div className="content">{this.renderTab()}</div>
- </div>
- <Contact data={base.contact} />
- <Footer />
- <AskCourseModal getContainer={() => (showTab ? document.getElementById(this.video.state.id) : document.body)} show={showAsk} defaultData={ask} course={data} courseNo={item} selectList={timelineSelect} onConfirm={() => this.setState({ showAsk: false })} onCancel={() => this.setState({ showAsk: false })} />
- <CourseNoteModal getContainer={() => (showTab ? document.getElementById(this.video.state.id) : document.body)} show={showNote} defaultData={note} course={data} courseNos={courseNos} noteMap={this.noteMap} onConfirm={() => {
- this.setState({ showNote: false });
- this.refreshNote();
- }} onCancel={() => this.setState({ showNote: false })} />
- <CommentModal
- show={showComment}
- defaultData={comment}
- onConfirm={() => this.setState({ showComment: false, commnet: {}, showFinish: true })}
- onCancel={() => this.setState({ showComment: false, commnet: {} })}
- onClose={() => this.setState({ showComment: false, commnet: {} })}
- />
- <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false, faq: {} })} onConfirm={() => this.setState({ showFaq: false, faq: {}, showFinish: true })} />
- <FinishModal
- getContainer={() => document.getElementById(this.video.state.id)}
- show={showFinish}
- onConfirm={() => this.setState({ showFinish: false })}
- />
- </div >
- );
- }
- renderRightTab1() {
- const { asks = [], data = {}, position } = this.state;
- return [
- <div className="all-answer">
- <span className="d-i-b b m-r-5" />
- <span className="d-i-b t-6">{position}:00~{position + 5}:00</span>
- <a className="f-r d-i-b t-4 c-p" href={`/course/answer/${data.id}`} target="_blank">全部问答 ></a>
- </div>,
- <div className="answer-layout">
- {asks.map(item => {
- return (
- <div className="answer-item">
- <div>
- <div className="small-tag">提问</div>
- </div>
- <div className="desc">
- <OpenText>{item.content}</OpenText>
- </div>
- {item.answerStatus > 0 && (
- <div>
- <div className="small-tag">回答</div>
- </div>
- )}
- {item.answerStatus > 0 && (
- <div className="desc">
- <OpenText onOpen={() => this.viewAsk(item.id)}>{item.answer}</OpenText>
- </div>
- )}
- </div>
- );
- })}
- </div>,
- ];
- }
- renderRightTab2() {
- const { data = {}, no } = this.state;
- const { courseNos = [] } = data;
- return (
- <div className="item-layout">
- {courseNos.map(item => {
- return (
- <div className={`item ${item.no === no ? 'active' : ''}`} onClick={() => this.onChangeItem(item.no)}>
- <span className="t-1">课时{item.no}</span>
- <span className="t-2 p-l-1">{item.title}</span>
- </div>
- );
- })}
- </div>
- );
- }
- renderTab() {
- const { tab } = this.state;
- return [
- <div className="bottom">
- <div className="content">
- <Tabs
- type="full"
- border
- active={tab}
- tabs={[
- { title: '课程介绍', key: '1' },
- { title: '授课大纲', key: '2' },
- { title: '小助手', key: '3' },
- { title: 'FAQs', key: '4' },
- { title: '优惠信息', key: '5' },
- { title: '学员评价', key: '6' },
- ]}
- onChange={key => this.onChangeTab(key)}
- />
- {this[`renderTab${tab}`]()}
- </div>
- </div>,
- ];
- }
- renderTab1() {
- const { data = {} } = this.state;
- return (
- <div className="tab-layout">
- <div className="tab-title">老师资历</div>
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.teacherContent }} />
- <div className="tab-title">基本参数</div>
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.baseContent }} />
- <div className="tab-title">授课重点</div>
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.pointContent }} />
- <div className="tab-title">适合人群</div>
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.crowdContent }} />
- </div>
- );
- }
- renderTab2() {
- const { data } = this.state;
- return (
- <div className="tab-layout">
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.syllabusContent }} />
- </div>
- );
- }
- renderTab3() {
- return (
- <div className="tab-layout">
- <div className="qr-layout">
- <Assets name={QrCodeAssets} className="m-r-2 v-a-t" />
- <div className="p-l-1 d-i-b t-l">
- <div className="t-1">千行小助手:</div>
- <div className="t-1 m-b-2">1232104-310431</div>
- <div className="t-2 t-s-12">微信扫码添加千行小助手为好友,</div>
- <div className="t-2 t-s-12">咨询课程,了解更多信息</div>
- </div>
- </div>
- </div>
- );
- }
- renderTab4() {
- const { faqs, data = {} } = this.state;
- return (
- <div className="tab-layout">
- <AnswerCarousel
- hideBtn
- list={faqs}
- onFaq={() => User.needLogin().then(() => this.setState({ showFaq: true, faq: { channel: 'course-video', position: data.id } }))}
- />
- </div>
- );
- }
- renderTab5() {
- const { data = {} } = this.state;
- return (
- <div className="tab-layout">
- <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.promoteContent }} />
- </div>
- );
- }
- renderTab6() {
- const { data = {}, comments = [] } = this.state;
- return (
- <div className="tab-layout">
- {data.have && <div className="m-b-1 t-r">
- <Button width={100} radius onClick={() => User.needLogin().then(() => this.setState({ showComment: true, comment: { channel: 'course-video', position: data.id } }))}>
- 写评论
- </Button>
- </div>}
- {(comments || []).map(item => {
- return <Comment data={item} />;
- })}
- </div>
- );
- }
- }
|