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";
8995import User from " @jx3box/jx3box-common/js/user" ;
9096import { getPaper , createPaper , updatePaper } from " @/service/publish/exam" ;
9197import examData from " @/assets/data/publish/exam.json" ;
92- const { awards , marks , styles } = examData;
9398import { 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+
94140export 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 (() => {
0 commit comments