Skip to content

Commit 6f11b9a

Browse files
committed
fix:试卷题目状态 #5
1 parent 7280688 commit 6f11b9a

5 files changed

Lines changed: 147 additions & 81 deletions

File tree

src/assets/data/publish/exam.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"radio": "单选题",
44
"checkbox": "多选题"
55
},
6+
"statusmap": {
7+
"-2": "已删除",
8+
"-1": "未通过审核",
9+
"0": "待审核",
10+
"1": "已入库",
11+
"2": "私有"
12+
},
613
"styles": [
714
{ "label": "蓝色", "value": "default" },
815
{ "label": "绿色", "value": "green" },

src/bucket/paper.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,10 @@
3737

3838
<script>
3939
import examData from "@/assets/data/publish/exam.json";
40-
const { types } = examData;
4140
import dateFormat from "@/utils/dateFormat";
4241
import { getLink } from "@jx3box/jx3box-common/js/utils";
4342
import { deletePaper } from "@/service/publish/exam.js";
44-
const statusmap = {
45-
"-2": "已删除",
46-
"-1": "未通过审核",
47-
0: "待审核",
48-
1: "已入库",
49-
2: "私有",
50-
};
43+
const { types, statusmap } = examData;
5144
export default {
5245
name: "paper",
5346
props: ["data"],

src/bucket/question.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ import examData from "@/assets/data/publish/exam.json";
4141
import dateFormat from "@/utils/dateFormat";
4242
import { getLink } from "@jx3box/jx3box-common/js/utils";
4343
import { deleteQuestion } from "@/service/publish/exam.js";
44-
const { types } = examData;
45-
const statusmap = {
46-
"-2": "已删除",
47-
"-1": "未通过审核",
48-
0: "待审核",
49-
1: "已入库",
50-
};
44+
const { types, statusmap } = examData;
5145
export default {
5246
name: "question",
5347
props: ["data"],

src/post/exam_paper.vue

Lines changed: 71 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
<el-form label-position="left" label-width="80px" class="m-publish-exam">
1010
<!-- 客户端 -->
1111
<publish-client v-model="primary.client"></publish-client>
12+
<el-form-item label="状态" class="m-publish-exam-common">
13+
<el-radio-group v-model="primary.status">
14+
<el-radio value="">公开</el-radio>
15+
<el-radio :value="PRIVATE_STATUS">私有</el-radio>
16+
</el-radio-group>
17+
</el-form-item>
1218
<el-form-item label="标题" class="m-publish-exam-title">
1319
<el-input
1420
v-model="primary.title"
@@ -89,30 +95,61 @@ import exam_tags from "@/components/publish/exam_tags.vue";
8995
import User from "@jx3box/jx3box-common/js/user";
9096
import { getPaper, createPaper, updatePaper } from "@/service/publish/exam";
9197
import examData from "@/assets/data/publish/exam.json";
92-
const { awards, marks, styles } = examData;
9398
import { getLink } from "@jx3box/jx3box-common/js/utils";
99+
const { awards, marks, styles } = examData;
100+
const DEFAULT_CLIENT = "std";
101+
const PRIVATE_STATUS = 2;
102+
103+
function getDefaultPrimary() {
104+
return {
105+
client: DEFAULT_CLIENT,
106+
status: "",
107+
title: "",
108+
desc: "",
109+
questionList: [],
110+
hardStar: 0,
111+
tags: [],
112+
corner: "",
113+
medalAward: "",
114+
style: "default",
115+
iframe: "",
116+
};
117+
}
118+
119+
function getFormStatus(status) {
120+
return Number(status) === PRIVATE_STATUS ? PRIVATE_STATUS : "";
121+
}
122+
123+
function hasStatus(status) {
124+
return status !== "" && status !== undefined && status !== null;
125+
}
126+
127+
function getSubmitData(primary, originalStatus) {
128+
const data = { ...primary };
129+
data.client = data.client || DEFAULT_CLIENT;
130+
if (Number(data.status) === PRIVATE_STATUS) {
131+
data.status = PRIVATE_STATUS;
132+
} else if (hasStatus(originalStatus)) {
133+
data.status = originalStatus;
134+
} else {
135+
delete data.status;
136+
}
137+
return data;
138+
}
139+
94140
export default {
95141
name: "exam_paper",
96142
props: [],
97143
data: function () {
98144
return {
99-
primary: {
100-
client: "std",
101-
title: "",
102-
desc: "",
103-
questionList: [],
104-
hardStar: 0,
105-
tags: [],
106-
corner: "",
107-
medalAward: "",
108-
style: "default",
109-
iframe: "",
110-
},
145+
primary: getDefaultPrimary(),
111146
list: "",
112147
isSuper: User.isEditor(),
113148
awards,
114149
marks,
115150
styles,
151+
PRIVATE_STATUS,
152+
originalStatus: "",
116153
processing: false,
117154
loading: false,
118155
};
@@ -126,25 +163,18 @@ export default {
126163
methods: {
127164
publish: function () {
128165
this.processing = true;
129-
this.primary.questionList = this.checkList();
130-
if (!this.primary.questionList) return;
131-
if (this.id) {
132-
updatePaper(this.id, this.primary, this)
133-
.then((res) => {
134-
this.success(res);
135-
})
136-
.finally(() => {
137-
this.processing = false;
138-
});
139-
} else {
140-
createPaper(this.primary, this)
141-
.then((res) => {
142-
this.success(res);
143-
})
144-
.finally(() => {
145-
this.processing = false;
146-
});
147-
}
166+
const data = getSubmitData(this.primary, this.id ? this.originalStatus : undefined);
167+
data.questionList = this.checkList();
168+
if (!data.questionList) return;
169+
const request = this.id ? updatePaper(this.id, data) : createPaper(data);
170+
request
171+
.then((res) => {
172+
this.success(res);
173+
})
174+
.catch(() => {})
175+
.finally(() => {
176+
this.processing = false;
177+
});
148178
},
149179
success: function (res) {
150180
this.$message({
@@ -160,9 +190,15 @@ export default {
160190
getPaper(this.id, this)
161191
.then((res) => {
162192
let data = res.data;
163-
this.primary = data;
164-
this.primary.tags = JSON.parse(data.tags);
165-
this.primary.questionList = JSON.parse(data.questionList);
193+
this.originalStatus = data.status;
194+
this.primary = {
195+
...getDefaultPrimary(),
196+
...data,
197+
client: data.client || DEFAULT_CLIENT,
198+
status: getFormStatus(data.status),
199+
};
200+
this.primary.tags = data.tags ? JSON.parse(data.tags) : [];
201+
this.primary.questionList = data.questionList ? JSON.parse(data.questionList) : [];
166202
this.list = this.primary.questionList.toString();
167203
})
168204
.finally(() => {

src/post/exam_question.vue

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<!-- <h1 class="m-publish-exam-header">贡献题目</h1> -->
99
<el-form label-position="left" label-width="80px" class="m-publish-exam">
1010
<publish-client v-model="primary.client"></publish-client>
11+
<el-form-item label="状态" class="m-publish-exam-common">
12+
<el-radio-group v-model="primary.status">
13+
<el-radio value="">公开</el-radio>
14+
<el-radio :value="PRIVATE_STATUS">私有</el-radio>
15+
</el-radio-group>
16+
</el-form-item>
1117
<el-form-item label="题目" class="m-publish-exam-title">
1218
<el-input
1319
v-model="primary.title"
@@ -83,22 +89,53 @@ import Tinymce from "@jx3box/jx3box-editor/src/Tinymce";
8389
import User from "@jx3box/jx3box-common/js/user";
8490
import { getQuestion, createQuestion, updateQuestion } from "@/service/publish/exam";
8591
import { getLink } from "@jx3box/jx3box-common/js/utils";
92+
const DEFAULT_CLIENT = "std";
93+
const PRIVATE_STATUS = 2;
94+
95+
function getDefaultPrimary() {
96+
return {
97+
client: DEFAULT_CLIENT,
98+
status: "",
99+
title: "",
100+
type: "radio",
101+
options: ["", "", "", ""],
102+
answer: [],
103+
hardStar: 0,
104+
tags: [],
105+
whyami: "",
106+
pool: "common",
107+
};
108+
}
109+
110+
function getFormStatus(status) {
111+
return Number(status) === PRIVATE_STATUS ? PRIVATE_STATUS : "";
112+
}
113+
114+
function hasStatus(status) {
115+
return status !== "" && status !== undefined && status !== null;
116+
}
117+
118+
function getSubmitData(primary, originalStatus) {
119+
const data = { ...primary };
120+
data.client = data.client || DEFAULT_CLIENT;
121+
if (Number(data.status) === PRIVATE_STATUS) {
122+
data.status = PRIVATE_STATUS;
123+
} else if (hasStatus(originalStatus)) {
124+
data.status = originalStatus;
125+
} else {
126+
delete data.status;
127+
}
128+
return data;
129+
}
130+
86131
export default {
87132
name: "exam_question",
88133
props: [],
89134
data: function () {
90135
return {
91-
primary: {
92-
client: "std",
93-
title: "",
94-
type: "radio",
95-
options: ["", "", "", ""],
96-
answer: [],
97-
hardStar: 0,
98-
tags: [],
99-
whyami: "",
100-
pool: "common",
101-
},
136+
primary: getDefaultPrimary(),
137+
PRIVATE_STATUS,
138+
originalStatus: "",
102139
processing: false,
103140
loading: false,
104141
@@ -130,23 +167,16 @@ export default {
130167
methods: {
131168
publish: function () {
132169
this.processing = true;
133-
if (this.id) {
134-
updateQuestion(this.id, this.primary)
135-
.then((res) => {
136-
this.success(res);
137-
})
138-
.finally(() => {
139-
this.processing = false;
140-
});
141-
} else {
142-
createQuestion(this.primary)
143-
.then((res) => {
144-
this.success(res);
145-
})
146-
.finally(() => {
147-
this.processing = false;
148-
});
149-
}
170+
const data = getSubmitData(this.primary, this.id ? this.originalStatus : undefined);
171+
const request = this.id ? updateQuestion(this.id, data) : createQuestion(data);
172+
request
173+
.then((res) => {
174+
this.success(res);
175+
})
176+
.catch(() => {})
177+
.finally(() => {
178+
this.processing = false;
179+
});
150180
},
151181
success: function (res) {
152182
this.$message({
@@ -162,9 +192,15 @@ export default {
162192
getQuestion(this.id)
163193
.then((res) => {
164194
let data = res.data;
165-
this.primary = data;
166-
this.primary.options = JSON.parse(data.options);
167-
this.primary.tags = JSON.parse(data.tags);
195+
this.originalStatus = data.status;
196+
this.primary = {
197+
...getDefaultPrimary(),
198+
...data,
199+
client: data.client || DEFAULT_CLIENT,
200+
status: getFormStatus(data.status),
201+
};
202+
this.primary.options = data.options ? JSON.parse(data.options) : ["", "", "", ""];
203+
this.primary.tags = data.tags ? JSON.parse(data.tags) : [];
168204
this.primary.answer = data.answerList || [];
169205
})
170206
.finally(() => {

0 commit comments

Comments
 (0)