preview.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. <template>
  2. <div class="pb_content" style="background: #F0F2F5;" v-loading="loading || isloading">
  3. <div class="pb_content_body" style="position: relative; margin: 0">
  4. <div class="right">
  5. <div class="courseTop" :style="`justify-content: ${isN==1?'flex-end':'space-between'};`">
  6. <div class="stepsNav" v-if="isN !=1">
  7. <el-breadcrumb separator-class="el-icon-arrow-right">
  8. <el-breadcrumb-item :to="{
  9. path:
  10. '/testPerson?userid=' +
  11. userid +
  12. '&oid=' +
  13. oid +
  14. '&org=' +
  15. org +
  16. '&role=' +
  17. role,
  18. }" v-if="type == 3">个人中心</el-breadcrumb-item>
  19. <el-breadcrumb-item :to="{
  20. path:
  21. '/testStudent?userid=' +
  22. userid +
  23. '&oid=' +
  24. oid +
  25. '&org=' +
  26. org +
  27. '&role=' +
  28. role +
  29. '&isN=' +
  30. isN +
  31. '&tcid=' +
  32. tcid ,
  33. }" v-else>表单中心</el-breadcrumb-item>
  34. <el-breadcrumb-item>
  35. <span style="color: rgb(15, 126, 255)">{{ title }}</span>
  36. </el-breadcrumb-item>
  37. </el-breadcrumb>
  38. </div>
  39. <div class="r_pub_button_retrun" @click="retrunCourse">返回</div>
  40. </div>
  41. <div class="step_box">
  42. <div class="edit_top" :style="isN==1?'border-bottom:none;justify-content:space-between;padding:10px':''">
  43. <div v-if="isN==1" class="edit_title" :style=" isN==1? 'margin-left : 12px' : ''">提交记录</div>
  44. <div class="op_btn">
  45. <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="autoFill" v-if="(showAutoFillBtn && isN!=1)">智能填写</el-button>
  46. <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="refresh" v-if="isReset">刷新</el-button>
  47. <el-button :type="isN!=1?'primary':'info'" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="reset">重置</el-button>
  48. <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="save" v-if="(type != 3 && isN!=1)">保存</el-button>
  49. <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="publish">提交</el-button>
  50. </div>
  51. </div>
  52. <topicVue :cJson.sync="cJson" :title="title" :brief="brief" ref="topicVue" v-if="!loading"
  53. @getTestWorkByCid="getTestWorkByCid" @publish2="publish2" :tid="tid" :gcourseid="gcourseid"></topicVue>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import topicVue from './component/topic.vue';
  61. export default {
  62. components: {
  63. topicVue
  64. },
  65. data() {
  66. return {
  67. userid: this.$route.query.userid,
  68. oid: this.$route.query.oid,
  69. org: this.$route.query.org,
  70. role: this.$route.query.role,
  71. cid: this.$route.query.cid,
  72. tid: this.$route.query.tid,
  73. type: this.$route.query.type,
  74. updateType: this.$route.query.type,
  75. isN: this.$route.query.isN,
  76. tcid: this.$route.query.tcid,
  77. steps: 1,
  78. title: "",
  79. brief: "",
  80. testType: [],
  81. see: false,
  82. cJson: [],
  83. cJson2: [],
  84. loading: false,
  85. look: "",
  86. isReset: false,
  87. isloading: false,
  88. courseid: '',
  89. gcourseid: this.$route.query.courseid
  90. }
  91. },
  92. computed:{
  93. showAutoFillBtn(){
  94. let _json = this.JSONSetting(this.cJson)
  95. return _json.filter(i=>i.type==3).length>0;
  96. }
  97. },
  98. methods: {
  99. retrunCourse() {
  100. this
  101. .$confirm("是否确认返回?", "提示", {
  102. confirmButtonText: "确认",
  103. cancelButtonText: "取消",
  104. distinguishCancelAndClose: true,
  105. type: "warning",
  106. })
  107. .then(() => {
  108. if (this.type == 3) {
  109. this.goTo(
  110. "/testPerson?userid=" +
  111. this.userid +
  112. "&oid=" +
  113. this.oid +
  114. "&org=" +
  115. this.org +
  116. "&role=" +
  117. this.role
  118. );
  119. } else {
  120. this.goTo(
  121. "/testStudent?userid=" +
  122. this.userid +
  123. "&oid=" +
  124. this.oid +
  125. "&org=" +
  126. this.org +
  127. "&role=" +
  128. this.role +
  129. "&isN=" +
  130. this.isN +
  131. "&tcid=" +
  132. this.tcid
  133. );
  134. }
  135. })
  136. .catch((v) => {
  137. });
  138. },
  139. goTo(path) {
  140. this.$router.push(path);
  141. },
  142. reset() {
  143. this
  144. .$confirm("是否将已经填写的内容重置?", "提示", {
  145. confirmButtonText: "确定",
  146. cancelButtonText: "取消",
  147. type: "warning",
  148. })
  149. .then(() => {
  150. if(this.tid){
  151. this.deleteTest(this.tid)
  152. }else{
  153. if(this.courseid){
  154. this.cJson = this.setCourseid(JSON.parse(JSON.stringify(this.cJson2)));
  155. }else{
  156. this.cJson = JSON.parse(JSON.stringify(this.cJson2));
  157. }
  158. this.loading = true
  159. this.isReset = false
  160. setTimeout(() => {
  161. this.loading = false
  162. }, 0);
  163. this.$forceUpdate()
  164. }
  165. })
  166. .catch(() => {
  167. });
  168. },
  169. refresh() {
  170. this
  171. .$confirm("是否将现在的题目刷新成最新的题目", "提示", {
  172. confirmButtonText: "确定",
  173. cancelButtonText: "取消",
  174. type: "warning",
  175. })
  176. .then(() => {
  177. if(this.tid){
  178. this.deleteTest(this.tid)
  179. }else{
  180. if(this.courseid){
  181. this.cJson = this.setCourseid(JSON.parse(JSON.stringify(this.cJson2)));
  182. }else{
  183. this.cJson = JSON.parse(JSON.stringify(this.cJson2));
  184. }
  185. this.loading = true
  186. this.isReset = false
  187. setTimeout(() => {
  188. this.loading = false
  189. }, 0);
  190. this.$forceUpdate()
  191. }
  192. })
  193. .catch(() => {
  194. });
  195. },
  196. getTestWorks() {
  197. let params = {
  198. cid: this.cid,
  199. uid: this.userid,
  200. };
  201. this.ajax
  202. .get(this.$store.state.api + "getTestWorks", params)
  203. .then((res) => {
  204. // this.cJson = JSON.parse(res.data[0][0].chapters);
  205. if (res.data[2].length) {
  206. this.cJson = JSON.parse(res.data[2][0].courseJson)
  207. let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
  208. let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
  209. if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
  210. this.isReset = true
  211. }
  212. }
  213. this.$forceUpdate()
  214. this.loading = false
  215. })
  216. .catch((err) => {
  217. this.loading = false
  218. console.error(err);
  219. });
  220. },
  221. getTestWorks2() {
  222. let params = {
  223. cid: this.cid,
  224. tid: this.tid,
  225. };
  226. this.ajax
  227. .get(this.$store.state.api + "getTestWorks2", params)
  228. .then((res) => {
  229. // this.cJson = JSON.parse(res.data[0][0].chapters);
  230. if (res.data[2].length) {
  231. this.cJson = JSON.parse(res.data[2][0].courseJson)
  232. let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
  233. let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
  234. if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
  235. this.isReset = true
  236. }
  237. }
  238. this.$forceUpdate()
  239. this.loading = false
  240. })
  241. .catch((err) => {
  242. this.loading = false
  243. console.error(err);
  244. });
  245. },
  246. getTestWorkByCid(courseid) {
  247. this.isloading = true
  248. this.courseid = courseid
  249. let params = {
  250. cid: this.cid,
  251. uid: this.userid,
  252. };
  253. let _courseid = courseid
  254. this.ajax
  255. .get(this.$store.state.api + "selectTestWorksCid", params)
  256. .then((res) => {
  257. if (res.data[0].length) {
  258. console.log(res.data[0]);
  259. let rData = res.data[0]
  260. this.tid = ''
  261. aa: for (var i = 0; i < rData.length; i++) {
  262. let rDataJson = this.JSONSetting(JSON.parse(rData[i].courseJson))
  263. let _json = JSON.parse(rData[i].courseJson)
  264. for (var j = 0; j < rDataJson.length; j++) {
  265. let _param = rDataJson[j]
  266. if (_param.type == 6 && _param.json.answer2 && _param.json.answer2 == _courseid) {
  267. console.log(_json);
  268. this.cJson = _json
  269. let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
  270. let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
  271. if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
  272. this.isReset = true
  273. }
  274. this.tid = rData[i].id
  275. this.$forceUpdate()
  276. break aa;
  277. }
  278. }
  279. }
  280. if (!this.tid) {
  281. this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
  282. }
  283. }else{
  284. this.tid = ''
  285. this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
  286. }
  287. this.$forceUpdate()
  288. this.isloading = false
  289. })
  290. .catch((err) => {
  291. this.isloading = false
  292. console.error(err);
  293. });
  294. },
  295. JSONSetting(json) {
  296. let _json = json
  297. let array = []
  298. _json.filter((item) => {
  299. if (item.array) {
  300. item.array = item.array.filter((item2) => {
  301. if (item2.ttype == 1 && item2.json) {
  302. array.push(item2)
  303. }
  304. if (item2.array) {
  305. item2.array = item2.array.filter((item3) => {
  306. if (item3.ttype == 1 && item3.json) {
  307. array.push(item3)
  308. }
  309. return item3;
  310. });
  311. }
  312. return item2;
  313. });
  314. }
  315. if (item.ttype == 1 && item.json) {
  316. array.push(item)
  317. }
  318. console.log(item.array);
  319. return item;
  320. });
  321. console.log(array);
  322. return array;
  323. },
  324. setJSON(json) {
  325. return json.filter((item) => {
  326. if (item.array) {
  327. item.array = item.array.filter((item2) => {
  328. if (item2.ttype == 1 && item2.json) {
  329. delete item2.json.answer2
  330. delete item2.json.score2
  331. delete item2.json.file
  332. }
  333. if (item2.array) {
  334. item2.array = item2.array.filter((item3) => {
  335. if (item3.ttype == 1 && item3.json) {
  336. delete item3.json.answer2
  337. delete item3.json.score2
  338. delete item3.json.file
  339. }
  340. return item3;
  341. });
  342. }
  343. return item2;
  344. });
  345. } else if (item.ttype == 1 && item.json) {
  346. delete item.json.answer2
  347. delete item.json.score2
  348. delete item.json.file
  349. }
  350. return item
  351. console.log(item.array);
  352. });
  353. },
  354. setJson2(json) {
  355. let _json = json;
  356. // this.type = _json[0].ttype;
  357. let checkArray = _json.filter((item) => {
  358. if (item.array) {
  359. item.array = item.array.filter((item2) => {
  360. if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
  361. item2.json.answer2 = [];
  362. }
  363. if (item2.array) {
  364. item2.array = item2.array.filter((item3) => {
  365. if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
  366. item3.json.answer2 = [];
  367. }
  368. return item3;
  369. });
  370. }
  371. return (
  372. (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
  373. );
  374. });
  375. }
  376. if (item.ttype == 1 && item.json && !item.json.answer2) {
  377. item.json.answer2 = [];
  378. }
  379. console.log(item.array);
  380. return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
  381. });
  382. console.log(checkArray);
  383. return checkArray;
  384. },
  385. setCourseid(json) {
  386. let _json = json;
  387. // this.type = _json[0].ttype;
  388. let checkArray = _json.filter((item) => {
  389. if (item.array) {
  390. item.array = item.array.filter((item2) => {
  391. if (item2.ttype == 1 && item2.json && !item2.json.answer2 && item2.type != 6 && item2.type != 7 && item2.type != 8) {
  392. item2.json.answer2 = [];
  393. }else if(item2.type == 6){
  394. item2.json.answer2 = this.courseid ? this.courseid : '';
  395. }else if(item2.type == 7 || item2.type == 8){
  396. item2.json.answer2 = '';
  397. }
  398. if (item2.array) {
  399. item2.array = item2.array.filter((item3) => {
  400. if (item3.ttype == 1 && item3.json && !item3.json.answer2 && item3.type != 6 && item3.type != 7 && item3.type != 8) {
  401. item3.json.answer2 = [];
  402. }else if(item3.type == 6){
  403. item3.json.answer2 = this.courseid ? this.courseid : '';
  404. }else if(item3.type == 7 || item3.type == 8){
  405. item3.json.answer2 = '';
  406. }
  407. return item3;
  408. });
  409. }
  410. return (
  411. (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
  412. );
  413. });
  414. }
  415. if (item.ttype == 1 && item.json && !item.json.answer2 && item.type != 6 && item.type != 6 && item.type != 7 && item.type != 8) {
  416. item.json.answer2 = [];
  417. }else if(item.type == 6){
  418. item.json.answer2 = this.courseid ? this.courseid : '';
  419. }else if(item.type == 7 || item.type == 8){
  420. item.json.answer2 = '';
  421. }
  422. console.log(item.array);
  423. return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
  424. });
  425. console.log(checkArray);
  426. return checkArray;
  427. },
  428. getData() {
  429. this.loading = true
  430. let params = {
  431. cid: this.cid,
  432. };
  433. this.ajax
  434. .get(this.$store.state.api + "getTestCourseDetail", params)
  435. .then((res) => {
  436. this.cJson = JSON.parse(res.data[0][0].chapters);
  437. this.cJson2 = JSON.parse(res.data[0][0].chapters);
  438. this.title = res.data[0][0].title;
  439. this.brief = res.data[0][0].brief;
  440. this.see = res.data[0][0].open == 1 ? true : false;
  441. this.testType = [];
  442. for (var i = 0; i < res.data[1].length; i++) {
  443. this.testType.push(res.data[1][i].typeid);
  444. }
  445. console.log(this.testType);
  446. this.look = res.data[0][0].look
  447. if(this.isN!=1){
  448. if (this.type == 3) {
  449. this.getTestWorks2()
  450. } else {
  451. this.getTestWorks()
  452. }
  453. }else{
  454. this.loading = false;
  455. this.isReset = true;
  456. }
  457. this.$forceUpdate();
  458. })
  459. .catch((err) => {
  460. this.loading = false
  461. console.error(err);
  462. });
  463. },
  464. save() {
  465. let cjson = this.$refs['topicVue'].checkArray
  466. console.log(cjson);
  467. let params = [
  468. {
  469. uid: this.userid,
  470. cid: this.cid,
  471. cjson: JSON.stringify(cjson),
  472. type: '1',
  473. },
  474. ];
  475. this.ajax
  476. .post(this.$store.state.api + "addTestWorks", params)
  477. .then((res) => {
  478. this.$message.success('保存成功')
  479. this.goTo(
  480. "/testStudent?userid=" +
  481. this.userid +
  482. "&oid=" +
  483. this.oid +
  484. "&org=" +
  485. this.org +
  486. "&role=" +
  487. this.role +
  488. "&isN=" +
  489. this.isN +
  490. "&tcid=" +
  491. this.tcid
  492. );
  493. })
  494. .catch((err) => {
  495. this.$message.error("网络不佳");
  496. console.error(err);
  497. });
  498. },
  499. publish() {
  500. let cjson = this.$refs['topicVue'].checkArray
  501. console.log(cjson);
  502. let _uid = ''
  503. if(this.isN == 1){
  504. _uid = this.tcid
  505. }else {
  506. _uid = (this.tid) ? this.tid : this.userid
  507. }
  508. let params = [
  509. {
  510. uid: _uid,
  511. cid: this.cid,
  512. cjson: JSON.stringify(cjson),
  513. type: '2',
  514. },
  515. ];
  516. this.ajax
  517. .post(this.$store.state.api + ((this.tid) ? "addTestWorks2" : "addTestWorks"), params)
  518. .then((res) => {
  519. this.$message.success('提交成功')
  520. if (this.type == 3) {
  521. this.goTo(
  522. "/testPerson?userid=" +
  523. this.userid +
  524. "&oid=" +
  525. this.oid +
  526. "&org=" +
  527. this.org +
  528. "&role=" +
  529. this.role
  530. );
  531. } else {
  532. this.goTo(
  533. "/testStudent?userid=" +
  534. this.userid +
  535. "&oid=" +
  536. this.oid +
  537. "&org=" +
  538. this.org +
  539. "&role=" +
  540. this.role +
  541. "&isN=" +
  542. this.isN +
  543. "&tcid=" +
  544. this.tcid
  545. );
  546. }
  547. })
  548. .catch((err) => {
  549. this.$message.error("网络不佳");
  550. console.error(err);
  551. });
  552. },
  553. publish2() {
  554. this.isloading = true
  555. let cjson = this.$refs['topicVue'].checkArray
  556. let _cjson = this.JSONSetting(JSON.parse(JSON.stringify(cjson)));
  557. let pan = this.panJSON(_cjson)
  558. if(!pan){
  559. setTimeout(() => {
  560. this.isloading = false
  561. }, 500);
  562. return
  563. }
  564. console.log(cjson);
  565. let params = [
  566. {
  567. uid: (this.tid) ? this.tid : this.userid,
  568. cid: this.cid,
  569. cjson: JSON.stringify(cjson),
  570. type: '2',
  571. },
  572. ];
  573. this.ajax
  574. .post(this.$store.state.api + ((this.tid) ? "addTestWorks2" : "addTestWorks"), params)
  575. .then((res) => {
  576. this.$message.success('保存成功')
  577. setTimeout(() => {
  578. this.isloading = false
  579. }, 500);
  580. })
  581. .catch((err) => {
  582. this.$message.error("网络不佳");
  583. this.isloading = false
  584. console.error(err);
  585. });
  586. },
  587. panJSON(array){
  588. var pan = 0
  589. for(var i = 0; i < array.length; i++){
  590. if(array[i].type != 6){
  591. let param = array[i].json
  592. if(array[i].type == 5 && param.file && param.file.length > 0){
  593. pan++
  594. }else if(param.answer2.length || typeof(param.answer2) == 'number'){
  595. pan++
  596. }
  597. }
  598. }
  599. if(pan > 0){
  600. return true
  601. }else {
  602. return false
  603. }
  604. },
  605. deleteTest(tid) {
  606. let _this = this;
  607. let params = [
  608. {
  609. tid: tid
  610. }
  611. ];
  612. _this.ajax
  613. .post(_this.$store.state.api + "deleteTestCourseWorks", params)
  614. .then(res => {
  615. this.getTestWorkByCid(this.courseid)
  616. })
  617. .catch(err => {
  618. console.error(err);
  619. });
  620. },
  621. autoFill(){
  622. this
  623. .$confirm("这将覆盖原有的内容,是否继续?", "提示", {
  624. confirmButtonText: "确定",
  625. cancelButtonText: "取消",
  626. type: "warning",
  627. })
  628. .then(() => {
  629. console.log(this.$refs['topicVue'])
  630. this.$refs['topicVue'].autoFillGapV();
  631. })
  632. .catch(() => {
  633. });
  634. }
  635. },
  636. mounted() {
  637. this.getData();
  638. },
  639. }
  640. </script>
  641. <style scoped>
  642. .pb_content {
  643. height: 100% !important;
  644. /* margin: 0 20px 0 20px; */
  645. }
  646. .pb_content_body {
  647. width: 100% !important;
  648. height: 100%;
  649. }
  650. .right {
  651. height: 100%;
  652. width: 100%;
  653. display: flex;
  654. overflow: hidden;
  655. flex-direction: column;
  656. }
  657. .basic_box {
  658. margin: 0 auto;
  659. position: relative;
  660. padding: 0 20px 0 20px;
  661. }
  662. .courseTop {
  663. display: flex;
  664. flex-direction: row;
  665. justify-content: space-between;
  666. align-items: center;
  667. width: calc(100% - 40px);
  668. margin: 0 auto;
  669. padding: 10px 0;
  670. }
  671. .stepsNav {
  672. display: flex;
  673. flex-direction: row;
  674. justify-content: flex-start;
  675. align-items: center;
  676. }
  677. .step_box {
  678. width: calc(100%);
  679. margin: 0 auto;
  680. height: calc(100% - 38px);
  681. }
  682. .edit_top {
  683. height: 50px;
  684. background: #fff;
  685. display: flex;
  686. align-items: center;
  687. justify-content: flex-end;
  688. position: relative;
  689. /* padding: 0 30px; */
  690. padding-right: 10px;
  691. border-top: 2px solid #eee;
  692. border-bottom: 2px solid #eee;
  693. width: 95%;
  694. margin: 0 auto;
  695. box-sizing: border-box;
  696. }
  697. .edit_title{
  698. font-size: 22px;
  699. margin-left: 30px;
  700. position: relative;
  701. }
  702. .edit_title::after{
  703. content: "";
  704. width: 5px;
  705. height: 100%;
  706. background-color: #078DFF;
  707. border-radius: 2px;
  708. position: absolute;
  709. left: -10px;
  710. top: 0;
  711. }
  712. </style>