card.vue 7.4 KB

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