card.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="waterfall-item" :style="{ width, ...customStyle }">
  3. <view class="waterfall-item__image" @click="goWork(item)"
  4. :style="{ width, backgroundColor: item.backgroundColor }">
  5. <image :src="item.image" mode="widthFix" style="border-radius: 20rpx"></image>
  6. <view class="mask"></view>
  7. </view>
  8. <view class="waterfall-item__ft">
  9. <view class="waterfall-item__ft__title">
  10. <text class="value" :style="{ color: titleTextColor || textColor }">{{
  11. item.title
  12. }}</text>
  13. </view>
  14. <view class="waterfall-item__ft__desc" style="margin-top: 4rpx;" @click="goAuthor(item)">
  15. <view class="user">
  16. <image :src="item.avator" mode="aspectFill" class="avater"> </image>
  17. <text class="name one-omit">{{
  18. item.nickname
  19. }}</text>
  20. </view>
  21. <view class="like" @click="changeLike">
  22. <image class="like-icon" :src="isLike ? '/static/icon/icon-18.png' : '/static/icon/icon-19.png'
  23. " mode="">
  24. </image>
  25. <text class="value">{{
  26. item.num_like
  27. }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="waterfall-item__tips" v-if="findType != 'search'">
  32. <view class="item">
  33. <image class="look-icon" src="@/static/icon/icon-17.png" mode=""></image>
  34. <text class="value" style="color: #fff">{{ item.num_view }}</text>
  35. </view>
  36. <!-- <view class="item" style="background-color: #1f1f1f"> -->
  37. <image src="../../static/home/jingxuan.png" mode="widthFix" class="item2"></image>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name: "card",
  44. props: {
  45. width: {
  46. type: String,
  47. default: "",
  48. },
  49. item: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. textColor: {
  54. type: String,
  55. default: "#ff0000",
  56. },
  57. titleTextColor: {
  58. type: String,
  59. default: "",
  60. },
  61. customStyle: {
  62. type: Object,
  63. default: () => ({
  64. background: "#3F4141",
  65. }),
  66. },
  67. goLink: {
  68. type: String,
  69. default: "",
  70. },
  71. findType: {
  72. type: String,
  73. default: "",
  74. },
  75. },
  76. data() {
  77. return {
  78. isLike: false,
  79. isLiking: false,
  80. localLikeCount: 0,
  81. };
  82. },
  83. created() {
  84. this.isLike = this.item.is_like || false;
  85. this.localLikeCount = this.item.num_like || 0;
  86. },
  87. methods: {
  88. changeLike(e) {
  89. return;
  90. e && e.stopPropagation();
  91. if (this.isLiking) return;
  92. this.isLiking = true;
  93. const prevLikeState = this.isLike;
  94. const prevLikeCount = this.localLikeCount;
  95. this.isLike = !this.isLike;
  96. this.localLikeCount = this.isLike ? prevLikeCount + 1 : prevLikeCount - 1;
  97. this.item.num_like = this.localLikeCount;
  98. if (!getApp().globalData.uuid) {
  99. uni.showToast({
  100. title: "请先登录",
  101. icon: "none",
  102. });
  103. this.isLike = prevLikeState;
  104. this.localLikeCount = prevLikeCount;
  105. this.item.num_like = prevLikeCount;
  106. this.isLiking = false;
  107. return;
  108. }
  109. uni.request({
  110. url: this.$apiHost + "/Work/zanTA",
  111. data: {
  112. uuid: getApp().globalData.uuid,
  113. id: this.item.id,
  114. },
  115. header: {
  116. "content-type": "application/json",
  117. sign: getApp().globalData.headerSign,
  118. },
  119. success: (res) => {
  120. if (res.data.success === "yes") {
  121. uni.showToast({
  122. title: this.isLike ? "点赞成功" : "取消点赞",
  123. icon: "none",
  124. });
  125. } else {
  126. this.isLike = prevLikeState;
  127. this.localLikeCount = prevLikeCount;
  128. this.item.num_like = prevLikeCount;
  129. uni.showToast({
  130. title: res.data.str || "操作失败",
  131. icon: "none",
  132. });
  133. }
  134. },
  135. fail: (e) => {
  136. console.error("点赞失败:", e);
  137. this.isLike = prevLikeState;
  138. this.localLikeCount = prevLikeCount;
  139. this.item.num_like = prevLikeCount;
  140. uni.showToast({
  141. title: "网络请求失败",
  142. icon: "none",
  143. });
  144. },
  145. complete: () => {
  146. setTimeout(() => {
  147. this.isLiking = false;
  148. }, 500);
  149. },
  150. });
  151. },
  152. goWork(item) {
  153. // console.log("跳转2", item.type);
  154. var url = "/pages/index/workDetail?id=";
  155. if (this.goLink) {
  156. url = this.goLink;
  157. }
  158. if (item.type == 'crowdfund') {
  159. url = "/pages/crowdFunding/crowdfundingDetailsDesign?id="
  160. }
  161. if (item.type == 'article') {
  162. url = '/pages/index/articleDetail?id=';
  163. }
  164. // console.log(url);
  165. // return;
  166. // uni.$emit('check_login', () => {
  167. uni.navigateTo({
  168. url: url + item.id,
  169. });
  170. // })
  171. },
  172. goAuthor(item) {
  173. console.log("goAuthor", item);
  174. uni.$emit("check_login", () => {
  175. if (!item.userID) {
  176. return;
  177. }
  178. uni.navigateTo({
  179. url: "/pages/my/userHomepage?id=" + item.userID,
  180. });
  181. });
  182. },
  183. },
  184. };
  185. </script>
  186. <style lang="scss">
  187. .waterfall-item {
  188. margin-bottom: 0rpx;
  189. border-radius: 30rpx;
  190. position: relative;
  191. border-radius: 16rpx;
  192. overflow: hidden;
  193. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  194. // box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  195. &:active {
  196. transform: scale(0.98);
  197. box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.05);
  198. }
  199. // #ifndef APP-NVUE
  200. .waterfall-item__image {
  201. border-radius: 16rpx;
  202. width: 100%;
  203. height: auto;
  204. box-sizing: border-box;
  205. // padding: 28rpx 20rpx;
  206. transition: all 0.3s ease;
  207. background-color: transparent !important;
  208. position: relative;
  209. left: 0;
  210. top: 0;
  211. .mask {
  212. position: absolute;
  213. top: 0;
  214. left: 0;
  215. width: 100%;
  216. height: 100%;
  217. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
  218. width: 100%;
  219. height: 88rpx;
  220. border-top-right-radius: 16rpx;
  221. border-top-left-radius: 16rpx;
  222. }
  223. &:active {
  224. opacity: 0.9;
  225. }
  226. image {
  227. width: 100%;
  228. height: 100%;
  229. transition: all 0.3s ease;
  230. }
  231. }
  232. // #endif
  233. .waterfall-item__tips {
  234. position: absolute;
  235. top: 10rpx;
  236. padding: 0rpx 10rpx;
  237. // #ifndef APP-NVUE
  238. box-sizing: border-box;
  239. // #endif
  240. width: 100%;
  241. display: flex;
  242. flex-direction: row;
  243. align-items: center;
  244. justify-content: space-between;
  245. .item {
  246. // #ifndef APP-NVUE
  247. // #endif
  248. display: flex;
  249. flex-direction: row;
  250. align-items: center;
  251. // background: rgba(0, 0, 0, 0.2);
  252. padding: 8rpx 14rpx;
  253. border-radius: 12rpx;
  254. .look-icon {
  255. width: 26rpx;
  256. height: 26rpx;
  257. margin-right: 10rpx;
  258. }
  259. .value {
  260. font-size: 24rpx;
  261. // font-weight: 600;
  262. }
  263. }
  264. .item2 {
  265. position: absolute;
  266. top: 7rpx;
  267. right: 14rpx;
  268. width: 86rpx;
  269. height: 32rpx;
  270. }
  271. }
  272. .waterfall-item__ft {
  273. padding: 10rpx 20rpx;
  274. padding-top: 0;
  275. padding-left: 0;
  276. &__title {
  277. line-height: 48rpx;
  278. font-weight: 700;
  279. .value {
  280. font-size: 26rpx;
  281. }
  282. }
  283. &__desc {
  284. width: 100%;
  285. // #ifndef APP-NVUE
  286. display: flex;
  287. // #endif
  288. // #ifdef APP-NVUE
  289. // #endif
  290. flex-direction: row;
  291. align-items: center;
  292. justify-content: space-between;
  293. margin: 20rpx 0;
  294. .user {
  295. // #ifndef APP-NVUE
  296. display: flex;
  297. // #endif
  298. // #ifdef APP-NVUE
  299. flex-direction: row;
  300. // #endif
  301. align-items: center;
  302. .avater {
  303. width: 44rpx;
  304. height: 44rpx;
  305. border-radius: 50%;
  306. margin-right: 10rpx;
  307. }
  308. .name {
  309. font-size: 24rpx;
  310. max-width: 80px;
  311. display: inline-block;
  312. color: #999;
  313. }
  314. }
  315. .like {
  316. // #ifndef APP-NVUE
  317. display: flex;
  318. // #endif
  319. // #ifdef APP-NVUE
  320. flex-direction: row;
  321. // #endif
  322. align-items: center;
  323. font-weight: bold;
  324. .like-icon {
  325. width: 30rpx;
  326. height: 30rpx;
  327. margin-right: 10rpx;
  328. }
  329. .value {
  330. font-size: 24rpx;
  331. color: #999;
  332. }
  333. }
  334. }
  335. &__btn {
  336. height: 65rpx;
  337. border-radius: 18px;
  338. background-image: linear-gradient(to bottom, #bffe9c, #aee75d);
  339. // #ifndef APP-NVUE
  340. background: linear-gradient(180deg,
  341. #bffe9c 0%,
  342. #aee75d 62%,
  343. #aee75d 100%);
  344. display: flex;
  345. // #endif
  346. justify-content: center;
  347. align-items: center;
  348. &__icon {
  349. width: 155rpx;
  350. height: 32rpx;
  351. }
  352. }
  353. }
  354. }
  355. </style>