km-fullsearch-header.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div :class="$style.searchheader">
  3. <div :class="$style.topbg">
  4. <div :class="$style.logo"></div>
  5. <a-divider type="vertical" />
  6. <h2>全文检索</h2>
  7. </div>
  8. <div :class="$style.bottombg">
  9. <a-select label-in-value :default-value="{ key: 'file' }" :size="size" @change="handleChange">
  10. <a-select-option v-for="item in selectTypeData" :key="item.value">
  11. {{ item.label }}
  12. </a-select-option>
  13. </a-select>
  14. <div :class="$style.inputsearch">
  15. <a-input-search
  16. v-model="inputValue"
  17. :size="size"
  18. show-search
  19. placeholder="请输入搜索内容"
  20. :class="$style.input"
  21. @change="onInputChange"
  22. @search="onBtnSearch"
  23. />
  24. <a-select
  25. v-decorator="['value']"
  26. :size="size"
  27. :class="$style.selectsearch"
  28. placeholder=""
  29. show-search
  30. :default-active-first-option="false"
  31. :show-arrow="false"
  32. :filter-option="false"
  33. :not-found-content="null"
  34. :open="isOpen"
  35. label-in-value
  36. @search="onOptinonSearch"
  37. @change="onSelectChange"
  38. >
  39. <a-select-option v-for="(item, index) in data" :key="index">
  40. {{ item }}
  41. </a-select-option>
  42. </a-select>
  43. </div>
  44. <span :class="$style.result" @click="onResultSearch">在结果中搜索</span>
  45. </div>
  46. <!-- 用户信息 -->
  47. <div :class="$style.userarea">
  48. <slot name="userinfo">
  49. <a-dropdown :class="$style.userinfowrap">
  50. <div>
  51. <a-avatar
  52. :class="$style.userinfo"
  53. icon="user"
  54. :src="`api/mobile/v1/user-manager/userAvatar/${userInfo.account}` | sdResource"
  55. alt="avatar"
  56. />
  57. {{ userInfo.name }}
  58. <a-icon type="down" />
  59. </div>
  60. <a-menu slot="overlay">
  61. <a-menu-item @click="$router.push('/sd-frame/sd-account-info')">
  62. <a-icon type="user" />个人中心
  63. </a-menu-item>
  64. <a-menu-divider />
  65. <a-menu-item @click="logout"> <a-icon type="logout" />退出登录 </a-menu-item>
  66. </a-menu>
  67. </a-dropdown>
  68. </slot>
  69. <a-divider type="vertical" />
  70. <div :class="$style.gobance" @click="$router.push('/sd-frame')">
  71. 进入工作台
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import loginService from '@/login/login-service'
  78. import storeMixin from '@/common/store-mixin'
  79. import KmKnowledageService from '../km-knowledage-service'
  80. import components from './_import-components/km-fullsearch-header-import'
  81. const selectTypeData = [
  82. {
  83. label: '文件',
  84. value: 'file',
  85. },
  86. {
  87. label: '应用',
  88. value: 'apply',
  89. },
  90. ]
  91. export default {
  92. name: 'KmFullsearchHeader',
  93. components,
  94. mixins: [storeMixin],
  95. props: {
  96. searchVal: {
  97. type: String,
  98. default: '请输入搜索内容',
  99. },
  100. },
  101. data() {
  102. return {
  103. data: [],
  104. inputValue: this.searchVal === '请输入搜索内容' ? '' : this.searchVal,
  105. value: '',
  106. selectTypeData,
  107. isApply: false,
  108. isOpen: false,
  109. size: 'large',
  110. }
  111. },
  112. methods: {
  113. // 文件/应用
  114. handleChange(val) {
  115. if (val.key === 'apply') {
  116. this.$emit('handleSelect', 'apply')
  117. this.isApply = true
  118. } else {
  119. this.$emit('handleSelect', 'file')
  120. this.isApply = false
  121. }
  122. },
  123. // 输入框提示
  124. getSeachInputTip(text) {
  125. this.data = []
  126. KmKnowledageService.seachInputTip(text).then((res) => {
  127. if (res.data && res.data.length > 0) {
  128. this.data = res.data
  129. } else {
  130. this.data.push(text)
  131. }
  132. })
  133. },
  134. // input change
  135. onInputChange(e) {
  136. this.value = e.target.value
  137. this.isOpen = true
  138. this.onOptinonSearch(e.target.value)
  139. },
  140. onSelectChange(val) {
  141. this.value = val.label.trim()
  142. this.inputValue = val.label.trim()
  143. this.isOpen = false
  144. this.$emit('onSearch', this.inputValue, 'searchText')
  145. },
  146. onOptinonSearch(val) {
  147. this.getSeachInputTip(val)
  148. },
  149. // 搜索
  150. onBtnSearch() {
  151. if (this.isApply) {
  152. this.$emit('onSearch', this.inputValue, 'fileType')
  153. } else {
  154. this.isOpen = false
  155. this.$emit('onSearch', this.inputValue, 'searchText')
  156. }
  157. },
  158. // 在结果中搜索
  159. onResultSearch() {
  160. this.$emit('onSearch', this.inputValue, 'searchResult')
  161. },
  162. // 退出登录
  163. logout() {
  164. loginService.doLogout()
  165. },
  166. },
  167. }
  168. </script>
  169. <style module lang="scss">
  170. @use '@/common/design' as *;
  171. $fontcolor: #fff;
  172. .searchheader {
  173. position: relative;
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. justify-content: center;
  178. width: 100%;
  179. height: 100%;
  180. .topbg {
  181. display: flex;
  182. align-items: center;
  183. .logo {
  184. display: inline-block;
  185. width: 256px;
  186. height: 64px;
  187. background: url('~@custom/images/logo.png') no-repeat center;
  188. }
  189. h2 {
  190. color: $fontcolor;
  191. /* stylelint-disable-next-line */
  192. margin-bottom: 0;
  193. margin-left: 20px;
  194. }
  195. }
  196. .bottombg {
  197. display: flex;
  198. align-items: center;
  199. .inputsearch {
  200. position: relative;
  201. display: flex;
  202. flex-direction: column;
  203. width: 570px;
  204. height: 40px;
  205. .input {
  206. z-index: 20;
  207. }
  208. .selectsearch {
  209. position: absolute;
  210. width: 570px;
  211. opacity: 0;
  212. }
  213. }
  214. .result {
  215. display: flex;
  216. align-items: center;
  217. height: 40px;
  218. margin-left: 1.5rem;
  219. color: $fontcolor;
  220. cursor: pointer;
  221. }
  222. }
  223. .userarea {
  224. position: absolute;
  225. top: 5px;
  226. right: 15px;
  227. display: flex;
  228. align-items: center;
  229. color: $fontcolor;
  230. .gobance {
  231. cursor: pointer;
  232. }
  233. .userinfowrap {
  234. padding-right: 10px;
  235. cursor: pointer;
  236. &:hover {
  237. /* stylelint-disable-next-line */
  238. background-color: rgba(0, 0, 0, 0.2);
  239. }
  240. }
  241. .userinfo {
  242. margin: 0 10px;
  243. }
  244. }
  245. }
  246. </style>