| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <template>
- <div class="box community-u" ref="container" @scroll="containerScroll">
- <div class="top" style="opacity:0">
- <div class="left">
- <span>合集:{{info ? info.title : ''}}</span>
- </div>
- <div class="right">
- <van-icon name="replay" />
- <span>刷新</span>
- </div>
- </div>
- <van-checkbox class="top2-box" v-model="allchecked" @click="checkAll" style="opacity:0">全选</van-checkbox>
- <div class="top2">
- <div class="top">
- <div class="left">
- <span>合集:{{info ? info.title : ''}}</span>
- </div>
- <div class="right">
- <van-icon name="replay" @click="refresh" />
- <span>刷新</span>
- </div>
- </div>
- <van-checkbox class="top2-box" v-model="allchecked" @click="checkAll">全选</van-checkbox>
- </div>
- <form>
- <van-checkbox-group v-model="result" ref="checkboxGroup">
- <template v-for="item in list">
- <van-checkbox class="checkbox" :key="item.id" :name="item.id" bind:change="onChange" v-if="item.cover_url">
- <!-- //有图 -->
- <div class="article have-img align-center">
- <div class="article-left">
- <div class="article-title">{{item.title}}</div>
- <div class="article-desc">
- </div>
- <div class="source align-center">
- <div class="live-source align-center">
- <img :src="item.avatar" style=" border-radius: 50%;"/>
- <div style="margin-left: 5px">{{item.name}}</div>
- </div>
- <div class="live-time gray-153">
- <div>{{formatPublichTime(item.updated_at)}}</div>
- </div>
- <div class="live-time gray-153 align-center">
- <img class="icon" src="~@/assets/quan/icon/zan.png" />
- <div>{{item.like_count}}</div>
- </div>
- <div class="live-people gray-153 align-center">
- <img class="icon" src="@/assets/quan/icon/common.png" />
- <div>{{item.reply_count}}</div>
- </div>
- </div>
- </div>
- <img class="article-right" :src="item.cover_url" />
- </div>
- </van-checkbox>
- <van-checkbox class="checkbox" :name="item.id" bind:change="onChange" v-else :key="item.id">
- <!-- 无图 -->
- <div class="article no-img">
- <div class="article-title">{{item.title}}</div>
- <div class="article-desc">
- </div>
- <div class="source align-center">
- <div class="live-source align-center">
- <img :src="item.avatar" style=" border-radius: 50%;"/>
- <div style="margin-left: 5px;">{{item.name}}</div>
- </div>
- <div class="live-time gray-153">
- <div>{{formatPublichTime(item.updated_at)}}</div>
- </div>
- <div class="live-people gray-153 align-center">
- <img class="icon" src="@/assets/quan/icon/zan.png" />
- <div>{{item.like_count}}</div>
- </div>
- <div class="live-people gray-153 align-center">
- <img class="icon" src="@/assets/quan/icon/common.png" />
- <div>{{item.reply_count}}</div>
- </div>
- </div>
- </div>
- </van-checkbox>
- </template>
- </van-checkbox-group>
- <van-loading class="margin-0-auto text-center" color="#1989fa" v-if="list.lengt == 0 || isLoading" />
- <div class="margin-0-auto text-center bottom-tip" v-if="noMore">没有可以添加到合集的文章了</div>
- </form>
- <div class="add-btn">
- <van-button :loading="subin" type="info" @click="sub()" block>确认添加</van-button>
- </div>
- </div>
- </template>
- <script>
- import "@/assets/css/common.css";
- import WxMixin from "@/mixins/wx";
- import Vue from "vue";
- import {
- Form
- } from "vant";
- import {
- Icon
- } from "vant";
- import {
- Checkbox,
- CheckboxGroup,
- Toast
- } from "vant";
- let container;
- let page = 1;
- export default {
- layout: "opacity_header",
- async asyncData({
- $axios,
- params,
- req
- }) {
- return {
- title: `添加文章到合集-程序员客栈`
- };
- },
- head() {
- return {
- title: this.title,
- script: [{
- src: "https://hm.baidu.com/hm.js?18455f493c982100e5a82ec978a8d06e"
- }]
- };
- },
- data() {
- return {
- cid: this.$route.params.cid,
- allchecked: false,
- isLoading: 0,
- currentPage: 1,
- result: [],
- list: [],
- noMore: false,
- subin: false,
- info:null
- };
- },
- created() {
- },
- mounted() {
- container = this.$refs.container;
- this.needLogin();
- this.getList();
- this.getDetail()
- },
- methods: {
- formatPublichTime(ts) {
- try {
- ts = moment(ts).toDate().getTime()
- let now = new Date().getTime()
- let fromNow = Math.floor((now - ts) / 1000)
- if (fromNow < 5 * 60) {
- return "刚刚";
- } else if (fromNow < 60 * 60) {
- return Math.floor(fromNow / 60) + "分钟前";
- } else if (fromNow < 60 * 60 * 24) {
- return Math.floor(fromNow / 3600) + "小时前";
- } else if (fromNow < 60 * 60 * 24 * 10) {
- return Math.floor(fromNow / 86400) + "天前";
- } else {
- return moment(ts).format("YYYY-MM-DD HH:mm")
- }
- } catch (e) {
- console.log(e)
- return ""
- }
- },
- async getDetail() {
- let that = this;
- let res = await this.$axios.$post(
- "/api/kaifawu/get_provider",
- {
- id: that.cid,
- },
- {
- neverLogout: true
- }
- );
- if (res.status) {
- that.info = res.data
- }
- },
- checkAll() {
- if (this.allchecked) {
- this.$refs.checkboxGroup.toggleAll(false);
- } else {
- this.$refs.checkboxGroup.toggleAll(true);
- }
- },
- refresh() {
- (this.allchecked = false),
- (this.isLoading = 0),
- (this.currentPage = 1),
- (this.result = []),
- (this.list = []),
- (this.noMore = false);
- this.getList();
- Toast.success("刷新成功!");
- },
- //提交
- async sub() {
- let that = this;
- let str = this.result.toString();
- if (this.result.length == 0) {
- Toast.fail("您尚未选择文章!");
- return 0;
- }
- this.subin = true;
- let res = await this.$axios.$post(
- "/api/jishuquan/attach_topic_to_collection", {
- collection_id: that.cid,
- topic_id: str
- }
- );
- this.subin = false;
- if (res.status) {
- Toast.success("添加成功!");
- that.$router.go(-1);
- } else {
- Toast.fail("添加失败,请刷新后尝试!");
- }
- },
- //获取列表
- async getList() {
- let that = this;
- if (this.isLoading) {
- return 0;
- }
- this.isLoading = true;
- let res = await this.$axios.$post(
- "/api/jishuquan/getUncollectedTopics", {
- collecte_id: that.cid,
- page: this.currentPage,
- size: 15
- }, {
- neverLogout: true
- }
- );
- this.isLoading = false;
- if (res) {
- if (!res.data.length) {
- this.noMore = true;
- return;
- } else {
- let list2 = this.list;
- this.list = list2.concat(res.data);
- }
- }
- },
- /**
- * 监听滚动
- */
- containerScroll() {
- if (this.isLoading || this.noMore) return;
- // PC不监听
- if (this.$store.state.isPC) return;
- if (
- container.scrollHeight - container.scrollTop - container.clientHeight <
- 150
- ) {
- this.currentPage++;
- this.getList();
- }
- }
- }
- };
- </script>
- <style >
- @import "../../../assets/css/user/article.css";
- .van-checkbox__label{
- display: block;
- width:100%;
- }
- .bottom-tip {
- line-height: 0.8rem;
- font-size: 0.3rem;
- }
- .top2-box {
- padding: 0.3rem 2.5% 5px 2.5%;
- }
- .top2 {
- position: fixed;
- width: 100%;
- top: 0;
- background-color: white;
- z-index: 1000;
- }
- .add-btn {
- position: fixed;
- bottom: 0;
- left: 0.2rem;
- right: 0.2rem;
- padding: 10px 0;
- background: white;
- }
- body {
- background-color: white;
- }
- .checkbox {
- border-bottom: 1px solid rgb(0, 0, 0, 0.06);
- }
- .company-info>img {
- width: 30px;
- height: 30px;
- border-radius: 50%;
- }
- form {
- padding: 0rem 2.5%;
- padding-bottom: 1.3rem;
- }
- .main {
- margin: 0;
- }
- .live-zan {
- margin-left: 0.25rem;
- }
- .article-left {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .source {
- justify-content: space-between;
- margin-top: 0.16rem;
- font-size: 0.22rem;
- }
- .live-source>img {
- width: 0.36rem;
- height: 0.36rem;
- }
- .live-time {
- border: 0;
- padding: 0;
- }
- .live-people {
- padding: 0;
- }
- .article-desc {
- display: none;
- }
- .article-title {
- font-size: 0.3rem;
- line-height: 0.42rem;
- }
- .article-right {
- width: 29%;
- }
- .article-left {
- width: 69%;
- margin-right: 2%;
- }
- .article-list {
- width: 100%;
- }
- .article {
- padding: 0.38rem 0 0.4rem 0;
- width: 100%;
- }
- </style>
- <style lang='less' scoped>
- .box {
- width: 100%;
- height: 100vh;
- overflow-y: scroll;
- .top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0.22rem 0.18rem;
- .left {
- font-size: 0.32rem;
- font-family: PingFangSC-Semibold, PingFang SC;
- font-weight: 600;
- color: rgba(34, 34, 34, 1);
- line-height: 0.44rem;
- padding-left: 0.1rem;
- border-left: 0.06rem solid rgba(48, 142, 255, 1);
- }
- }
- }
- </style>
|