list.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #list li{
  13. width: 95% !important;
  14. line-height: 55px;
  15. font-size: 14px;
  16. border-bottom: 1px solid #BBBBBB20;
  17. }
  18. #list li a{
  19. color: #0065D7;
  20. }
  21. </style>
  22. <body>
  23. <section id="app">
  24. <header>
  25. <div class="left_nav">
  26. <img @click="show=!show" class="phone" width="30" src="img/menu.png" alt="">
  27. <img class="logo" src="img/logo.jpg" alt="logo">
  28. </div>
  29. <div class="nav">
  30. <a class="act" href="/index.html">猿人学面试</a>
  31. <a href="">爬虫比赛</a>
  32. <a href="">关于猿人学</a>
  33. </div>
  34. <div class="login">
  35. <div class="pc">
  36. <img width="30px" src="img/logo.jpg" alt="logo">
  37. <div v-if="userInfo" class="menu">
  38. {{userInfo.name}}
  39. <ul>
  40. <li><a href="/record.html">我的刷题记录</a></li>
  41. <li @click="logout"><a>退出登录</a></li>
  42. </ul>
  43. </div>
  44. <a v-else href="/login.html">请先登录</a>
  45. </div>
  46. <div class="phone">
  47. <span v-if="userInfo">{{userInfo.name}}</span>
  48. <a v-else href="/login.html">请先登录</a>
  49. </div>
  50. </div>
  51. </header>
  52. <transition name="slide">
  53. <div class="slide" v-if="show">
  54. <a class="act" href="/index.html">猿人学面试</a>
  55. <a href="">爬虫比赛</a>
  56. <a href="">关于猿人学</a>
  57. <a v-if="userInfo" href="/record.html">我的刷题记录</a>
  58. <a v-if="userInfo" @click="logout">退出登录</a>
  59. </div>
  60. </transition>
  61. <div class="content">
  62. <div class="left">
  63. <div class="banner" style="align-items: anchor-center;display: flex;padding: 0 10px;">
  64. <img align="left" width='100' height="100" :src="img[0]" alt="">
  65. <p style="color: #333;text-align: left;padding: 10px;">
  66. 描述描述描述描述描述描述描述描述描述描述描述描述
  67. </p>
  68. </div>
  69. </div>
  70. <div class="right">
  71. <div class="banner">
  72. <img width="100%" height="100%" :src="img[1]" alt="">
  73. </div>
  74. </div>
  75. <p class="navtation"><a href="/index.html">回到首页</a> -
  76. <span v-if="parm.category=='crawler'">爬虫</span>
  77. <span v-else-if="parm.category=='js'">JS</span>
  78. <span v-else>安卓</span>
  79. 面试题</p>
  80. <div class="left">
  81. <div class="part">
  82. <ul class="list" id="list">
  83. <li v-for="item in list">
  84. <a :href="'/detail.html?cat='+parm.category+'&id='+item.interviewId">{{item.name}}</a>
  85. </li>
  86. </ul>
  87. <p class="page">
  88. <button :disabled="parm.page==1?'disabled':false" @click="parm.page--,getData()">上一页</button>
  89. <span><b>{{parm.page}}</b>/{{pages}}</span>
  90. <button :disabled="parm.page==pages?'disabled':false" @click="parm.page++,getData()">下一页</button>
  91. </p>
  92. </div>
  93. </div>
  94. <div class="right">
  95. <div class="part">
  96. <h2 class="sec_title"><span>面试排行榜</span> <a href="">更多</a></h2>
  97. <ul class="list list_100">
  98. <li v-for="item in top"><a href="">{{item.cname}}</a><span>{{item.count}}</span></li>
  99. </ul>
  100. </div>
  101. <div class="part">
  102. <h2 class="sec_title"><span>贡献面试题</span></h2>
  103. <form class="form" action="">
  104. <input v-model="name" type="text" placeholder="面试题目">
  105. <textarea v-model="content"></textarea>
  106. <button type="button" @click="post">提交</button>
  107. </form>
  108. </div>
  109. </div>
  110. </div>
  111. </section>
  112. <script src="js/public.js"></script>
  113. <script>
  114. const { createApp } = Vue;
  115. createApp({
  116. data() {
  117. return {
  118. list:[],
  119. parm:{
  120. category:'js',
  121. page:1,
  122. page_size:20
  123. },
  124. total:0,
  125. img:[],
  126. top:[],
  127. name: '',
  128. content: '',
  129. show: 0, // 添加 show 变量
  130. userInfo: {} // 添加 userInfo 变量
  131. }
  132. },
  133. computed:{
  134. pages(){
  135. return Math.ceil(this.total/20);
  136. }
  137. },
  138. created(){
  139. this.parm.category = new URLSearchParams(window.location.search).get('cat') || 'js'; // 获取URL中的cat参数并赋值给category
  140. this.getData();
  141. const userInfo = JSON.parse(localStorage.getItem('userInfo')); // 获取本地存储的用户信息
  142. this.userInfo = userInfo;
  143. },
  144. methods:{
  145. getData(){
  146. // 首页
  147. axios.get(url+'/api/yrx/banner/list?position=index_left').then(res=>{
  148. this.img[0] = res.data.data[0].img;
  149. })
  150. axios.get(url+'/api/yrx/banner/list?position=index_right').then(res=>{
  151. this.img[1] = res.data.data[0].img;
  152. })
  153. axios.get(url+'/api/yrx/que/user/top').then(res=>{
  154. this.top = res.data.data;
  155. })
  156. // 列表
  157. axios.get(url+'/api/yrx/que/list', { params: this.parm }).then(res=>{
  158. this.list = res.data.data.list;
  159. this.total = res.data.data.total;
  160. })
  161. },
  162. post(){ // 添加post方法
  163. if (!this.name || !this.content) {
  164. alert('面试题目和内容不能为空');
  165. return;
  166. }
  167. const token = localStorage.getItem('token'); // 获取token
  168. axios.post(url+'/api/yrx/que/user/post', { name: this.name, content: this.content }, {
  169. headers: {
  170. 'Authorization': `${token}` // 添加token到header
  171. }
  172. })
  173. .then(res => {
  174. if(res.data.code === 0){
  175. alert('提交成功');
  176. this.name = '';
  177. this.content = '';
  178. }
  179. })
  180. .catch(err => {
  181. alert('提交失败,请重试');
  182. console.error(err);
  183. });
  184. },
  185. logout() { // 添加 logout 方法
  186. localStorage.removeItem('userInfo');
  187. localStorage.removeItem('token');
  188. this.userInfo = null;
  189. }
  190. }
  191. }).mount('#app');
  192. </script>
  193. </body>
  194. </html>