index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="web-home">
  3. <div class="title">
  4. <img src="@/assets/images/web/web-home_title.png"/>
  5. </div>
  6. <div class="area">
  7. <div class="selected">
  8. <div class="label">搜索范围:</div>
  9. <div class="value">
  10. <template v-if="searchAreaCpt.text">
  11. {{searchAreaCpt.text}}
  12. </template>
  13. <template v-else>
  14. <template v-for="item in searchAreaCpt.arr">
  15. <div>{{item.indexName}}</div>
  16. </template>
  17. </template>
  18. </div>
  19. </div>
  20. <div class="search-input">
  21. <div class="left-select __hover" @click="state.showArea = true">
  22. 搜索范围<SvgIcon name="arrow_1" rotate="90" size="14" color="var(--cus-text-color-3)"/>
  23. </div>
  24. <el-input v-model="state.searchText" placeholder="请输入关键字进行查询" @keyup.enter="toList(state.searchText)"/>
  25. <div class="right-icon __hover" @click="toList(state.searchText)">
  26. <SvgIcon name="search_1" color="var(--cus-main-color)" size="40"/>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="history" v-if="state.historyList?.length > 0">
  31. <div class="label">搜索记录</div>
  32. <div class="result">
  33. <template v-for="(item, index) in state.historyList">
  34. <span class="__hover" @click="toList(item, true)">{{index + 1}}.{{item}}</span>
  35. </template>
  36. </div>
  37. </div>
  38. <CusDialog
  39. :show="state.showArea"
  40. @onClose="$emit('update:show', false)"
  41. width="1000px"
  42. height="auto"
  43. submit-text="关闭"
  44. :show-close="false"
  45. @onSubmit="state.showArea = false"
  46. >
  47. <CusTab :tabs="state.areaList" type="type1" v-model:param="state.areaTab" label-key="treeName" value-key="treeId"/>
  48. <div class="index-list">
  49. <div class="all">
  50. <div class="__check" :class="{active: indexTabAllCpt}" @click="onIndexTabAll">全选</div>
  51. </div>
  52. <div class="list">
  53. <template v-for="(item, index) in indexListCpt">
  54. <div class="list-item">
  55. <div class="__check" :class="{active: item.__select}" @click="item.__select = !item.__select">{{ item.indexName }}</div>
  56. </div>
  57. </template>
  58. </div>
  59. </div>
  60. </CusDialog>
  61. </div>
  62. </template>
  63. <script setup lang="ts">
  64. import {computed, getCurrentInstance, onMounted, reactive} from "vue";
  65. import router from "@/router";
  66. import {ElMessage} from "element-plus";
  67. import {useWebStore} from "@/stores";
  68. const {proxy} = getCurrentInstance()
  69. const WebStore = useWebStore()
  70. const state: any = reactive({
  71. searchText: '',
  72. historyList: [],
  73. areaList: [],
  74. showArea: false,
  75. areaTab: ''
  76. })
  77. const indexListCpt = computed(() => {
  78. return state.areaList.filter(v => v.treeId === state.areaTab)?.[0]?.children || []
  79. })
  80. const indexTabAllCpt = computed(() => {
  81. return indexListCpt.value.every(v => v.__select)
  82. })
  83. const searchAreaCpt = computed(() => {
  84. const obj = {
  85. text: '',
  86. arr: []
  87. }
  88. let i = 0
  89. state.areaList.forEach(v => {
  90. v.children.forEach(c => {
  91. i++
  92. if (c.__select) {
  93. obj.arr.push(c)
  94. }
  95. })
  96. })
  97. if (i === obj.arr.length) {
  98. obj.arr = []
  99. }
  100. if (obj.arr.length === 0) {
  101. obj.text = '全部'
  102. }
  103. return obj
  104. })
  105. const initHistory = () => {
  106. proxy.$api.mockGetSearchHistory().then(res => {
  107. state.historyList = res.data
  108. })
  109. }
  110. const initArea = () => {
  111. WebStore.getSearchAreaTree().then(res => {
  112. state.areaList = JSON.parse(JSON.stringify(res))
  113. state.areaTab = state.areaList[0].treeId
  114. })
  115. }
  116. const onIndexTabAll = () => {
  117. const flag = JSON.parse(JSON.stringify(indexTabAllCpt.value))
  118. indexListCpt.value.forEach(v => {
  119. v.__select = !flag
  120. })
  121. }
  122. const toList = (text, isAll = false) => {
  123. if (text) {
  124. const routerUrl = router.resolve({
  125. name: '4f6dd2ea-7c0a-4923-9a57-932ef42235f6',
  126. query: {
  127. text,
  128. index: isAll ? '' : searchAreaCpt.value.arr.map(v => v.indexKey).join(',')
  129. }
  130. });
  131. window.open(routerUrl.href, "_blank");
  132. } else {
  133. ElMessage({
  134. message: '请输入关键字进行查询!',
  135. grouping: true,
  136. type: 'warning',
  137. })
  138. }
  139. }
  140. onMounted(() => {
  141. initHistory()
  142. initArea()
  143. })
  144. </script>
  145. <style lang="scss" scoped>
  146. .web-home {
  147. width: 100%;
  148. height: 100%;
  149. background-image: url("@/assets/images/web/web-home_bg.png");
  150. background-size: 100% 100%;
  151. background-repeat: no-repeat;
  152. display: flex;
  153. flex-direction: column;
  154. justify-content: center;
  155. align-items: center;
  156. gap: 40px;
  157. .area {
  158. width: 1000px;
  159. .selected {
  160. display: flex;
  161. line-height: 30px;
  162. .label {
  163. font-weight: 500;
  164. font-size: 16px;
  165. color: var(--cus-main-color);
  166. padding-left: 16px;
  167. }
  168. .value {
  169. flex: 1;
  170. color: var(--cus-text-color-2);
  171. display: flex;
  172. flex-wrap: wrap;
  173. column-gap: 20px;
  174. }
  175. }
  176. .search-input {
  177. margin-top: 10px;
  178. display: flex;
  179. align-items: center;
  180. width: 100%;
  181. height: 60px;
  182. background: rgba(255,255,255,0.9);
  183. box-shadow: 0px 0px 2px 0px rgba(167,220,255,0.5);
  184. border-radius: 60px;
  185. border: 1px solid var(--cus-main-color);
  186. .left-select {
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. width: 184px;
  191. gap: 17px;
  192. color: var(--cus-text-color-4);
  193. font-size: 18px;
  194. position: relative;
  195. &:after {
  196. content: '';
  197. position: absolute;
  198. right: 0;
  199. height: 40px;
  200. width: 1px;
  201. background-color: var(--cus-main-color);
  202. }
  203. }
  204. :deep(.el-input) {
  205. font-size: 18px;
  206. color: var(--cus-text-color-2);
  207. .el-input__wrapper {
  208. box-shadow: none !important;
  209. background-color: transparent;
  210. .el-input__inner {
  211. &::placeholder {
  212. color: var(--cus-text-color-4);
  213. }
  214. }
  215. }
  216. }
  217. .right-icon {
  218. margin-right: 20px;
  219. }
  220. }
  221. }
  222. .history {
  223. width: 1000px;
  224. .label {
  225. font-weight: 500;
  226. font-size: 16px;
  227. color: var(--cus-main-color);
  228. padding-left: 16px;
  229. }
  230. .result {
  231. margin-top: 10px;
  232. width: 100%;
  233. padding: 16px;
  234. background: rgba(255,255,255,0.8);
  235. box-shadow: 0px 4px 4px 0px rgba(255,255,255,0.15);
  236. border-radius: 8px;
  237. font-weight: 400;
  238. font-size: 16px;
  239. color: var(--cus-text-color-2);
  240. display: flex;
  241. flex-wrap: wrap;
  242. gap: 10px 32px;
  243. }
  244. }
  245. }
  246. .cus-tab {
  247. padding: 30px 0 22px 28px;
  248. :deep(.cus-tab-item::after) {
  249. bottom: -23px !important;
  250. }
  251. }
  252. .index-list {
  253. padding: 20px 28px 0;
  254. .list {
  255. margin-top: 10px;
  256. display: flex;
  257. flex-wrap: wrap;
  258. gap: 30px;
  259. }
  260. }
  261. </style>