_cid.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="box community-u" ref="container" @scroll="containerScroll">
  3. <div class="top" style="opacity:0">
  4. <div class="left">
  5. <span>合集:{{info ? info.title : ''}}</span>
  6. </div>
  7. <div class="right">
  8. <van-icon name="replay" />
  9. <span>刷新</span>
  10. </div>
  11. </div>
  12. <van-checkbox class="top2-box" v-model="allchecked" @click="checkAll" style="opacity:0">全选</van-checkbox>
  13. <div class="top2">
  14. <div class="top">
  15. <div class="left">
  16. <span>合集:{{info ? info.title : ''}}</span>
  17. </div>
  18. <div class="right">
  19. <van-icon name="replay" @click="refresh" />
  20. <span>刷新</span>
  21. </div>
  22. </div>
  23. <van-checkbox class="top2-box" v-model="allchecked" @click="checkAll">全选</van-checkbox>
  24. </div>
  25. <form>
  26. <van-checkbox-group v-model="result" ref="checkboxGroup">
  27. <template v-for="item in list">
  28. <van-checkbox class="checkbox" :key="item.id" :name="item.id" bind:change="onChange" v-if="item.cover_url">
  29. <!-- //有图 -->
  30. <div class="article have-img align-center">
  31. <div class="article-left">
  32. <div class="article-title">{{item.title}}</div>
  33. <div class="article-desc">
  34. </div>
  35. <div class="source align-center">
  36. <div class="live-source align-center">
  37. <img :src="item.avatar" style=" border-radius: 50%;"/>
  38. <div style="margin-left: 5px">{{item.name}}</div>
  39. </div>
  40. <div class="live-time gray-153">
  41. <div>{{formatPublichTime(item.updated_at)}}</div>
  42. </div>
  43. <div class="live-time gray-153 align-center">
  44. <img class="icon" src="~@/assets/quan/icon/zan.png" />
  45. <div>{{item.like_count}}</div>
  46. </div>
  47. <div class="live-people gray-153 align-center">
  48. <img class="icon" src="@/assets/quan/icon/common.png" />
  49. <div>{{item.reply_count}}</div>
  50. </div>
  51. </div>
  52. </div>
  53. <img class="article-right" :src="item.cover_url" />
  54. </div>
  55. </van-checkbox>
  56. <van-checkbox class="checkbox" :name="item.id" bind:change="onChange" v-else :key="item.id">
  57. <!-- 无图 -->
  58. <div class="article no-img">
  59. <div class="article-title">{{item.title}}</div>
  60. <div class="article-desc">
  61. </div>
  62. <div class="source align-center">
  63. <div class="live-source align-center">
  64. <img :src="item.avatar" style=" border-radius: 50%;"/>
  65. <div style="margin-left: 5px;">{{item.name}}</div>
  66. </div>
  67. <div class="live-time gray-153">
  68. <div>{{formatPublichTime(item.updated_at)}}</div>
  69. </div>
  70. <div class="live-people gray-153 align-center">
  71. <img class="icon" src="@/assets/quan/icon/zan.png" />
  72. <div>{{item.like_count}}</div>
  73. </div>
  74. <div class="live-people gray-153 align-center">
  75. <img class="icon" src="@/assets/quan/icon/common.png" />
  76. <div>{{item.reply_count}}</div>
  77. </div>
  78. </div>
  79. </div>
  80. </van-checkbox>
  81. </template>
  82. </van-checkbox-group>
  83. <van-loading class="margin-0-auto text-center" color="#1989fa" v-if="list.lengt == 0 || isLoading" />
  84. <div class="margin-0-auto text-center bottom-tip" v-if="noMore">没有可以添加到合集的文章了</div>
  85. </form>
  86. <div class="add-btn">
  87. <van-button :loading="subin" type="info" @click="sub()" block>确认添加</van-button>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import "@/assets/css/common.css";
  93. import WxMixin from "@/mixins/wx";
  94. import Vue from "vue";
  95. import {
  96. Form
  97. } from "vant";
  98. import {
  99. Icon
  100. } from "vant";
  101. import {
  102. Checkbox,
  103. CheckboxGroup,
  104. Toast
  105. } from "vant";
  106. let container;
  107. let page = 1;
  108. export default {
  109. layout: "opacity_header",
  110. async asyncData({
  111. $axios,
  112. params,
  113. req
  114. }) {
  115. return {
  116. title: `添加文章到合集-程序员客栈`
  117. };
  118. },
  119. head() {
  120. return {
  121. title: this.title,
  122. script: [{
  123. src: "https://hm.baidu.com/hm.js?18455f493c982100e5a82ec978a8d06e"
  124. }]
  125. };
  126. },
  127. data() {
  128. return {
  129. cid: this.$route.params.cid,
  130. allchecked: false,
  131. isLoading: 0,
  132. currentPage: 1,
  133. result: [],
  134. list: [],
  135. noMore: false,
  136. subin: false,
  137. info:null
  138. };
  139. },
  140. created() {
  141. },
  142. mounted() {
  143. container = this.$refs.container;
  144. this.needLogin();
  145. this.getList();
  146. this.getDetail()
  147. },
  148. methods: {
  149. formatPublichTime(ts) {
  150. try {
  151. ts = moment(ts).toDate().getTime()
  152. let now = new Date().getTime()
  153. let fromNow = Math.floor((now - ts) / 1000)
  154. if (fromNow < 5 * 60) {
  155. return "刚刚";
  156. } else if (fromNow < 60 * 60) {
  157. return Math.floor(fromNow / 60) + "分钟前";
  158. } else if (fromNow < 60 * 60 * 24) {
  159. return Math.floor(fromNow / 3600) + "小时前";
  160. } else if (fromNow < 60 * 60 * 24 * 10) {
  161. return Math.floor(fromNow / 86400) + "天前";
  162. } else {
  163. return moment(ts).format("YYYY-MM-DD HH:mm")
  164. }
  165. } catch (e) {
  166. console.log(e)
  167. return ""
  168. }
  169. },
  170. async getDetail() {
  171. let that = this;
  172. let res = await this.$axios.$post(
  173. "/api/kaifawu/get_provider",
  174. {
  175. id: that.cid,
  176. },
  177. {
  178. neverLogout: true
  179. }
  180. );
  181. if (res.status) {
  182. that.info = res.data
  183. }
  184. },
  185. checkAll() {
  186. if (this.allchecked) {
  187. this.$refs.checkboxGroup.toggleAll(false);
  188. } else {
  189. this.$refs.checkboxGroup.toggleAll(true);
  190. }
  191. },
  192. refresh() {
  193. (this.allchecked = false),
  194. (this.isLoading = 0),
  195. (this.currentPage = 1),
  196. (this.result = []),
  197. (this.list = []),
  198. (this.noMore = false);
  199. this.getList();
  200. Toast.success("刷新成功!");
  201. },
  202. //提交
  203. async sub() {
  204. let that = this;
  205. let str = this.result.toString();
  206. if (this.result.length == 0) {
  207. Toast.fail("您尚未选择文章!");
  208. return 0;
  209. }
  210. this.subin = true;
  211. let res = await this.$axios.$post(
  212. "/api/jishuquan/attach_topic_to_collection", {
  213. collection_id: that.cid,
  214. topic_id: str
  215. }
  216. );
  217. this.subin = false;
  218. if (res.status) {
  219. Toast.success("添加成功!");
  220. that.$router.go(-1);
  221. } else {
  222. Toast.fail("添加失败,请刷新后尝试!");
  223. }
  224. },
  225. //获取列表
  226. async getList() {
  227. let that = this;
  228. if (this.isLoading) {
  229. return 0;
  230. }
  231. this.isLoading = true;
  232. let res = await this.$axios.$post(
  233. "/api/jishuquan/getUncollectedTopics", {
  234. collecte_id: that.cid,
  235. page: this.currentPage,
  236. size: 15
  237. }, {
  238. neverLogout: true
  239. }
  240. );
  241. this.isLoading = false;
  242. if (res) {
  243. if (!res.data.length) {
  244. this.noMore = true;
  245. return;
  246. } else {
  247. let list2 = this.list;
  248. this.list = list2.concat(res.data);
  249. }
  250. }
  251. },
  252. /**
  253. * 监听滚动
  254. */
  255. containerScroll() {
  256. if (this.isLoading || this.noMore) return;
  257. // PC不监听
  258. if (this.$store.state.isPC) return;
  259. if (
  260. container.scrollHeight - container.scrollTop - container.clientHeight <
  261. 150
  262. ) {
  263. this.currentPage++;
  264. this.getList();
  265. }
  266. }
  267. }
  268. };
  269. </script>
  270. <style >
  271. @import "../../../assets/css/user/article.css";
  272. .van-checkbox__label{
  273. display: block;
  274. width:100%;
  275. }
  276. .bottom-tip {
  277. line-height: 0.8rem;
  278. font-size: 0.3rem;
  279. }
  280. .top2-box {
  281. padding: 0.3rem 2.5% 5px 2.5%;
  282. }
  283. .top2 {
  284. position: fixed;
  285. width: 100%;
  286. top: 0;
  287. background-color: white;
  288. z-index: 1000;
  289. }
  290. .add-btn {
  291. position: fixed;
  292. bottom: 0;
  293. left: 0.2rem;
  294. right: 0.2rem;
  295. padding: 10px 0;
  296. background: white;
  297. }
  298. body {
  299. background-color: white;
  300. }
  301. .checkbox {
  302. border-bottom: 1px solid rgb(0, 0, 0, 0.06);
  303. }
  304. .company-info>img {
  305. width: 30px;
  306. height: 30px;
  307. border-radius: 50%;
  308. }
  309. form {
  310. padding: 0rem 2.5%;
  311. padding-bottom: 1.3rem;
  312. }
  313. .main {
  314. margin: 0;
  315. }
  316. .live-zan {
  317. margin-left: 0.25rem;
  318. }
  319. .article-left {
  320. display: flex;
  321. flex-direction: column;
  322. justify-content: space-between;
  323. }
  324. .source {
  325. justify-content: space-between;
  326. margin-top: 0.16rem;
  327. font-size: 0.22rem;
  328. }
  329. .live-source>img {
  330. width: 0.36rem;
  331. height: 0.36rem;
  332. }
  333. .live-time {
  334. border: 0;
  335. padding: 0;
  336. }
  337. .live-people {
  338. padding: 0;
  339. }
  340. .article-desc {
  341. display: none;
  342. }
  343. .article-title {
  344. font-size: 0.3rem;
  345. line-height: 0.42rem;
  346. }
  347. .article-right {
  348. width: 29%;
  349. }
  350. .article-left {
  351. width: 69%;
  352. margin-right: 2%;
  353. }
  354. .article-list {
  355. width: 100%;
  356. }
  357. .article {
  358. padding: 0.38rem 0 0.4rem 0;
  359. width: 100%;
  360. }
  361. </style>
  362. <style lang='less' scoped>
  363. .box {
  364. width: 100%;
  365. height: 100vh;
  366. overflow-y: scroll;
  367. .top {
  368. display: flex;
  369. justify-content: space-between;
  370. align-items: center;
  371. padding: 0.22rem 0.18rem;
  372. .left {
  373. font-size: 0.32rem;
  374. font-family: PingFangSC-Semibold, PingFang SC;
  375. font-weight: 600;
  376. color: rgba(34, 34, 34, 1);
  377. line-height: 0.44rem;
  378. padding-left: 0.1rem;
  379. border-left: 0.06rem solid rgba(48, 142, 255, 1);
  380. }
  381. }
  382. }
  383. </style>