card.vue 7.5 KB

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