detail.html 15 KB

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