preview.vue 19 KB

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