Single.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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">
  9. <span class="adult-book-lable">标题:</span>
  10. <el-input
  11. class="adult-book-input"
  12. type="textarea"
  13. autosize
  14. placeholder="请输入标题"
  15. v-model="curQue.title"
  16. @blur="onBlur(curQue, 'title')"
  17. ></el-input>
  18. </div>
  19. <div class="adult-book-input-item">
  20. <span class="adult-book-lable">录音:</span>
  21. <el-radio-group v-model="curQue.IsRecord">
  22. <el-radio :label="true">需要</el-radio>
  23. <el-radio :label="false">不需要</el-radio>
  24. </el-radio-group>
  25. </div>
  26. <div
  27. class="Big-Book-main"
  28. v-for="(item, index) in curQue.option"
  29. :key="item + index"
  30. style="border-bottom: 1px #ccc solid; margin-bottom: 20px"
  31. >
  32. <SingleModule
  33. :curQueItem="item"
  34. :index="index"
  35. :changAnswer="changAnswer"
  36. :deleteOptionOne="deleteOptionOne"
  37. :type="curQue.type"
  38. />
  39. </div>
  40. <div class="addoption" @click="addOption">添加一个选项</div>
  41. <div class="Big-Book-divide">
  42. <el-divider content-position="center">功能设置</el-divider>
  43. <span style="margin: 0 10px">请选择每行数量</span>
  44. <el-select v-model="curQue.numberList.con" placeholder="请选择">
  45. <el-option
  46. v-for="(item, i) in curQue.numberList.arr"
  47. :key="i"
  48. :label="item.value"
  49. :value="item.id"
  50. >
  51. </el-option>
  52. </el-select>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import Inputmodule from "../common/Inputmodule.vue";
  59. import SingleModule from "../common/SingleModule.vue";
  60. export default {
  61. name: "Single",
  62. props: ["curQue", "fn_data", "changeCurQue"],
  63. components: {
  64. Inputmodule,
  65. SingleModule,
  66. },
  67. data() {
  68. return {
  69. form: {
  70. stem: {
  71. con: "",
  72. pinyin: "",
  73. english: "",
  74. highlight: "",
  75. underline: "",
  76. img_url: [],
  77. mp3_url: [],
  78. },
  79. },
  80. data_structure: {
  81. type: "single_chs",
  82. name: "单选题",
  83. title: "",
  84. IsRecord: false,
  85. option: [
  86. {
  87. topic: {
  88. con: "",
  89. img_list: [],
  90. mp3_list: [],
  91. },
  92. img_list: [],
  93. mp3_list: [],
  94. isAnswer: "",
  95. },
  96. {
  97. topic: {
  98. con: "",
  99. img_list: [],
  100. mp3_list: [],
  101. },
  102. con: "",
  103. img_list: [],
  104. mp3_list: [],
  105. isAnswer: "",
  106. },
  107. ],
  108. correct: [],
  109. numberList: {
  110. type: "number",
  111. name: "每行几个",
  112. con: "2",
  113. arr: [
  114. {
  115. id: 1,
  116. value: 1,
  117. },
  118. {
  119. id: 2,
  120. value: 2,
  121. },
  122. {
  123. id: 3,
  124. value: 3,
  125. },
  126. {
  127. id: 4,
  128. value: 4,
  129. },
  130. ],
  131. },
  132. },
  133. };
  134. },
  135. computed: {},
  136. watch: {},
  137. //方法集合
  138. methods: {
  139. // 修改正确选项中得某一个为正确答案
  140. changAnswer(index) {
  141. let arr = [];
  142. if (this.curQue.type == "single_chs") {
  143. this.curQue.option.forEach((item, i) => {
  144. if (index == i) {
  145. this.curQue.correct = [];
  146. arr.push(i);
  147. } else {
  148. item.isAnswer = "";
  149. }
  150. });
  151. this.curQue.correct = arr;
  152. } else if (this.curQue.type == "checkbox") {
  153. this.curQue.option.forEach((item, i) => {
  154. if (index == i && item.isAnswer != "") {
  155. this.curQue.correct.push(i);
  156. } else if (index == i && item.isAnswer == "") {
  157. this.curQue.correct.splice(i, 1);
  158. }
  159. });
  160. }
  161. },
  162. // 删除其中一个选项
  163. deleteOptionOne(index) {
  164. if (this.curQue.option.length <= 2) {
  165. this.$message.warning("至少要保留两个选项");
  166. return;
  167. }
  168. this.curQue.option.splice(index, 1);
  169. },
  170. //添加一个选项
  171. addOption() {
  172. let obj = JSON.parse(JSON.stringify(this.data_structure.option[0]));
  173. this.curQue.option.push(obj);
  174. },
  175. },
  176. //生命周期 - 创建完成(可以访问当前this实例)
  177. created() {
  178. if (!this.curQue) {
  179. this.changeCurQue(this.data_structure);
  180. }
  181. },
  182. //生命周期 - 挂载完成(可以访问DOM元素)
  183. mounted() {},
  184. beforeCreate() {}, //生命周期 - 创建之前
  185. beforeMount() {}, //生命周期 - 挂载之前
  186. beforeUpdate() {}, //生命周期 - 更新之前
  187. updated() {}, //生命周期 - 更新之后
  188. beforeDestroy() {}, //生命周期 - 销毁之前
  189. destroyed() {}, //生命周期 - 销毁完成
  190. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  191. };
  192. </script>
  193. <style lang='scss' scope>
  194. //@import url(); 引入公共css类
  195. .Big-Book-Single {
  196. &-content {
  197. &.m {
  198. display: flex;
  199. justify-content: flex-start;
  200. align-items: flex-start;
  201. }
  202. .Big-Book-title {
  203. font-size: 16px;
  204. line-height: 40px;
  205. color: #000;
  206. margin-right: 15px;
  207. }
  208. .Big-Book-main {
  209. > div {
  210. margin-bottom: 10px;
  211. &.Big-Book-pinyin {
  212. display: flex;
  213. justify-content: flex-start;
  214. align-items: center;
  215. }
  216. }
  217. }
  218. }
  219. .addoption {
  220. width: 565px;
  221. height: 40px;
  222. left: 40px;
  223. top: 304px;
  224. background: #f3f3f3;
  225. border: 1px dashed rgba(0, 0, 0, 0.15);
  226. box-sizing: border-box;
  227. border-radius: 4px;
  228. text-align: center;
  229. line-height: 40px;
  230. cursor: pointer;
  231. }
  232. }
  233. </style>
  234. <style lang="scss">
  235. </style>