index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="lli-index-page">
  3. <view class="uni-margin-wrap">
  4. <swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="5000">
  5. <swiper-item v-for="item in banners" :key="item.id" @click="handleBannerSelect(item)">
  6. <image :src="item.pic"></image>
  7. </swiper-item>
  8. </swiper>
  9. </view>
  10. <view>
  11. 新闻:{{data.xinwen}}
  12. </view>
  13. <br />
  14. <view>
  15. 公告: {{data.gonggao}}
  16. </view>
  17. <br />
  18. <view>
  19. 校务: {{data.xiaowu}}
  20. </view>
  21. <view @click="getXiaowu()"> 获取校务数据 </view>
  22. </view>
  23. </template>
  24. <script setup>
  25. import {
  26. ref,
  27. reactive
  28. } from "vue";
  29. import {
  30. onLoad
  31. } from "@dcloudio/uni-app"
  32. import * as httpApi from "@/api/common.js"
  33. const banners = ref('');
  34. const data = reactive({
  35. xinwen: [],
  36. xinwenTotal: 0,
  37. gonggao: [],
  38. gonggaoTotal: 0,
  39. xiaowu: [],
  40. xiaowuTotal:0,
  41. isGonggao: true,
  42. })
  43. onLoad(() => {
  44. pageInit();
  45. })
  46. function handleBannerSelect(item) {
  47. if (item.url) {
  48. window.location.href = item.url;
  49. }
  50. }
  51. function changeGonggao() {
  52. if (this.isGonggao) {
  53. return true
  54. }
  55. data.isGonggao = true;
  56. getGonggao()
  57. }
  58. function changeXiaowu() {
  59. if (!this.isGonggao) {
  60. return true
  61. }
  62. data.isGonggao = false;
  63. getXiaowu()
  64. }
  65. function getGonggao() {
  66. httpApi.getCommonXinwenTongzhiList().then(res => {
  67. data.gonggao = res.data.data;
  68. data.gonggaoTotal = res.data.total;
  69. })
  70. }
  71. function getXiaowu() {
  72. httpApi.getCommonXinwenXiaowuList().then(res => {
  73. data.xiaowu = res.data.data;
  74. data.xiaowuTotal = res.data.total;
  75. })
  76. }
  77. function pageInit() {
  78. Promise.all([
  79. httpApi.getCommonBanners({
  80. size: 1000
  81. }),
  82. httpApi.getCommonXinwenYuanxiaoList({
  83. page: 1,
  84. size: 3
  85. }),
  86. httpApi.getCommonXinwenTongzhiList({
  87. page: 1,
  88. size: 5
  89. })
  90. ]).then(([res1, res2, res3]) => {
  91. banners.value = res1.data.data;
  92. data.xinwen = res2.data.data;
  93. data.xinwenTotal = res2.data.total;
  94. data.gonggao = res3.data.data;
  95. data.gonggaoTotal = res3.data.total;
  96. })
  97. }
  98. </script>
  99. <style lang="scss">
  100. </style>