myHome.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <view class="container" v-if="userInfo !== null">
  3. <!-- 页面标题 -->
  4. <view class="title" :style="{ height: customBarH * 2 + 'rpx', top: statusBarH * 2 + 'rpx' }" v-if="!headerType">个人主页</view>
  5. <view class="title_icon" :style="{ height: customBarH * 2 + 'rpx', top: statusBarH * 2 + 'rpx' }" v-if="!headerType" @click="handleBack">
  6. <img src="../../static/index/left.png" />
  7. </view>
  8. <view class="title" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx', backgroundColor: '#fff', color: '#000' }" v-if="headerType">
  9. 个人主页
  10. </view>
  11. <view class="title_icon" :style="{ height: customBarH * 2 + 'rpx', top: statusBarH * 2 + 'rpx' }" v-if="headerType" @click="handleBack">
  12. <img src="../../static/index/left2.png" />
  13. </view>
  14. <!-- 顶部用户信息区域 -->
  15. <view class="header">
  16. <img src="https://jinganminsu-1320402385.cos.ap-nanjing.myqcloud.com/static//20240523163442_12.png" />
  17. <!-- 头像区域 -->
  18. <img class="img" mode="aspectFill" :src="userInfo.image || '../../static/my/portrait.png'" />
  19. <!-- 姓名区域 -->
  20. <view class="name">{{ userInfo.userName }}</view>
  21. <view class="follow" v-if="userInfo.isFollow !== 2" @click="handleFollow">{{ info.isFollow === 0 ? '关注' : '已关注' }}</view>
  22. <!-- 用户id区域 -->
  23. <view class="number">ID:{{ userInfo.id }}</view>
  24. <!-- 简介区域 -->
  25. <view class="desc" v-if="!showInput" @click="handleClickInput">{{ userInfo.descript }}</view>
  26. <view class="desc_input" v-else>
  27. <input type="text" confirm-type="done" auto-focus placeholder-style="color:#ccc" placeholder="请输入简介" @blur="handleBlur" @confirm="handleClickDesc" />
  28. </view>
  29. <!-- 粉丝 关注 获赞 区域 -->
  30. <view class="info">
  31. <!-- 粉丝区域 -->
  32. <view class="info_box">
  33. <view class="box_num">{{ userInfo.fansNum }}</view>
  34. <view class="box_key">粉丝</view>
  35. </view>
  36. <!-- 关注区域 -->
  37. <view class="info_box">
  38. <view class="box_num">{{ userInfo.followNum }}</view>
  39. <view class="box_key">关注</view>
  40. </view>
  41. <!-- 获赞区域 -->
  42. <view class="info_box">
  43. <view class="box_num">{{ userInfo.likeNum }}</view>
  44. <view class="box_key">获赞</view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 内容区域 -->
  49. <view class="body">
  50. <!-- 分段器区域 -->
  51. <view class="control">
  52. <uni-segmented-control :current="current" :values="items" style-type="text" active-color="#096562" @clickItem="onClickItem" />
  53. </view>
  54. <!-- 推文列表区域 -->
  55. <view class="list" v-if="list.length">
  56. <!-- 每一个推文区域 -->
  57. <view class="item_box" v-for="item in list" :key="item.id" @click="handleGoDetail(item)">
  58. <!-- 视频推文 -->
  59. <view class="box_video" v-if="item.video">
  60. <!-- :show-play-btn="false" -->
  61. <video
  62. :id="'id' + item.id"
  63. :show-fullscreen-btn="false"
  64. :direction="0"
  65. :src="item.video"
  66. @fullscreenchange="fullscreenchange"
  67. @click.stop="handleClickVideo('id' + item.id)"
  68. ></video>
  69. </view>
  70. <!-- 图片推文 -->
  71. <view class="box_image" v-if="item.images">
  72. <view class="image_box" v-for="(ele, index) in item.images" :key="index">
  73. <img mode="aspectFill" :src="ele" @click.stop="handleLookImg(item.images, index)" />
  74. </view>
  75. </view>
  76. <!-- 标题区域 -->
  77. <view class="box_title">{{ item.title }}</view>
  78. <view class="box_info">
  79. <view class="info_time">{{ item.date.slice(0, 19) }}</view>
  80. <view class="info_town">{{ item.townName }}</view>
  81. <img class="img" :src="item.isLike === 0 ? '../../static/index/upvote.png' : '../../static/index/upvote-active.png'" @click.stop="handleClickLike(item)" />
  82. <view class="info_like">{{ item.likeNum }}</view>
  83. <img class="img2" src="../../static/index/comment.png" />
  84. <view class="info_comment">{{ item.commentNum }}</view>
  85. <!-- 审核中印章区域 -->
  86. <img v-if="item.approve === 1" class="box_audit" src="../../static/index/audit.png" />
  87. <!-- 已驳回印章区域 -->
  88. <img v-if="item.approve === 3" class="box_rejected" src="../../static/index/rejected.png" />
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 没有数据时展示的区域 -->
  93. <view class="noData" v-else>
  94. <img src="../../static/images/noData.png" />
  95. 暂无数据
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. export default {
  102. data() {
  103. return {
  104. // 是否是本人
  105. isSelf: true,
  106. // 用户信息
  107. userInfo: null,
  108. // 状态栏高度
  109. statusBarH: 0,
  110. // 胶囊按钮栏高度
  111. customBarH: 0,
  112. // 顶部页面标题栏显示隐藏控制
  113. headerType: false,
  114. // 简介输入框显示隐藏控制
  115. showInput: false,
  116. // 分段器当前索引
  117. current: 0,
  118. // 分段器数组
  119. items: ['全部推文', '审核中', '驳回'],
  120. // 推文列表数组
  121. list: [],
  122. // video 上下文 videoContext 对象
  123. videoContext: null,
  124. // 是否是全屏状态
  125. isFullScreen: false,
  126. // 当前用户id
  127. userId: '',
  128. // 当前页
  129. page: 1,
  130. // 每页多少条
  131. rows: 6,
  132. // 总条数
  133. total: null
  134. }
  135. },
  136. created() {
  137. // 获取系统信息
  138. uni.getSystemInfo({
  139. success: (e) => {
  140. // 获取状态栏高度
  141. this.statusBarH = e.statusBarHeight + 10
  142. // // 获取菜单按钮栏高度
  143. let custom = uni.getMenuButtonBoundingClientRect()
  144. this.customBarH = custom.height + 10
  145. }
  146. })
  147. },
  148. onPageScroll(e) {
  149. if (e.scrollTop > 50) {
  150. this.headerType = true
  151. } else {
  152. this.headerType = false
  153. }
  154. },
  155. onLoad(options) {
  156. let id = uni.getStorageSync('userInfo').id
  157. this.userId = options.userId
  158. if (id != this.userId) {
  159. this.isSelf = false
  160. this.items = ['全部推文']
  161. }
  162. this.getUserInfo()
  163. this.getTweetList()
  164. },
  165. onReachBottom() {
  166. if (this.list.length < this.total) {
  167. this.page++
  168. this.getTweetList()
  169. } else {
  170. uni.showToast({
  171. title: '没有更多数据了',
  172. icon: 'none'
  173. })
  174. }
  175. },
  176. methods: {
  177. // 获取个人信息
  178. async getUserInfo() {
  179. const res = await this.$myRequest({
  180. url: '/mhotel/articlequeryUserInfo.action',
  181. data: {
  182. userId: this.userId
  183. }
  184. })
  185. // console.log(res)
  186. if (res.code === 200) {
  187. this.userInfo = res.data
  188. }
  189. },
  190. // 获取推文列表数组
  191. async getTweetList() {
  192. const res = await this.$myRequest({
  193. url: '/mhotel/articlequeryOwnerArticlePage.action',
  194. data: {
  195. userId: this.userId,
  196. type: this.current,
  197. page: this.page,
  198. rows: this.rows
  199. }
  200. })
  201. // console.log(res)
  202. if (res.code === 200) {
  203. this.list = [...this.list, ...res.data.pageList]
  204. this.total = res.data.total
  205. }
  206. },
  207. // 关注或者取消关注请求
  208. async handleFollow() {
  209. const res = await this.$myRequest({
  210. url: '/mhotel/articlefollowAuthor.action',
  211. data: {
  212. authorId: this.userInfo.id,
  213. userId: uni.getStorageSync('userInfo').id
  214. }
  215. })
  216. // console.log(res)
  217. if (res.code === 200) {
  218. this.userInfo.isFollow === 0 ? (this.userInfo.isFollow = 1) : (this.userInfo.isFollow = 0)
  219. }
  220. },
  221. handleGoDetail(item) {
  222. if (item.approve === 2) {
  223. uni.navigateTo({
  224. url: `/pagesSub/tweetDetail/tweetDetail?id=${item.id}&townId=${item.townId}`
  225. })
  226. }
  227. },
  228. // 进入全屏和退出全屏时触发的回调
  229. fullscreenchange(e) {
  230. this.isFullScreen = e.detail.fullScreen
  231. },
  232. // 点击视频控件时触发的回调
  233. handleClickVideo(id) {
  234. this.videoContext = uni.createVideoContext(id)
  235. if (this.isFullScreen) {
  236. this.videoContext.pause()
  237. this.videoContext.exitFullScreen()
  238. } else {
  239. this.videoContext.requestFullScreen()
  240. this.videoContext.play()
  241. }
  242. },
  243. // 左上角返回按钮回调
  244. handleBack() {
  245. uni.navigateBack(1)
  246. },
  247. handleClickInput() {
  248. if (this.isSelf) {
  249. this.showInput = true
  250. }
  251. },
  252. async handleClickDesc(e) {
  253. this.showInput = false
  254. if (e.detail.value.length > 12) {
  255. uni.showToast({
  256. title: '简介不能超过12个字,请重新输入',
  257. icon: 'none',
  258. mask: true
  259. })
  260. return
  261. }
  262. let id = uni.getStorageSync('userInfo').id
  263. const res = await this.$myRequest({
  264. url: '/mhotel/articleupdateDescript.action',
  265. data: {
  266. descript: e.detail.value,
  267. authorId: id,
  268. userId: id
  269. }
  270. })
  271. // console.log(res);
  272. if (res.code === 200) {
  273. uni.showToast({
  274. title: res.message,
  275. icon: 'success',
  276. mask: true
  277. })
  278. setTimeout(() => {
  279. this.getUserInfo()
  280. }, 1500)
  281. }
  282. },
  283. handleBlur() {
  284. this.showInput = false
  285. },
  286. // 分段器切换回调
  287. onClickItem(e) {
  288. this.current = e.currentIndex
  289. this.list = []
  290. this.page = 1
  291. this.getTweetList()
  292. },
  293. // 点击图片回调
  294. handleLookImg(urls, current) {
  295. uni.previewImage({
  296. urls,
  297. current
  298. })
  299. },
  300. async handleClickLike(item) {
  301. const res = await this.$myRequest({
  302. url: '/mhotel/articlelikeArticle.action',
  303. data: {
  304. id: item.id,
  305. userId: this.userId
  306. }
  307. })
  308. // console.log(res);
  309. if (res.code === 200) {
  310. item.isLike === 1 ? ((item.isLike = 0), (item.likeNum -= 1)) : ((item.isLike = 1), (item.likeNum += 1))
  311. }
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .container {
  318. position: relative;
  319. min-height: 100vh;
  320. .title {
  321. z-index: 999;
  322. position: fixed;
  323. top: 0;
  324. left: 0;
  325. right: 0;
  326. font-size: 28rpx;
  327. color: #fff;
  328. text-align: center;
  329. }
  330. .title_icon {
  331. z-index: 999;
  332. position: fixed;
  333. top: 0;
  334. left: 10rpx;
  335. right: 0;
  336. img {
  337. width: 47rpx;
  338. height: 47rpx;
  339. }
  340. }
  341. .header {
  342. position: relative;
  343. height: 510rpx;
  344. color: #fff;
  345. overflow: hidden;
  346. img {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. .img {
  351. position: absolute;
  352. top: 190rpx;
  353. left: 32rpx;
  354. width: 140rpx;
  355. height: 140rpx;
  356. border-radius: 50%;
  357. }
  358. .name {
  359. position: absolute;
  360. top: 200rpx;
  361. left: 202rpx;
  362. font-size: 40rpx;
  363. font-weight: bold;
  364. }
  365. .follow {
  366. position: absolute;
  367. top: 206rpx;
  368. left: 580rpx;
  369. display: flex;
  370. align-items: center;
  371. padding: 0 30rpx;
  372. font-size: 28rpx;
  373. border-radius: 70rpx;
  374. border: 1rpx solid #fff;
  375. }
  376. .number {
  377. position: absolute;
  378. top: 265rpx;
  379. left: 202rpx;
  380. font-size: 24rpx;
  381. opacity: 0.5;
  382. }
  383. .desc {
  384. position: absolute;
  385. top: 350rpx;
  386. left: 32rpx;
  387. font-size: 28rpx;
  388. color: #fff;
  389. }
  390. .desc_input {
  391. position: absolute;
  392. top: 350rpx;
  393. left: 32rpx;
  394. width: 300rpx;
  395. height: 40rpx;
  396. line-height: 40rpx;
  397. font-size: 28rpx;
  398. border-radius: 15rpx;
  399. border: 1rpx solid #fff;
  400. input {
  401. box-sizing: border-box;
  402. padding: 0 10rpx;
  403. width: 100%;
  404. height: 100%;
  405. }
  406. }
  407. .info {
  408. position: absolute;
  409. top: 410rpx;
  410. left: 0rpx;
  411. display: flex;
  412. font-size: 28rpx;
  413. color: #fff;
  414. .info_box {
  415. display: flex;
  416. flex-direction: column;
  417. align-items: center;
  418. padding: 0 20rpx 0 35rpx;
  419. .box_num {
  420. }
  421. .box_key {
  422. }
  423. }
  424. }
  425. }
  426. .body {
  427. position: absolute;
  428. top: 510rpx;
  429. box-sizing: border-box;
  430. width: 100%;
  431. min-height: calc(100vh - 510rpx);
  432. border-radius: 20rpx 20rpx 0 0;
  433. background-color: #f7f7f7;
  434. .control {
  435. padding: 0 100rpx;
  436. height: 95rpx;
  437. background-color: #fff;
  438. }
  439. .list {
  440. padding: 20rpx 30rpx;
  441. .item_box {
  442. margin-bottom: 22rpx;
  443. padding-bottom: 30rpx;
  444. width: 690rpx;
  445. border-radius: 12rpx;
  446. border-bottom: 1rpx solid #e6e6e6;
  447. background-color: #fff;
  448. .box_video {
  449. height: 335rpx;
  450. border-radius: 12rpx;
  451. background-color: skyblue;
  452. video {
  453. width: 100%;
  454. height: 100%;
  455. }
  456. }
  457. .box_image {
  458. display: grid;
  459. grid-template-columns: repeat(3, 1fr);
  460. grid-auto-rows: auto;
  461. gap: 20rpx;
  462. .image_box {
  463. width: 216rpx;
  464. height: 126rpx;
  465. img {
  466. width: 100%;
  467. height: 100%;
  468. border-radius: 12rpx;
  469. }
  470. }
  471. }
  472. .box_title {
  473. padding: 10rpx 25rpx;
  474. font-size: 28rpx;
  475. font-weight: bold;
  476. }
  477. .box_info {
  478. position: relative;
  479. display: flex;
  480. align-items: center;
  481. padding-left: 25rpx;
  482. color: #999999;
  483. font-size: 24rpx;
  484. .info_time {
  485. }
  486. .info_town {
  487. margin-left: 15rpx;
  488. }
  489. .img {
  490. margin-left: auto;
  491. width: 28rpx;
  492. height: 28rpx;
  493. }
  494. .info_like {
  495. margin-left: 10rpx;
  496. }
  497. .img2 {
  498. margin-left: 15rpx;
  499. width: 25rpx;
  500. height: 25rpx;
  501. }
  502. .info_comment {
  503. margin: 0 10rpx;
  504. }
  505. .box_audit {
  506. position: absolute;
  507. top: -45rpx;
  508. left: 410rpx;
  509. width: 100rpx;
  510. height: 100rpx;
  511. }
  512. .box_rejected {
  513. position: absolute;
  514. top: -45rpx;
  515. left: 410rpx;
  516. width: 100rpx;
  517. height: 100rpx;
  518. }
  519. }
  520. }
  521. }
  522. .noData {
  523. display: flex;
  524. flex-direction: column;
  525. justify-content: center;
  526. align-items: center;
  527. img {
  528. margin-top: 60rpx;
  529. width: 400rpx;
  530. height: 400rpx;
  531. }
  532. }
  533. }
  534. }
  535. </style>