index.vue 7.3 KB

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