card.vue 8.0 KB

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