_id.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div class="community-u" ref="container" @scroll="containerScroll">
  3. <div alt="back" class="background"></div>
  4. <div class="userinfo">
  5. <img :src="info.icon_url" alt class="header-avatar"/>
  6. <div class="header-nickname">{{ info.nickname }}</div>
  7. <div class="header-title">{{ info.title }}</div>
  8. <div class="count-infos">
  9. <div class="info">
  10. {{ idInfo.topics_count }}
  11. <span>文章</span>
  12. </div>
  13. <div class="info">
  14. {{ idInfo.fans_count }}
  15. <span>粉丝</span>
  16. </div>
  17. <div class="info">
  18. {{ idInfo.followers_count }}
  19. <span>关注</span>
  20. </div>
  21. </div>
  22. <button
  23. class="focu-btn followed"
  24. v-if="idInfo.has_follow"
  25. @click="doFollow"
  26. >
  27. 已关注
  28. </button>
  29. <button class="focu-btn" v-else @click="doFollow">关注TA</button>
  30. </div>
  31. <div class="content-box">
  32. <div class="content-left">
  33. <div class="arts-title">
  34. 一共
  35. <span style="color: var(--mainColor)">{{ idInfo.topics_count }}</span>
  36. 篇文章
  37. </div>
  38. <div
  39. class="art"
  40. v-for="(art, index) of arts"
  41. :key="index"
  42. @click="clickArt(art, index)"
  43. >
  44. <img v-if="art.cover_url" :src="art.cover_url" alt class="art-img"/>
  45. <section class="art-info">
  46. <h3 class="art-title">{{ art.title }}</h3>
  47. <p class="art-summary">{{ art.intro }}</p>
  48. <div class="art-subinfo">
  49. <div class="author">
  50. <img
  51. :src="info.icon_url"
  52. alt="author-img"
  53. class="author-avatar"
  54. />
  55. <span style="font-size: 10px">{{ info.nickname }}</span>
  56. <span class="create-time">{{ art.updated_at }}</span>
  57. </div>
  58. <div class="art-counts-info">
  59. <div class="good">
  60. <img src="~@/assets/img/community/good_icon.png"/>
  61. <span class="good-count">{{ art.like_count }}</span>
  62. </div>
  63. <div class="comment">
  64. <img src="~@/assets/img/community/comment_icon.png"/>
  65. <span class="comment-count">{{ art.reply_count }}</span>
  66. </div>
  67. </div>
  68. </div>
  69. </section>
  70. </div>
  71. <el-pagination
  72. v-if="$store.state.isPC"
  73. background
  74. layout="prev, pager, next"
  75. :total="+idInfo.topics_count"
  76. :page-size="10"
  77. :current-page="currentPage"
  78. @current-change="changePagination"
  79. ></el-pagination>
  80. </div>
  81. <div class="content-right">
  82. 关注微信
  83. <img src="~@/assets/img/wechat.jpg" alt="wechat" class="qr-code"/>
  84. </div>
  85. </div>
  86. <div class="loading" v-if="isLoading">
  87. <i class="el-icon-loading"></i>
  88. 正在加载
  89. </div>
  90. <div class="loading" v-if="noMore">已加载全部内容</div>
  91. </div>
  92. </template>
  93. <script>
  94. import http from "@/plugins/http";
  95. import WxMixin from "@/mixins/wx";
  96. let container;
  97. let page = 1;
  98. export default {
  99. layout: "opacity_header",
  100. async asyncData({$axios, params, req}) {
  101. let id = params.id;
  102. let headers = req && req.headers;
  103. let res = await $axios.$get(
  104. `/api/user/getUserInfo?id=${id}&page=1&size=10`,
  105. {headers}
  106. );
  107. return {
  108. title: `${res.data.info.nickname}的技术圈主页-程序员客栈`,
  109. };
  110. },
  111. head() {
  112. return {
  113. title: this.title,
  114. script: [{src: "https://res.wx.qq.com/open/js/jweixin-1.2.0.js"}],
  115. };
  116. },
  117. mixins: [WxMixin],
  118. data() {
  119. return {
  120. list: [],
  121. currentPage: 1,
  122. isLoading: false,
  123. noMore: false,
  124. idInfo: {},
  125. };
  126. },
  127. computed: {
  128. info() {
  129. return this.idInfo.info || {};
  130. },
  131. arts() {
  132. return this.idInfo.topics || [];
  133. },
  134. },
  135. mounted() {
  136. container = this.$refs.container;
  137. this.getDetail();
  138. },
  139. methods: {
  140. async getDetail() {
  141. let res = await this.$axios.$get(
  142. `/api/user/getUserInfo?id=${this.$route.params.id}&page=1&size=10`
  143. );
  144. console.log(res.data);
  145. if (res) {
  146. this.idInfo = res.data;
  147. }
  148. },
  149. clickLancer({id}) {
  150. this.$router.push(`/cert/type/${id}`);
  151. },
  152. btnDisabled(item) {
  153. return item.btn_name !== "申请认证" || !item.can_click;
  154. },
  155. async getList() {
  156. let id = this.$route.params.id;
  157. this.isLoading = true;
  158. // console.log(id)
  159. let res = await this.$axios.$get(
  160. `/api/user/getUserInfo?id=${id}&page=${this.currentPage}&size=10`,
  161. {},
  162. {neverLogout: true}
  163. );
  164. this.isLoading = false;
  165. if (res) {
  166. if (this.currentPage === 1 || this.$store.state.isPC) {
  167. this.idInfo = res.data;
  168. } else {
  169. if (!res.data.topics.length) {
  170. this.noMore = true;
  171. return;
  172. }
  173. this.idInfo.topics = [...this.idInfo.topics, ...res.data.topics];
  174. }
  175. }
  176. },
  177. canApply(item) {
  178. return item.end_date && item.is_cert_validate && item.cert_no;
  179. },
  180. configWx() {
  181. try {
  182. let conf = this.$store.state.wxConfig;
  183. wx.ready(function () {
  184. //需在用户可能点击分享按钮前就先调用
  185. wx.config({
  186. debug: true,
  187. appId: conf.appId,
  188. timestamp: conf.timestamp,
  189. nonceStr: conf.nonceStr,
  190. signature: conf.signature,
  191. jsApiList: [
  192. // 所有要调用的 API 都要加到这个列表中
  193. "onMenuShareTimeline", // 分享到朋友圈接口
  194. "onMenuShareAppMessage", // 分享到朋友接口
  195. "onMenuShareQQ", // 分享到QQ接口
  196. "onMenuShareWeibo", // 分享到微博接口
  197. ],
  198. success: function () {
  199. alert("wx.config ok");
  200. },
  201. error: function (d) {
  202. alert("wx.config err:" + JSON.stringify(d));
  203. },
  204. });
  205. wx.updateAppMessageShareData({
  206. title: "开发者资质认证", // 分享标题
  207. desc: "通过平台审核、认证,将获得更多接单机会", // 分享描述
  208. link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  209. imgUrl: "https://stacdn.proginn.com/favicon.ico", // 分享图标
  210. success: function () {
  211. // 设置成功
  212. alert("微信图标设置成功");
  213. },
  214. });
  215. });
  216. } catch (error) {
  217. // alert(error)
  218. }
  219. },
  220. /**
  221. * 修改页码
  222. */
  223. changePagination(page) {
  224. this.currentPage = page;
  225. this.getList();
  226. },
  227. /**
  228. * 点击关注按钮
  229. */
  230. async doFollow() {
  231. // 移动端处理
  232. if (!this.$store.state.isPC && !this.$store.getters.isLogin) {
  233. location.href = "proginn://login";
  234. return;
  235. }
  236. let res = await this.$axios.$post(`/api/user/follow`, {
  237. follow_id: this.$route.params.id,
  238. });
  239. if (res) {
  240. this.idInfo.has_follow = res.data.follow_status ? 1 : 0;
  241. }
  242. },
  243. /**
  244. * 点击文章
  245. */
  246. clickArt(art, index) {
  247. location.href = `/topics/${art.id}.html`;
  248. },
  249. /**
  250. * 监听滚动
  251. */
  252. containerScroll() {
  253. if (this.isLoading || this.noMore) return;
  254. // PC不监听
  255. if (this.$store.state.isPC) return;
  256. if (
  257. container.scrollHeight - container.scrollTop - container.clientHeight <
  258. 50
  259. ) {
  260. this.currentPage++;
  261. this.getList();
  262. }
  263. },
  264. },
  265. };
  266. </script>
  267. <style lang='less' scoped>
  268. @max768: ~"(max-width: 768px)";
  269. .community-u {
  270. min-width: 0;
  271. min-height: 0;
  272. max-width: 1000px;
  273. }
  274. .background {
  275. position: absolute;
  276. left: 0;
  277. top: 0;
  278. width: 100%;
  279. height: 428px;
  280. z-index: -1;
  281. background: url(~@/assets/img/community/u_background.png) 0 0 ~"/" 100% 100% no-repeat;
  282. }
  283. .community-u {
  284. .userinfo {
  285. display: flex;
  286. flex-direction: column;
  287. align-items: center;
  288. height: 350px;
  289. overflow: hidden;
  290. margin-bottom: 10px;
  291. color: white;
  292. margin-top: 20px;
  293. }
  294. }
  295. .header-avatar {
  296. @size: 88px;
  297. width: @size;
  298. height: @size;
  299. border-radius: @size / 2;
  300. }
  301. .header-nickname {
  302. font-size: 16px;
  303. font-weight: 600;
  304. margin: 10px 0 2px;
  305. }
  306. .header-title {
  307. font-size: 10px;
  308. margin-top: 8px;
  309. }
  310. .count-infos {
  311. display: flex;
  312. align-items: center;
  313. margin: 23px 0 30px;
  314. }
  315. .info {
  316. display: flex;
  317. align-items: flex-end;
  318. align-items: center;
  319. font-size: 25px;
  320. font-weight: bold;
  321. margin: 0 16px;
  322. border-right: 1px solid white;
  323. &:last-child {
  324. border-right: none;
  325. }
  326. span {
  327. font-size: 10px;
  328. margin: 0 30px 0 6px;
  329. }
  330. }
  331. .create-time {
  332. font-size: 10px;
  333. color: #999;
  334. border-left: 1px solid #999;
  335. margin-left: 2px;
  336. padding-left: 2px;
  337. }
  338. .focu-btn {
  339. width: 150px;
  340. height: 40px;
  341. background: var(--mainColor);
  342. color: white;
  343. border-radius: 20px;
  344. }
  345. .followed {
  346. background: grey;
  347. }
  348. .content-box {
  349. display: flex;
  350. }
  351. .content-left {
  352. width: 740px;
  353. padding: 20px 20px 40px;
  354. background: white;
  355. }
  356. .art {
  357. display: flex;
  358. margin-top: 20px;
  359. padding-bottom: 20px;
  360. cursor: pointer;
  361. border-bottom: 1px solid #f2f2f2;
  362. }
  363. .art-img {
  364. width: 154px;
  365. height: 114px;
  366. margin-right: 20px;
  367. }
  368. .art-info {
  369. flex: 1;
  370. }
  371. .overflow {
  372. max-width: 520px;
  373. display: block;
  374. overflow: hidden;
  375. text-overflow: ellipsis;
  376. white-space: nowrap;
  377. }
  378. .art-title {
  379. .overflow;
  380. font-size: 18px;
  381. }
  382. .art-summary {
  383. .overflow;
  384. font-size: 10px;
  385. color: #666;
  386. margin-top: 10px;
  387. }
  388. .art-subinfo {
  389. display: flex;
  390. justify-content: space-between;
  391. align-items: center;
  392. margin-top: 50px;
  393. .author-avatar {
  394. margin-right: 4px;
  395. border-radius: 10px;
  396. }
  397. .author {
  398. display: flex;
  399. align-items: center;
  400. }
  401. .author-avatar {
  402. @size: 20px;
  403. width: @size;
  404. height: @size;
  405. }
  406. }
  407. .art-counts-info {
  408. display: flex;
  409. align-items: center;
  410. .good-count,
  411. .comment-count {
  412. font-size: 10px;
  413. font-weight: 500;
  414. color: #999;
  415. }
  416. .good,
  417. .comment {
  418. display: flex;
  419. align-items: center;
  420. img {
  421. @size: 16px;
  422. width: @size;
  423. height: @size;
  424. margin-right: 4px;
  425. }
  426. }
  427. .comment {
  428. margin-left: 10px;
  429. }
  430. }
  431. .content-right {
  432. display: flex;
  433. flex-direction: column;
  434. align-items: center;
  435. width: 250px;
  436. height: 274px;
  437. background: white;
  438. margin-left: 10px;
  439. padding-top: 20px;
  440. .qr-code {
  441. @size: 176px;
  442. width: @size;
  443. height: @size;
  444. margin-top: 20px;
  445. }
  446. }
  447. .arts-title {
  448. padding-bottom: 10px;
  449. border-bottom: 1px solid #f2f2f2;
  450. }
  451. @media @max768 {
  452. .community-u {
  453. width: 100%;
  454. margin-bottom: 0;
  455. height: 100vh;
  456. overflow-y: scroll;
  457. }
  458. .background {
  459. background: url(~@/assets/img/community/u_background_small.png) 0 0 ~"/" 100% 100% no-repeat;
  460. }
  461. .followed {
  462. border: 1px solid white;
  463. background: transparent;
  464. }
  465. .content-left {
  466. display: flex;
  467. flex-direction: column;
  468. align-items: center;
  469. padding: 10px 0 0;
  470. width: 100%;
  471. }
  472. .arts-title {
  473. width: calc(100% - 40px);
  474. }
  475. .art {
  476. flex-direction: row-reverse;
  477. border-bottom: 1px solid rgba(244, 244, 244, 1);
  478. padding-bottom: 10px;
  479. width: calc(100% - 40px);
  480. .art-img {
  481. width: 120px;
  482. height: 90px;
  483. margin-left: 20px;
  484. margin-right: 0;
  485. }
  486. .art-info {
  487. border-bottom: none;
  488. }
  489. .art-title {
  490. white-space: normal;
  491. font-size: 14px;
  492. line-height: 20px;
  493. }
  494. .art-summary {
  495. display: none;
  496. }
  497. }
  498. .art-subinfo {
  499. margin-top: 26px;
  500. }
  501. .content-right {
  502. display: none;
  503. }
  504. .el-pagination {
  505. margin-bottom: 20px;
  506. }
  507. }
  508. .el-pagination {
  509. margin-top: 40px;
  510. text-align: center;
  511. }
  512. .loading {
  513. display: flex;
  514. justify-content: center;
  515. align-items: center;
  516. margin: 20px 0;
  517. }
  518. </style>