CourseFile.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view>
  3. <uni-collapse>
  4. <uni-collapse-item v-for="dir in dataList" :title="dir.title" :name="dir.id" :open="true">
  5. <view v-for="item in dir.fileList" @click="changeFile(item)" class="file-item">
  6. {{item.title}} <span style="float: right; font-size: 12px; color: #666;">{{item.learnMin}}/{{item.needLearn}}分钟</span>
  7. <view v-if="item.unlocked">
  8. <cmd-progress :percent="percent(item)"></cmd-progress>
  9. </view>
  10. <view v-else style="color: #666; font-size: 12px; display: flex; align-items: center;">
  11. <icon type="warn" size="14" style="margin-right:5px;"/> 当前文件未解锁
  12. </view>
  13. </view>
  14. </uni-collapse-item>
  15. </uni-collapse>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'CourseFile',
  21. props: {
  22. value: Array,
  23. courseId: String,
  24. drag: Boolean,
  25. checkOn: Boolean,
  26. checkSec: Number
  27. },
  28. data() {
  29. return {
  30. current: {},
  31. dataList: []
  32. }
  33. },
  34. watch: {
  35. value: {
  36. handler(val) {
  37. this.dataList = val
  38. }
  39. }
  40. },
  41. created() {
  42. this.dataList = this.value
  43. },
  44. methods: {
  45. // 切换文件跳转
  46. changeFile(data) {
  47. // 未解锁,不允许学习
  48. if (!data.unlocked) {
  49. uni.showToast({
  50. icon:"none",
  51. title: "此课件尚未解锁,请按顺序学习!"
  52. })
  53. return
  54. }
  55. // 通用参数
  56. const params = `courseId=${this.courseId}&fileId=${data.fileId}&drag=${this.drag}&checkOn=${this.checkOn}&checkSec=${this.checkSec}`
  57. if (data.fileType === '11') {
  58. uni.navigateTo({
  59. url: `/pages/course/pdf?${params}&path=${encodeURIComponent(data.viewUrl)}`
  60. });
  61. return;
  62. }
  63. if (data.fileType === '22') {
  64. uni.navigateTo({
  65. url: `/pages/course/pdf?${params}&path=${encodeURIComponent(data.fileUrl)}`
  66. });
  67. return;
  68. }
  69. // PDF直接查看
  70. if (data.fileType === '33') {
  71. uni.navigateTo({
  72. url: `/pages/course/video?${params}&path=${encodeURIComponent(data.viewUrl)}`
  73. });
  74. return;
  75. }
  76. },
  77. // 计算进度
  78. percent(item) {
  79. if (!item.learnMin) {
  80. return 0
  81. }
  82. if (item.learnMin >= item.needLearn) {
  83. return 100
  84. }
  85. return parseInt((item.learnMin * 100 / item.needLearn))
  86. },
  87. }
  88. }
  89. </script>
  90. <style scoped>
  91. .file-item {
  92. border: #ddd 1px solid;
  93. text-align: left;
  94. padding: 10px;
  95. cursor: pointer;
  96. background: #fff;
  97. margin: 5px 0px 15px 0px;
  98. }
  99. .file-item-active {
  100. border: #1890ff 1px solid;
  101. box-sizing: border-box;
  102. color: #1890ff;
  103. font-weight: 700;
  104. }
  105. /deep/
  106. .uni-collapse-item__title-box{
  107. padding: 0px !important;
  108. }
  109. /deep/
  110. .uni-collapse-item__title-box .uni-collapse-item__title-text{
  111. font-size: 16px !important;
  112. font-weight: 700 ;
  113. color: rgb(0, 122, 255);
  114. }
  115. </style>