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