setChoiceQuestion.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <template>
  2. <div class="setChoiceQuestion">
  3. <div class="testItem" v-for="(item, index) in jsonData.testJson" :key="item.id">
  4. <div class="ti_header">
  5. <span>{{ lang.ssTopic }}{{ index + 1 }} <span v-if="item.answer.length==0">{{lang.ssNoSettingAnswer}}</span></span>
  6. <div class="ti_h_edit">
  7. <span @click="copyTest(item.id)">
  8. <svg viewBox="0 0 1024 1024" version="1.1" p-id="4608" width="200" height="200">
  9. <path
  10. d="M731.68184 676.057473 731.68184 183.323259c0-30.233582-24.512277-54.745858-54.747905-54.745858L184.216093 128.577401c-30.233582 0-54.746882 24.512277-54.746882 54.745858l0 492.734214c0 30.207999 24.5133 54.746882 54.746882 54.746882l492.717841 0C707.16854 730.804355 731.68184 706.265472 731.68184 676.057473zM622.1891 676.057473 238.962975 676.057473c-30.233582 0-54.746882-24.538883-54.746882-54.745858L184.216093 238.07014c0-30.233582 24.5133-54.746882 54.746882-54.746882l383.226125 0c30.233582 0 54.744835 24.512277 54.744835 54.746882l0 383.242498C676.933935 651.51859 652.421658 676.057473 622.1891 676.057473zM841.17458 292.817022l-54.745858 0 0 54.746882c30.232558 0 54.745858 24.5133 54.745858 54.759161l0 383.228171c0 30.206976-24.5133 54.745858-54.745858 54.745858L403.201573 840.297095c-30.233582 0-54.746882-24.538883-54.746882-54.745858l-54.746882 0 0 54.745858c0 30.207999 24.5133 54.747905 54.746882 54.747905l492.719888 0c30.234605 0 54.747905-24.539906 54.747905-54.747905L895.922485 347.563904C895.922485 317.329299 871.408161 292.817022 841.17458 292.817022z"
  11. p-id="4609"></path>
  12. </svg>
  13. </span>
  14. <!-- 上 -->
  15. <span @click="changeIndex(item, index, 'up')">
  16. <svg viewBox="0 0 1024 1024" width="200" height="200" fill="#6B7280">
  17. <path
  18. d="M959.804421 511.603981l-84.009346 84.023672L576.143391 293.406446l0 665.582911L448.20351 958.989357 448.20351 293.406446 147.619594 595.628676l-84.024695-84.023672L512.213359 63.546292 959.804421 511.603981z">
  19. </path>
  20. </svg>
  21. </span>
  22. <!-- 下 -->
  23. <span @click="changeIndex(item, index, 'down')">
  24. <svg style="transform: rotate(180deg);" viewBox="0 0 1024 1024" width="200" height="200" fill="#6B7280">
  25. <path
  26. d="M959.804421 511.603981l-84.009346 84.023672L576.143391 293.406446l0 665.582911L448.20351 958.989357 448.20351 293.406446 147.619594 595.628676l-84.024695-84.023672L512.213359 63.546292 959.804421 511.603981z">
  27. </path>
  28. </svg>
  29. </span>
  30. <span @click="deleteTest(item.id)" v-show="jsonData.testJson.length > 1">
  31. <svg viewBox="0 0 1024 1024" version="1.1" p-id="12415" width="200" height="200">
  32. <path
  33. d="M902.4 282.1H117.7c-13.4 0-23.5-10.1-23.5-23.5v-3.4c0-13.4 10.1-23.5 23.5-23.5h788.1c13.4 0 23.5 10.1 23.5 23.5v3.4c0 13.4-10.1 23.5-26.9 23.5zM634.1 151.3H386c-13.4 0-26.8-10.1-23.5-23.5v-6.7c0-13.4 10.1-23.5 23.5-23.5h248.2c13.4 0 23.5 10.1 23.5 23.5v3.4c3.3 13.3-10.1 26.8-23.6 26.8z m228.1 238.1c0-13.4-10.1-26.8-26.8-26.8-16.8 0-26.8 10.1-26.8 26.8L775 798.5v13.4c0 23.5-10.1 43.6-30.2 53.7-13.4 6.7-30.2 10.1-50.3 10.1H332.3c-33.5 3.4-60.4 0-70.4-33.5-3.4-6.7-6.7-16.8-6.7-26.8l-10.1-104-36.9-322c0-13.4-10.1-23.5-23.5-23.5s-26.8 10.1-26.8 23.5l47 462.8c0 40.2 40.2 73.8 80.5 73.8h459.5c40.2 0 80.5-33.5 80.5-73.8l36.8-462.8c0 3.3 0 0 0 0z m0 0"
  34. p-id="12416"></path>
  35. </svg>
  36. </span>
  37. </div>
  38. </div>
  39. <div class="ti_title">
  40. <div class="ti_t_input" contenteditable="true" v-text="item.teststitle"
  41. @blur="setTestTitle(item.id, $event.target.innerText)"></div>
  42. <div class="uploadImage" @click="uploadImage(item.id)">
  43. <svg viewBox="0 0 1024 1024" version="1.1" p-id="15953" width="200" height="200">
  44. <path
  45. d="M368 480c-62.4 0-112-49.6-112-112s49.6-112 112-112 112 49.6 112 112-49.6 112-112 112z m0-160c-27.2 0-48 20.8-48 48s20.8 48 48 48 48-20.8 48-48-20.8-48-48-48z m464 608H192c-52.8 0-96-43.2-96-96V192c0-52.8 43.2-96 96-96h640c52.8 0 96 43.2 96 96v640c0 52.8-43.2 96-96 96zM192 160c-17.6 0-32 14.4-32 32v640c0 17.6 14.4 32 32 32h640c17.6 0 32-14.4 32-32V192c0-17.6-14.4-32-32-32H192z m259.2 556.8c-25.6 0-51.2-11.2-70.4-30.4l-38.4-40c-12.8-12.8-33.6-12.8-46.4 0l-49.6 52.8c-12.8 12.8-32 12.8-44.8 1.6s-12.8-32-1.6-44.8l49.6-52.8c17.6-19.2 43.2-30.4 68.8-30.4s51.2 11.2 70.4 30.4l38.4 40c12.8 12.8 33.6 12.8 46.4 0l160-168c17.6-19.2 43.2-30.4 70.4-30.4s51.2 11.2 70.4 30.4L920 628.8c12.8 12.8 11.2 33.6-1.6 44.8-12.8 12.8-33.6 11.2-44.8-1.6L728 518.4c-12.8-12.8-33.6-12.8-46.4 0L521.6 688c-19.2 17.6-44.8 28.8-70.4 28.8z"
  46. fill="#333333" p-id="15954"></path>
  47. </svg>
  48. </div>
  49. </div>
  50. <!-- 图片 -->
  51. <div class="imageList">
  52. <div v-for="(image, imageIndex) in item.timuList" :key="item.id + '_' + imageIndex">
  53. <el-image style="width: 100px; height: 100px" :src="image.url" :preview-src-list="[image.url]"
  54. fit="cover"></el-image>
  55. <svg @click="delImage(item.id, imageIndex)" t="1774237005199" viewBox="0 0 1024 1024" width="200"
  56. height="200">
  57. <path
  58. d="M512 1024A512 512 0 1 1 512 0a512 512 0 0 1 0 1024zM305.956571 370.395429L447.488 512 305.956571 653.604571a45.568 45.568 0 1 0 64.438858 64.438858L512 576.512l141.604571 141.531429a45.568 45.568 0 0 0 64.438858-64.438858L576.512 512l141.531429-141.604571a45.568 45.568 0 1 0-64.438858-64.438858L512 447.488 370.395429 305.956571a45.568 45.568 0 0 0-64.438858 64.438858z"
  59. fill="#FF2525" p-id="4716"></path>
  60. </svg>
  61. </div>
  62. </div>
  63. <!-- 选择题 -->
  64. <div class="checkList">
  65. <div class="checkItem" v-for="(check, checkIndex) in item.checkList" :key="checkIndex"
  66. draggable="true"
  67. @dragstart="dragStart($event, item, checkIndex)"
  68. @dragover.prevent="dragOver($event, item, checkIndex)"
  69. @drop="drop($event, item, checkIndex)"
  70. @dragend="dragEnd">
  71. <div class="drag">
  72. <svg viewBox="0 0 1024 1024" width="200" height="200">
  73. <path
  74. d="M867.995 459.647h-711.99c-27.921 0-52.353 24.434-52.353 52.353s24.434 52.353 52.353 52.353h711.99c27.921 0 52.353-24.434 52.353-52.353s-24.434-52.353-52.353-52.353z"
  75. p-id="9455"></path>
  76. <path
  77. d="M867.995 763.291h-711.99c-27.921 0-52.353 24.434-52.353 52.353s24.434 52.353 52.353 52.353h711.99c27.921 0 52.353-24.434 52.353-52.353s-24.434-52.353-52.353-52.353z"
  78. p-id="9456"></path>
  79. <path
  80. d="M156.005 260.709h711.99c27.921 0 52.353-24.434 52.353-52.353s-24.434-52.353-52.353-52.353h-711.99c-27.921 0-52.353 24.434-52.353 52.353s24.434 52.353 52.353 52.353z">
  81. </path>
  82. </svg>
  83. </div>
  84. <div class="check" :class="{ 'checked': item.answer.includes(checkIndex) }"
  85. @click="checkClick(item.id, checkIndex)">
  86. <svg v-if="item.answer.includes(checkIndex)" t="1773996159000" viewBox="0 0 1024 1024" version="1.1"
  87. xmlns="http://www.w3.org/2000/svg" p-id="5894" width="200" height="200">
  88. <path
  89. d="M404.352 685.354667L789.632 213.333333 853.333333 267.52 409.941333 810.666667 170.666667 566.4l58.581333-59.818667z"
  90. p-id="5895"></path>
  91. </svg>
  92. </div>
  93. <el-input v-model="item.checkList[checkIndex]" :placeholder="lang.ssEnterOption"
  94. @blur="setTestJson()"></el-input>
  95. <div class="btn">
  96. <div @click="addCheck(item.id, checkIndex)" v-if="item.checkList.length > 2">
  97. <svg style="width: .7rem; height: .7rem;" viewBox="0 0 1024 1024" width="200" height="200">
  98. <path
  99. d="M47.653 439.326c-24.501 0-44.368 19.881-44.368 44.4v56.548c0 24.492 19.862 44.4 44.368 44.4h928.694c24.501 0 44.368-19.881 44.368-44.4v-56.548c0-24.497-19.862-44.4-44.368-44.4H47.653z"
  100. p-id="11474"></path>
  101. <path
  102. d="M586.326 47.653c0-24.501-19.881-44.368-44.4-44.368h-56.548c-24.492 0-44.4 19.862-44.4 44.368v928.694c0 24.501 19.881 44.368 44.4 44.368h56.548c24.497 0 44.4-19.862 44.4-44.368V47.653z">
  103. </path>
  104. </svg>
  105. </div>
  106. <div @click="delCheck(item.id, checkIndex)" v-if="item.checkList.length > 2">
  107. <svg viewBox="0 0 1024 1024" width="200" height="200">
  108. <path
  109. d="M632.117978 513.833356l361.805812 361.735298a85.462608 85.462608 0 1 1-121.001515 120.789974L511.116463 634.552816 146.913186 998.756094a86.026718 86.026718 0 0 1-121.706652-121.706652L389.480325 512.775651 27.674513 150.969839A85.392095 85.392095 0 0 1 148.393973 30.250379L510.199785 392.056191l366.671258-366.671258a86.026718 86.026718 0 0 1 121.706652 121.706652z">
  110. </path>
  111. </svg>
  112. </div>
  113. </div>
  114. </div>
  115. <div class="addCheck" @click="addCheck(item.id)">
  116. <svg viewBox="0 0 1024 1024" version="1.1" p-id="2732" width="200" height="200">
  117. <path
  118. d="M925.696 384q19.456 0 37.376 7.68t30.72 20.48 20.48 30.72 7.68 37.376q0 20.48-7.68 37.888t-20.48 30.208-30.72 20.48-37.376 7.68l-287.744 0 0 287.744q0 20.48-7.68 37.888t-20.48 30.208-30.72 20.48-37.376 7.68q-20.48 0-37.888-7.68t-30.208-20.48-20.48-30.208-7.68-37.888l0-287.744-287.744 0q-20.48 0-37.888-7.68t-30.208-20.48-20.48-30.208-7.68-37.888q0-19.456 7.68-37.376t20.48-30.72 30.208-20.48 37.888-7.68l287.744 0 0-287.744q0-19.456 7.68-37.376t20.48-30.72 30.208-20.48 37.888-7.68q39.936 0 68.096 28.16t28.16 68.096l0 287.744 287.744 0z"
  119. p-id="2733"></path>
  120. </svg>
  121. <span>{{ lang.ssOption }}</span>
  122. </div>
  123. </div>
  124. <!-- 解释说明 -->
  125. <div class="explanation">
  126. <div class="e_header">
  127. <span>{{ lang.ssExplanationTip }}</span>
  128. <div v-show="false">
  129. <svg t="1774233113566" viewBox="0 0 1027 1024" width="200" height="200">
  130. <path
  131. d="M511.979521 544.586217a54.525819 54.525819 0 0 1-23.359066-5.247791L31.038758 321.427143a54.397824 54.397824 0 0 1 0-98.236071L488.620455 5.279789c14.719411-7.039718 31.99872-7.039718 46.718131 0l457.581697 217.911283a54.397824 54.397824 0 0 1 0 98.236071l-457.581697 217.911283A54.525819 54.525819 0 0 1 511.979521 544.586217zM180.984761 272.341106L511.979521 429.966801l331.058757-157.625695L511.979521 114.587417 180.984761 272.341106z m354.417823 746.402144l457.517699-217.911283a54.397824 54.397824 0 1 0-46.718131-98.236071L511.979521 909.371625l-434.158634-206.775729a54.397824 54.397824 0 0 0-46.718131 98.236071l457.581697 217.911283a54.525819 54.525819 0 0 0 46.718131 0z m0-239.73441l457.517699-217.847286a54.397824 54.397824 0 1 0-46.718131-98.300068L511.979521 669.573217l-434.158634-206.711731a54.397824 54.397824 0 0 0-46.718131 98.300068l457.581697 217.847286a54.525819 54.525819 0 0 0 46.718131 0z"
  132. p-id="9073"></path>
  133. </svg>
  134. <span>{{ lang.ssAIGenerate }}</span>
  135. </div>
  136. </div>
  137. <el-input type="textarea" rows="3" resize="none" v-model="item.explanation"
  138. :placeholder="lang.ssEnterExplanation" @blur="setTestJson()"></el-input>
  139. </div>
  140. </div>
  141. <!-- 添加题目 -->
  142. <div class="addTest" @click="addTest()">
  143. <svg viewBox="0 0 1024 1024" version="1.1" p-id="2732" width="200" height="200">
  144. <path
  145. d="M925.696 384q19.456 0 37.376 7.68t30.72 20.48 20.48 30.72 7.68 37.376q0 20.48-7.68 37.888t-20.48 30.208-30.72 20.48-37.376 7.68l-287.744 0 0 287.744q0 20.48-7.68 37.888t-20.48 30.208-30.72 20.48-37.376 7.68q-20.48 0-37.888-7.68t-30.208-20.48-20.48-30.208-7.68-37.888l0-287.744-287.744 0q-20.48 0-37.888-7.68t-30.208-20.48-20.48-30.208-7.68-37.888q0-19.456 7.68-37.376t20.48-30.72 30.208-20.48 37.888-7.68l287.744 0 0-287.744q0-19.456 7.68-37.376t20.48-30.72 30.208-20.48 37.888-7.68q39.936 0 68.096 28.16t28.16 68.096l0 287.744 287.744 0z"
  146. p-id="2733"></path>
  147. </svg>
  148. <span>{{ lang.ssTopic }}</span>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. import { v4 as uuidv4 } from 'uuid';
  154. import { uploadOneFile } from '@/components/tools/uploadFile'
  155. export default {
  156. emits: ['setTestJson', 'save'],
  157. props: {
  158. workData: {
  159. type: Object,
  160. default: () => { }
  161. }
  162. },
  163. data() {
  164. return {
  165. jsonData: {},
  166. dragItem: null
  167. }
  168. },
  169. watch: {
  170. workData: {
  171. handler(newVal, oldVal) {
  172. if (newVal.type == 45) {
  173. if (JSON.stringify(newVal.json) != JSON.stringify(this.jsonData)) {
  174. this.jsonData = JSON.parse(JSON.stringify(newVal.json));
  175. if(this.jsonData.testJson.length == 0){
  176. this.addTest();
  177. }
  178. }
  179. }
  180. },
  181. deep: true,
  182. immediate: true
  183. }
  184. },
  185. methods: {
  186. // 更新题目
  187. setTestJson() {
  188. // console.log(this.jsonData)
  189. this.jsonData.testCount = this.jsonData.testJson.length;
  190. this.$emit('setTestJson', this.jsonData);
  191. },
  192. // 添加题目
  193. addTest() {
  194. this.jsonData.testJson.push({
  195. id: uuidv4(),
  196. type: "2",
  197. teststitle: "",
  198. checkList: ['', '', ''],
  199. timuList: [],
  200. answer: [],
  201. userAnswer: [],
  202. explanation: '',
  203. });
  204. this.setTestJson();
  205. },
  206. //修改标题
  207. setTestTitle(id, title) {
  208. console.log('修改标题', id, title)
  209. let test = this.jsonData.testJson.find(item => item.id == id);
  210. if (test) {
  211. test.teststitle = title;
  212. }
  213. this.setTestJson();
  214. },
  215. // 点击复选框
  216. checkClick(id, index) {
  217. let test = this.jsonData.testJson.find(item => item.id == id);
  218. if (test) {
  219. if (test.answer.includes(index)) {
  220. test.answer.splice(test.answer.indexOf(index), 1);
  221. } else {
  222. test.answer.push(index);
  223. }
  224. }
  225. this.setTestJson();
  226. },
  227. // 删除题目
  228. deleteTest(id) {
  229. let index = this.jsonData.testJson.findIndex(item => item.id == id);
  230. this.jsonData.testJson.splice(index, 1);
  231. this.setTestJson();
  232. },
  233. // 添加选项
  234. addCheck(id, checkIndex = null) {
  235. let index = this.jsonData.testJson.findIndex(item => item.id == id);
  236. let test = this.jsonData.testJson[index];
  237. if (!checkIndex) {
  238. checkIndex = test.checkList.length;
  239. }else{
  240. checkIndex = checkIndex + 1;
  241. }
  242. test.checkList.splice(checkIndex, 0, '');
  243. this.setTestJson();
  244. },
  245. // 删除选项
  246. delCheck(id, index) {
  247. let test = this.jsonData.testJson.find(item => item.id == id);
  248. if (test) {
  249. if (test.checkList.length == 1) {
  250. this.$message.error("至少保留一个选项");
  251. return;
  252. }
  253. test.checkList.splice(index, 1);
  254. }
  255. this.setTestJson();
  256. },
  257. // 上传图片
  258. uploadImage(id) {
  259. const input = document.createElement('input');
  260. input.type = 'file';
  261. input.accept = 'image/*';
  262. input.click();
  263. input.onchange = (e) => {
  264. if (e.target.files[0]) {
  265. uploadOneFile(e.target.files[0]).then(res => {
  266. res.src = res.url
  267. this.jsonData.testJson.find(item => item.id == id).timuList = [res];
  268. this.setTestJson();
  269. })
  270. }
  271. }
  272. },
  273. // 复制题目
  274. copyTest(id) {
  275. let test = this.jsonData.testJson.find(item => item.id == id);
  276. if (test) {
  277. test = JSON.parse(JSON.stringify(test));
  278. test.id = uuidv4();
  279. this.jsonData.testJson.push(test);
  280. this.setTestJson();
  281. }
  282. },
  283. // 删除图片
  284. delImage(id, index) {
  285. let test = this.jsonData.testJson.find(item => item.id == id);
  286. if (test) {
  287. test.timuList.splice(index, 1);
  288. }
  289. this.setTestJson();
  290. },
  291. // 移动题目
  292. changeIndex(item, index, direction) {
  293. let test = this.jsonData.testJson.find(i => i.id == item.id);
  294. if (test) {
  295. if (direction == 'up') {
  296. if (index == 0) {
  297. this.$message.info("已到顶部");
  298. return;
  299. }
  300. this.jsonData.testJson.splice(index, 1);
  301. this.jsonData.testJson.splice(index - 1, 0, JSON.parse(JSON.stringify(test)));
  302. } else if (direction == 'down') {
  303. if (index == this.jsonData.testJson.length - 1) {
  304. this.$message.info("已到底部");
  305. return;
  306. }
  307. this.jsonData.testJson.splice(index, 1);
  308. this.jsonData.testJson.splice(index + 1, 0, JSON.parse(JSON.stringify(test)));
  309. }
  310. this.setTestJson();
  311. }
  312. },
  313. // 拖拽相关方法
  314. dragStart(e, item, checkIndex) {
  315. this.dragItem = { item, checkIndex };
  316. const checkItem = e.target.closest('.checkItem');
  317. if (checkItem) checkItem.classList.add('dragging');
  318. e.dataTransfer.effectAllowed = 'move';
  319. },
  320. dragOver(e, item, checkIndex) {
  321. e.preventDefault();
  322. e.dataTransfer.dropEffect = 'move';
  323. document.querySelectorAll('.checkItem').forEach(el => {
  324. el.style.borderTop = '';
  325. el.style.borderBottom = '';
  326. });
  327. const checkItems = e.target.closest('.checkItem');
  328. if (checkItems && this.dragItem && this.dragItem.checkIndex !== checkIndex) {
  329. if (this.dragItem.checkIndex < checkIndex) {
  330. checkItems.style.borderBottom = '2px solid #ffa502';
  331. } else {
  332. checkItems.style.borderTop = '2px solid #ffa502';
  333. }
  334. }
  335. },
  336. drop(e, targetItem, targetCheckIndex) {
  337. e.preventDefault();
  338. document.querySelectorAll('.checkItem').forEach(el => {
  339. el.style.borderTop = '';
  340. el.style.borderBottom = '';
  341. el.classList.remove('dragging');
  342. });
  343. if (!this.dragItem) return;
  344. const { item: sourceItem, checkIndex: sourceCheckIndex } = this.dragItem;
  345. if (sourceItem.id !== targetItem.id) return;
  346. if (sourceCheckIndex === targetCheckIndex) return;
  347. const test = this.jsonData.testJson.find(i => i.id === sourceItem.id);
  348. if (test) {
  349. let newAnswerIndex;
  350. if (sourceCheckIndex < targetCheckIndex) {
  351. newAnswerIndex = targetCheckIndex - 1;
  352. } else {
  353. newAnswerIndex = targetCheckIndex;
  354. }
  355. const item = test.checkList[sourceCheckIndex];
  356. test.checkList.splice(sourceCheckIndex, 1);
  357. test.checkList.splice(targetCheckIndex, 0, item);
  358. if (test.answer.includes(sourceCheckIndex)) {
  359. const answerIndex = test.answer.indexOf(sourceCheckIndex);
  360. test.answer.splice(answerIndex, 1);
  361. test.answer.push(newAnswerIndex);
  362. test.answer.sort((a, b) => a - b);
  363. } else {
  364. test.answer = test.answer.map(idx => {
  365. if (sourceCheckIndex < targetCheckIndex) {
  366. return idx > sourceCheckIndex && idx <= targetCheckIndex ? idx - 1 : idx;
  367. } else {
  368. return idx >= targetCheckIndex && idx < sourceCheckIndex ? idx + 1 : idx;
  369. }
  370. });
  371. }
  372. this.setTestJson();
  373. }
  374. this.dragItem = null;
  375. },
  376. dragEnd(e) {
  377. const checkItem = e.target.closest('.checkItem');
  378. if (checkItem) checkItem.classList.remove('dragging');
  379. document.querySelectorAll('.checkItem').forEach(el => {
  380. el.style.borderTop = '';
  381. el.style.borderBottom = '';
  382. });
  383. this.dragItem = null;
  384. },
  385. },
  386. }
  387. </script>
  388. <style scoped>
  389. .setChoiceQuestion {
  390. width: 100%;
  391. height: auto;
  392. background: #fff;
  393. display: flex;
  394. flex-direction: column;
  395. overflow: auto;
  396. padding: 4rem;
  397. box-sizing: border-box;
  398. gap: 2rem;
  399. }
  400. .addTest {
  401. border-radius: 5px;
  402. border: 1px dashed #d1d5db;
  403. padding: .5rem 1rem;
  404. height: fit-content;
  405. width: fit-content;
  406. display: flex;
  407. align-items: center;
  408. gap: .5rem;
  409. cursor: pointer;
  410. }
  411. .addTest>svg {
  412. width: .7rem;
  413. height: .7rem;
  414. fill: #6E7583;
  415. }
  416. .addTest>span {
  417. font-weight: bold;
  418. font-size: .9rem;
  419. color: #6b7280;
  420. }
  421. .testItem {
  422. width: 100%;
  423. height: auto;
  424. display: flex;
  425. align-items: center;
  426. gap: 1rem;
  427. flex-direction: column;
  428. }
  429. .ti_header {
  430. width: 100%;
  431. display: flex;
  432. align-items: center;
  433. justify-content: space-between;
  434. }
  435. .ti_header>span {
  436. font-size: 1rem;
  437. font-weight: 600;
  438. color: #ff9300;
  439. }
  440. .ti_header>span>span {
  441. font-size: .8rem;
  442. color: rgb(117, 117, 117);
  443. margin-left: .5rem;
  444. }
  445. .ti_h_edit {
  446. display: flex;
  447. align-items: center;
  448. gap: 1rem;
  449. }
  450. .ti_h_edit>span {
  451. width: 1.5rem;
  452. height: 1.5rem;
  453. display: flex;
  454. align-items: center;
  455. justify-content: center;
  456. background: #F9FAFB;
  457. border-radius: 4px;
  458. cursor: pointer;
  459. }
  460. .ti_h_edit>span>svg {
  461. width: 1rem;
  462. height: 1rem;
  463. fill: #6B7280;
  464. }
  465. .ti_title {
  466. width: 100%;
  467. height: fit-content;
  468. padding-bottom: 2rem;
  469. min-height: 4rem;
  470. background: #FAFBFC;
  471. border-radius: 8px;
  472. border: 1px solid #E5E7EB;
  473. position: relative;
  474. }
  475. .ti_t_input {
  476. width: 100%;
  477. height: 100%;
  478. padding: 1rem;
  479. box-sizing: border-box;
  480. border: none;
  481. outline: none;
  482. background: none;
  483. font-size: .8rem;
  484. resize: none;
  485. max-height: 10rem;
  486. overflow: auto;
  487. /* padding-right: 2rem; */
  488. }
  489. .uploadImage {
  490. position: absolute;
  491. bottom: 0.5rem;
  492. right: 0.5rem;
  493. background: #fff;
  494. border-radius: .5rem;
  495. display: flex;
  496. justify-content: center;
  497. align-items: center;
  498. border: 1px solid #E5E7EB;
  499. cursor: pointer;
  500. padding: .5rem;
  501. }
  502. .uploadImage>svg {
  503. width: 1rem;
  504. height: 1rem;
  505. }
  506. .checkList {
  507. width: 100%;
  508. height: auto;
  509. display: flex;
  510. flex-direction: column;
  511. gap: 1rem;
  512. /* padding-left: 4rem; */
  513. }
  514. .checkItem {
  515. width: 100%;
  516. height: auto;
  517. display: flex;
  518. align-items: center;
  519. justify-content: flex-start;
  520. gap: .5rem;
  521. padding: .3rem .5rem;
  522. transition: .2s;
  523. }
  524. .checkItem:hover {
  525. background: #F9FAFB;
  526. }
  527. .drag {
  528. width: 1.1rem;
  529. height: 1.1rem;
  530. display: flex;
  531. justify-content: center;
  532. align-items: center;
  533. cursor: move;
  534. margin-right: 1rem;
  535. opacity: 0;
  536. transition: .2s;
  537. }
  538. .checkItem:hover > .drag {
  539. opacity: 1;
  540. }
  541. .checkItem[draggable="true"] {
  542. cursor: move;
  543. }
  544. .checkItem.dragging {
  545. opacity: 0.5;
  546. background: #FEF3C7;
  547. }
  548. .drag>svg {
  549. width: 100%;
  550. height: 100%;
  551. fill: #D1D5DC;
  552. }
  553. .check {
  554. width: 1.1rem;
  555. height: 1.1rem;
  556. border: solid 1px #D1D5DB;
  557. border-radius: .25rem;
  558. cursor: pointer;
  559. display: flex;
  560. justify-content: center;
  561. align-items: center;
  562. }
  563. .checked {
  564. background: #FF9300;
  565. }
  566. .checked>svg {
  567. width: .7rem;
  568. height: .7rem;
  569. fill: #fff;
  570. }
  571. .checkItem>.el-input {
  572. width: calc(100% - 10rem);
  573. }
  574. .addCheck {
  575. border-radius: 5px;
  576. border: 1px dashed #d1d5db;
  577. padding: .3rem .8rem;
  578. height: fit-content;
  579. width: fit-content;
  580. display: flex;
  581. align-items: center;
  582. gap: .5rem;
  583. cursor: pointer;
  584. margin-left: 2.2rem;
  585. }
  586. .addCheck>svg {
  587. width: .5rem;
  588. height: .5rem;
  589. fill: #6E7583;
  590. }
  591. .addCheck>span {
  592. font-weight: bold;
  593. font-size: .8rem;
  594. color: #6b7280;
  595. }
  596. .btn {
  597. display: flex;
  598. align-items: center;
  599. gap: 1em;
  600. opacity: 0;
  601. margin-left: 1rem;
  602. }
  603. .checkItem:hover>.btn {
  604. opacity: 1;
  605. }
  606. .btn>div {
  607. width: 1rem;
  608. height: 1rem;
  609. display: flex;
  610. justify-content: center;
  611. align-items: center;
  612. /* background: #F9FAFB; */
  613. border-radius: .4px;
  614. cursor: pointer;
  615. }
  616. .btn>div>svg {
  617. width: .6rem;
  618. height: .6rem;
  619. fill: #9DA3AF;
  620. }
  621. .explanation {
  622. width: 100%;
  623. height: auto;
  624. padding: 1rem;
  625. background: #FAFBFC;
  626. border-radius: 5px;
  627. display: flex;
  628. flex-direction: column;
  629. gap: 1rem;
  630. border-radius: .8rem;
  631. }
  632. .e_header {
  633. display: flex;
  634. align-items: center;
  635. justify-content: space-between;
  636. }
  637. .e_header>span {
  638. color: #6b7280;
  639. font-size: .8rem;
  640. font-weight: 500;
  641. }
  642. .e_header>div {
  643. display: flex;
  644. align-items: center;
  645. gap: .5rem;
  646. background: #ff9300;
  647. color: #fff;
  648. padding: .3rem .8rem;
  649. font-size: .8rem;
  650. font-weight: 500;
  651. border-radius: .5rem;
  652. cursor: pointer;
  653. }
  654. .e_header>div>svg {
  655. width: .8rem;
  656. height: .8rem;
  657. fill: #fff;
  658. }
  659. .imageList {
  660. width: 100%;
  661. height: auto;
  662. display: flex;
  663. flex-wrap: wrap;
  664. gap: 1rem;
  665. }
  666. .imageList>div {
  667. width: 100px;
  668. height: 100px;
  669. display: flex;
  670. align-items: center;
  671. justify-content: center;
  672. /* overflow: hidden; */
  673. border-radius: .5rem;
  674. position: relative;
  675. }
  676. .imageList>div:hover>svg {
  677. display: flex;
  678. }
  679. .imageList>div>svg {
  680. width: 1rem;
  681. height: 1rem;
  682. position: absolute;
  683. top: -.3rem;
  684. right: -.3rem;
  685. font-weight: 500;
  686. border-radius: .5rem;
  687. cursor: pointer;
  688. display: flex;
  689. align-items: center;
  690. justify-content: center;
  691. display: none;
  692. }
  693. </style>