123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <template>
- <view class="main">
- <view class="one">
- <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
- indicator-active-color="#ffffff" :autoplay="false" :interval="3000" :duration="1000">
- <swiper-item class="list" v-for="(item,index) in imgList" :key="index">
- <image class="image"
- v-if="item.url.indexOf('gif') != -1 || item.url.indexOf('jpg') != -1 || item.url.indexOf('png') != -1 || item.url.indexOf('jpeg') !=-1"
- :src="item.url" mode=""></image>
- <video class="image" :autoplay='false' :show-fullscreen-btn="false" :loop="false" controls v-else
- :src="item.url"></video>
- </swiper-item>
- </swiper>
- </view>
- <view class="bottom">
- <view class="two">
- <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
- indicator-active-color="#007AFF" :autoplay="false">
- <swiper-item class="swiper-item" v-for="(item,index) in moduleList" :key="index">
- <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
- <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
- </image>
- <text class="text">{{ as.name }}</text>
- </view>
- </swiper-item>
- </swiper>
- </view>
- <view class="thr">
- <uni-notice-bar speed='50' showGetMore='true' moreText='更多' @getmore="toMore" show-icon scrollable
- :text="content" />
- </view>
- <view class="four" v-if="advertList.length>0">
- <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
- indicator-active-color="#007AFF" :autoplay="false">
- <swiper-item class="swiper-item" v-for="(item,index) in advertList" :key="index">
- <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
- <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
- </image>
- <text class="text">{{ as.name }}</text>
- </view>
- </swiper-item>
- </swiper>
- </view>
- <view class="five">
- <tabs :tabs="tabs" @tabsChange="tabsChange">
- <view class="tabsList">
- <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
- <view class="list-scroll-view">
- <!-- 瀑布流布局列表 -->
- <view class="pubuBox">
- <view class="pubuItem">
- <view class="list" v-for="(item, index) in list" :key="index"
- @tap="toInfo(item)">
- <image :src="item.file&&item.file.length>0?item.file[0].url:''"
- mode="widthFix">
- </image>
- <view class="title"> <!-- 这是没有高度的父盒子(下半部分) -->
- <view class="title_1">{{ item.title ||'暂无'}}</view>
- <view class="title_2">
- <view class="left">
- {{item.contact_name||'暂无昵称'}}
- </view>
- <view class="right" @tap.stop="toLike(item)">
- <text v-if="item.is_like" class="iconfont icon-aixin1"></text>
- <text v-else class="iconfont icon-aixin"></text>
- {{item.like_num||'0'}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>{{config.bottom_title||'到底了!'}}</text>
- </view>
- </view>
- </scroll-view>
- </view>
- </tabs>
- </view>
- </view>
- </view>
- </template>
- <script>
- import moment from 'moment';
- import tabs from '../../components/tabs/index.vue';
- export default {
- components: {
- tabs
- },
- data() {
- return {
- user: {},
- config: {},
- // 轮播图
- imgList: [],
- // 模块
- moduleList: [],
- // 广告
- advertList: [],
- // 公告内容
- content: '',
- tabs: {
- active: '0',
- bgColor: '#ffffff',
- menu: []
- },
- list: [],
- total: 0,
- skip: 0,
- limit: 6,
- page: 0,
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- }
- },
- onShow: async function(e) {
- const that = this;
- that.searchToken();
- await that.searchOther();
- that.clearPage();
- await that.search();
- },
- onPullDownRefresh: async function() {
- const that = this;
- await that.searchOther();
- that.clearPage();
- await that.search();
- uni.stopPullDownRefresh();
- },
- methods: {
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) that.$set(that, `user`, res);
- } catch (e) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- },
- // 查询
- async search() {
- const that = this;
- let info = {
- skip: that.skip,
- limit: that.limit,
- is_use: '0',
- status: '1',
- type: that.tabs.active,
- }
- if (that.user._id) info.user = that.user._id
- let res;
- res = await that.$api(`/article/article`, 'GET', {
- ...info,
- });
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list);
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- // 点击模块
- toChange(item) {
- uni.navigateTo({
- url: `${item.route}?title=${item.name}&type=${item.type}`,
- })
- },
- // 查看更多公告
- toMore() {
- uni.navigateTo({
- url: `/pagesHome/notice/index`,
- })
- },
- // 查看详情
- toInfo(item) {
- uni.navigateTo({
- url: `/pagesHome/article/index?id=${item.id||item._id}`
- })
- },
- // 点赞/取消点赞
- async toLike(item) {
- const that = this;
- let res;
- if (item.is_like == false) {
- const form = {
- user: that.user._id,
- source: item._id,
- source_type: "article",
- type: '0',
- create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
- }
- res = await that.$api(`/like`, 'POST', form);
- } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
- if (res.errcode == '0') {
- that.clearPage();
- that.search()
- }
- },
- // 查询其他信息
- async searchOther() {
- const that = this;
- let res;
- // 基本设置
- res = await that.$api(`/config`, 'GET', {});
- if (res.errcode == '0') {
- that.$set(that, `imgList`, [...res.data.video, ...res.data.file]);
- that.$set(that, `config`, res.data);
- }
- //模块
- res = await that.$api(`/module`, 'GET', {
- is_use: '0'
- });
- if (res.errcode == '0') {
- const data = res.data.reduce((acc, cur, i) => {
- if (i % 10 === 0) acc.push([cur]); // 新增一个小数组
- else acc[acc.length - 1].push(cur); // 将当前元素加入最后一个小数组中
- return acc;
- }, []);
- that.$set(that, `moduleList`, data);
- }
- // 公告
- res = await that.$api(`/notice`, 'GET', {
- is_use: '0',
- limit: 1
- });
- if (res.errcode == '0') that.$set(that, `content`, res.data[0].name);
- // 查询状态
- res = await that.$api(`/dictData`, 'GET', {
- type: 'home_tabs',
- is_use: '0',
- })
- if (res.errcode == '0') {
- const menu = res.data.map((item) => {
- return {
- title: item.label,
- active: item.value
- }
- })
- that.$set(that.tabs, `menu`, menu)
- }
- // 广告
- res = await that.$api(`/advert`, 'GET', {
- is_use: '0'
- });
- if (res.errcode == '0') that.$set(that, `advertList`, res.data);
- },
- // 选择选项卡
- tabsChange(e) {
- const that = this;
- that.$set(that.tabs, `active`, e.active)
- that.clearPage();
- that.search()
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- } else that.$set(that, `is_bottom`, true)
- },
- // 触底
- toScroll(e) {
- const that = this;
- let up = that.scrollTop;
- that.$set(that, `scrollTop`, e.detail.scrollTop);
- let num = Math.sign(up - e.detail.scrollTop);
- if (num == 1) that.$set(that, `is_bottom`, false);
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 6)
- that.$set(that, `page`, 0)
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .main {
- .one {
- padding: 0 0 2vw 0;
- .swiper {
- height: 70vw;
- .list {
- .image {
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- .bottom {
- position: absolute;
- top: 65vw;
- left: 0;
- right: 0;
- background-color: var(--mainColor);
- border-radius: 20px;
- padding: 2vw 0 0 0;
- .two {
- .swiper {
- height: 48vw;
- margin: 2vw 0 0 0;
- .swiper-item {
- display: flex;
- flex-wrap: wrap;
- .list {
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 20vw;
- .image {
- width: 14vw;
- height: 14vw;
- border-radius: 14vw;
- }
- .text {
- font-size: var(--font14Size);
- margin-top: 5px;
- color: var(--f85Color);
- }
- }
- }
- }
- }
- .thr {
- padding: 0 2vw;
- }
- .four {
- padding: 2vw;
- }
- .five {
- background-color: var(--footColor);
- .tabsList {
- position: relative;
- width: 100vw;
- height: 80vh;
- .pubuBox {
- padding: 2vw;
- }
- .pubuItem {
- column-count: 2;
- column-gap: 2vw;
- }
- .list {
- box-sizing: border-box;
- border-radius: 2vw;
- overflow: hidden;
- background-color: var(--mainColor);
- break-inside: avoid;
- /*避免在元素内部插入分页符*/
- box-sizing: border-box;
- margin-bottom: 2vw;
- }
- .list image {
- width: 100%;
- }
- .title {
- padding: 2vw;
- .title_1 {
- font-size: var(--font14Size);
- line-height: 4vw;
- text-overflow: -o-ellipsis-lastline;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- -webkit-box-orient: vertical;
- min-height: 6vw;
- max-height: 20vw;
- }
- .title_2 {
- display: flex;
- justify-content: space-between;
- font-size: var(--font12Size);
- color: var(--f69Color);
- padding: 1vw 0;
- .right {
- display: flex;
- align-items: center;
- text:first-child {
- padding: 0 1vw 0 0;
- }
- }
- }
- }
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- .is_bottom {
- width: 100%;
- text-align: center;
- text {
- padding: 2vw 0;
- display: inline-block;
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- </style>
|