detail.html 13 KB

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