card.vue 7.2 KB

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