ChoiceStatistics.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="choice-statistics-panel">
  3. <div v-if="isChoiceQuestion && statistics" class="statistics-content">
  4. <div class="statistics-title">选择题统计</div>
  5. <div class="statistics-summary">
  6. 总提交:{{ statistics.totalSubmissions }} 人
  7. </div>
  8. </div>
  9. <div v-else class="statistics-empty">
  10. <div v-if="!isChoiceQuestion">当前页面不是选择题</div>
  11. <div v-else-if="!statistics">暂无统计数据</div>
  12. </div>
  13. <div class="statistics-chart">
  14. <div class="tool45" v-if="statistics && statistics.tool=='45'">
  15. <div v-for="(item,index) in statistics.titles" :key="index">
  16. <div class="t45_title">
  17. <span>{{ index+1 }}、</span>
  18. <div>{{ item.title }}</div>
  19. </div>
  20. <div class="t45_btn">
  21. <span @click="lookStudent(item.checkList)">查看学生</span>
  22. </div>
  23. <div class="t45_list">
  24. <div class="t45_l_item" v-for="(i,index2) in item.checkList" :key="index+'_'+index2">
  25. <div class="t45_l_i_option">
  26. <span>{{ i.index }}:</span>
  27. <div>
  28. <div :style="{width:i.proportion}"></div>
  29. </div>
  30. <span>{{ i.proportion }}</span>
  31. </div>
  32. <!-- <div class="t45_l_i_user">
  33. <template v-for="(j,index3) in i.user" :key="index+'_'+index2+'_'+index3">
  34. <div v-if="item.showAllUser || (!item.showAllUser && index3 < 3)">
  35. <span>{{ j }}</span>
  36. </div>
  37. </template>
  38. <span class="t45_o_btn" v-if="i.user.length > 3 && !item.showAllUser" @click="()=>{item.showAllUser = true,$forceUpdate()}">
  39. <svg t="1756278651830" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7545" width="200" height="200"><path d="M293.546667 253.013333l264.533333 266.666667-264.106667 266.24 70.4 70.826667 334.506667-337.066667-334.933333-337.066667z" p-id="7546"></path></svg>
  40. </span>
  41. <span class="t45_o_btn" v-if="i.user.length > 3 && item.showAllUser" @click="()=>{item.showAllUser = false,$forceUpdate()}">
  42. <svg style="transform: rotate(180deg);" t="1756278651830" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7545" width="200" height="200"><path d="M293.546667 253.013333l264.533333 266.666667-264.106667 266.24 70.4 70.826667 334.506667-337.066667-334.933333-337.066667z" p-id="7546"></path></svg>
  43. </span>
  44. </div> -->
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <Modal :visible="visible" :width="720" :closeButton="true" @update:visible="visible = false">
  52. <div class="userBox">
  53. <div class="ub_item" v-for="(item,index) in userCheckList" :key="index">
  54. <div class="ub_i_options">{{ item.options }}</div>
  55. <div class="ub_i_user">
  56. <span>选择同学:</span>
  57. <div class="ub_i_u_item" v-for="(item2,index2) in item.user" :key="index+'_'+index2">{{ item2 }}</div>
  58. </div>
  59. </div>
  60. </div>
  61. </Modal>
  62. </template>
  63. <script lang="ts" setup>
  64. import { computed, reactive, ref } from 'vue'
  65. import { ElementTypes } from '@/types/slides'
  66. import Modal from '@/components/Modal.vue'
  67. interface Props {
  68. workArray: any[]
  69. elementList: any[]
  70. }
  71. const props = defineProps<Props>()
  72. const visible = ref<boolean>(false)
  73. let userCheckList = reactive<any[]>([])
  74. // 检查当前是否为选择题(toolType为45)
  75. const isChoiceQuestion = computed(() => {
  76. const frame = props.elementList.find(element => element.type === ElementTypes.FRAME)
  77. return frame?.toolType === 45
  78. })
  79. const optionList: Array<string> = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  80. const lookStudent = (checkList:any) => {
  81. userCheckList = checkList
  82. visible.value = true
  83. }
  84. // 选择题统计信息
  85. const statistics = computed(() => {
  86. if (!isChoiceQuestion.value || !props.workArray || props.workArray.length === 0) return null
  87. // 统计信息结构优化
  88. let titles: Array<{
  89. title: string,
  90. showAllUser: boolean,
  91. checkList: Array<{ options: string, num: number, proportion: string, index :string, user: Array<[]>}>
  92. }> = []
  93. let totalSubmissions = 0
  94. let tool: string = ''
  95. // 只初始化一次题目结构
  96. let isTitleInitialized = false
  97. props.workArray.forEach((work) => {
  98. if (!work.content) return
  99. try {
  100. if (work.atool === '45') {
  101. const content = JSON.parse(decodeURIComponent(work.content))
  102. const testJson = content.testJson
  103. // 初始化题目结构
  104. if (!isTitleInitialized && Array.isArray(testJson)) {
  105. tool = work.atool
  106. titles = testJson.map((item: any) => ({
  107. title: item.teststitle || '',
  108. showAllUser: false,
  109. checkList: Array.isArray(item.checkList)
  110. ? item.checkList.map((i: any) => ({ options: i, num: 0, user: [], proportion: '', index: '' }))
  111. : []
  112. }))
  113. isTitleInitialized = true
  114. }
  115. // 统计每道题的选项被选择次数
  116. if (Array.isArray(titles) && Array.isArray(testJson)) {
  117. testJson.forEach((item: any, index: number) => {
  118. const answer = item.userAnswer
  119. if (typeof answer === 'number') {
  120. if (titles[index] && titles[index].checkList[answer]) {
  121. titles[index].checkList[answer].num += 1
  122. titles[index].checkList[answer].user.push(work.name)
  123. }
  124. }
  125. else if (Array.isArray(answer) && answer.length > 0) {
  126. answer.forEach((i: number) => {
  127. if (titles[index] && titles[index].checkList[i]) {
  128. titles[index].checkList[i].num += 1
  129. titles[index].checkList[i].user.push(work.name)
  130. }
  131. })
  132. }
  133. })
  134. }
  135. totalSubmissions++
  136. }
  137. }
  138. catch (e) {
  139. // eslint-disable-next-line no-console
  140. console.log('解析选择题答案失败:', e, work.content)
  141. }
  142. })
  143. titles.forEach((item: any) => {
  144. const total = item.checkList.reduce((sum: number, cur: any) => sum + cur.num, 0)
  145. item.checkList.forEach((option: any, index :number) => {
  146. option.proportion = total > 0 ? ((option.num / total) * 100).toFixed(1) + '%' : '0.0%'
  147. option.index = optionList[index]
  148. })
  149. })
  150. // 返回结构优化,便于前端展示
  151. return {
  152. totalSubmissions,
  153. titles,
  154. tool
  155. }
  156. })
  157. </script>
  158. <style lang="scss" scoped>
  159. .choice-statistics-panel {
  160. height: 100%;
  161. padding: 16px;
  162. }
  163. .statistics-content {
  164. background: #f8f9fa;
  165. border-radius: 8px;
  166. border: 1px solid #e9ecef;
  167. padding: 16px;
  168. }
  169. .statistics-title {
  170. font-size: 14px;
  171. font-weight: 600;
  172. color: #333;
  173. margin-bottom: 12px;
  174. text-align: center;
  175. }
  176. .statistics-summary {
  177. text-align: center;
  178. color: #666;
  179. font-size: 13px;
  180. margin-bottom: 16px;
  181. padding: 8px;
  182. background: #fff;
  183. border-radius: 6px;
  184. }
  185. .statistics-chart {
  186. display: flex;
  187. flex-direction: column;
  188. gap: 12px;
  189. }
  190. .statistics-item {
  191. display: flex;
  192. align-items: center;
  193. gap: 8px;
  194. }
  195. .option-label {
  196. min-width: 40px;
  197. font-size: 12px;
  198. color: #333;
  199. font-weight: 500;
  200. }
  201. .option-bar {
  202. flex: 1;
  203. height: 8px;
  204. background: #e9ecef;
  205. border-radius: 4px;
  206. overflow: hidden;
  207. }
  208. .option-fill {
  209. height: 100%;
  210. background: linear-gradient(90deg, #1890ff, #40a9ff);
  211. border-radius: 4px;
  212. transition: width 0.3s ease;
  213. }
  214. .option-count {
  215. min-width: 35px;
  216. font-size: 11px;
  217. color: #666;
  218. text-align: right;
  219. }
  220. .statistics-empty {
  221. padding: 40px 20px;
  222. text-align: center;
  223. color: #999;
  224. font-size: 14px;
  225. }
  226. .tool45{
  227. width: 100%;
  228. height: auto;
  229. &>div{
  230. width: 100%;
  231. height: auto;
  232. margin: 10px 0;
  233. background-color: #F8F9FA;
  234. border-radius: 8px;
  235. border: 1px solid #e9ecef;
  236. box-sizing: border-box;
  237. padding: 16px;
  238. position: relative;
  239. .t45_title{
  240. width: 100%;
  241. display: flex;
  242. // align-items: center;
  243. margin-top: 5px;
  244. margin-bottom: 5px;
  245. span{
  246. font-size: 16px;
  247. color: #1890ff;
  248. }
  249. }
  250. .t45_btn{
  251. position: absolute;
  252. right: 5px;
  253. top: 3px;
  254. span{
  255. font-size: 12px;
  256. cursor: pointer;
  257. color: #409EFF;
  258. }
  259. }
  260. }
  261. .t45_list{
  262. width: 100%;
  263. height: auto;
  264. .t45_l_item{
  265. margin-top: 5px;
  266. .t45_l_i_option{
  267. display: flex;
  268. align-items: center;
  269. height: auto;
  270. width: 100%;
  271. justify-content: space-between;
  272. span{
  273. display: flex;
  274. width: 40px;
  275. &:nth-of-type(1){
  276. width: 20px;
  277. }
  278. }
  279. &>div{
  280. margin: 0 5px;
  281. width: calc(100% - 10px - 20px - 40px);
  282. height: 15px;
  283. background-color: #FFFFFF;
  284. // box-sizing: border-box;
  285. border: solid 1px #E9ECEF;
  286. border-radius: 4px;
  287. overflow: hidden;
  288. &>div{
  289. height: 100%;
  290. background-color: #3681FC;
  291. }
  292. }
  293. }
  294. .t45_l_i_user{
  295. width: 100%;
  296. height: auto;
  297. display: flex;
  298. align-items: center;
  299. flex-wrap: wrap;
  300. margin-top: 8px;
  301. margin-bottom: 8px;
  302. &>div{
  303. align-items: center;
  304. flex-wrap: wrap;
  305. height: 35px;
  306. span{
  307. width: auto;
  308. height: auto;
  309. padding: 4px 10px;
  310. background-color: #fff;
  311. border: solid 1px #2f80ed;
  312. border-radius: 6px;
  313. margin-right:8px ;
  314. margin-bottom: 5px;
  315. color: #2f80ed;
  316. }
  317. }
  318. &>span{
  319. width: auto;
  320. height: auto;
  321. padding: 4px 10px;
  322. background-color: #fff;
  323. border: solid 1px #E9ECEF;
  324. border-radius: 6px;
  325. margin-right:8px;
  326. cursor: pointer;
  327. transition: .2s;
  328. &:hover{
  329. background-color: #f1f1f1;
  330. }
  331. svg{
  332. width: 15px;
  333. height: 15px;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. .userBox{
  341. width: 100%;
  342. height: auto;
  343. .ub_item{
  344. width: 100%;
  345. height: auto;
  346. margin-bottom: 10px;
  347. border-bottom: solid 1px #D8D8D8;
  348. .ub_i_options{
  349. font-size: 20px;
  350. }
  351. .ub_i_user{
  352. display: flex;
  353. margin: 10px 0;
  354. align-items: center;
  355. flex-wrap: wrap;
  356. &>span{
  357. color: #ADADAD;
  358. }
  359. .ub_i_u_item{
  360. padding: 5px 10px;
  361. border: solid 1px #0061FF;
  362. border-radius: 4px;
  363. background-color: #fff;
  364. margin-left: 10px;
  365. margin-top: 10px;
  366. color: #0061FF;
  367. }
  368. }
  369. }
  370. }
  371. </style>