AutoCreateNew.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div class="auto-create-container">
  3. <p class="auto-create-title">设置自动出题条件</p>
  4. <div class="auto-filter-wrap">
  5. <div class="filter-wrap-item">
  6. <span class="filter-title">题目来源 : </span>
  7. <div class="filter-content">
  8. <CheckboxGroup v-model="filterOrigin">
  9. <Checkbox label="private" v-if="!isSchoolPaper" :disabled="filterOrigin.length === 1 && filterOrigin[0] === 'private'">个人题库</Checkbox>
  10. <Checkbox label="school" :disabled="filterOrigin.length === 1 && filterOrigin[0] === 'school'">校本题库</Checkbox>
  11. </CheckboxGroup>
  12. </div>
  13. </div>
  14. <div class="filter-wrap-item animated fadeIn" v-if="includeSchool">
  15. <span class="filter-title">校本占比 : </span>
  16. <div class="filter-content">
  17. <InputNumber :max="100" :min="0" :step="10" v-model="schoolRate"></InputNumber>
  18. <span style="margin-left: 10px;"> %</span>
  19. </div>
  20. </div>
  21. <div class="filter-wrap-item animated fadeIn" v-if="includeSchool">
  22. <span class="filter-title">选择学段 : </span>
  23. <div class="filter-content">
  24. <Select v-model="periodCode" >
  25. <Option v-for="item in periodList" :value="item.id" :key="item.id">{{ item.name }}</Option>
  26. </Select>
  27. </div>
  28. </div>
  29. <div class="filter-wrap-item animated fadeIn" v-if="includeSchool">
  30. <span class="filter-title">选择科目 : </span>
  31. <div class="filter-content">
  32. <Select v-model="subjectCode">
  33. <Option v-for="item in subjectList" :value="item.id" :key="item.id">{{ item.name }}</Option>
  34. </Select>
  35. </div>
  36. </div>
  37. <div class="filter-wrap-item" v-for="(item,index) in quInfos" :key="index">
  38. <span class="filter-title">{{ item.label }} :</span>
  39. <div class="filter-content">
  40. <span class="filter-content-text">难度 </span>
  41. <Select v-model="item.policy">
  42. <Option v-for="item in diffList" :value="item.level" :key="item.level">{{ item.label }}</Option>
  43. </Select>
  44. <span class="filter-content-text">共 </span>
  45. <InputNumber :max="10" :min="0" v-model="item.count"></InputNumber>
  46. <span class="filter-content-text"> 道题 </span>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="auto-btn-wrap">
  51. <Button type="info" :loading="isLoading" @click="doAutoCreate">开始组题</Button>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. export default{
  57. name:'AutoCreate',
  58. data(){
  59. return {
  60. isLoading:false,
  61. filterOrigin:['private'],
  62. periodList:[],
  63. periodCode:'',
  64. subjectList:[],
  65. subjectCode:'',
  66. schoolRate:50,
  67. quInfos:[{
  68. type:'single',
  69. label:'单选题',
  70. count:0,
  71. policy:'random'
  72. },{
  73. type:'multiple',
  74. label:'多选题',
  75. count:0,
  76. policy:'random'
  77. },{
  78. type:'judge',
  79. label:'判断题',
  80. count:0,
  81. policy:'random'
  82. },{
  83. type:'complete',
  84. label:'填空题',
  85. count:0,
  86. policy:'random'
  87. },{
  88. type:'subjective',
  89. label:'问答题',
  90. count:0,
  91. policy:'random'
  92. },{
  93. type:'compose',
  94. label:'综合题',
  95. count:0,
  96. policy:'random'
  97. }],
  98. diffList:[
  99. {
  100. level: 'random',
  101. label: '随机',
  102. value: -1
  103. },
  104. {
  105. level: 'average',
  106. label: '平均分配',
  107. value: 0
  108. },
  109. {
  110. level: 'relativeEasy',
  111. label: '较易',
  112. value: 1
  113. },
  114. {
  115. level: 'easy',
  116. label: '容易',
  117. value: 2
  118. },
  119. {
  120. level: 'common',
  121. label: '一般',
  122. value: 3
  123. },
  124. {
  125. level: 'difficulty',
  126. label: '困难',
  127. value: 4
  128. },
  129. {
  130. level: 'relativeDifficulty',
  131. label: '较难',
  132. value: 5
  133. }
  134. ]
  135. }
  136. },
  137. created() {
  138. this.getSchoolBaseInfo().then(res => {
  139. if (!res) return
  140. if(res.period.length){
  141. this.periodList = res.period
  142. this.periodCode = res.period[0].id
  143. this.subjectList = res.period[0].subjects
  144. this.subjectCode = this.subjectList.length ? this.subjectList[0].id : ''
  145. }
  146. })
  147. },
  148. methods:{
  149. /** 获取当前学校基础数据 */
  150. getSchoolBaseInfo() {
  151. return new Promise((r, j) => {
  152. this.$store.dispatch("user/getSchoolProfile").then((res) => {
  153. let schoolBaseInfo = res.school_base;
  154. if (schoolBaseInfo) {
  155. r(schoolBaseInfo)
  156. } else {
  157. r(null)
  158. }
  159. });
  160. })
  161. },
  162. /* 开始组题 */
  163. doAutoCreate(){
  164. console.log(this.quInfos)
  165. console.log(this.filterOrigin)
  166. this.isLoading = true
  167. let params = []
  168. let copyInfos = JSON.parse(JSON.stringify(this.quInfos))
  169. this.filterOrigin.forEach(scope => {
  170. if(scope === 'private'){
  171. params.push({
  172. code:'Item-' + this.$store.state.userInfo.TEAMModelId,
  173. scope: scope,
  174. period: '',
  175. points:[],
  176. quInfos: copyInfos.map(i => {
  177. i.count = (i.count - Math.round(i.count * this.schoolRate * 0.01))
  178. return i
  179. })
  180. })
  181. }else{
  182. params.push({
  183. code:'Item-' + this.$store.state.userInfo.schoolCode,
  184. scope: scope,
  185. period: '',
  186. points:[],
  187. quInfos: this.quInfos.map(i => {
  188. i.count = Math.round(i.count * this.schoolRate * 0.01)
  189. return i
  190. })
  191. })
  192. }
  193. })
  194. // 访问API获取随机题目
  195. this.$api.learnActivity.Automatic(params).then(
  196. res => {
  197. if (res.length > 0) {
  198. console.log('组题成功', res)
  199. this.isLoading = false
  200. } else {
  201. this.$Message.error('未能匹配满足条件的题目!')
  202. setTimeout(() => {
  203. this.isLoading = false
  204. }, 1000)
  205. }
  206. },
  207. err => {
  208. this.$Message.error('API ERROR!')
  209. setTimeout(() => {
  210. this.isLoading = false
  211. }, 1000)
  212. }
  213. )
  214. console.log(params)
  215. }
  216. },
  217. mounted() {
  218. if(this.isSchoolPaper){
  219. this.filterOrigin = ['school']
  220. this.schoolRate = 100
  221. }
  222. },
  223. computed:{
  224. includeSchool(){
  225. return this.filterOrigin.indexOf('school') > -1
  226. },
  227. isSchoolPaper(){
  228. return this.$route.name === 'newSchoolPaper'
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="less">
  234. @import "./AutoCreateNew.less";
  235. </style>