Commit 0ea48be7 authored by wangxuelai's avatar wangxuelai

''

parent 76a213fe
......@@ -17,6 +17,6 @@
</head>
<body>
<div id="root"></div>
<script src="dist/main.js?1574673220194" charset="utf-8"></script>
<script src="dist/main.js?1574677618779" charset="utf-8"></script>
</body>
</html>
\ No newline at end of file
......@@ -37,12 +37,12 @@ export default {
params: {},
},
});
yield put({
type: 'selectCourseList',
payload: {
params: {},
},
});
// yield put({
// type: 'selectCourseList',
// payload: {
// params: {},
// },
// });
},
* pageInit({ payload }, { call, put, select }) {
yield put({
......
......@@ -5,6 +5,8 @@ import { message } from 'antd';
import {
getFileType,
getRandomFilename,
getAudioDuration,
getVideoDuration,
} from '../utils/index';
import * as uploader from '../services/uploader';
import errorcode from '../common/errorcode';
......@@ -157,6 +159,7 @@ export default {
message.error('上传失败', 1);
return;
}
let duration = 0;
const { name, size, type: fileType } = file;
const typeObject = getFileType(fileType);
let ajax = null;
......@@ -167,10 +170,12 @@ export default {
params = { type: 1, token: userInfo.token, schoolId: sid };
break;
case 2: // 视频
duration = yield call(getVideoDuration, file);
ajax = uploader.uploadVideoSignature;
params = { type: 1, token: userInfo.token, schoolId: sid };
break;
case 3: // 录音
duration = yield call(getAudioDuration, file);
ajax = uploader.uploadVideoSignature;
params = { type: 2, token: userInfo.token, schoolId: sid };
break;
......@@ -196,6 +201,7 @@ export default {
yield put({
type: 'uploadFile',
payload: {
duration,
signature,
successCallBack,
file,
......@@ -237,6 +243,7 @@ export default {
file,
successCallBack,
uploaderLoading,
duration,
} = payload;
const filename = `${signature.dir}${getRandomFilename(file.name)}`;
const { name, size, type: fileType } = file;
......@@ -258,6 +265,7 @@ export default {
name,
size,
fileType,
duration,
},
filename,
type: getFileType(fileType).filetype,
......@@ -274,6 +282,7 @@ export default {
name,
size,
fileType,
duration,
},
filename,
images: getFileType(fileType).filetype == 1 ? [filename] : [],
......
......@@ -6,7 +6,15 @@ import { message } from 'antd';
import * as uploader from '../services/uploader';
import * as courseMateriaAjax from '../services/courseMateria';
import errorcode from '../common/errorcode';
import { getRandomFilename, getFileType, imagify, videoPoster, LocalStorage } from '../utils/index';
import {
getRandomFilename,
getFileType,
imagify,
videoPoster,
LocalStorage,
getAudioDuration,
getVideoDuration,
} from '../utils/index';
export default {
namespace: 'uploadcourseware',
state: {
......@@ -33,16 +41,19 @@ export default {
const typeObject = getFileType(fileType);
let ajax = null;
let params = null;
let duration = 0;
switch (typeObject.fileSmalltype) {
case 1: // 图片
ajax = uploader.uploadImageSignature;
params = { type: 1, token: userInfo.token, schoolId: sid };
break;
case 2: // 视频
duration = yield call(getVideoDuration, file);
ajax = uploader.uploadVideoSignature;
params = { type: 1, token: userInfo.token, schoolId: sid };
break;
case 3: // 录音
duration = yield call(getAudioDuration, file);
ajax = uploader.uploadVideoSignature;
params = { type: 2, token: userInfo.token, schoolId: sid };
break;
......@@ -72,6 +83,7 @@ export default {
successCallBack,
file,
uploaderLoading,
duration,
},
});
} else {
......@@ -89,6 +101,7 @@ export default {
file,
successCallBack,
uploaderLoading,
duration,
} = payload;
const filename = `${signature.dir}${getRandomFilename(file.name)}`;
const { name, size, type: fileType } = file;
......@@ -102,18 +115,6 @@ export default {
};
const uploadFileData = yield call(uploader.uploadImg, params);
setTimeout(uploaderLoading);
// yield put({
// type: 'createCourseMateria',
// payload: {
// content: {
// name,
// size,
// fileType,
// },
// filename,
// type: getFileType(fileType).filetype,
// },
// });
yield put({
type: 'updateState',
payload: {
......@@ -122,6 +123,7 @@ export default {
name,
size,
fileType,
duration,
},
images: getFileType(fileType).filetype == 1 ? [filename] : [],
src: filename,
......
......@@ -214,13 +214,6 @@ class ManageCourse extends React.Component { // eslint-disable-line
render: (text, record) => {
const { content } = record;
let hasWare = false;
// if (!content) {
// hasWare = false;
// } else if (content && !JSON.parse(content).src) {
// hasWare = false;
// } else if (content && JSON.parse(content).src) {
// hasWare = true;
// }
let name = '';
if (manageCourseObj[record.id] && manageCourseObj[record.id].content && manageCourseObj[record.id].content.src) {
hasWare = true;
......
......@@ -350,8 +350,7 @@ class StaticCenter extends React.Component {
}
materialSave = (values) => {
const { dispatch, materiaSaveTo, editSingleCourseInfo } = this.props;
console.log(values, 'values');
console.log(materiaSaveTo, 'materiaSaveTo');
console.log(materiaSaveTo, 'materiaSaveTomateriaSaveTo');
if (materiaSaveTo == 1) {
dispatch({
type: 'coursegatherdetail/updateCover',
......@@ -502,7 +501,6 @@ class StaticCenter extends React.Component {
uploadCourseware = (values) => {
const { dispatch } = this.props;
const { addWareType } = this.state;
console.log(addWareType, 'asdasdas');
if (addWareType == 1) {
dispatch({
type: 'coursegatherdetail/saveCourseWare',
......
......@@ -97,6 +97,7 @@ class singleDetailForm extends React.Component {
size: content.size,
fileType: content.fileType,
name: content.name,
duration: content.duration,
},
images: content.images,
src: checkValue.src,
......
......@@ -820,7 +820,42 @@ function getFileType(type) {
fileSmalltype,
};
}
function getAudioDuration(file) {
return new Promise((resolve, reject) => {
const url = URL.createObjectURL(file);
const audioElement = new Audio(url);
let duration;
audioElement.addEventListener('loadedmetadata', (event) => {
// eslint-disable-next-line prefer-destructuring
duration = audioElement.duration;
resolve(Number(duration).toFixed(0));
// callback(duration);
audioElement.removeEventListener('loadedmetadata', (event) => {
duration = 0;
}, false);
}, false);
});
}
function getVideoDuration(file) {
return new Promise((resolve, reject) => {
const url = URL.createObjectURL(file);
const videoElement = document.createElement('video');
videoElement.id = 'videoElement';
videoElement.src = url;
let duration;
videoElement.addEventListener('loadedmetadata', (event) => {
// eslint-disable-next-line prefer-destructuring
duration = videoElement.duration;
resolve(Number(duration).toFixed(0));
// callback(duration);
videoElement.removeEventListener('loadedmetadata', (event) => {
duration = 0;
}, false);
}, false);
});
}
export {
getAudioDuration,
pageIn,
SessionStorage,
LocalStorage,
......@@ -866,4 +901,5 @@ export {
getDateStamp,
getFileType,
pptImagify,
getVideoDuration,
};
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