index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <div class="search">
  3. <Header
  4. :headerBg="'#299772'"
  5. :headerBorder="'#30A47D'"
  6. :userBg="'rgba(0, 0, 0, 0.08)'"
  7. :LoginNavIndex="-1"
  8. />
  9. <div class="banner">
  10. <a class="goback" @click="$router.go(-1)"
  11. ><i class="el-icon-arrow-left"></i>返回</a
  12. >
  13. <img src="../../assets/search-big.png" />
  14. </div>
  15. <SearchInput
  16. class="search-compent"
  17. :selectIndex="selectIndex"
  18. @changeSelectIndex="changeSelectIndex"
  19. :isIndex="true"
  20. />
  21. <div class="main">
  22. <div v-if="lastSearchList.length > 0">
  23. <h2>搜索历史</h2>
  24. <ul>
  25. <li v-for="(item, index) in lastSearchList" :key="index">
  26. <b @click="goto(item)">{{ item }}</b>
  27. <i class="el-icon-close" @click="handleDelete(index)"></i>
  28. </li>
  29. </ul>
  30. </div>
  31. <div v-if="hotSearchList.length > 0">
  32. <h2>热门搜索</h2>
  33. <ul class="hotSearch">
  34. <li
  35. v-for="(item, index) in hotSearchList"
  36. :key="index"
  37. :class="[index % 3 == 2 ? 'noMargin' : '']"
  38. @click="goto(item)"
  39. >
  40. <span :class="['xuhao_' + index]">{{ index + 1 }}</span>
  41. <b :title="item">{{ item }}</b>
  42. </li>
  43. </ul>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  50. //例如:import 《组件名称》from ‘《组件路径》';
  51. import Header from "../../components/Header.vue";
  52. import SearchInput from "./components/SearchInput.vue";
  53. import { getLogin } from "@/api/ajax";
  54. export default {
  55. //import引入的组件需要注入到对象中才能使用
  56. components: { Header, SearchInput },
  57. props: {},
  58. data() {
  59. //这里存放数据
  60. return {
  61. selectIndex: 0,
  62. hotSearchList: [],
  63. lastSearchList: [], // 查询记录列表
  64. config: this.$route.query.headerConfig
  65. ? decodeURIComponent(this.$route.query.headerConfig)
  66. : "",
  67. LoginNavIndex: 0,
  68. userBg: "rgba(0, 0, 0, 0.24)",
  69. headerBorder: "#5C5C5C",
  70. headerBg: "#1F1F1F",
  71. };
  72. },
  73. //计算属性 类似于data概念
  74. computed: {},
  75. //监控data中数据变化
  76. watch: {},
  77. //方法集合
  78. methods: {
  79. // 删除热门查询某条
  80. handleDelete(index) {
  81. this.lastSearchList.splice(index, 1);
  82. },
  83. goto(content) {
  84. this.$router.push({
  85. path: "/search/detail",
  86. query: {
  87. content: content,
  88. headerConfig: encodeURIComponent(this.config),
  89. },
  90. });
  91. },
  92. // 查询系统搜索关键热词
  93. getHotWordList() {
  94. let MethodName = "/PaperServer/Client/Search/QueryHotWordList";
  95. let data = {
  96. limit: 9,
  97. };
  98. getLogin(MethodName, data).then((res) => {
  99. if (res.status === 1) {
  100. this.hotSearchList = res.data;
  101. }
  102. });
  103. },
  104. // 查询用户最近搜索的单词
  105. getUserSearchList() {
  106. let MethodName = "/PaperServer/Client/Dict/QueryUserSearchWordList";
  107. let data = {
  108. limit: 10,
  109. };
  110. getLogin(MethodName, data).then((res) => {
  111. if (res.status === 1) {
  112. this.lastSearchList = res.data;
  113. }
  114. });
  115. },
  116. changeSelectIndex(val) {
  117. this.selectIndex = val;
  118. },
  119. },
  120. //生命周期 - 创建完成(可以访问当前this实例)
  121. created() {
  122. if (this.config) {
  123. let arr = this.config.split("&&&");
  124. this.LoginNavIndex = arr[0] * 1;
  125. this.userBg = arr[1];
  126. this.headerBorder = arr[2];
  127. this.headerBg = arr[3];
  128. this.selectIndex = arr[0] * 1 < 2 ? arr[0] * 1 : 0;
  129. }
  130. this.getHotWordList();
  131. this.getUserSearchList();
  132. },
  133. //生命周期 - 挂载完成(可以访问DOM元素)
  134. mounted() {},
  135. //生命周期-创建之前
  136. beforeCreated() {},
  137. //生命周期-挂载之前
  138. beforeMount() {},
  139. //生命周期-更新之前
  140. beforUpdate() {},
  141. //生命周期-更新之后
  142. updated() {},
  143. //生命周期-销毁之前
  144. beforeDestory() {},
  145. //生命周期-销毁完成
  146. destoryed() {},
  147. //如果页面有keep-alive缓存功能,这个函数会触发
  148. activated() {},
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. /* @import url(); 引入css类 */
  153. .search {
  154. position: relative;
  155. .banner {
  156. background: #299772;
  157. height: 209px;
  158. text-align: center;
  159. position: relative;
  160. .goback {
  161. position: absolute;
  162. left: 24px;
  163. top: 24px;
  164. width: 96px;
  165. height: 40px;
  166. display: block;
  167. text-align: center;
  168. cursor: pointer;
  169. color: #ffffff;
  170. line-height: 40px;
  171. .el-icon-arrow-left {
  172. width: 24px;
  173. height: 24px;
  174. text-align: center;
  175. line-height: 24px;
  176. margin: 0 4px;
  177. }
  178. }
  179. img {
  180. height: 64px;
  181. margin-top: 73px;
  182. }
  183. }
  184. .search-compent {
  185. box-shadow: 0px 6px 30px 5px rgba(0, 0, 0, 0.05),
  186. 0px 16px 24px 2px rgba(0, 0, 0, 0.04),
  187. 0px 8px 10px -5px rgba(0, 0, 0, 0.08);
  188. width: 740px;
  189. position: absolute;
  190. top: 181px;
  191. left: 50%;
  192. margin-left: -370px;
  193. }
  194. .main {
  195. width: 740px;
  196. margin: 0 auto;
  197. padding-top: 36px;
  198. h2 {
  199. font-weight: 500;
  200. font-size: 16px;
  201. line-height: 24px;
  202. color: rgba(0, 0, 0, 0.45);
  203. margin-top: 32px;
  204. margin-bottom: 0;
  205. }
  206. ul {
  207. list-style: none;
  208. display: flex;
  209. flex-flow: wrap;
  210. margin: 0;
  211. padding: 8px 0 0 0;
  212. li {
  213. padding: 8px 12px 8px;
  214. background: #e9f7f2;
  215. border-radius: 20px;
  216. display: flex;
  217. align-items: center;
  218. margin: 8px 7px 8px 0;
  219. b {
  220. color: #299772;
  221. font-weight: 400;
  222. font-size: 16px;
  223. line-height: 24px;
  224. cursor: pointer;
  225. }
  226. .el-icon-close {
  227. color: #299772;
  228. cursor: pointer;
  229. margin-left: 8px;
  230. }
  231. }
  232. }
  233. .hotSearch {
  234. li {
  235. width: 240px;
  236. height: 56px;
  237. background: #ffffff;
  238. border-radius: 8px;
  239. cursor: pointer;
  240. margin-right: 10px;
  241. padding: 16px 26px;
  242. &.noMargin {
  243. margin-right: 0;
  244. }
  245. span {
  246. display: block;
  247. background: #7796c4;
  248. border-radius: 2px;
  249. width: 18px;
  250. height: 18px;
  251. font-weight: 400;
  252. font-size: 14px;
  253. line-height: 18px;
  254. text-align: center;
  255. color: #ffffff;
  256. &.xuhao_0 {
  257. background: #ea1e1e;
  258. }
  259. &.xuhao_1 {
  260. background: #ff8e4f;
  261. }
  262. &.xuhao_2 {
  263. background: #f0a432;
  264. }
  265. }
  266. b {
  267. color: #000;
  268. margin-left: 10px;
  269. flex: 1;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. white-space: nowrap;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. </style>