Single.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-Single" v-if="curQue">
  4. <div
  5. class="Big-Book-Single-content"
  6. style="margin-left: 20px; margin-top: 20px"
  7. >
  8. <div class="adult-book-input-item" v-if="type == 'single_chs'">
  9. <span class="adult-book-lable">题号:</span>
  10. <el-input
  11. class="adult-book-input"
  12. :autosize="{ minRows: 2 }"
  13. type="textarea"
  14. placeholder="请输入题号"
  15. v-model="curQue.topicNumber"
  16. @blur="onBlur(curQue, 'topicNumber')"
  17. ></el-input>
  18. </div>
  19. <div class="adult-book-input-item" v-else>
  20. <span class="adult-book-lable">标题:</span>
  21. <el-input
  22. class="adult-book-input"
  23. :autosize="{ minRows: 2 }"
  24. type="textarea"
  25. placeholder="请输入标题"
  26. v-model="curQue.title"
  27. @blur="onBlur(curQue, 'title')"
  28. ></el-input>
  29. </div>
  30. <div
  31. class="adult-book-input-item"
  32. v-if="type == 'single_chs' || type == 'checkbox_chs'"
  33. >
  34. <span class="adult-book-lable">录音:</span>
  35. <el-radio-group v-model="curQue.IsRecord">
  36. <el-radio :label="true">需要</el-radio>
  37. <el-radio :label="false">不需要</el-radio>
  38. </el-radio-group>
  39. </div>
  40. <div class="adult-book-input-item" v-if="curQue.IsRecord">
  41. <span class="adult-book-lable">录音控件:</span>
  42. <img src="../../../assets/adult/pro.png" alt="" />
  43. </div>
  44. <div class="adult-book-input-item">
  45. <span class="adult-book-lable">题目:</span>
  46. <el-input
  47. class="adult-book-input"
  48. :autosize="{ minRows: 2 }"
  49. type="textarea"
  50. placeholder="请输入题目"
  51. v-model="curQue.topic.con"
  52. @blur="curQue.topic.con = curQue.topic.con.trim()"
  53. ></el-input>
  54. </div>
  55. <div
  56. class="adult-book-input-item"
  57. v-if="type == 'single_chs' || type == 'checkbox_chs'"
  58. >
  59. <span class="adult-book-lable">题目图片:</span>
  60. <Upload
  61. :changeFillId="timuchangeImage"
  62. :datafileList="curQue.topic.img_list"
  63. :filleNumber="imgNumber"
  64. :uploadType="'image'"
  65. />
  66. </div>
  67. <div class="adult-book-input-item">
  68. <span class="adult-book-lable">题目音频:</span>
  69. <Upload
  70. :changeFillId="timuchangeMp3"
  71. :datafileList="curQue.topic.mp3_list"
  72. :filleNumber="mp3Number"
  73. :uploadType="'mp3'"
  74. />
  75. </div>
  76. <div
  77. class="Big-Book-main"
  78. v-for="(item, index) in curQue.option"
  79. :key="item + index"
  80. style="border-bottom: 1px #ccc solid; margin-bottom: 20px"
  81. >
  82. <SingleModule
  83. :curQueItem="item"
  84. :index="index"
  85. :changAnswer="changAnswer"
  86. :deleteOptionOne="deleteOptionOne"
  87. :type="curQue.type"
  88. />
  89. </div>
  90. <div class="addoption" @click="addOption">添加一个选项</div>
  91. <div class="Big-Book-divide">
  92. <el-divider content-position="center">功能设置</el-divider>
  93. <span style="margin: 0 10px">请选择每行数量</span>
  94. <el-select v-model="curQue.numberList.con" placeholder="请选择">
  95. <el-option
  96. v-for="(item, i) in curQue.numberList.arr"
  97. :key="i"
  98. :label="item.value"
  99. :value="item.id"
  100. >
  101. </el-option>
  102. </el-select>
  103. </div>
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import Inputmodule from "../common/Inputmodule.vue";
  109. import SingleModule from "../common/SingleModule.vue";
  110. import Upload from "../common/Upload.vue";
  111. export default {
  112. name: "Single",
  113. props: ["curQue", "fn_data", "changeCurQue", "type"],
  114. components: {
  115. Inputmodule,
  116. SingleModule,
  117. Upload,
  118. },
  119. data() {
  120. return {
  121. form: {
  122. stem: {
  123. con: "",
  124. pinyin: "",
  125. english: "",
  126. highlight: "",
  127. underline: "",
  128. img_url: [],
  129. mp3_url: [],
  130. },
  131. },
  132. imgNumber: 1,
  133. mp3Number: 1,
  134. data_structure: {
  135. type: "single_chs",
  136. name: "单选题",
  137. topicNumber: "",
  138. IsRecord: false,
  139. topic: {
  140. con: "",
  141. img_list: [],
  142. mp3_list: [],
  143. },
  144. option: [
  145. {
  146. number: "",
  147. con: "",
  148. img_list: [],
  149. mp3_list: [],
  150. isAnswer: "",
  151. },
  152. {
  153. number: "",
  154. con: "",
  155. img_list: [],
  156. mp3_list: [],
  157. isAnswer: "",
  158. },
  159. ],
  160. correct: [],
  161. numberList: {
  162. type: "number",
  163. name: "每行几个",
  164. con: "2",
  165. arr: [
  166. {
  167. id: 1,
  168. value: 1,
  169. },
  170. {
  171. id: 2,
  172. value: 2,
  173. },
  174. {
  175. id: 3,
  176. value: 3,
  177. },
  178. {
  179. id: 4,
  180. value: 4,
  181. },
  182. ],
  183. },
  184. },
  185. data_structure2: {
  186. type: "checkbox_chs",
  187. name: "多选题",
  188. title: "",
  189. IsRecord: false,
  190. topic: {
  191. con: "",
  192. img_list: [],
  193. mp3_list: [],
  194. },
  195. option: [
  196. {
  197. con: "",
  198. img_list: [],
  199. mp3_list: [],
  200. isAnswer: "",
  201. number: "",
  202. },
  203. {
  204. con: "",
  205. img_list: [],
  206. mp3_list: [],
  207. isAnswer: "",
  208. number: "",
  209. },
  210. ],
  211. correct: [],
  212. numberList: {
  213. type: "number",
  214. name: "每行几个",
  215. con: "2",
  216. arr: [
  217. {
  218. id: 1,
  219. value: 1,
  220. },
  221. {
  222. id: 2,
  223. value: 2,
  224. },
  225. {
  226. id: 3,
  227. value: 3,
  228. },
  229. {
  230. id: 4,
  231. value: 4,
  232. },
  233. ],
  234. },
  235. },
  236. data_structure3: {
  237. type: "listen_record_single_chs",
  238. name: "听录音选答案",
  239. title: "",
  240. topic: {
  241. con: "",
  242. mp3_list: [],
  243. },
  244. option: [
  245. {
  246. con: "",
  247. mp3_list: [],
  248. isAnswer: "",
  249. number: "",
  250. },
  251. {
  252. con: "",
  253. mp3_list: [],
  254. isAnswer: "",
  255. number: "",
  256. },
  257. ],
  258. correct: [],
  259. numberList: {
  260. type: "number",
  261. name: "每行几个",
  262. con: "2",
  263. arr: [
  264. {
  265. id: 1,
  266. value: 1,
  267. },
  268. {
  269. id: 2,
  270. value: 2,
  271. },
  272. {
  273. id: 3,
  274. value: 3,
  275. },
  276. {
  277. id: 4,
  278. value: 4,
  279. },
  280. ],
  281. },
  282. },
  283. };
  284. },
  285. computed: {},
  286. watch: {},
  287. //方法集合
  288. methods: {
  289. // 修改正确选项中得某一个为正确答案
  290. changAnswer(index) {
  291. let arr = [];
  292. if (this.curQue.type == "single_chs") {
  293. this.curQue.option.forEach((item, i) => {
  294. if (index == i) {
  295. this.curQue.correct = [];
  296. arr.push(i);
  297. } else {
  298. item.isAnswer = "";
  299. }
  300. });
  301. this.curQue.correct = arr;
  302. } else if (this.curQue.type == "checkbox_chs") {
  303. this.curQue.option.forEach((item, i) => {
  304. if (index == i && item.isAnswer != "") {
  305. this.curQue.correct.push(i);
  306. } else if (index == i && item.isAnswer == "") {
  307. this.curQue.correct.splice(i, 1);
  308. }
  309. });
  310. }
  311. },
  312. // 删除其中一个选项
  313. deleteOptionOne(index) {
  314. if (this.curQue.option.length <= 2) {
  315. this.$message.warning("至少要保留两个选项");
  316. return;
  317. }
  318. this.curQue.option.splice(index, 1);
  319. },
  320. //添加一个选项
  321. addOption() {
  322. let obj = JSON.parse(JSON.stringify(this.data_structure.option[0]));
  323. this.curQue.option.push(obj);
  324. },
  325. timuchangeMp3(fileList) {
  326. console.log(fileList);
  327. const articleImgList = JSON.parse(JSON.stringify(fileList));
  328. const articleImgRes = [];
  329. articleImgList.forEach((item) => {
  330. if (item.response) {
  331. const obj = {
  332. name: item.name,
  333. url: item.response.file_info_list[0].file_url,
  334. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  335. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  336. };
  337. articleImgRes.push(obj);
  338. }
  339. });
  340. this.curQue.topic.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
  341. },
  342. timuchangeImage(fileList) {
  343. console.log(fileList);
  344. const articleImgList = JSON.parse(JSON.stringify(fileList));
  345. const articleImgRes = [];
  346. articleImgList.forEach((item) => {
  347. if (item.response) {
  348. const obj = {
  349. name: item.name,
  350. url: item.response.file_info_list[0].file_url,
  351. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  352. };
  353. articleImgRes.push(obj);
  354. }
  355. });
  356. this.curQue.topic.img_list = JSON.parse(JSON.stringify(articleImgRes));
  357. },
  358. },
  359. //生命周期 - 创建完成(可以访问当前this实例)
  360. created() {
  361. if (!this.curQue) {
  362. if (this.type == "single_chs") {
  363. this.changeCurQue(this.data_structure);
  364. } else if (this.type == "checkbox_chs") {
  365. this.changeCurQue(this.data_structure2);
  366. } else if (this.type == "listen_record_single_chs") {
  367. this.changeCurQue(this.data_structure3);
  368. }
  369. }
  370. },
  371. //生命周期 - 挂载完成(可以访问DOM元素)
  372. mounted() {},
  373. beforeCreate() {}, //生命周期 - 创建之前
  374. beforeMount() {}, //生命周期 - 挂载之前
  375. beforeUpdate() {}, //生命周期 - 更新之前
  376. updated() {}, //生命周期 - 更新之后
  377. beforeDestroy() {}, //生命周期 - 销毁之前
  378. destroyed() {}, //生命周期 - 销毁完成
  379. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  380. };
  381. </script>
  382. <style lang='scss' scope>
  383. //@import url(); 引入公共css类
  384. .Big-Book-Single {
  385. &-content {
  386. &.m {
  387. display: flex;
  388. justify-content: flex-start;
  389. align-items: flex-start;
  390. }
  391. .Big-Book-title {
  392. font-size: 16px;
  393. line-height: 40px;
  394. color: #000;
  395. margin-right: 15px;
  396. }
  397. .Big-Book-main {
  398. > div {
  399. margin-bottom: 10px;
  400. &.Big-Book-pinyin {
  401. display: flex;
  402. justify-content: flex-start;
  403. align-items: center;
  404. }
  405. }
  406. }
  407. }
  408. .addoption {
  409. width: 565px;
  410. height: 40px;
  411. left: 40px;
  412. top: 304px;
  413. background: #f3f3f3;
  414. border: 1px dashed rgba(0, 0, 0, 0.15);
  415. box-sizing: border-box;
  416. border-radius: 4px;
  417. text-align: center;
  418. line-height: 40px;
  419. cursor: pointer;
  420. }
  421. }
  422. </style>
  423. <style lang="scss">
  424. </style>