card.vue 7.2 KB

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