addTest.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="pb_content" style="background: #F0F2F5;" v-loading="loading">
  3. <div class="pb_content_body" style="position: relative; margin: 0">
  4. <div class="right">
  5. <div class="courseTop">
  6. <div class="stepsNav">
  7. <el-breadcrumb separator-class="el-icon-arrow-right">
  8. <el-breadcrumb-item :to="{
  9. path:
  10. '/test?userid=' +
  11. userid +
  12. '&oid=' +
  13. oid +
  14. '&org=' +
  15. org +
  16. '&role=' +
  17. role,
  18. }">评测管理</el-breadcrumb-item>
  19. <el-breadcrumb-item>
  20. <span style="color: rgb(15, 126, 255)">新建评测</span>
  21. </el-breadcrumb-item>
  22. </el-breadcrumb>
  23. </div>
  24. <div class="r_pub_button_retrun" @click="retrunCourse">返回</div>
  25. </div>
  26. <div class="step_box" :style="{ width: steps == 2 && '100%' }">
  27. <setInfo v-if="steps == 1 && !loading" :oid="oid" :org="org" :steps.sync="steps" :title.sync="title"
  28. :testType.sync="testType" :see.sync="see" :cJson.sync="cJson" :typeid.sync="typeid" :brief.sync="brief" :juri.sync="juri" :overDate.sync="overDate" :juriList.sync="juriList"></setInfo>
  29. <editInfo v-if="steps == 2 && !loading" :oid="oid" :org="org" :steps.sync="steps" :title.sync="title"
  30. :cJson.sync="cJson" @save="save" @publish="publish"></editInfo>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import setInfo from './setInfo/index.vue'
  38. import editInfo from './edit/index.vue'
  39. export default {
  40. components: {
  41. setInfo, editInfo
  42. },
  43. data() {
  44. return {
  45. userid: this.$route.query.userid,
  46. oid: this.$route.query.oid,
  47. org: this.$route.query.org,
  48. role: this.$route.query.role,
  49. cid: this.$route.query.cid,
  50. steps: 1,
  51. title: "",
  52. testType: [],
  53. see: false,
  54. cJson: [],
  55. loading:false,
  56. look:"",
  57. typeid:"",
  58. brief:"",
  59. juri:'0',
  60. overDate:"",
  61. juriList:"",
  62. }
  63. },
  64. watch: {
  65. steps(newValue, oldValue) {
  66. if (!this.title) {
  67. this.$message.error("请补充填写课程名称");
  68. this.steps = 1
  69. return;
  70. }
  71. // else if(!this.juriList.length){
  72. // this.$message.error("请选择权限")
  73. // this.steps = 1
  74. // return
  75. // }
  76. if (this.cid) {
  77. this.updateWork(this.look)
  78. } else {
  79. this.addWork();
  80. }
  81. }
  82. },
  83. methods: {
  84. retrunCourse() {
  85. this
  86. .$confirm("是否保存已编辑内容?", "提示", {
  87. confirmButtonText: "保存",
  88. cancelButtonText: "不保存",
  89. distinguishCancelAndClose: true,
  90. type: "warning",
  91. })
  92. .then(() => {
  93. if (this.cid == "" || this.cid == undefined) {
  94. if (this.title == "") {
  95. this.$message.error("请补充填写课程名称");
  96. return;
  97. }else if(!this.juriList.length){
  98. this.$message.error("请选择权限")
  99. return
  100. }else {
  101. this.addWork(5);
  102. }
  103. } else {
  104. if (this.title == "") {
  105. this.$message.error("请补充填写课程名称");
  106. return;
  107. }else if(!this.juriList.length){
  108. this.$message.error("请选择权限")
  109. return
  110. }else {
  111. this.updateWork(5);
  112. }
  113. }
  114. })
  115. .catch((v) => {
  116. console.log(v)
  117. if (v == "cancel") {
  118. this.goTo(
  119. "/test?userid=" +
  120. this.userid +
  121. "&oid=" +
  122. this.oid +
  123. "&org=" +
  124. this.org +
  125. "&role=" +
  126. this.role
  127. );
  128. }
  129. });
  130. },
  131. goTo(path) {
  132. this.$router.push(path);
  133. },
  134. addWork(look) {
  135. let params = [
  136. {
  137. uid: this.userid,
  138. title: this.title.replace(/%/g, "%25"),
  139. brief: this.brief.replace(/%/g, "%25"),
  140. cover: "",
  141. evaId: "",
  142. astudent: this.juri,
  143. see: this.see == true ? 1 : 0,
  144. chapters: JSON.stringify(this.cJson).replaceAll(/%/g, "%25"),
  145. template: "",
  146. courseType: JSON.stringify(this.testType),
  147. ateacher: "",
  148. inviteCode: "",
  149. typeid: this.typeid ? this.typeid : '',
  150. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  151. j2: this.juriList.length ? this.juriList.join(",") : ''
  152. },
  153. ];
  154. this.ajax
  155. .post(this.$store.state.api + "addTestCourse", params)
  156. .then((res) => {
  157. this.cid = res.data.courseId;
  158. if(look == 5){
  159. this.$message.success("保存成功")
  160. this.goTo(
  161. "/test?userid=" +
  162. this.userid +
  163. "&oid=" +
  164. this.oid +
  165. "&org=" +
  166. this.org +
  167. "&role=" +
  168. this.role
  169. );
  170. }
  171. setTimeout(() => {
  172. this.getData(2);
  173. }, 1000);
  174. })
  175. .catch((err) => {
  176. this.$message.error("网络不佳");
  177. console.error(err);
  178. });
  179. },
  180. formatTime(timestamp) {
  181. const date = new Date(timestamp);
  182. const year = date.getFullYear();
  183. const month = String(date.getMonth() + 1).padStart(2, '0');
  184. const day = String(date.getDate()).padStart(2, '0');
  185. return `${year}-${month}-${day}`;
  186. },
  187. updateWork(look) {
  188. let params = [
  189. {
  190. cid: this.cid,
  191. title: this.title.replace(/%/g, "%25"),
  192. brief: this.brief.replace(/%/g, "%25"),
  193. cover: "",
  194. evaId: "",
  195. astudent: this.juri,
  196. see: this.see == true ? 1 : 0,
  197. chapters: JSON.stringify(this.cJson).replaceAll(/%/g, "%25"),
  198. uid: this.userid,
  199. courseType: JSON.stringify(this.testType),
  200. ateacher: "",
  201. inviteCode: "",
  202. look: look == 3 ? 2 : look == 4 ? this.look : look == 5 ? this.look : look,
  203. typeid: this.typeid ? this.typeid : '',
  204. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  205. j2: this.juriList.length ? this.juriList.join(",") : ''
  206. },
  207. ];
  208. this.ajax
  209. .post(this.$store.state.api + "updateTestCourse", params)
  210. .then((res) => {
  211. if(look == 3){
  212. this.$message.success("发布成功")
  213. this.goTo(
  214. "/test?userid=" +
  215. this.userid +
  216. "&oid=" +
  217. this.oid +
  218. "&org=" +
  219. this.org +
  220. "&role=" +
  221. this.role
  222. );
  223. }else if(look == 4){
  224. this.$message.success("保存成功")
  225. }else if( look == 1 || look == 2){
  226. // this.$message.success("保存成功")
  227. }else if(look == 5){
  228. this.$message.success("保存成功")
  229. this.goTo(
  230. "/test?userid=" +
  231. this.userid +
  232. "&oid=" +
  233. this.oid +
  234. "&org=" +
  235. this.org +
  236. "&role=" +
  237. this.role
  238. );
  239. }
  240. setTimeout(() => {
  241. this.getData(2);
  242. }, 1000);
  243. })
  244. .catch((err) => {
  245. this.$message.error("网络不佳");
  246. console.error(err);
  247. });
  248. },
  249. getData(type) {
  250. if (this.cid == "" || this.cid == undefined) {
  251. console.log("这是新增课程");
  252. } else {
  253. if(type != 2){
  254. this.loading = true
  255. }
  256. let params = {
  257. cid: this.cid,
  258. };
  259. this.ajax
  260. .get(this.$store.state.api + "getTestCourseDetail", params)
  261. .then((res) => {
  262. this.cJson = JSON.parse(res.data[0][0].chapters);
  263. this.title = res.data[0][0].title;
  264. this.juri = res.data[0][0].juri ? res.data[0][0].juri : '0';
  265. this.overDate = res.data[0][0].overTime ? res.data[0][0].overTime : '';
  266. this.juriList = res.data[0][0].juri2 ? res.data[0][0].juri2.split(',') : [];
  267. this.see = res.data[0][0].open == 1 ? true : false;
  268. this.typeid = res.data[0][0].typeid;
  269. this.brief = res.data[0][0].brief;
  270. this.testType = [];
  271. for (var i = 0; i < res.data[1].length; i++) {
  272. this.testType.push(res.data[1][i].typeid);
  273. }
  274. console.log(this.testType);
  275. this.look = res.data[0][0].look
  276. this.$forceUpdate()
  277. if(type != 2){
  278. this.loading = false
  279. }
  280. })
  281. .catch((err) => {
  282. console.error(err);
  283. });
  284. }
  285. },
  286. save(look) {
  287. this.updateWork(look == 4 ? look : this.look)
  288. },
  289. publish() {
  290. this.updateWork(3)
  291. },
  292. },
  293. mounted () {
  294. this.getData();
  295. },
  296. }
  297. </script>
  298. <style scoped>
  299. .pb_content {
  300. height: 100% !important;
  301. /* margin: 0 20px 0 20px; */
  302. }
  303. .pb_content_body {
  304. width: 100% !important;
  305. height: 100%;
  306. }
  307. .right {
  308. height: 100%;
  309. width: 100%;
  310. display: flex;
  311. overflow: hidden;
  312. flex-direction: column;
  313. }
  314. .basic_box {
  315. margin: 0 auto;
  316. position: relative;
  317. padding: 0 20px 0 20px;
  318. }
  319. .courseTop {
  320. display: flex;
  321. flex-direction: row;
  322. justify-content: space-between;
  323. align-items: center;
  324. width: calc(100% - 40px);
  325. margin: 0 auto;
  326. padding: 10px 0;
  327. }
  328. .stepsNav {
  329. display: flex;
  330. flex-direction: row;
  331. justify-content: flex-start;
  332. align-items: center;
  333. }
  334. .step_box {
  335. width: calc(100% - 40px);
  336. margin: 0 auto;
  337. height: calc(100% - 38px);
  338. }
  339. </style>