list.html 8.0 KB

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