CompleteList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <el-dialog
  3. :class="['complete-list', { 'align-left': !isAlignCenter }]"
  4. :visible="dialogVisibleComplete"
  5. :width="dialogWidth + 'px'"
  6. :modal="false"
  7. :close-on-click-modal="false"
  8. @close="dialogCompleteClose"
  9. >
  10. <div slot="title" class="dialog-header">
  11. <span class="dialog-header-title">
  12. {{ $t('Key274') }} - {{ material_type === 'COURSEWARE' ? $t('Key309') : $t('Key244') }} - {{ material_name }}
  13. </span>
  14. <span @click="isAlignCenter = !isAlignCenter">
  15. <svg-icon :icon-class="isAlignCenter ? 'align-left' : 'align-center'" />
  16. </span>
  17. </div>
  18. <div class="complete-list-top">
  19. <div class="student-list">
  20. <i class="el-icon-arrow-left" @click="listMove('left')" />
  21. <div ref="avatar" class="avatar-list">
  22. <div ref="list" class="avatar-list-wrapper" :style="{ 'margin-left': marginLeft + 'px' }">
  23. <span
  24. v-for="item in student_list"
  25. :key="item.student_id"
  26. :class="{ active: curStudentID === item.student_id }"
  27. >
  28. <el-avatar
  29. icon="el-icon-user"
  30. :src="item.student_image_url"
  31. @click.native="getStudentExamAnswer_FinishMaterial(item.student_id, item.student_name)"
  32. />
  33. </span>
  34. </div>
  35. </div>
  36. <i class="el-icon-arrow-right" @click="listMove('right')" />
  37. </div>
  38. <div v-show="isStudent" class="answer-info">
  39. <span class="current-student-name">{{ curStudentName }}:</span>
  40. <template v-if="material_type === 'COURSEWARE'">
  41. <span>{{ $t('Key320') }}</span>
  42. <span class="answer-info-duration">{{ duration }}{{ $t('Key321') }}</span>
  43. <span class="answer-info-label">{{ $t('Key194') }}</span>
  44. <span class="answer-info-count-right">{{ count_right }}</span>
  45. <span class="answer-info-label">{{ $t('Key195') }}</span>
  46. <span class="answer-info-count-error">{{ count_error }}</span>
  47. </template>
  48. </div>
  49. </div>
  50. <div class="complete-list-container">
  51. <template v-if="material_type === 'COURSEWARE'">
  52. <template v-if="category === 'OC' || category.length === 0">
  53. <bookreport
  54. v-if="isStudent"
  55. :context="context"
  56. :book-client-width="800"
  57. :book-answer-content="bookAnswerContent"
  58. />
  59. <bookquestion v-else :context="context" />
  60. </template>
  61. <template v-else-if="category === 'AILP'">
  62. <bookailp :context="context" :ui-type="ui_type" :preview-width="800" :preview-height="450" />
  63. </template>
  64. <template v-else-if="category === 'NPC'">
  65. <booknpc v-if="context" ref="previewAnswer" :theme-color="themeColor" :context="context" />
  66. </template>
  67. <template v-if="category == 'NNPE'">
  68. <booknnpe v-if="context" :context="context" :theme-color="themeColor" />
  69. </template>
  70. </template>
  71. <template v-else>
  72. <!-- pdf -->
  73. <template v-if="fileType === 'pdf'">
  74. <pdf v-for="i in numPages" :key="i" :src="pdfSrc" :page="i" />
  75. </template>
  76. <template v-else-if="isImage(fileType)">
  77. <el-image fit="contain" :src="file_url_https" />
  78. </template>
  79. <div v-else-if="fileType === 'mp3'" class="audio-file">
  80. <audio :src="file_url_https" controls />
  81. </div>
  82. <div v-else-if="fileType === 'mp4'" class="video-file">
  83. <video :src="file_url_https" controls />
  84. </div>
  85. <div v-else-if="fileType === 'txt'" class="text-file">
  86. <el-input v-model="text" type="textarea" :readonly="true" resize="none" />
  87. </div>
  88. <template v-else-if="fileType !== 'pdf'">
  89. <iframe
  90. :src="'https://view.officeapps.live.com/op/view.aspx?src=' + `${file_url_https}`"
  91. width="100%"
  92. height="490px"
  93. scrolling="no"
  94. />
  95. </template>
  96. </template>
  97. </div>
  98. <div slot="footer" />
  99. </el-dialog>
  100. </template>
  101. <script>
  102. import pdf from 'vue-pdf';
  103. import { GetCurMaterialSent, GetStudentList_FinishMaterial, GetStudentExamAnswer_FinishMaterial } from '@/api/live';
  104. import { GetCoursewareContent_View, GetMaterialInfo } from '@/api/course';
  105. import { GetFileStoreInfo, getContentFile } from '@/api/app';
  106. export default {
  107. components: {
  108. pdf
  109. },
  110. props: {
  111. dialogVisibleComplete: {
  112. default: false,
  113. type: Boolean
  114. },
  115. taskId: {
  116. default: '',
  117. type: String
  118. },
  119. materialId: {
  120. default: '',
  121. type: String
  122. },
  123. materialType: {
  124. default: '',
  125. type: String
  126. }
  127. },
  128. data() {
  129. return {
  130. material_id: '',
  131. material_name: '',
  132. material_type: '',
  133. material_picture_url: '',
  134. context: null,
  135. ui_type: '',
  136. category: '',
  137. themeColor: '',
  138. dialogWidth: '900',
  139. bookAnswerContent: '',
  140. duration: 0,
  141. count_not_done: 0,
  142. count_right: 0,
  143. count_error: 0,
  144. file_relative_path: '',
  145. file_url_https: '',
  146. pdfSrc: '',
  147. numPages: 1,
  148. student_list: [],
  149. curStudentID: '',
  150. curStudentName: '',
  151. listTimer: null,
  152. marginLeft: 0,
  153. isAlignCenter: true,
  154. text: ''
  155. };
  156. },
  157. computed: {
  158. fileType() {
  159. return this.file_url_https.slice(this.file_url_https.lastIndexOf('.') + 1, this.file_url_https.length);
  160. },
  161. isStudent() {
  162. return this.curStudentID.length > 0;
  163. }
  164. },
  165. watch: {
  166. dialogVisibleComplete(newVal) {
  167. if (newVal && this.materialId.length === 0) {
  168. this.getCurMaterialSent();
  169. }
  170. if (newVal && this.materialId.length > 0) {
  171. this.getMaterialInfo();
  172. }
  173. // 对话框,关闭时清理
  174. if (!newVal) {
  175. clearInterval(this.listTimer);
  176. this.material_id = '';
  177. this.material_name = '';
  178. this.student_list = [];
  179. this.marginLeft = 0;
  180. this.context = null;
  181. this.curStudentID = '';
  182. this.bookAnswerContent = '';
  183. this.text = '';
  184. }
  185. },
  186. material_id(newVal) {
  187. if (newVal) {
  188. this.listTimer = setInterval(() => {
  189. this.getStudentList_FinishMaterial();
  190. }, 3000);
  191. if (this.material_type === 'COURSEWARE') {
  192. this.getCoursewareContent_View();
  193. } else {
  194. this.getFileStoreInfo();
  195. }
  196. }
  197. }
  198. },
  199. created() {
  200. this.updateWordPack({
  201. word_key_list: ['Key274', 'Key309', 'Key244', 'Key320', 'Key321', 'Key194', 'Key195']
  202. });
  203. },
  204. methods: {
  205. getCurMaterialSent() {
  206. GetCurMaterialSent({ task_id: this.taskId }).then(
  207. ({ material_id, material_name, material_type, material_picture_url }) => {
  208. if (material_id !== undefined && material_id.length > 0) {
  209. this.material_id = material_id;
  210. this.material_name = material_name;
  211. this.material_type = material_type;
  212. this.material_picture_url = material_picture_url;
  213. }
  214. }
  215. );
  216. },
  217. getMaterialInfo() {
  218. GetMaterialInfo({ task_id: this.taskId, material_id: this.materialId, material_type: this.materialType }).then(
  219. ({ material_id, material_name, material_type }) => {
  220. this.material_id = material_id;
  221. this.material_name = material_name;
  222. this.material_type = material_type;
  223. }
  224. );
  225. },
  226. getStudentList_FinishMaterial() {
  227. GetStudentList_FinishMaterial({
  228. task_id: this.taskId,
  229. material_id: this.material_id,
  230. material_type: this.material_type
  231. })
  232. .then(({ student_list }) => {
  233. this.student_list = student_list;
  234. })
  235. .catch(() => {
  236. clearInterval(this.listTimer);
  237. });
  238. },
  239. getCoursewareContent_View() {
  240. GetCoursewareContent_View({ id: this.material_id }).then(({ content, category, book_theme_color }) => {
  241. if (!content) {
  242. this.context = null;
  243. return;
  244. }
  245. this.category = category;
  246. if (category === 'OC' || category.length === 0) {
  247. this.dialogWidth = '900';
  248. this.context = {
  249. id: this.material_id,
  250. ui_type: JSON.parse(content).question.ui_type,
  251. content: JSON.parse(content)
  252. };
  253. return;
  254. }
  255. if (category === 'AILP') {
  256. this.dialogWidth = '900';
  257. const contents = JSON.parse(content);
  258. if (contents.question && contents.question.length > 0) {
  259. this.context = JSON.parse(contents.question);
  260. this.ui_type = contents.ui_type ? contents.ui_type : '';
  261. }
  262. return;
  263. }
  264. if (category === 'NPC') {
  265. this.themeColor = book_theme_color;
  266. this.dialogWidth = '920';
  267. this.context = JSON.parse(content);
  268. return;
  269. }
  270. if (category === 'NNPE') {
  271. this.dialogWidth = '920';
  272. this.themeColor = book_theme_color;
  273. this.context = JSON.parse(content);
  274. }
  275. });
  276. },
  277. getFileStoreInfo() {
  278. GetFileStoreInfo({ file_id: this.material_id }).then(({ file_relative_path, file_url_https }) => {
  279. this.file_relative_path = file_relative_path;
  280. this.file_url_https = file_url_https;
  281. let fileType = file_url_https.slice(file_url_https.lastIndexOf('.') + 1, file_url_https.length);
  282. if (fileType === 'pdf') {
  283. this.getNumPages(file_relative_path);
  284. }
  285. if (fileType === 'txt') {
  286. fetch(`${process.env.VUE_APP_PDF}${file_relative_path}`).then(async res => {
  287. if (!res.ok) return;
  288. this.text = await res.text();
  289. });
  290. }
  291. });
  292. },
  293. getNumPages(url) {
  294. let loadingTask = pdf.createLoadingTask(`${process.env.VUE_APP_PDF}${url}`);
  295. loadingTask.promise
  296. .then(pdf => {
  297. this.pdfSrc = loadingTask;
  298. this.numPages = pdf.numPages;
  299. })
  300. .catch(err => {
  301. console.error('pdf加载失败', err);
  302. });
  303. },
  304. dialogCompleteClose() {
  305. this.$emit('dialogCompleteClose');
  306. },
  307. isImage(type) {
  308. return ['jpeg', 'gif', 'jpg', 'png', 'bmp', 'pic', 'svg'].includes(type);
  309. },
  310. // 下载文件zip
  311. downloadBookWriteParent(idList) {
  312. getContentFile('file_store_manager-StartCreateFileCompressPack', {
  313. file_id_list: JSON.parse(idList)
  314. }).then(res => {
  315. let id = res.file_compress_task_id;
  316. this.bookDownTimer = setInterval(() => {
  317. this.checkTaskProgress(id);
  318. }, 2000);
  319. });
  320. },
  321. listMove(direction) {
  322. let w = this.$refs.list.clientWidth - this.$refs.avatar.clientWidth;
  323. if (w > 60) {
  324. let left = Number(this.$refs.list.style['margin-left'].slice(0, -2));
  325. let width = direction === 'right' ? left - 60 : left + 60;
  326. if (Math.abs(width) > w) width = -w;
  327. this.marginLeft = width > 0 ? 0 : width;
  328. }
  329. },
  330. getStudentExamAnswer_FinishMaterial(student_id, student_name) {
  331. GetStudentExamAnswer_FinishMaterial({
  332. task_id: this.taskId,
  333. material_id: this.material_id,
  334. material_type: this.material_type,
  335. student_id
  336. }).then(({ content, duration, count_not_done, count_right, count_error }) => {
  337. this.bookAnswerContent = content;
  338. this.duration = duration;
  339. this.count_not_done = count_not_done;
  340. this.count_right = count_right;
  341. this.count_error = count_error;
  342. this.curStudentID = '';
  343. this.$nextTick(() => {
  344. this.curStudentID = student_id;
  345. });
  346. this.curStudentName = student_name;
  347. });
  348. }
  349. }
  350. };
  351. </script>
  352. <style lang="scss">
  353. @import '~@/styles/mixin';
  354. .complete-list {
  355. @include dialog;
  356. &.align-left {
  357. .el-dialog {
  358. margin-left: 20px;
  359. }
  360. }
  361. .el-dialog__header {
  362. .dialog-header {
  363. display: flex;
  364. justify-content: space-between;
  365. padding-right: 24px;
  366. &-title {
  367. font-size: 18px;
  368. font-weight: bold;
  369. line-height: 24px;
  370. }
  371. .svg-icon {
  372. cursor: pointer;
  373. }
  374. }
  375. }
  376. &-top {
  377. .student-list {
  378. display: flex;
  379. align-items: center;
  380. justify-content: space-between;
  381. height: 66px;
  382. margin-bottom: 12px;
  383. overflow: hidden;
  384. .avatar-list {
  385. width: calc(100% - 48px);
  386. height: 100%;
  387. overflow: hidden;
  388. &-wrapper {
  389. display: inline-block;
  390. white-space: nowrap;
  391. .active {
  392. position: relative;
  393. display: inline-block;
  394. width: 58px;
  395. &::after {
  396. position: absolute;
  397. top: 58px;
  398. left: 24px;
  399. display: inline-block;
  400. width: 8px;
  401. height: 8px;
  402. content: '';
  403. background-color: #2ece5b;
  404. border-radius: 50%;
  405. }
  406. }
  407. .el-avatar {
  408. margin: 0 9px;
  409. cursor: pointer;
  410. }
  411. }
  412. }
  413. > i {
  414. margin-top: -24px;
  415. font-size: 18px;
  416. cursor: pointer;
  417. }
  418. }
  419. .answer-info {
  420. display: flex;
  421. align-items: center;
  422. margin-bottom: 12px;
  423. font-size: 16px;
  424. .current-student-name {
  425. margin-right: 24px;
  426. font-weight: 700;
  427. }
  428. &-label {
  429. margin-left: 24px;
  430. }
  431. &-duration,
  432. &-count-right,
  433. &-count-error {
  434. min-width: 60px;
  435. padding: 0 24px;
  436. text-align: center;
  437. border-right: 2px solid #dfdfdf;
  438. }
  439. &-count-error {
  440. border-right-width: 0;
  441. }
  442. }
  443. }
  444. &-container {
  445. max-height: calc(55vh - 117px);
  446. overflow: auto;
  447. .el-image {
  448. width: 100%;
  449. height: calc(100% - 4px);
  450. }
  451. .audio-file {
  452. display: flex;
  453. justify-content: center;
  454. }
  455. .video-file {
  456. display: flex;
  457. justify-content: center;
  458. height: 100%;
  459. }
  460. .text-file {
  461. height: calc(55vh - 117px);
  462. .el-textarea,
  463. textarea {
  464. height: 100%;
  465. }
  466. }
  467. }
  468. }
  469. </style>