card.vue 8.2 KB

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