card.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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("跳转");
  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. // uni.$emit('check_login', () => {
  162. uni.navigateTo({
  163. url: url + item.id,
  164. });
  165. // })
  166. },
  167. goAuthor(item) {
  168. console.log("goAuthor", item);
  169. uni.$emit("check_login", () => {
  170. if (!item.userID) {
  171. return;
  172. }
  173. uni.navigateTo({
  174. url: "/pages/my/userHomepage?id=" + item.userID,
  175. });
  176. });
  177. },
  178. },
  179. };
  180. </script>
  181. <style lang="scss">
  182. .waterfall-item {
  183. margin-bottom: 0rpx;
  184. border-radius: 30rpx;
  185. position: relative;
  186. border-radius: 16rpx;
  187. overflow: hidden;
  188. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  189. // box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  190. &:active {
  191. transform: scale(0.98);
  192. box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.05);
  193. }
  194. // #ifndef APP-NVUE
  195. .waterfall-item__image {
  196. border-radius: 16rpx;
  197. width: 100%;
  198. height: auto;
  199. box-sizing: border-box;
  200. // padding: 28rpx 20rpx;
  201. transition: all 0.3s ease;
  202. background-color: transparent !important;
  203. position: relative;
  204. left: 0;
  205. top: 0;
  206. .mask{
  207. position: absolute;
  208. top: 0;
  209. left: 0;
  210. width: 100%;
  211. height: 100%;
  212. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0));
  213. width: 100%;
  214. height: 88rpx;
  215. border-top-right-radius: 16rpx;
  216. border-top-left-radius: 16rpx;
  217. }
  218. &:active {
  219. opacity: 0.9;
  220. }
  221. image {
  222. width: 100%;
  223. height: 100%;
  224. transition: all 0.3s ease;
  225. }
  226. }
  227. // #endif
  228. .waterfall-item__tips {
  229. position: absolute;
  230. top: 10rpx;
  231. padding: 0rpx 10rpx;
  232. // #ifndef APP-NVUE
  233. box-sizing: border-box;
  234. // #endif
  235. width: 100%;
  236. display: flex;
  237. flex-direction: row;
  238. align-items: center;
  239. justify-content: space-between;
  240. .item {
  241. // #ifndef APP-NVUE
  242. // #endif
  243. display: flex;
  244. flex-direction: row;
  245. align-items: center;
  246. // background: rgba(0, 0, 0, 0.2);
  247. padding: 8rpx 14rpx;
  248. border-radius: 12rpx;
  249. .look-icon {
  250. width: 26rpx;
  251. height: 26rpx;
  252. margin-right: 10rpx;
  253. }
  254. .value {
  255. font-size: 24rpx;
  256. // font-weight: 600;
  257. }
  258. }
  259. .item2 {
  260. position: absolute;
  261. top: 7rpx;
  262. right: 14rpx;
  263. width: 86rpx;
  264. height: 32rpx;
  265. }
  266. }
  267. .waterfall-item__ft {
  268. padding: 10rpx 20rpx;
  269. padding-top: 0;
  270. padding-left: 0;
  271. &__title {
  272. line-height: 48rpx;
  273. font-weight: 700;
  274. .value {
  275. font-size: 26rpx;
  276. }
  277. }
  278. &__desc {
  279. width: 100%;
  280. // #ifndef APP-NVUE
  281. display: flex;
  282. // #endif
  283. // #ifdef APP-NVUE
  284. // #endif
  285. flex-direction: row;
  286. align-items: center;
  287. justify-content: space-between;
  288. margin: 20rpx 0;
  289. .user {
  290. // #ifndef APP-NVUE
  291. display: flex;
  292. // #endif
  293. // #ifdef APP-NVUE
  294. flex-direction: row;
  295. // #endif
  296. align-items: center;
  297. .avater {
  298. width: 44rpx;
  299. height: 44rpx;
  300. border-radius: 50%;
  301. margin-right: 10rpx;
  302. }
  303. .name {
  304. font-size: 24rpx;
  305. max-width: 80px;
  306. display: inline-block;
  307. color: #999;
  308. }
  309. }
  310. .like {
  311. // #ifndef APP-NVUE
  312. display: flex;
  313. // #endif
  314. // #ifdef APP-NVUE
  315. flex-direction: row;
  316. // #endif
  317. align-items: center;
  318. font-weight: bold;
  319. .like-icon {
  320. width: 30rpx;
  321. height: 30rpx;
  322. margin-right: 10rpx;
  323. }
  324. .value {
  325. font-size: 24rpx;
  326. color: #999;
  327. }
  328. }
  329. }
  330. &__btn {
  331. height: 65rpx;
  332. border-radius: 18px;
  333. background-image: linear-gradient(to bottom, #bffe9c, #aee75d);
  334. // #ifndef APP-NVUE
  335. background: linear-gradient(180deg,
  336. #bffe9c 0%,
  337. #aee75d 62%,
  338. #aee75d 100%);
  339. display: flex;
  340. // #endif
  341. justify-content: center;
  342. align-items: center;
  343. &__icon {
  344. width: 155rpx;
  345. height: 32rpx;
  346. }
  347. }
  348. }
  349. }
  350. </style>