detail.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>详情</title>
  7. <link rel="stylesheet" href="css/index.css">
  8. <script src="js/axios.min.js"></script>
  9. <script src="js/vue.js"></script>
  10. </head>
  11. <style>
  12. .search_left{
  13. width: 30%;
  14. }
  15. .search_left .list li{
  16. width: 100%;
  17. }
  18. .part{
  19. border-radius: 5px;
  20. }
  21. .search input{
  22. width: 100%;
  23. height: 30px;
  24. border: 1px solid #ccc;
  25. border-radius: 3px;
  26. padding: 0 10px;
  27. margin-bottom: 15px;
  28. outline: none;
  29. text-align: center;
  30. }
  31. .detail_right{
  32. width: 69%;
  33. }
  34. .tag{
  35. margin-top: 10px;
  36. /* padding-left: 20px; */
  37. }
  38. .tag span{
  39. background-color: #000;
  40. color: #fff;
  41. display: inline-block;
  42. padding: 2px 5px;
  43. margin-right: 10px;
  44. font-size: 12px;
  45. border-radius: 2px;
  46. }
  47. .tag a{
  48. color: #333;
  49. float: right;
  50. }
  51. .discuss{
  52. text-align: center;
  53. background-color: #f5f5f5;
  54. padding: 40px 20px;
  55. border: 1px solid #ccc;
  56. }
  57. .answer{
  58. padding: 20px;
  59. line-height: 26px;
  60. text-align: left;
  61. }
  62. .detail_right button{
  63. width: 150px;
  64. height: 40px;
  65. border: none;
  66. background-color: #000;
  67. color: #fff;
  68. font-weight: 600;
  69. border-radius: 3px;
  70. outline: none;
  71. }
  72. .user{
  73. margin-bottom: 10px;
  74. color: #999;
  75. font-size: 13px;
  76. }
  77. .ans{
  78. line-height: 25px;
  79. margin-bottom: 10px;
  80. color: #333;
  81. }
  82. .login_div{
  83. height: 300px;
  84. background-image: linear-gradient(90deg,#0B0B0A,#E1CAA0);
  85. text-align: center;
  86. padding-top: 140px;
  87. border-radius: 10px;
  88. }
  89. </style>
  90. <body>
  91. <section id="app">
  92. <header>
  93. <div class="left_nav">
  94. <img @click="show=!show" class="phone" width="30" src="img/menu.png" alt="">
  95. <img class="logo" src="img/logo.jpg" alt="logo">
  96. </div>
  97. <div class="nav">
  98. <a class="act" href="/index.html">猿人学面试</a>
  99. <a href="">爬虫比赛</a>
  100. <a href="">关于猿人学</a>
  101. </div>
  102. <div class="login">
  103. <div class="pc">
  104. <img width="30px" src="img/logo.jpg" alt="logo">
  105. <div v-if="userInfo" class="menu">
  106. {{userInfo.name}}
  107. <ul>
  108. <li><a href="/record.html">我的刷题记录</a></li>
  109. <li @click="logout"><a>退出登录</a></li>
  110. </ul>
  111. </div>
  112. <a v-else href="/login.html">请先登录</a>
  113. </div>
  114. <div class="phone">
  115. <span v-if="userInfo">{{userInfo.name}}</span>
  116. <a v-else href="/login.html">请先登录</a>
  117. </div>
  118. </div>
  119. </header>
  120. <transition name="slide">
  121. <div class="slide" v-if="show">
  122. <a class="act" href="/index.html">猿人学面试</a>
  123. <a href="">爬虫比赛</a>
  124. <a href="">关于猿人学</a>
  125. <a v-if="userInfo" href="/record.html">我的刷题记录</a>
  126. <a v-if="userInfo" @click="logout">退出登录</a>
  127. </div>
  128. </transition>
  129. <div class="content">
  130. <p class="navtation"><a href="/index.html">回到首页</a> - <a href="/list.html">
  131. <span v-if="detail.category=='crawler'">爬虫</span>
  132. <span v-else-if="detail.category=='js'">JS</span>
  133. <span v-else>安卓</span>面试题</a> - {{detail.name}}</p>
  134. <div class="left search_left">
  135. <div class="part">
  136. <p class="search">
  137. <input type="text" v-model="searchKeyword" @input="search" placeholder="题目搜索">
  138. </p>
  139. <ul class="list">
  140. <li v-for="item in list" :key="item.interviewId"><a :href="'/detail.html?id='+item.interviewId">{{item.name}}</a></li>
  141. </ul>
  142. </div>
  143. <div class="part">
  144. <h2 class="sec_title"><span>贡献面试题</span></h2>
  145. <form class="form">
  146. <input v-model="name" type="text" placeholder="面试题目">
  147. <textarea v-model="content"></textarea>
  148. <button type="button" @click="post">提交</button>
  149. </form>
  150. </div>
  151. </div>
  152. <div class="right detail_right">
  153. <div class="part">
  154. <b>{{detail.name}}</b>
  155. <p class="tag">
  156. <span>{{detail.category}}</span>
  157. <a href="">分享给朋友</a>
  158. </p>
  159. </div>
  160. <div class="part">
  161. <h2 class="sec_title"><span>答题讨论</span></h2>
  162. <div class="discuss answer" v-if="userInfo">
  163. {{detail.content}}
  164. </div>
  165. <div class="discuss" v-else>
  166. <button @click="login">请登录</button>
  167. </div>
  168. </div>
  169. <div class="part">
  170. <h2 class="sec_title"><span>网友热议</span></h2>
  171. <template v-for="(item,index) in comment">
  172. <template v-if="index == 0">
  173. <p class="user">
  174. {{item.cname}} {{item.ctime}}
  175. </p>
  176. <p class="ans">
  177. {{item.content}}
  178. </p>
  179. </template>
  180. <template v-else-if="index > 0 && userInfo">
  181. <p class="user">
  182. {{item.cname}} {{item.ctime}}
  183. </p>
  184. <p class="ans">
  185. {{item.content}}
  186. </p>
  187. </template>
  188. </template>
  189. <div class="login_div" v-if="!userInfo">
  190. <button @click="login">登录后查看全部</button>
  191. </div>
  192. <div class="comment" v-if="userInfo">
  193. <textarea v-model="form.content" placeholder="留下你的想法..."></textarea>
  194. <button style="width: 100px;" @click="sendComment">提交评论</button>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </section>
  200. <script src="js/public.js"></script>
  201. <script>
  202. const { createApp } = Vue;
  203. createApp({
  204. data() {
  205. return {
  206. name: '',
  207. content: '',
  208. userInfo: {},
  209. id: '',
  210. detail: {},
  211. comment: [],
  212. form: {
  213. content: '',
  214. interviewName: '',
  215. interviewId: ''
  216. },
  217. searchKeyword: '', // 添加 searchKeyword 变量
  218. list: [], // 添加 list 变量用于存储题目列表
  219. show: 0 // 添加 show 变量
  220. }
  221. },
  222. created() {
  223. this.id = new URLSearchParams(window.location.search).get('id') || '';
  224. // 获取本地存储的用户ID并赋值给cid
  225. const userInfo = JSON.parse(localStorage.getItem('userInfo'));
  226. this.userInfo = userInfo;
  227. this.getData();
  228. this.getComment();
  229. },
  230. methods: {
  231. login() {
  232. window.location.href = '/login.html';
  233. },
  234. getData() {
  235. // 列表
  236. axios.get(url + '/api/yrx/que/info?interviewId=' + this.id).then(res => {
  237. if (res.data.code === 0) {
  238. this.detail = res.data.data;
  239. this.form.interviewId = this.detail.interviewId;
  240. this.form.interviewName = this.detail.name;
  241. }
  242. });
  243. // 获取题目列表
  244. axios.get(url + '/api/yrx/que/list').then(res => {
  245. if (res.data.code === 0) {
  246. this.list = res.data.data.list;
  247. }
  248. });
  249. },
  250. getComment() {
  251. axios.get(url + '/api/yrx/que/comments/list?interviewId=' + this.id).then(res => {
  252. if (res.data.code === 0) {
  253. this.comment = res.data.data.list;
  254. }
  255. });
  256. },
  257. sendComment() {
  258. if (!this.form.content) {
  259. alert('评论内容不能为空');
  260. return;
  261. }
  262. const token = localStorage.getItem('token'); // 获取token
  263. axios.post(url + '/api/yrx/que/comments', this.form, {
  264. headers: {
  265. 'Authorization': `${token}` // 添加token到header
  266. }
  267. })
  268. .then(res => {
  269. if (res.data.code === 0) {
  270. alert('评论成功');
  271. this.form.content = '';
  272. this.getComment();
  273. }
  274. })
  275. .catch(err => {
  276. alert('评论失败,请重试');
  277. console.error(err);
  278. });
  279. },
  280. post() { // 添加post方法
  281. if (!this.name || !this.content) {
  282. alert('面试题目和内容不能为空');
  283. return;
  284. }
  285. const token = localStorage.getItem('token'); // 获取token
  286. axios.post(url + '/api/yrx/que/user/post', { name: this.name, content: this.content }, {
  287. headers: {
  288. 'Authorization': `${token}` // 添加token到header
  289. }
  290. })
  291. .then(res => {
  292. if (res.data.code === 0) {
  293. alert('提交成功');
  294. this.name = '';
  295. this.content = '';
  296. }
  297. })
  298. .catch(err => {
  299. alert('提交失败,请重试');
  300. console.error(err);
  301. });
  302. },
  303. search() { // 添加 search 方法
  304. axios.get(url + '/api/yrx/que/list', {
  305. params: {
  306. name: this.searchKeyword,
  307. category:this.detail.category,
  308. page:1,
  309. page_size:1000
  310. }
  311. })
  312. .then(res => {
  313. if (res.data.code === 0) {
  314. this.list = res.data.data.list;
  315. }
  316. })
  317. },
  318. logout() { // 添加 logout 方法
  319. localStorage.removeItem('userInfo');
  320. localStorage.removeItem('token');
  321. this.userInfo = null;
  322. }
  323. }
  324. }).mount('#app');
  325. </script>
  326. </body>
  327. </html>