index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="c_box">
  3. <div class="c_box_title">{{ title }}</div>
  4. <div class="c_body">
  5. <div v-if="type == 3">
  6. <div v-for="(item, index) in checkArray[page].array" :key="index" class="check_box">
  7. <div class="title">{{ selectType(item, index) }}</div>
  8. <div v-if="item.ttype == 1" class="answerBox"><choiceV :cJson.sync="item.json"></choiceV></div>
  9. <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
  10. <div class="title">{{ selectType(item2, index2) }}</div>
  11. <div v-if="item2.ttype == 1" class="answerBox"><choiceV :cJson.sync="item2.json"></choiceV></div>
  12. </div>
  13. </div>
  14. </div>
  15. <div v-else>
  16. <div v-for="(item, index) in checkArray" :key="index" class="check_box">
  17. <div class="title">{{ selectType(item, index) }}</div>
  18. <div v-if="item.ttype == 1" class="answerBox"><choiceV :cJson.sync="item.json"></choiceV></div>
  19. <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
  20. <div class="title">{{ selectType(item2, index2) }}</div>
  21. <div v-if="item2.ttype == 1" class="answerBox"><choiceV :cJson.sync="item2.json"></choiceV></div>
  22. </div>
  23. </div>
  24. </div>
  25. <div v-if="checkArray.length > 1 && type == 3" class="page">
  26. <el-button type="primary" size="mini" :disabled="page == 0" @click="page--">上一页</el-button>
  27. <div class="p_page"><span>{{ page + 1 }}</span><span>/</span><span>{{ checkArray.length }}</span></div>
  28. <el-button type="primary" size="mini" :disabled="page == (checkArray.length - 1)" @click="page++">下一页</el-button>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import choiceV from './choice.vue';
  35. export default {
  36. props: {
  37. cJson: {
  38. type: Array,
  39. },
  40. title: {
  41. type: String,
  42. }
  43. },
  44. components: {
  45. choiceV
  46. },
  47. data() {
  48. return {
  49. checkArray: [],
  50. type: 1,
  51. page: 0,
  52. options2: {
  53. 1: "选择题",
  54. 2: "问答题",
  55. 3: "填空题",
  56. 4: "添加文档"
  57. },
  58. }
  59. },
  60. computed: {
  61. selectType() {
  62. return function (item, index) {
  63. if (item.ttype == 1) {
  64. return index + 1 + "、" + this.options2[item.type];
  65. } else if (item.ttype == 2) {
  66. return `第${index + 1}组 (共${item.array.length}题)`;
  67. } else if (item.ttype == 3) {
  68. return `分页${index + 1}`;
  69. }
  70. };
  71. }
  72. },
  73. watch: {
  74. cJson: {
  75. handler(newVal, oldVal) {
  76. console.log(newVal);
  77. console.log(oldVal);
  78. this.checkArray = this.setJson(this.depthCopy(newVal))
  79. },
  80. deep: true
  81. }
  82. },
  83. methods: {
  84. depthCopy(s) {
  85. return JSON.parse(JSON.stringify(s));
  86. },
  87. setJson(json) {
  88. if (json.length > 0) {
  89. let _json = this.depthCopy(json)
  90. this.type = _json[0].ttype
  91. let checkArray = _json.filter(item => {
  92. if (item.array) {
  93. item.array = item.array.filter(item2 => {
  94. if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
  95. item2.json.answer2 = []
  96. }
  97. if (item2.array) {
  98. item2.array = item2.array.filter(item3 => {
  99. if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
  100. item3.json.answer2 = []
  101. }
  102. return item3
  103. })
  104. }
  105. return (item2.ttype != 1 && item2.array.length > 0) || (item2.ttype == 1)
  106. })
  107. }
  108. if (item.ttype == 1 && item.json && !item.json.answer2) {
  109. item.json.answer2 = []
  110. }
  111. console.log(item.array);
  112. return (item.ttype != 1 && item.array.length > 0) || (item.ttype == 1)
  113. })
  114. console.log(checkArray);
  115. return checkArray
  116. } else {
  117. return []
  118. }
  119. }
  120. },
  121. mounted() {
  122. this.checkArray = this.setJson(this.depthCopy(this.cJson))
  123. },
  124. }
  125. </script>
  126. <style scoped>
  127. .c_box {
  128. padding: 10px 0 0;
  129. box-sizing: border-box;
  130. width: 95%;
  131. margin: 10px auto 0;
  132. background: #fff;
  133. height: calc(100% - 10px);
  134. overflow: auto;
  135. }
  136. .c_box_title {
  137. width: 90%;
  138. text-align: center;
  139. font-size: 24px;
  140. font-weight: bold;
  141. word-break: break-all;
  142. margin: 20px;
  143. }
  144. .c_body {
  145. width: 90%;
  146. margin: 0 auto;
  147. }
  148. .check_box{
  149. }
  150. .check_box + .check_box{
  151. margin-top: 10px;
  152. }
  153. .check_box > .title{
  154. font-size:20px;
  155. word-break: break-all;
  156. font-weight: bold;
  157. }
  158. .check_box > .answerBox{
  159. margin-top: 10px;
  160. }
  161. .check_box > .noanswerBox{
  162. margin-top: 10px;
  163. }
  164. .check_box_xia{
  165. margin-top: 10px;
  166. }
  167. .check_box_xia > .title{
  168. font-size: 18px;
  169. font-weight: bold;
  170. }
  171. .check_box_xia > .answerBox{
  172. margin-top: 10px;
  173. }
  174. .check_box_xia > .noanswerBox{
  175. margin-top: 10px;
  176. }
  177. .page{
  178. margin: 20px;
  179. display: flex;
  180. align-items: center;
  181. }
  182. .p_page{
  183. margin: 0 10px;
  184. }
  185. </style>