index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div class="invite" @scroll="handleScroll">
  3. <div class="head">
  4. <img @click="back" src="@/assets/images/back.png" class="arrow_img" />
  5. <!-- <span>{{ $t('lang219') }}</span> -->
  6. <van-tabs class="tabs" v-model="navActive" color="#29B286" title-active-color="#29B286" title-inactive-color="#080808" @change="changeTab">
  7. <van-tab v-for="(item, index) in type" :key="index" :title="item.value"></van-tab>
  8. </van-tabs>
  9. </div>
  10. <van-field v-model="key" :placeholder="$t('lang454')" class="input" left-icon="search" @click-left-icon="search" @keyup.enter="search" />
  11. <van-tabs class="child_tabs" v-model="childActive" color="#29B286" title-active-color="#29B286" title-inactive-color="#080808" @change="changeChildTab" v-if="childType.length > 0">
  12. <!-- <van-tab key="0" title="全部"></van-tab> -->
  13. <van-tab v-for="(item, index) in childType" :name="item.id" :key="index" :title="item.name"></van-tab>
  14. </van-tabs>
  15. <div v-if="list.length > 0" class="notice_box">
  16. <div class="notice" v-for="(item, index) in list" :key="index" @click="navigatorTo('bulletinDetail', item.id)">
  17. <!-- <img class="notice_img" :src="item.img_url" alt="" v-if="item.img_url" /> -->
  18. <span class="title">{{ item.title }}</span>
  19. <div class="right">
  20. <div class="tag_box">
  21. <span class="tag" v-if="childActive == 0" :style="{ color: item.sub_type_name[0]?.color, backgroundColor: hexToRgbObject(item.sub_type_name[0]?.color) }">{{
  22. item.sub_type_name[0]?.title
  23. }}</span>
  24. <span v-else>
  25. <span v-for="(it, idx) in item.sub_type_name" :key="idx">
  26. <span class="tag" v-if="it.id == childActive" :style="{ color: it.color, backgroundColor: hexToRgbObject(it.color) }">{{ it.title }}</span>
  27. </span>
  28. </span>
  29. </div>
  30. <span class="time_text">
  31. <svg t="1748345661681" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8571" width="10" height="10" v-if="item.is_top == 1">
  32. <path
  33. d="M938.8032 640.256l-378.9312-503.2448c-17.408-25.8048-55.2448-26.4192-73.8816-1.1776l-398.7456 503.2448c-21.6064 30.0032-0.6144 72.0896 36.608 72.0896h187.392v233.6256c0 35.4304 28.8256 64.8704 64.8704 64.8704h270.848c35.4304 0 64.8704-28.8256 64.8704-64.8704V711.168h189.184c36.608-0.0512 58.2144-40.9088 37.7856-70.912z m0 0"
  34. p-id="8572"
  35. fill="#29b286"
  36. ></path>
  37. <path
  38. d="M126.8736 115.4048h768.6656c28.2112 0 51.0464-22.8352 51.0464-51.0464 0-28.2112-22.8352-51.0464-51.0464-51.0464H126.8736c-28.2112 0-51.0464 22.8352-51.0464 51.0464 0.0512 28.2112 22.8352 51.0464 51.0464 51.0464z m0 0"
  39. p-id="8573"
  40. fill="#29b286"
  41. ></path>
  42. </svg>
  43. <span class="new" v-if="isToday(new Date(item.createtime * 1000))">New</span>
  44. {{ dateFormatFn(item.createtime) }}
  45. </span>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="bare" v-else>
  50. <span>{{ $t('lang60') }}</span>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { homeApi } from '@/api/index';
  56. import { dateFormat } from '@/utils/formatTool.js';
  57. export default {
  58. data() {
  59. return {
  60. list: [],
  61. page: 1,
  62. loading: false,
  63. finished: false,
  64. total: 0,
  65. finishText: this.$t('lang200'),
  66. key: '',
  67. type: [],
  68. navActive: 0,
  69. childActive: 0,
  70. childType: [],
  71. };
  72. },
  73. mounted() {
  74. this.gettype();
  75. // window.addEventListener('scroll', this.scrollBottom);
  76. },
  77. destroyed() {
  78. // window.removeEventListener('scroll', this.scrollBottom);
  79. },
  80. computed: {},
  81. methods: {
  82. isToday(date) {
  83. const today = new Date();
  84. return date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate();
  85. },
  86. hexToRgbObject(hex) {
  87. console.log(hex);
  88. if (hex) {
  89. hex = hex.replace('#', '');
  90. return `rgba(${parseInt(hex.slice(0, 2), 16)},
  91. ${parseInt(hex.slice(2, 4), 16)},
  92. ${parseInt(hex.slice(4, 6), 16)},0.2)`;
  93. }
  94. },
  95. //返回上一页
  96. back() {
  97. this.$router.back();
  98. },
  99. handleScroll(event) {
  100. const container = event.target;
  101. const scrollTop = container.scrollTop; // 滚动距离
  102. const scrollHeight = container.scrollHeight; // 内容总高度
  103. const clientHeight = container.clientHeight; // 可视区域高度
  104. // 判断是否滑动到底部
  105. if (scrollTop + clientHeight >= scrollHeight - 10) {
  106. console.log('Bottom', this.page);
  107. if (this.page != -1) {
  108. this.page++; // 页数加 1
  109. this.getAnnouncement(); // 触发加载更多
  110. }
  111. }
  112. },
  113. gettype() {
  114. homeApi.gettype().then(res => {
  115. if (res.code == 200) {
  116. this.type = res.data;
  117. // console.log(this.type);
  118. // this.navActive = this.type[0].key;
  119. this.childType = Object.entries(this.type[0].sun_type_name).map(([id, name]) => ({ id, name }));
  120. if (this.childType.length > 0) {
  121. this.childType.unshift({
  122. id: 0,
  123. name: this.$t('lang201'),
  124. });
  125. }
  126. this.getAnnouncement();
  127. }
  128. });
  129. },
  130. search() {
  131. this.page = 1;
  132. this.list = [];
  133. this.getAnnouncement();
  134. },
  135. changeTab(e, i, d) {
  136. console.log(e, i, d);
  137. this.childType = Object.entries(this.type[this.navActive].sun_type_name).map(([id, name]) => ({ id, name }));
  138. if (this.childType.length > 0) {
  139. this.childType.unshift({
  140. id: 0,
  141. name: this.$t('lang201'),
  142. });
  143. }
  144. this.childActive = 0;
  145. this.search();
  146. },
  147. changeChildTab() {
  148. this.search();
  149. },
  150. navigatorTo(name, id) {
  151. this.$router.push({ name, query: { id: id } });
  152. },
  153. dateFormatFn(date) {
  154. return dateFormat(new Date(date * 1000), 'yyyy-MM-dd hh:mm:ss');
  155. },
  156. getAnnouncement() {
  157. let params = {
  158. page: this.page,
  159. query: {},
  160. type_id: this.type[this.navActive].key,
  161. sub_type_id: this.childActive,
  162. title: this.key,
  163. };
  164. homeApi.getAnnouncement(params).then(res => {
  165. if (res.code == 200) {
  166. if (this.list.length >= res.data.total) {
  167. this.page = -1; // 重置为 -1,表示没有更多数据
  168. } else {
  169. this.list = [...this.list, ...res.data.rows];
  170. if (this.list.length >= res.data.total) {
  171. this.page = -1; // 重置为 -1,表示没有更多数据
  172. }
  173. }
  174. } else {
  175. }
  176. });
  177. },
  178. // onLoad() {
  179. // this.page += 1;
  180. // this.getAnnouncement();
  181. // },
  182. },
  183. };
  184. </script>
  185. <style lang="less" scoped>
  186. .invite {
  187. padding: 56px 0;
  188. height: 100vh;
  189. overflow: auto;
  190. background: #fff;
  191. .head {
  192. position: fixed;
  193. top: 0;
  194. width: 100%;
  195. left: 0;
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. color: rgba(#000, 0.8);
  200. letter-spacing: 1.5px;
  201. font-weight: 550;
  202. font-weight: 18px;
  203. padding: 4px 0;
  204. z-index: 99999;
  205. background: #fff;
  206. .arrow_img {
  207. position: absolute;
  208. left: 20px;
  209. width: 10px;
  210. height: 16px;
  211. z-index: 99;
  212. }
  213. .tabs {
  214. // width: 100vw;
  215. // padding: 0 50px 0 0;
  216. width: calc(100% - 90px);
  217. // padding: 0 45px;
  218. overflow: auto;
  219. display: flex;
  220. justify-content: center;
  221. }
  222. /deep/.van-tab {
  223. width: fit-content !important;
  224. flex: none;
  225. padding: 0 15px;
  226. }
  227. /deep/.van-tabs__nav {
  228. // justify-content: center !important;
  229. }
  230. /deep/.van-tab__text {
  231. // width: 100px !important;
  232. font-size: 16px;
  233. text-align: center !important;
  234. }
  235. /deep/.van-tab--active {
  236. font-weight: 550;
  237. }
  238. /deep/.van-tabs__wrap {
  239. overflow-x: auto;
  240. }
  241. // .van-tabs__wrap--scrollable .van-tab {
  242. // padding: 0;
  243. // }
  244. }
  245. /deep/.van-tabs__line {
  246. width: 20px !important;
  247. bottom: 20px !important;
  248. }
  249. .input {
  250. // height: 35px;
  251. // line-height: 35px;
  252. // border: 1px solid #29b286;
  253. width: calc(100% - 32px);
  254. margin: 0 auto;
  255. box-sizing: border-box;
  256. border-radius: 20px;
  257. background-color: #f5f5f5;
  258. ::v-deep .van-field__control {
  259. padding: 2px 0;
  260. }
  261. ::v-deep .van-icon-search {
  262. font-size: 18px;
  263. color: #a1a1a1;
  264. font-weight: bold;
  265. margin: 3px 8px;
  266. }
  267. }
  268. /deep/.van-tabs__nav--line.van-tabs__nav--complete {
  269. padding-left: 0 !important;
  270. }
  271. .child_tabs {
  272. border-bottom: 0.5px solid rgba(190, 190, 190, 0.3) !important;
  273. // ::v-deep.van-tab {
  274. // line-height: 0 !important;
  275. // }
  276. }
  277. .notice_box {
  278. padding: 16px;
  279. }
  280. .notice {
  281. position: relative;
  282. display: flex;
  283. flex-direction: column;
  284. color: #000;
  285. font-size: 14px;
  286. letter-spacing: 0.8px;
  287. padding-bottom: 10px;
  288. margin-bottom: 18px;
  289. border-bottom: 0.5px solid rgba(190, 190, 190, 0.3);
  290. // box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.59);
  291. // background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 0, rgba(255, 255, 255, 0.3) 100%, rgba(255, 255, 255, 0.3) 100%);
  292. .title {
  293. font-weight: 600;
  294. min-height: 22px;
  295. }
  296. .right {
  297. display: flex;
  298. align-items: center;
  299. justify-content: space-between;
  300. padding-top: 10px;
  301. .tag_box {
  302. display: flex;
  303. align-items: center;
  304. flex-wrap: wrap;
  305. // width: 56%;
  306. }
  307. .tag {
  308. font-size: 11px;
  309. // color: #3b98e4;
  310. padding: 1px 3px;
  311. border-radius: 4px;
  312. margin-left: 3px;
  313. margin-bottom: 3px;
  314. // background-color: rgba(#3b98e4, 0.2);
  315. }
  316. .time_text {
  317. color: #b4b4b4;
  318. font-weight: normal;
  319. font-size: 11px;
  320. margin-bottom: 3px;
  321. white-space: nowrap;
  322. }
  323. .new {
  324. color: #ec413e;
  325. letter-spacing: 0;
  326. font-weight: 600;
  327. font-size: 10px;
  328. padding: 0 4px;
  329. }
  330. }
  331. //svg {
  332. // position: absolute;
  333. // left: -13px;
  334. // top: 3px;
  335. //}
  336. }
  337. .bare {
  338. text-align: center;
  339. font-size: 14px;
  340. padding: 60px 14px;
  341. color: #888;
  342. }
  343. }
  344. </style>