HomePage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="home-page">
  3. <el-carousel trigger="click" :autoplay="false" style="margin-top: 30px;">
  4. <el-carousel-item v-for="(item, index) in carousel" :key="index">
  5. <div class="carousel-box" @click="openBanner(item)">
  6. <img :src="item.img" alt="" />
  7. <!-- <div class="title-box">
  8. <p>{{ item.title }}</p>
  9. <p>{{ item.subtitle }}</p>
  10. </div> -->
  11. </div>
  12. </el-carousel-item>
  13. </el-carousel>
  14. <div class="act-list-box">
  15. <div style="margin-top: 20px; display: flex; justify-content: space-between;">
  16. <el-radio-group v-model="actType">
  17. <el-radio-button value="all">{{ $t('home.actType.all') }}</el-radio-button>
  18. <!-- <el-radio-button label="notStart">未开始</el-radio-button> -->
  19. <el-radio-button value="going">{{ $t('home.actType.going') }}</el-radio-button>
  20. <el-radio-button value="finish">{{ $t('home.actType.finish') }}</el-radio-button>
  21. </el-radio-group>
  22. <el-input v-model="searchWord" clearable :placeholder="$t('placeholderlist.searchActName')" style="width: 200px;">
  23. <template #append>
  24. <el-button :icon="Search" @click="searchWords(lessonList)" />
  25. </template>
  26. </el-input>
  27. </div>
  28. <div class="act-list" v-if="lessonListShow.length">
  29. <div v-for="(item, index) in lessonListShow" :key="index" class="lesson-info" @click="openInfo(item)">
  30. <div class="img-box">
  31. <img :src="item.posterShow" alt="">
  32. </div>
  33. <div class="info-box">
  34. <div class="lesson-name">
  35. <p class="type-box" :style="{'background-color': item.scope === 'area' ? '#ff9900' : (item.scope === 'school' ? '#19be43' : '#a8a8a8')}">
  36. {{ item.scope === 'public' ? $t('home.scope.public') : (item.scope === 'area' ? $t('home.scope.area') : $t('home.scope.school')) }}
  37. </p>
  38. <p>{{ item.name }}</p>
  39. </div>
  40. <p class="info-title">
  41. <span>{{ $t('home.actInfo.time') }}</span>:
  42. <span>{{ $tools.formatTime(item.stime, 'yyyy-MM-dd') }}</span> - <span>{{ $tools.formatTime(item.etime, 'yyyy-MM-dd') }}</span>
  43. </p>
  44. <p class="info-title">
  45. <span>{{ $t('home.actInfo.profile') }}</span>
  46. :{{ item.description || '-' }}
  47. </p>
  48. <p class="info-title">
  49. <span>{{ $t('home.actInfo.place') }}</span>
  50. :{{ item.address || '-' }}
  51. </p>
  52. <p class="info-title">
  53. <span>{{ $t('home.actInfo.host') }}</span>:
  54. <span v-for="(zb, zIndex) in item.zb" :key="zIndex">{{ zb || '-' }}</span>
  55. </p>
  56. </div>
  57. <div :class="['lesson-type', item.publish === 1 ? 'going' : 'end']">
  58. {{ item.publish === 1 ? $t('home.actType.going') : item.publish === 2 ? $t('home.actType.finish') : '' }}
  59. </div>
  60. </div>
  61. </div>
  62. <el-empty v-else :description="$t('elMessage.noAct')" :image-size="300" />
  63. <!-- <div class="act-list" v-else style="justify-content: center; font-size: 20px; margin: 40px 0;">
  64. 暂无活动
  65. </div> -->
  66. </div>
  67. </div>
  68. </template>
  69. <script setup>
  70. import { Search } from '@element-plus/icons-vue'
  71. import { getCurrentInstance, onMounted, reactive, ref, toRaw, watch } from "vue"
  72. import { useRouter } from "vue-router"
  73. // import { useStore } from "vuex"
  74. import { useStore } from "@/pinia/common"
  75. import { ElLoading } from "element-plus"
  76. const router = useRouter()
  77. let store = useStore()
  78. let { proxy } = getCurrentInstance()
  79. let actType = ref('all')
  80. let searchWord = ref('')
  81. let carousel = ref([])
  82. let lessonList = ref([])
  83. let lessonListShow = ref([])
  84. onMounted(() => {
  85. let banners = store.website.banners
  86. banners.forEach(item => {
  87. if(item.source === 'upload') {
  88. item.img = store.website.url + item.blob + '?' + store.website.sas
  89. } else if(item.source === 'activity') {
  90. item.img = store.website.url + item.blob + '?' + store.website.sas
  91. }
  92. carousel.value.push(item)
  93. })
  94. if(!carousel.value.length) {
  95. carousel.value.push({
  96. img: require('@/assets/img/no-poster-cn.jpg'),
  97. title: '醍摩豆',
  98. subtitle: ''
  99. })
  100. }
  101. getActList()
  102. })
  103. function openInfo(info) {
  104. router.push({
  105. name: 'activityInfo',
  106. params: {
  107. info: info.id
  108. }
  109. })
  110. }
  111. function getActList() {
  112. /* const loading = ElLoading.service({
  113. lock: true,
  114. text: '加载中',
  115. background: 'rgba(0, 0, 0, 0.7)'
  116. }) */
  117. let areaRoute = window.location.pathname.split('/')
  118. let params = {
  119. route: areaRoute[1]
  120. }
  121. proxy.$api.getActivityList(params).then(res => {
  122. if(res.activities) {
  123. res.activities.forEach(item => {
  124. item.posterShow = !item.poster ? require('@/assets/img/no-poster-cn.jpg') : item.url + item.poster + '?' + item.sas
  125. lessonList.value.push(item)
  126. })
  127. lessonList.value = lessonList.value.sort((a, b) => b.createTime - a.createTime)
  128. lessonListShow.value = lessonList.value
  129. }
  130. }).finally(() => {
  131. // loading.close()
  132. })
  133. }
  134. function openBanner(data) {
  135. if(data.source === 'activity') {
  136. router.push({
  137. name: 'activityInfo',
  138. params: {
  139. info: data.url
  140. }
  141. })
  142. } else {
  143. window.open(data.url)
  144. }
  145. }
  146. function searchWords() {
  147. if(actType.value != 'all') {
  148. lessonListShow.value = lessonList.value.filter(item => actType.value === 'going' ? item.publish === 1 : item.publish === 2)
  149. } else {
  150. lessonListShow.value = lessonList.value
  151. }
  152. lessonListShow.value = lessonListShow.value.filter(item => item.name.includes(searchWord.value))
  153. }
  154. watch(actType, ((newValue, oldValue) => {
  155. searchWords()
  156. }))
  157. </script>
  158. <style lang="less" scoped>
  159. .home-page {
  160. padding: 0 13%;
  161. // padding-top: 20px;
  162. height: 100%;
  163. background: linear-gradient(0deg, #c3d9e9, transparent);
  164. overflow: auto;
  165. .carousel-box {
  166. width: 100%;
  167. height: 100%;
  168. position: relative;
  169. display: flex;
  170. align-items: center;
  171. .title-box {
  172. position: absolute;
  173. bottom: 4%;
  174. left: 5%;
  175. &>p:first-child {
  176. font-size: 20px;
  177. font-weight: bold;
  178. margin-bottom: 10px;
  179. }
  180. }
  181. }
  182. .act-list-box {
  183. margin: 20px 0;
  184. background: #fff;
  185. border-radius: 10px;
  186. padding: 10px 20px;
  187. .act-list {
  188. margin: 20px 0;
  189. display: flex;
  190. flex-wrap: wrap;
  191. width: 100%;
  192. .lesson-info {
  193. width: 30%;
  194. margin-right: 30px;
  195. margin-bottom: 20px;
  196. position: relative;
  197. cursor: pointer;
  198. border-radius: 5px;
  199. background-color: #edf3f7;
  200. &:hover {
  201. box-shadow: 0 26px 40px -24px rgba(0, 36, 100, .3);
  202. -webkit-transform: translateY(-6px);
  203. transform: translateY(-6px);
  204. -webkit-transition: all .3s ease 0s;
  205. transition: all .3s ease 0s;
  206. }
  207. .img-box {
  208. max-width: 95%;
  209. /* border-top-left-radius: 5px;
  210. border-top-right-radius: 5px; */
  211. margin: 10px;
  212. height: 142px;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. img {
  217. width: auto;
  218. max-width: 100%;
  219. max-height: 100%;
  220. border-radius: 5px;
  221. }
  222. }
  223. .info-box {
  224. height: 150px;
  225. // border: 1px solid #ccc;
  226. padding: 20px 15px;
  227. padding-top: 10px;
  228. color: #ccc;
  229. line-height: 18px;
  230. border-bottom-left-radius: 5px;
  231. border-bottom-right-radius: 5px;
  232. // background-color: #F2F7FC;
  233. .lesson-name {
  234. margin-bottom: 15px;
  235. color: #000;
  236. font-size: 17px;
  237. display: flex;
  238. align-items: center;
  239. &>p:nth-child(2) {
  240. text-align: center;
  241. overflow: hidden;
  242. text-overflow: ellipsis;
  243. white-space: nowrap;
  244. }
  245. .type-box {
  246. background-color: #FF9900;
  247. font-size: 12px;
  248. font-weight: normal;
  249. color: #fff;
  250. padding: 3px 5px;
  251. border-radius: 5px;
  252. margin-right: 5px;
  253. min-width: 25px;
  254. }
  255. }
  256. .info-title {
  257. font-size: 14px;
  258. margin-bottom: 7px;
  259. color: #6a6a6a;
  260. /* &>span {
  261. color: #1B2773;
  262. } */
  263. }
  264. }
  265. .lesson-type {
  266. position: absolute;
  267. top: 10px;
  268. right: 10px;
  269. height: 20px;
  270. line-height: 20px;
  271. font-size: 14px;
  272. text-align: center;
  273. padding: 2px 10px;
  274. border-top-right-radius: 5px;
  275. border-bottom-left-radius: 5px;
  276. }
  277. .going {
  278. background-color: rgb(8, 153, 8);
  279. color: #fff;
  280. }
  281. .end {
  282. background-color: #ccc;
  283. color: #3f3f3f;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. </style>
  290. <style lang="less">
  291. .home-page {
  292. .el-carousel__container {
  293. height: 500px;
  294. }
  295. .el-carousel__item {
  296. img{
  297. max-width: 100%;
  298. max-height: 100%;
  299. display: block;
  300. cursor: pointer;
  301. border-radius: 10px;
  302. margin: auto;
  303. }
  304. }
  305. }
  306. </style>