index.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { Button, Icon, Search } from "vant";
  2. import { defineComponent, onMounted, ref, watch } from "vue";
  3. import styles from "./index.module.less";
  4. import IconLogo1 from "../../assets/logo-1.png";
  5. import TheSearch from "../../components/TheSearch";
  6. import HotAlbum from "../components/hot-album";
  7. import HotMusic from "../components/hot-music";
  8. import request from "@/helpers/request";
  9. import SearchList from "./components/search-list";
  10. import { useRoute, useRouter } from "vue-router";
  11. import TheDown from "@/components/TheDown";
  12. export default defineComponent({
  13. name: "Search",
  14. setup() {
  15. const route = useRoute();
  16. const router = useRouter();
  17. const keyword = ref((route.query.search as string) || "");
  18. watch(route, () => {
  19. keyword.value = (route.query.search as string) || "";
  20. });
  21. const hotTags = ref<any[]>([]);
  22. const getTags = async () => {
  23. try {
  24. const { data } = await request.get(
  25. "/api-website/open/music/sheet/hotTag/MUSIC"
  26. );
  27. if (Array.isArray(data)) hotTags.value = data;
  28. } catch (error) {}
  29. };
  30. onMounted(() => {
  31. getTags();
  32. });
  33. const onSearch = (val: string) => {
  34. if (!val) {
  35. keyword.value = val || "";
  36. return;
  37. }
  38. router.replace({
  39. path: "/search",
  40. query: {
  41. search: val,
  42. },
  43. });
  44. };
  45. const downRef = ref()
  46. return () => (
  47. <div class={styles.search}>
  48. <div class={styles.fixed}>
  49. <div class={styles.top}>
  50. <img class={styles.img} src={IconLogo1} />
  51. <span>打开APP看海量热门乐谱</span>
  52. <Button round class={styles.topBtn} onClick={() => downRef.value?.downLoadApp()}>
  53. 打开
  54. </Button>
  55. </div>
  56. <TheSearch
  57. keyword={keyword.value}
  58. onSearch={(val: string) => onSearch(val)}
  59. onBlur={(val: string) => onSearch(val)}
  60. onBack={() => {
  61. router.push('/')
  62. }}
  63. />
  64. </div>
  65. <div class={styles.tagContent}>
  66. <div class={styles.tagLeft}>热门搜索:</div>
  67. <div class={styles.tags}>
  68. {hotTags.value.map((n) => (
  69. <span onClick={() => onSearch(n.key)}>{n.key}</span>
  70. ))}
  71. </div>
  72. </div>
  73. {keyword.value && <SearchList />}
  74. <div style={{ display: keyword.value ? "none" : "block" }}>
  75. <div class={styles.searchContianer}>
  76. <HotAlbum />
  77. </div>
  78. <HotMusic />
  79. </div>
  80. <TheDown ref={downRef}/>
  81. </div>
  82. );
  83. },
  84. });