TaskList.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { ref, computed, inject, onMounted } from 'vue';
  2. import { GetMyTaskList } from '@/api/table';
  3. import { GetMyTaskList_CSItemGroup, GetMyCourseList_TaskBelong } from '@/api/list';
  4. import { GetMyBookBuyStatus_CurTaskCoursewareBook } from '@/api/user';
  5. import { Message } from 'element-ui';
  6. import { CreateEnterLiveRoomSession } from '@/api/live';
  7. import { taskModeList } from '@/store/data';
  8. import store from '@/store';
  9. const colorMatching = [
  10. {
  11. main: '#3479FF',
  12. background: 'rgba(52, 121, 255, 0.05)',
  13. border: 'rgba(52, 121, 255, 0.15)'
  14. },
  15. {
  16. main: '#754BEE',
  17. background: 'rgba(117, 75, 238, 0.05)',
  18. border: 'rgba(117, 75, 238, 0.15)'
  19. },
  20. {
  21. main: '#FF7134',
  22. background: 'rgba(255, 52, 52, 0.05)',
  23. border: 'rgba(255, 52, 52, 0.15)'
  24. },
  25. {
  26. main: '#56BD05',
  27. background: 'rgba(86, 189, 5, 0.05)',
  28. border: 'rgba(86, 189, 5, 0.15)'
  29. },
  30. {
  31. main: '#00BD84',
  32. background: 'rgba(0, 189, 132, 0.05)',
  33. border: 'rgba(0, 189, 132, 0.15)'
  34. },
  35. {
  36. main: '#DF339A',
  37. background: 'rgba(223, 51, 154, 0.05)',
  38. border: 'rgba(223, 51, 154, 0.15)'
  39. },
  40. {
  41. main: '#CF7B18',
  42. background: 'rgba(207, 123, 24, 0.05)',
  43. border: 'rgba(207, 123, 24, 0.15)'
  44. }
  45. ];
  46. export const buttonColorList = new Map([
  47. [0, '#63A1FF'],
  48. [1, '#f90'],
  49. [2, '#00CD8F']
  50. ]);
  51. /**
  52. * 任务列表
  53. * @param {ref} calendar
  54. */
  55. export function useTaskList(calendar) {
  56. let task_group_list = ref([]);
  57. const task_mode = store.state.app.config.task_mode;
  58. let course_id = ref('');
  59. let timeType = ref(-1);
  60. let time_unit = computed(() => calendar.value?.time_unit);
  61. let course_list = ref([]);
  62. function getMyTaskList() {
  63. const { curYear, curMonth, focusDate } = calendar.value;
  64. const data = {
  65. time_unit: time_unit.value,
  66. date_stamp: `${curYear}-${curMonth}-${focusDate}`,
  67. month_stamp: `${curYear}-${curMonth}`,
  68. time_type: timeType.value,
  69. course_id: course_id.value
  70. };
  71. (task_mode === taskModeList[0] ? GetMyTaskList : GetMyTaskList_CSItemGroup)(data).then(
  72. ({ task_group_list: list }) => {
  73. task_group_list.value = list;
  74. }
  75. );
  76. }
  77. function getMyCourseList_TaskBelong() {
  78. const { curYear, curMonth, focusDate } = calendar.value;
  79. GetMyCourseList_TaskBelong({
  80. time_unit: time_unit.value,
  81. date_stamp: `${curYear}-${curMonth}-${focusDate}`,
  82. month_stamp: `${curYear}-${curMonth}`
  83. }).then(({ course_list: list }) => {
  84. course_list.value = list;
  85. });
  86. }
  87. // 改变任务时间类型
  88. function changeTaskTime(time_type) {
  89. timeType.value = time_type;
  90. getMyTaskList();
  91. }
  92. function init() {
  93. course_id.value = '';
  94. getMyTaskList();
  95. getMyCourseList_TaskBelong();
  96. }
  97. onMounted(() => {
  98. init();
  99. });
  100. function changeCourse() {
  101. getMyTaskList();
  102. }
  103. return {
  104. task_group_list,
  105. task_mode,
  106. timeType,
  107. course_id,
  108. course_list,
  109. time_unit,
  110. changeTaskTime,
  111. changeCourse,
  112. init
  113. };
  114. }
  115. /**
  116. * 任务列表项相关
  117. */
  118. export function useTaskItem() {
  119. let courseIdList = ref([]); // 课程 id 列表,用于颜色显示
  120. function getItemStyle(id) {
  121. if (!courseIdList.value.includes(id)) courseIdList.value.push(id);
  122. const i = courseIdList.value.indexOf(id) % 7;
  123. return {
  124. 'background-color': colorMatching[i].background,
  125. color: colorMatching[i].main,
  126. border: `1px solid ${colorMatching[i].border}`
  127. };
  128. }
  129. function getItemIconStyle(id) {
  130. if (!courseIdList.value.includes(id)) courseIdList.value.push(id);
  131. const i = courseIdList.value.indexOf(id) % 7;
  132. return {
  133. color: colorMatching[i].main
  134. };
  135. }
  136. return { getItemStyle, getItemIconStyle };
  137. }
  138. /**
  139. * 任务链接
  140. */
  141. export function useTaskLink(router) {
  142. const $t = inject('$t');
  143. function taskLink(type, task_id) {
  144. const userType = store.state.user.user_type;
  145. GetMyBookBuyStatus_CurTaskCoursewareBook({ task_id }).then(({ is_buy_all }) => {
  146. if (is_buy_all === 'false' && userType === 'STUDENT') {
  147. return Message.warning($t('Key635'));
  148. }
  149. if (type === 10) {
  150. CreateEnterLiveRoomSession({
  151. task_id
  152. }).then(
  153. ({
  154. live_room_sys_user_id,
  155. room_id,
  156. session_id,
  157. room_user_id,
  158. is_remind_quota_lave_online,
  159. quota_lave_online
  160. }) => {
  161. if (is_remind_quota_lave_online === 'true') {
  162. Message({
  163. type: 'warning',
  164. message: `直播配额还剩余${quota_lave_online}小时`,
  165. duration: 5000
  166. });
  167. }
  168. router.push({
  169. path: `/live/${userType === 'TEACHER' ? 'teacher' : 'student'}`,
  170. query: { live_room_sys_user_id, room_id, session_id, task_id, room_user_id }
  171. });
  172. }
  173. );
  174. } else {
  175. router.push(`/task_detail/${userType === 'STUDENT' ? 'student' : 'teacher'}/${task_id}`);
  176. }
  177. });
  178. }
  179. function taskLink_outside(task_id) {
  180. GetMyBookBuyStatus_CurTaskCoursewareBook({ task_id }).then(({ is_buy_all }) => {
  181. const userType = store.state.user.user_type;
  182. if (is_buy_all === 'false' && userType === 'STUDENT') {
  183. return Message.warning($t('Key635'));
  184. }
  185. router.push(`/task_detail/${userType === 'STUDENT' ? 'student' : 'teacher'}/${task_id}`);
  186. });
  187. }
  188. return {
  189. taskLink,
  190. taskLink_outside
  191. };
  192. }
  193. /**
  194. * 得到任务类型名称
  195. * @param {Number} type
  196. * @returns String
  197. */
  198. export function getTimeTypeName(type) {
  199. if (type === 0) return 'Key292';
  200. if (type === 1) return 'Key293';
  201. if (type === 2) return 'Key294';
  202. return '';
  203. }