liveRoomList.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="live-room" style="min-height: 100vh; overflow: hidden">
  3. <!-- 78 -->
  4. <van-sticky
  5. offset-top="0"
  6. style="height: 44px; width: 100%"
  7. :style="{ height: params.liveState != '1' ? '78px' : '44px' }"
  8. >
  9. <van-tabs
  10. v-model="params.liveState"
  11. color="#01C1B5"
  12. line-width="16px"
  13. line-height="4px"
  14. class="van-hairline--bottom"
  15. @change="onSearch"
  16. >
  17. <van-tab name="1" title="直播中"></van-tab>
  18. <van-tab name="0" title="未开始"> </van-tab>
  19. <van-tab name="2" title="已结束"> </van-tab>
  20. </van-tabs>
  21. <div
  22. v-if="params.liveState != '1'"
  23. class="titleWrap week"
  24. style="height: 22px; line-height: 22px; padding: 13px 0.28rem"
  25. @click="showCalendar = true"
  26. >
  27. <!-- <div class="calendar">
  28. <div>{{ params.startTime }}~{{ params.endTime }}</div>
  29. </div> -->
  30. <van-row style="color: #01c1b5">
  31. <van-col span="10" class="flex">
  32. <img
  33. src="./images/icon_calendar.png"
  34. style="width: 14px; height: 14px; margin-right: 8px"
  35. />
  36. {{ params.startTime }}</van-col
  37. >
  38. <van-col span="4" class="flex" style="height: 22px">
  39. <span class="calendar-line"></span>
  40. </van-col>
  41. <van-col span="10" class="flex">
  42. <img
  43. src="./images/icon_calendar.png"
  44. style="width: 14px; height: 14px; margin-right: 8px"
  45. />
  46. {{ params.endTime }}
  47. </van-col>
  48. </van-row>
  49. </div>
  50. </van-sticky>
  51. <van-calendar
  52. v-model="showCalendar"
  53. :minDate="minDate"
  54. color="#01C1B5"
  55. :default-date="[
  56. dayjs(params.startTime).toDate(),
  57. dayjs(params.endTime).toDate(),
  58. ]"
  59. type="range"
  60. @confirm="onConfirm"
  61. :first-day-of-week="1"
  62. get-container="body"
  63. />
  64. <van-list
  65. v-model="loading"
  66. v-if="dataShow"
  67. style="margin-top: 0.15rem"
  68. key="ing"
  69. :finished="finished"
  70. finished-text=" "
  71. :immediate-check="false"
  72. @load="getList()"
  73. >
  74. <div v-for="(item, index) in dataList" :key="index">
  75. <live-room :item="item" />
  76. </div>
  77. </van-list>
  78. <m-empty v-else msg="暂无数据" />
  79. </div>
  80. </template>
  81. <script>
  82. import liveRoom from "./model/liveRoom";
  83. import MEmpty from "@/components/MEmpty";
  84. import { queryPageStudent } from "./api";
  85. import dayjs from "dayjs";
  86. const startTime = dayjs().startOf("month").format("YYYY-MM-DD");
  87. const endTime = dayjs().endOf("month").format("YYYY-MM-DD");
  88. export default {
  89. components: { liveRoom, MEmpty },
  90. data() {
  91. const query = this.$route.query;
  92. const s = sessionStorage.getItem("liveRoomListTab");
  93. return {
  94. minDate: new Date(2000, 0, 1),
  95. showCalendar: false,
  96. dataList: [],
  97. dataLoading: false,
  98. dataShow: true,
  99. loading: false,
  100. finished: false,
  101. params: {
  102. endTime: endTime,
  103. startTime: startTime,
  104. page: 1,
  105. rows: 20,
  106. liveState: query.t == 0 ? "0" : s || "1",
  107. },
  108. hiddenProperty: null,
  109. pageStatusTimer: null, // 页面判断
  110. };
  111. },
  112. mounted() {
  113. this.hiddenProperty =
  114. "hidden" in document
  115. ? "hidden"
  116. : "webkitHidden" in document
  117. ? "webkitHidden"
  118. : "mozHidden" in document
  119. ? "mozHidden"
  120. : null;
  121. this.visibilityChangeEvent = this.hiddenProperty.replace(
  122. /hidden/i,
  123. "visibilitychange"
  124. );
  125. document.addEventListener(
  126. this.visibilityChangeEvent,
  127. this.onVisibilityChange
  128. );
  129. document.title = "直播间";
  130. this.getList();
  131. },
  132. methods: {
  133. dayjs,
  134. onVisibilityChange() {
  135. // console.log("onVisibilityChange", document[this.hiddenProperty]);
  136. // console.log("hidden", document.hidden);
  137. // console.log("visibilityState", document.visibilityState);
  138. if (!document[this.hiddenProperty]) {
  139. clearInterval(this.pageStatusTimer);
  140. this.onSearch();
  141. } else {
  142. this.pageStatusTimer = setInterval(() => {
  143. if (!document[this.hiddenProperty]) {
  144. clearInterval(this.pageStatusTimer);
  145. this.onSearch();
  146. }
  147. }, 1000);
  148. }
  149. },
  150. onConfirm(date) {
  151. let [start, end] = date;
  152. this.params.startTime = dayjs(start).format("YYYY-MM-DD");
  153. this.params.endTime = dayjs(end).format("YYYY-MM-DD");
  154. this.showCalendar = false;
  155. this.onSearch();
  156. },
  157. onSearch() {
  158. sessionStorage.setItem("liveRoomListTab", this.params.liveState);
  159. this.dateShow = true;
  160. this.loading = false;
  161. this.finished = false;
  162. this.params.page = 1;
  163. this.dataList = [];
  164. this.getList();
  165. },
  166. async getList() {
  167. try {
  168. if (this.dataLoading) return;
  169. this.dataLoading = true;
  170. const { startTime, endTime, ...more } = this.params;
  171. const tempParams = {
  172. ...more,
  173. };
  174. if (this.params.liveState != "1") {
  175. tempParams.startTime = startTime;
  176. tempParams.endTime = endTime;
  177. }
  178. const res = await queryPageStudent(tempParams);
  179. this.dataLoading = false;
  180. let result = res.data;
  181. this.loading = false;
  182. // 如果列表有值且,在请求在第一页时
  183. if (this.dataList.length > 0 && result.pageNo == 1) {
  184. return;
  185. }
  186. this.dataList.push(...(result.rows || []));
  187. if (this.params.page >= Math.ceil(result.total / this.params.rows)) {
  188. this.finished = true;
  189. }
  190. this.params.page++;
  191. if (this.dataList.length <= 0) {
  192. this.dataShow = false;
  193. } else {
  194. this.dataShow = true;
  195. }
  196. } catch {
  197. //
  198. }
  199. },
  200. },
  201. beforeDestroy() {
  202. clearInterval(this.pageStatusTimer);
  203. document.removeEventListener(
  204. this.visibilityChangeEvent,
  205. this.onVisibilityChange
  206. );
  207. },
  208. };
  209. </script>
  210. <style lang="less" scoped>
  211. .live-room {
  212. /deep/.van-tabs__nav {
  213. background-color: #fff !important;
  214. }
  215. /deep/.van-tabs__wrap {
  216. // border-bottom: 1px solid #ccc;
  217. }
  218. /deep/.van-tab {
  219. font-size: 0.16rem;
  220. }
  221. /deep/.van-sticky {
  222. height: inherit !important;
  223. position: fixed;
  224. width: 100%;
  225. }
  226. /deep/.van-button--small {
  227. height: 28px;
  228. }
  229. }
  230. .titleWrap.week {
  231. background: #fff;
  232. justify-content: space-between;
  233. .calendar {
  234. font-size: 0.14rem;
  235. position: relative;
  236. &::after {
  237. right: -0.14rem;
  238. }
  239. }
  240. // div {
  241. // display: inline-flex;
  242. // flex-direction: row;
  243. // align-items: center;
  244. // font-size: 0.14rem;
  245. // }
  246. .active {
  247. color: #01c1b5;
  248. }
  249. }
  250. .flex {
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. }
  255. .calendar-line {
  256. display: inline-block;
  257. width: 25px;
  258. height: 2px;
  259. background: #d8d8d8;
  260. }
  261. .active.calendar::after {
  262. transform: rotate(-225deg) !important;
  263. margin-top: -2px;
  264. }
  265. .calendar::after {
  266. position: absolute;
  267. top: 50%;
  268. right: -4px;
  269. margin-top: -6px;
  270. border: 4px solid;
  271. border-top-color: transparent;
  272. border-top-style: solid;
  273. border-top-width: 4px;
  274. border-right-color: transparent;
  275. border-right-style: solid;
  276. border-right-width: 4px;
  277. border-bottom-color: #01c1b5;
  278. border-bottom-style: solid;
  279. border-bottom-width: 4px;
  280. border-left-color: #01c1b5;
  281. border-left-style: solid;
  282. border-left-width: 4px;
  283. border-image-source: initial;
  284. border-image-slice: initial;
  285. border-image-width: initial;
  286. border-image-outset: initial;
  287. border-image-repeat: initial;
  288. border-color: transparent transparent #01c1b5 #01c1b5;
  289. border-top-color: transparent;
  290. border-right-color: transparent;
  291. border-bottom-color: #01c1b5;
  292. border-left-color: #01c1b5;
  293. -webkit-transform: rotate(-45deg);
  294. transform: rotate(-45deg);
  295. opacity: 0.8;
  296. content: "";
  297. }
  298. </style>