discover.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <!-- 种草逛逛 -->
  3. <view :data-theme="theme">
  4. <view class="discover indexList" :style="[boxStyle]">
  5. <view class="bg_box" :style="[boxBgStyle]"></view>
  6. <view class='title acea-row row-between-wrapper'>
  7. <view class='text line1 tui-skeleton-rect acea-row'>
  8. <image :src="logoUrl"></image>
  9. <text class='label' :style="[titleColor]">{{titleText}}</text>
  10. </view>
  11. <view class='more tui-skeleton-rect' :style="[moreColor]" @click="goPage(dataConfig.linkConfig.val)">
  12. 更多
  13. <text class="iconfont icon-jiantou"></text>
  14. </view>
  15. </view>
  16. <view class='tips mb20'>Good brand store</view>
  17. <view class="conter" v-if="listStyle == 0">
  18. <scroll-view scroll-x="true" style="white-space: nowrap; vertical-align: middle;"
  19. show-scrollbar="false">
  20. <view class="itemCon" :style="[contentConfig]" v-for="item in discoverList" :key="item.id"
  21. @click="goDetail(item)">
  22. <view class="item">
  23. <view class="pictrue skeleton-rect">
  24. <easy-loadimage :image-src="item.cover"
  25. :radius="dataConfig.contentStyle.val"></easy-loadimage>
  26. <view class="author acea-row row-middle">
  27. <image v-show="avatarShow" :src="item.authorAvatar" mode="aspectFill"></image>
  28. <text v-show="nicknameShow" :style="[nameColor]"
  29. class="nickname line1">{{item.authorName}}</text>
  30. </view>
  31. <view v-show="titleShow" :style="[laberColor]" class="item_tit line1">{{item.title}}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. <view class="conter_y" :style="[contentConfig]" v-if="listStyle == 1">
  39. <view class="item" v-for="item in discoverList" :key="item.id"
  40. @click="goDetail(item)">
  41. <view class="pictrue skeleton-rect">
  42. <easy-loadimage :image-src="item.cover" :radius="dataConfig.contentStyle.val"></easy-loadimage>
  43. </view>
  44. <view v-show="titleShow" :style="[laberColor]" class="item_tit line1">{{item.title}}</view>
  45. <view class="author acea-row row-middle row-between">
  46. <view class="acea-row row-middle">
  47. <image v-show="avatarShow" :src="item.authorAvatar" mode="aspectFill"></image>
  48. <text v-show="nicknameShow" :style="[nameColor]" class="nickname">{{item.authorName}}</text>
  49. </view>
  50. <view class="item_count" @click.stop="likeToggle(item)">
  51. <text class="iconfont"
  52. :class="item.userIsLike ? 'icon-shoucang1' : 'icon-dianzan'"></text>
  53. <text>{{item.likeNum > 0 ? item.likeNum < 10000 ? item.likeNum : (item.likeNum / 10000).toFixed(2) : ''}}</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. // +----------------------------------------------------------------------
  63. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  64. // +----------------------------------------------------------------------
  65. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  66. // +----------------------------------------------------------------------
  67. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  68. // +----------------------------------------------------------------------
  69. // | Author: CRMEB Team <admin@crmeb.com>
  70. // +----------------------------------------------------------------------
  71. import {
  72. discoverListApi
  73. } from "@/api/discover";
  74. import {
  75. discoverNoteLike
  76. } from '@/libs/follow.js';
  77. import {
  78. toLogin
  79. } from '@/libs/login.js';
  80. import {
  81. Debounce
  82. } from '@/utils/validate.js'
  83. import easyLoadimage from '@/components/base/easy-loadimage.vue';
  84. let app = getApp();
  85. export default {
  86. name: 'homeDiscover',
  87. props: {
  88. dataConfig: {
  89. type: Object,
  90. default: () => {}
  91. },
  92. //是否登录
  93. isLogin: {
  94. type: Boolean,
  95. default: () => false
  96. }
  97. },
  98. data() {
  99. return {
  100. theme: app.globalData.theme,
  101. urlDomain: this.$Cache.get("imgHost"),
  102. discoverList: [],
  103. }
  104. },
  105. components: {
  106. easyLoadimage
  107. },
  108. computed: {
  109. //内容边距
  110. contentConfig() {
  111. if (this.listStyle === 0) {
  112. return {
  113. marginRight: this.dataConfig.contentConfig.val ? this.dataConfig.contentConfig.val +
  114. 'px' : '0',
  115. borderRadius: this.dataConfig.contentStyle.val + 'px'
  116. }
  117. } else {
  118. return {
  119. gridGap: this.dataConfig.contentConfig.val ? this.dataConfig.contentConfig.val + 'px' : '0',
  120. borderRadius: this.dataConfig.contentStyle.val + 'px'
  121. }
  122. }
  123. },
  124. //标题
  125. titleShow() {
  126. if (this.dataConfig.typeConfig.activeValue.indexOf(0) !== -1) {
  127. return true;
  128. } else {
  129. return false;
  130. }
  131. },
  132. //头像
  133. avatarShow() {
  134. if (this.dataConfig.typeConfig.activeValue.indexOf(1) !== -1) {
  135. return true;
  136. } else {
  137. return false;
  138. }
  139. },
  140. //昵称
  141. nicknameShow() {
  142. if (this.dataConfig.typeConfig.activeValue.indexOf(2) !== -1) {
  143. return true;
  144. } else {
  145. return false;
  146. }
  147. },
  148. //更多颜色
  149. moreColor() {
  150. return {
  151. 'color': this.dataConfig.moreColor.color[0].item
  152. }
  153. },
  154. //标题图片
  155. boxBgStyle() {
  156. return {
  157. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx' + ' ' + this.dataConfig.bgStyle.val * 2 + 'rpx' +
  158. ' ' + 0 + ' ' + 0,
  159. backgroundImage: `url(${this.urlDomain}crmebimage/presets/discover_bg_pic.png),linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`
  160. }
  161. },
  162. //最外层盒子的样式
  163. boxStyle() {
  164. return {
  165. borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
  166. margin: this.dataConfig.mbConfig.val * 2 + 'rpx' + ' ' + this.dataConfig.lrConfig.val * 2 + 'rpx' +
  167. ' ' + 0,
  168. padding: this.dataConfig.upConfig.val * 2 + 'rpx' + ' ' + '24rpx' + ' ' + this.dataConfig.downConfig
  169. .val * 2 + 'rpx'
  170. }
  171. },
  172. limit() {
  173. return this.dataConfig.numConfig.val
  174. },
  175. listStyle() {
  176. return this.dataConfig.tabConfig.tabVal
  177. },
  178. logoUrl() {
  179. return this.dataConfig.logoConfig.url
  180. },
  181. titleText() {
  182. return this.dataConfig.titleConfig.val
  183. },
  184. titleColor() {
  185. return {
  186. color: this.dataConfig.titleColor.color[0].item
  187. }
  188. },
  189. //更多颜色
  190. moreColor() {
  191. return {
  192. color: this.dataConfig.moreColor.color[0].item
  193. }
  194. },
  195. //作者昵称
  196. nameColor() {
  197. return {
  198. color: this.dataConfig.nameColor.color[0].item
  199. };
  200. },
  201. //文章标题颜色
  202. laberColor() {
  203. return {
  204. color: this.dataConfig.laberColor.color[0].item
  205. };
  206. },
  207. },
  208. created() {
  209. this.getList();
  210. },
  211. methods: {
  212. //点赞
  213. likeToggle: Debounce(function(item) {
  214. if (this.isLogin) {
  215. discoverNoteLike(item.id).then(() => {
  216. this.$set(item, 'userIsLike', !item.userIsLike);
  217. if (!item.userIsLike) {
  218. item.likeNum--;
  219. item.likeNum = item.likeNum == 0 ? 0 : item.likeNum
  220. } else {
  221. item.likeNum++;
  222. }
  223. });
  224. } else {
  225. toLogin();
  226. }
  227. }),
  228. //链接跳转
  229. goPage(url) {
  230. this.$util.navigateTo(url)
  231. },
  232. //种草列表
  233. getList() {
  234. discoverListApi({
  235. page: 1,
  236. limit: this.limit
  237. }).then(res => {
  238. this.discoverList = res.data.list;
  239. }).catch(err => {})
  240. },
  241. //详情跳转
  242. goDetail(item) {
  243. if (item.type == 1) {
  244. uni.navigateTo({
  245. url: `/pages/discover/discover_recommend/index?noteId=${item.id}`
  246. });
  247. } else {
  248. uni.navigateTo({
  249. //#ifdef APP
  250. url: `/pages/discover/discover_video/appVideo/index?noteId=${item.id}&fromTo=${this.fromTo}&sd=${this.uid}`
  251. //#endif
  252. //#ifndef APP
  253. url: `/pages/discover/discover_video/routineVideo/index?noteId=${item.id}&fromTo=${this.fromTo}&sd=${this.uid}`
  254. //#endif
  255. });
  256. }
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .item_count {
  263. font-size: 24rpx;
  264. display: flex;
  265. align-items: center;
  266. &:last-child {
  267. margin-left: 40rpx;
  268. }
  269. .iconfont {
  270. font-size: 26rpx;
  271. margin-right: 5rpx;
  272. }
  273. .icon-shoucang1 {
  274. @include main_color(theme);
  275. }
  276. }
  277. .discover {
  278. width: auto;
  279. background: #fff;
  280. border-radius: 14rpx;
  281. box-sizing: border-box;
  282. position: relative;
  283. .tips {
  284. position: relative;
  285. }
  286. .more {
  287. z-index: 9;
  288. }
  289. .title .text image {
  290. z-index: 9;
  291. }
  292. .bg_box {
  293. position: absolute;
  294. top: 0;
  295. left: 0;
  296. width: 100%;
  297. height: 174rpx;
  298. background-repeat: no-repeat;
  299. background-size: cover;
  300. border-radius: 14rpx 14rpx 0 0;
  301. }
  302. .conter {
  303. border-radius: 12px;
  304. margin-top: 30rpx;
  305. .itemCon {
  306. display: inline-block;
  307. width: 280rpx;
  308. margin-right: 20rpx;
  309. .item {
  310. width: 100%;
  311. .pictrue {
  312. width: 100%;
  313. height: 280rpx;
  314. border-radius: 10rpx;
  315. overflow: hidden;
  316. position: relative;
  317. color: #fff;
  318. image {
  319. width: 100%;
  320. height: 100%;
  321. border-radius: 16rpx;
  322. }
  323. }
  324. .author {
  325. position: absolute;
  326. bottom: 50rpx;
  327. left: 16rpx;
  328. image {
  329. width: 34rpx;
  330. height: 34rpx;
  331. border-radius: 50%;
  332. }
  333. .nickname {
  334. width: 200rpx;
  335. font-size: 20rpx;
  336. padding-left: 8rpx;
  337. }
  338. }
  339. .item_tit {
  340. position: absolute;
  341. bottom: 16rpx;
  342. left: 16rpx;
  343. width: 236rpx;
  344. font-size: 24rpx;
  345. font-weight: 500;
  346. }
  347. }
  348. }
  349. }
  350. }
  351. .conter_y {
  352. display: grid;
  353. grid-template-columns: repeat(2, 1fr);
  354. grid-template-rows: auto;
  355. grid-gap: 20rpx;
  356. width: 100%;
  357. margin-top: 30rpx;
  358. .item {
  359. width: 100%;
  360. .pictrue {
  361. //width: 316rpx;
  362. height: 316rpx;
  363. image {
  364. width: 100%;
  365. height: 100%;
  366. border-radius: 14rpx;
  367. }
  368. }
  369. .author {
  370. width: 316rpx;
  371. color: #333;
  372. image {
  373. width: 44rpx;
  374. height: 44rpx;
  375. border-radius: 50%;
  376. }
  377. .nickname {
  378. font-size: 24rpx;
  379. padding-left: 8rpx;
  380. }
  381. }
  382. .item_tit {
  383. color: #333;
  384. width: 316rpx;
  385. margin: 28rpx 0 16rpx;
  386. font-size: 28rpx;
  387. font-weight: 500;
  388. }
  389. }
  390. }
  391. </style>