card.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. // #ifndef APP-NVUE
  204. .waterfall-item__image {
  205. width: 100%;
  206. height: auto;
  207. box-sizing: border-box;
  208. padding: 28rpx 20rpx;
  209. image {
  210. width: 100%;
  211. height: 100%;
  212. }
  213. }
  214. // #endif
  215. .waterfall-item__tips {
  216. position: absolute;
  217. top: 10rpx;
  218. padding: 0rpx 10rpx;
  219. // #ifndef APP-NVUE
  220. box-sizing: border-box;
  221. // #endif
  222. width: 100%;
  223. display: flex;
  224. flex-direction: row;
  225. align-items: center;
  226. justify-content: space-between;
  227. .item {
  228. // #ifndef APP-NVUE
  229. // #endif
  230. display: flex;
  231. flex-direction: row;
  232. align-items: center;
  233. background: rgba(0, 0, 0, 0.2);
  234. padding: 4rpx 14rpx;
  235. border-radius: 12rpx;
  236. .look-icon {
  237. width: 26rpx;
  238. height: 26rpx;
  239. margin-right: 10rpx;
  240. }
  241. .value {
  242. font-size: 20rpx;
  243. }
  244. }
  245. }
  246. .waterfall-item__ft {
  247. padding: 10rpx 20rpx;
  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: 36rpx;
  276. height: 36rpx;
  277. border-radius: 18rpx;
  278. margin-right: 10rpx;
  279. }
  280. .name {
  281. font-size: 24rpx;
  282. }
  283. }
  284. .like {
  285. // #ifndef APP-NVUE
  286. display: flex;
  287. // #endif
  288. // #ifdef APP-NVUE
  289. flex-direction: row;
  290. // #endif
  291. align-items: center;
  292. .like-icon {
  293. width: 30rpx;
  294. height: 30rpx;
  295. margin-right: 10rpx;
  296. }
  297. .value {
  298. font-size: 24rpx;
  299. }
  300. }
  301. }
  302. &__btn {
  303. height: 65rpx;
  304. border-radius: 18px;
  305. background-image: linear-gradient(to bottom, #bffe9c, #aee75d);
  306. // #ifndef APP-NVUE
  307. background: linear-gradient(
  308. 180deg,
  309. #bffe9c 0%,
  310. #aee75d 62%,
  311. #aee75d 100%
  312. );
  313. display: flex;
  314. // #endif
  315. justify-content: center;
  316. align-items: center;
  317. &__icon {
  318. width: 155rpx;
  319. height: 32rpx;
  320. }
  321. }
  322. }
  323. }
  324. </style>