|
|
@ -4,13 +4,13 @@
|
|
|
|
* @Github:
|
|
|
|
* @Github:
|
|
|
|
* @Date: 2019-11-20 16:35:46
|
|
|
|
* @Date: 2019-11-20 16:35:46
|
|
|
|
* @LastEditors: tangjiang
|
|
|
|
* @LastEditors: tangjiang
|
|
|
|
* @LastEditTime: 2019-12-06 20:24:11
|
|
|
|
* @LastEditTime: 2019-12-10 19:54:56
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import types from './actionTypes';
|
|
|
|
import types from './actionTypes';
|
|
|
|
import CONST from '../../constants';
|
|
|
|
import CONST from '../../constants';
|
|
|
|
import { fetchPostOjForm, fetchGetOjById, publishTask } from '../../services/ojService';
|
|
|
|
import { fetchPostOjForm, fetchGetOjById, publishTask } from '../../services/ojService';
|
|
|
|
import { Base64 } from 'js-base64';
|
|
|
|
import { Base64 } from 'js-base64';
|
|
|
|
import { message, notification } from 'antd';
|
|
|
|
import { message, notification, Modal } from 'antd';
|
|
|
|
import { toStore } from 'educoder';
|
|
|
|
import { toStore } from 'educoder';
|
|
|
|
const { jcLabel } = CONST;
|
|
|
|
const { jcLabel } = CONST;
|
|
|
|
// 表单字段映射
|
|
|
|
// 表单字段映射
|
|
|
@ -85,6 +85,7 @@ export const validateOjForm = (props, type) => {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const {ojForm, testCases, identifier, code } = getState().ojFormReducer;
|
|
|
|
const {ojForm, testCases, identifier, code } = getState().ojFormReducer;
|
|
|
|
// console.log('code', code);
|
|
|
|
// console.log('code', code);
|
|
|
|
|
|
|
|
/** 表单验证开始 */
|
|
|
|
let keys = Object.keys(ojForm);
|
|
|
|
let keys = Object.keys(ojForm);
|
|
|
|
// 循环判断每个字段是否为空
|
|
|
|
// 循环判断每个字段是否为空
|
|
|
|
let hasSuccess = true;
|
|
|
|
let hasSuccess = true;
|
|
|
@ -104,14 +105,35 @@ export const validateOjForm = (props, type) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 验证测试用例中的数组是否都有对应的值
|
|
|
|
// 验证测试用例中的数组是否都有对应的值
|
|
|
|
const tcValidResult = [];
|
|
|
|
const tcValidResult = [];
|
|
|
|
testCases.forEach(obj => {
|
|
|
|
// 验证测试用例: 1.必须要有输出值 2. 输入值与输出值必须唯一
|
|
|
|
|
|
|
|
testCases.forEach((obj, i) => {
|
|
|
|
let tempObj = {};
|
|
|
|
let tempObj = {};
|
|
|
|
['input', 'output'].forEach(key => {
|
|
|
|
['input', 'output'].forEach(key => {
|
|
|
|
const value = obj[key];
|
|
|
|
const value = obj[key];
|
|
|
|
const validateResult = emptyValidate(key, value);
|
|
|
|
// 非空校验
|
|
|
|
|
|
|
|
let validateResult = emptyValidate(key, value);
|
|
|
|
const errMsg = validateResult[key].errMsg;
|
|
|
|
const errMsg = validateResult[key].errMsg;
|
|
|
|
if (errMsg) {
|
|
|
|
if (errMsg) {
|
|
|
|
hasSuccess = false;
|
|
|
|
hasSuccess = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 唯一性校验
|
|
|
|
|
|
|
|
const bool = testCases.some((item, j) => {
|
|
|
|
|
|
|
|
if (i !== j) {
|
|
|
|
|
|
|
|
return (item[key] === value);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bool) {
|
|
|
|
|
|
|
|
hasSuccess = false;
|
|
|
|
|
|
|
|
validateResult = {
|
|
|
|
|
|
|
|
[key]: {
|
|
|
|
|
|
|
|
validateStatus: 'error',
|
|
|
|
|
|
|
|
errMsg: key === 'input' ? '输入值必须是唯一的' : '输出值必须是唯一的'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object.assign(tempObj, validateResult);
|
|
|
|
Object.assign(tempObj, validateResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -151,6 +173,8 @@ export const validateOjForm = (props, type) => {
|
|
|
|
payload: false
|
|
|
|
payload: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 表单验证结束 */
|
|
|
|
|
|
|
|
/** 表单验证通过后,调用保存 or 更新 or 发布 */
|
|
|
|
if (hasSuccess) {
|
|
|
|
if (hasSuccess) {
|
|
|
|
// console.log('表单保存的数据为: ', getState());
|
|
|
|
// console.log('表单保存的数据为: ', getState());
|
|
|
|
const {ojFormReducer} = getState();
|
|
|
|
const {ojFormReducer} = getState();
|
|
|
@ -205,6 +229,7 @@ export const validateOjForm = (props, type) => {
|
|
|
|
paramsObj['identifier'] = identifier;
|
|
|
|
paramsObj['identifier'] = identifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 接口调用成功后,跳转至列表页
|
|
|
|
function linkToDev () {
|
|
|
|
function linkToDev () {
|
|
|
|
toStore('oj_description', '');
|
|
|
|
toStore('oj_description', '');
|
|
|
|
dispatch({
|
|
|
|
dispatch({
|
|
|
@ -216,51 +241,61 @@ export const validateOjForm = (props, type) => {
|
|
|
|
}, 1000);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fetchPostOjForm(paramsObj).then(res => {
|
|
|
|
// 调用保存或更新
|
|
|
|
// TODO
|
|
|
|
if (type === 'publish') {
|
|
|
|
if (res.status === 200) { // 保存成功后,重新跳转至列表页
|
|
|
|
// 提示发布信息
|
|
|
|
const {identifier} = res.data
|
|
|
|
Modal.confirm({
|
|
|
|
if (type === 'publish') { // 存在发布时,直接调用发布接口
|
|
|
|
title: '提示',
|
|
|
|
if (identifier) {
|
|
|
|
content: `
|
|
|
|
publishTask(identifier).then(res => {
|
|
|
|
发布后即可应用到自己管理的课堂,
|
|
|
|
if (res.data.status === 0) {
|
|
|
|
是否确定发布?`,
|
|
|
|
message.success('发布成功!');
|
|
|
|
okText: '确定',
|
|
|
|
linkToDev();
|
|
|
|
cancelText: '取消',
|
|
|
|
}
|
|
|
|
onOk () {
|
|
|
|
dispatch({
|
|
|
|
publishTask(identifier).then(res => {
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
if (res.data.status === 0) {
|
|
|
|
payload: false
|
|
|
|
message.success('发布成功!');
|
|
|
|
});
|
|
|
|
linkToDev();
|
|
|
|
}).catch(() => {
|
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
dispatch({
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
payload: false
|
|
|
|
payload: false
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
}).catch(() => {
|
|
|
|
dispatch({
|
|
|
|
dispatch({
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
payload: false
|
|
|
|
payload: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
},
|
|
|
|
|
|
|
|
onCancel () {
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.PUBLISH_LOADING_STATUS,
|
|
|
|
|
|
|
|
payload: false
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 调用更新
|
|
|
|
|
|
|
|
fetchPostOjForm(paramsObj).then(res => {
|
|
|
|
|
|
|
|
if (res.status === 200) { // 保存成功后,重新跳转至列表页
|
|
|
|
if (res.data.identifier) {
|
|
|
|
if (res.data.identifier) {
|
|
|
|
message.success('保存成功!');
|
|
|
|
message.success('保存成功!');
|
|
|
|
linkToDev();
|
|
|
|
linkToDev();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.SUBMIT_LOADING_STATUS,
|
|
|
|
|
|
|
|
payload: false
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch({
|
|
|
|
dispatch({
|
|
|
|
type: types.SUBMIT_LOADING_STATUS,
|
|
|
|
type: types.SUBMIT_LOADING_STATUS,
|
|
|
|
payload: false
|
|
|
|
payload: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.SUBMIT_LOADING_STATUS,
|
|
|
|
|
|
|
|
payload: false
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -361,6 +396,11 @@ export const getOJFormById = (id) => {
|
|
|
|
type: types.SAVE_EDIT_OJ_FORM_AND_TEST_CASE,
|
|
|
|
type: types.SAVE_EDIT_OJ_FORM_AND_TEST_CASE,
|
|
|
|
payload: res.data
|
|
|
|
payload: res.data
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 保存用户信息
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.SAVE_USER_INFO,
|
|
|
|
|
|
|
|
payload: res.data.user
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -371,7 +411,7 @@ export const saveOJFormId = (id) => {
|
|
|
|
payload: id
|
|
|
|
payload: id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 清空测试用例集合
|
|
|
|
// 清空值
|
|
|
|
export const clearOJFormStore = () => {
|
|
|
|
export const clearOJFormStore = () => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
type: types.CLEAR_JSFORM_STORE
|
|
|
|
type: types.CLEAR_JSFORM_STORE
|
|
|
@ -380,27 +420,76 @@ export const clearOJFormStore = () => {
|
|
|
|
|
|
|
|
|
|
|
|
// 测试用例输入值改变时
|
|
|
|
// 测试用例输入值改变时
|
|
|
|
export const testCaseInputChange = (value, index) => {
|
|
|
|
export const testCaseInputChange = (value, index) => {
|
|
|
|
const validate = emptyValidate('input', value)['input'];
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
return {
|
|
|
|
// 非空校验
|
|
|
|
type: types.TEST_CASE_INPUT_CHANGE,
|
|
|
|
let validate = emptyValidate('input', value)['input'];
|
|
|
|
payload: {
|
|
|
|
if (!validate.errMsg) {
|
|
|
|
input: validate,
|
|
|
|
// 唯一性校验
|
|
|
|
value,
|
|
|
|
const {testCases} = getState().ojFormReducer;
|
|
|
|
index
|
|
|
|
const bool = testCases.some((item, i) => {
|
|
|
|
|
|
|
|
if (i !== index) {
|
|
|
|
|
|
|
|
return item['input'] === value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (bool) {
|
|
|
|
|
|
|
|
validate = {
|
|
|
|
|
|
|
|
validateStatus: 'error',
|
|
|
|
|
|
|
|
errMsg: '输入值必须唯一'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.TEST_CASE_INPUT_CHANGE,
|
|
|
|
|
|
|
|
payload: {
|
|
|
|
|
|
|
|
input: validate,
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 测试用例输出值改变时
|
|
|
|
// 测试用例输出值改变时
|
|
|
|
export const testCaseOutputChange = (value, index) => {
|
|
|
|
export const testCaseOutputChange = (value, index) => {
|
|
|
|
const validate = emptyValidate('output', value)['output'];
|
|
|
|
// const validate = emptyValidate('output', value)['output'];
|
|
|
|
return {
|
|
|
|
// return {
|
|
|
|
type: types.TEST_CASE_OUTPUT_CHANGE,
|
|
|
|
// type: types.TEST_CASE_OUTPUT_CHANGE,
|
|
|
|
payload: {
|
|
|
|
// payload: {
|
|
|
|
output: validate,
|
|
|
|
// output: validate,
|
|
|
|
value,
|
|
|
|
// value,
|
|
|
|
index
|
|
|
|
// index
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
|
|
// 非空校验
|
|
|
|
|
|
|
|
let validate = emptyValidate('output', value)['output'];
|
|
|
|
|
|
|
|
if (!validate.errMsg) {
|
|
|
|
|
|
|
|
// 唯一性校验
|
|
|
|
|
|
|
|
const {testCases} = getState().ojFormReducer;
|
|
|
|
|
|
|
|
const bool = testCases.some((item, i) => {
|
|
|
|
|
|
|
|
if (i !== index) {
|
|
|
|
|
|
|
|
return item['output'] === value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (bool) {
|
|
|
|
|
|
|
|
validate = {
|
|
|
|
|
|
|
|
validateStatus: 'error',
|
|
|
|
|
|
|
|
errMsg: '输入值必须唯一'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
|
|
|
type: types.TEST_CASE_OUTPUT_CHANGE,
|
|
|
|
|
|
|
|
payload: {
|
|
|
|
|
|
|
|
output: validate,
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|