manualCreated.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <div class="mc_box">
  3. <div class="mc_addBox">
  4. <div class="mc_addBox_add">
  5. <div class="title">请添加题目类型与数量</div>
  6. <div class="select">
  7. <el-select
  8. v-model="topicType"
  9. placeholder="题目类型"
  10. clearable
  11. class="e-select"
  12. >
  13. <el-option
  14. v-for="item in options"
  15. :key="item.value"
  16. :label="item.label"
  17. :value="item.value"
  18. >
  19. </el-option>
  20. </el-select>
  21. <el-input
  22. v-model="number"
  23. placeholder="请输入题目数量"
  24. size="normal"
  25. clearable
  26. @change="numberPan"
  27. class="e-input"
  28. ></el-input>
  29. <img
  30. src="@/assets/icon/new/addStage.png"
  31. class="e-img"
  32. @click="addCheck"
  33. />
  34. </div>
  35. </div>
  36. <div class="mc_addBox_add">
  37. <div class="title">请添加试卷组件</div>
  38. <div class="btnBox">
  39. <!-- <el-button type="primary" size="mini" v-for="item in buttonOptions" :key="item.type" class="e-button"
  40. @click="addQtype(item.type)">{{ item.name }}</el-button> -->
  41. <button
  42. v-for="item in buttonOptions"
  43. :key="item.type"
  44. class="pub_test_btn"
  45. :class="{
  46. pub_test_btn_group: item.type == 1,
  47. pub_test_btn_page: item.type == 2,
  48. }"
  49. @click="addQtype(item.type)"
  50. >
  51. {{ item.name }}
  52. </button>
  53. </div>
  54. </div>
  55. <div class="mc_addBox_add">
  56. <div class="title">智能创建</div>
  57. <div class="btnBox">
  58. <aiCreate2 :aiJson="manualJson" @changeJson="changeJson"></aiCreate2>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="mc_checkBox">
  63. <checkOrder
  64. :checkC.sync="checkC"
  65. :checkJson="checkJson"
  66. @changeJson="changeJson"
  67. ></checkOrder>
  68. <div class="e_btn">
  69. <el-button type="primary" size="mini" @click="nextSteps()"
  70. >下一步</el-button
  71. >
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import checkOrder from "../components/checkOrder.vue";
  78. import aiCreate2 from "./aiCreate2.vue";
  79. import minxinVue from "../minxins/minxin";
  80. export default {
  81. mixins: [minxinVue],
  82. components: {
  83. checkOrder,
  84. aiCreate2,
  85. },
  86. props: {
  87. manualJson: {
  88. type: Array,
  89. },
  90. },
  91. data() {
  92. return {
  93. topicType: "",
  94. number: "",
  95. checkJson: [
  96. // {
  97. // ttype: 1, //题目分类 1普通题目 2分组 3分页
  98. // type: 1, //题型分类 1选择题, 3问答题 4添加文档
  99. // array:[] //题目
  100. // }
  101. ],
  102. checkC: "",
  103. };
  104. },
  105. watch: {
  106. manualJson: {
  107. handler: function (newVal, oldVal) {
  108. this.checkJson = this.depthCopy(newVal);
  109. },
  110. deep: true,
  111. },
  112. },
  113. methods: {
  114. numberPan() {
  115. if (/[^\d]/.test(this.number)) {
  116. this.$message.error("请填写数字");
  117. this.number = "";
  118. }
  119. },
  120. changeJson(json) {
  121. this.checkJson = json;
  122. this.$emit("update:manualJson", json);
  123. },
  124. addCheck() {
  125. if (!this.topicType) {
  126. this.$message.error("请选择题目类型");
  127. return;
  128. }
  129. if (!this.number) {
  130. this.$message.error("请填写题目数量");
  131. return;
  132. }
  133. let type = 1;
  134. if (this.checkJson.length > 0) {
  135. for (var i = 0; i < this.checkJson.length; i++) {
  136. if (this.checkJson[i].ttype == 2) {
  137. type = 2;
  138. } else if (this.checkJson[i].ttype == 3) {
  139. type = 3;
  140. }
  141. }
  142. }
  143. if (this.checkC) {
  144. let _check = this.checkC.replace("x", "").split("-");
  145. let _json = this.checkJson[_check[0]];
  146. let json = {
  147. ttype: 1,
  148. type: this.topicType,
  149. };
  150. if (this.topicType == 1) {
  151. json.json = {
  152. title: "标题",
  153. type: 1,
  154. array: [
  155. { option: "选项1", img: "" },
  156. { option: "选项2", img: "" },
  157. ],
  158. answer: "",
  159. };
  160. } else if (this.topicType == 3) {
  161. json.json = {
  162. title: "标题",
  163. type: 1,
  164. answer: "",
  165. };
  166. } else if (this.topicType == 5) {
  167. json.json = {
  168. title: "标题",
  169. type: 1,
  170. detail: "",
  171. };
  172. } else if (this.topicType == 6) {
  173. json.json = {
  174. title: "标题",
  175. detail: "",
  176. courses:[]
  177. };
  178. } else if (this.topicType == 7) {
  179. json.json = {
  180. title: "标题",
  181. detail: "",
  182. small: 0,
  183. big: 10,
  184. };
  185. }
  186. if (_json.array) {
  187. if (type == 3 && _check.length == 2) {
  188. if (this.checkJson[_check[0]].array[_check[1]].array) {
  189. for (var i = 0; i < this.number; i++) {
  190. this.checkJson[_check[0]].array[_check[1]].array.push(json);
  191. }
  192. } else {
  193. for (var i = 0; i < this.number; i++) {
  194. this.checkJson[_check[0]].array.splice(
  195. parseInt(_check[1]) + 1,
  196. 0,
  197. json
  198. );
  199. }
  200. }
  201. } else if (type == 3 && _check.length == 3) {
  202. for (var i = 0; i < this.number; i++) {
  203. this.checkJson[_check[0]].array[_check[1]].array.splice(
  204. parseInt(_check[2]) + 1,
  205. 0,
  206. json
  207. );
  208. }
  209. } else if (type == 2 && _check.length == 2) {
  210. for (var i = 0; i < this.number; i++) {
  211. this.checkJson[_check[0]].array.splice(
  212. parseInt(_check[1]) + 1,
  213. 0,
  214. json
  215. );
  216. }
  217. } else if (type == 2 && _check.length == 1) {
  218. for (var i = 0; i < this.number; i++) {
  219. this.checkJson[_check[0]].array.push(json);
  220. }
  221. } else if (type == 3 && _check.length == 1) {
  222. if (
  223. this.checkJson[_check[0]].array[0] &&
  224. this.checkJson[_check[0]].array[0].array
  225. ) {
  226. for (var i = 0; i < this.number; i++) {
  227. this.checkJson[_check[0]].array[0].array.push(json);
  228. }
  229. } else {
  230. for (var i = 0; i < this.number; i++) {
  231. this.checkJson[_check[0]].array.push(json);
  232. }
  233. }
  234. }
  235. } else {
  236. for (var i = 0; i < this.number; i++) {
  237. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  238. }
  239. }
  240. } else {
  241. if (type == 1) {
  242. for (var i = 0; i < this.number; i++) {
  243. let json1 = {
  244. ttype: 1,
  245. type: this.topicType,
  246. };
  247. if (this.topicType == 1) {
  248. json1.json = {
  249. title: "标题",
  250. type: 1,
  251. array: [
  252. { option: "选项1", img: "" },
  253. { option: "选项2", img: "" },
  254. ],
  255. answer: "",
  256. };
  257. } else if (this.topicType == 3) {
  258. json1.json = {
  259. title: "标题",
  260. type: 1,
  261. answer: "",
  262. };
  263. } else if (this.topicType == 5) {
  264. json1.json = {
  265. title: "标题",
  266. type: 1,
  267. detail: "",
  268. };
  269. } else if (this.topicType == 6) {
  270. json1.json = {
  271. title: "标题",
  272. detail: "",
  273. courses:[]
  274. };
  275. } else if (this.topicType == 7) {
  276. json1.json = {
  277. title: "标题",
  278. detail: "",
  279. small: 0,
  280. big: 10,
  281. };
  282. }
  283. this.checkJson.push(json1);
  284. }
  285. } else if (type == 3 || type == 2) {
  286. this.$message.error("请选中分页或者分组添加题目");
  287. return;
  288. }
  289. }
  290. this.topicType = "";
  291. this.number = "";
  292. this.$emit("update:manualJson", this.checkJson);
  293. },
  294. addQtype(type) {
  295. if (type == 1) {
  296. let type = 1;
  297. if (this.checkJson.length > 0) {
  298. for (var i = 0; i < this.checkJson.length; i++) {
  299. if (this.checkJson[i].ttype == 1) {
  300. type = 2;
  301. } else if (this.checkJson[i].ttype == 3) {
  302. type = 3;
  303. }
  304. }
  305. }
  306. let json = {
  307. ttype: 2,
  308. array: [],
  309. isopen: true,
  310. };
  311. if (type == 1) {
  312. if (this.checkC) {
  313. let _check = this.checkC.replace("x", "").split("-");
  314. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  315. } else {
  316. this.checkJson.push(json);
  317. }
  318. } else if (type == 2) {
  319. this.checkJson = [
  320. {
  321. ttype: 2,
  322. array: this.depthCopy(this.checkJson),
  323. isopen: true,
  324. },
  325. ];
  326. } else if (type == 3) {
  327. if (this.checkC) {
  328. let _check = this.checkC.replace("x", "").split("-");
  329. if (
  330. _check.length > 1 &&
  331. this.checkJson[_check[0]].array[0] &&
  332. this.checkJson[_check[0]].array[0].array
  333. ) {
  334. this.checkJson[_check[0]].array.splice(
  335. parseInt(_check[1]) + 1,
  336. 0,
  337. json
  338. );
  339. } else if (
  340. this.checkJson[_check[0]].array[0] &&
  341. !this.checkJson[_check[0]].array[0].array
  342. ) {
  343. this.checkJson[_check[0]].array = [
  344. {
  345. ttype: 2,
  346. array: this.depthCopy(this.checkJson[_check[0]].array),
  347. isopen: true,
  348. },
  349. ];
  350. } else {
  351. this.checkJson[_check[0]].array.push(json);
  352. }
  353. } else {
  354. this.$message.error("请选中分页添加分组");
  355. return;
  356. }
  357. }
  358. } else if (type == 2) {
  359. let type = 1;
  360. if (this.checkJson.length > 0) {
  361. for (var i = 0; i < this.checkJson.length; i++) {
  362. if (this.checkJson[i].ttype == 1 || this.checkJson[i].ttype == 2) {
  363. type = 2;
  364. }
  365. }
  366. }
  367. if (type == 1) {
  368. let json = {
  369. ttype: 3,
  370. array: [],
  371. isopen: true,
  372. };
  373. if (this.checkC) {
  374. let _check = this.checkC.replace("x", "").split("-");
  375. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  376. } else {
  377. this.checkJson.push(json);
  378. }
  379. } else {
  380. this.checkJson = [
  381. {
  382. ttype: 3,
  383. array: this.depthCopy(this.checkJson),
  384. isopen: true,
  385. },
  386. ];
  387. }
  388. }
  389. this.$emit("update:manualJson", this.checkJson);
  390. },
  391. depthCopy(s) {
  392. return JSON.parse(JSON.stringify(s));
  393. },
  394. nextSteps() {
  395. this.$emit("nextSteps");
  396. },
  397. },
  398. mounted() {
  399. this.checkJson = this.depthCopy(this.manualJson);
  400. this.$forceUpdate();
  401. },
  402. };
  403. </script>
  404. <style scoped>
  405. .mc_box {
  406. width: 90%;
  407. margin: 10px auto;
  408. display: flex;
  409. }
  410. .mc_addBox {
  411. width: 400px;
  412. border: 1px solid #898989;
  413. border-radius: 8px;
  414. padding: 20px 20px;
  415. box-sizing: border-box;
  416. min-height: 350px;
  417. height: fit-content;
  418. }
  419. .mc_addBox_add {
  420. }
  421. .mc_addBox_add + .mc_addBox_add {
  422. margin-top: 10px;
  423. }
  424. .mc_addBox_add .title {
  425. margin-bottom: 10px;
  426. font-size: 15px;
  427. font-weight: 700;
  428. display: flex;
  429. align-items: center;
  430. }
  431. .mc_addBox_add .title::before {
  432. content: "";
  433. width: 10px;
  434. height: 10px;
  435. border-radius: 50%;
  436. background: rgb(54, 129, 252);
  437. margin-right: 10px;
  438. display: block;
  439. }
  440. .mc_addBox_add .select {
  441. display: flex;
  442. align-items: center;
  443. }
  444. .mc_addBox_add .btnBox {
  445. display: flex;
  446. flex-wrap: wrap;
  447. }
  448. .mc_addBox_add .select .e-select {
  449. }
  450. .mc_addBox_add .select .e-input {
  451. margin-left: 10px;
  452. }
  453. .mc_addBox_add .select .e-img {
  454. cursor: pointer;
  455. width: 20px;
  456. margin-left: 10px;
  457. }
  458. .mc_addBox_add .btnBox .e-button {
  459. }
  460. .mc_checkBox {
  461. width: calc(100% - 420px);
  462. margin-left: 20px;
  463. border: 1px solid #898989;
  464. border-radius: 8px;
  465. padding: 20px;
  466. box-sizing: border-box;
  467. display: flex;
  468. flex-direction: column;
  469. }
  470. .e_btn {
  471. width: 100%;
  472. margin-top: auto;
  473. display: flex;
  474. justify-content: center;
  475. }
  476. </style>