km-knowledge-fullsearch.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div :class="$style.oafullbox">
  3. <a-layout :class="$style.fullsearch">
  4. <!-- header -->
  5. <a-layout-header :class="$style.searchheader">
  6. <km-fullsearch-header
  7. :search-val="searchVal"
  8. @onSearch="onSearch"
  9. @handleSelect="handleSelect"
  10. ></km-fullsearch-header>
  11. </a-layout-header>
  12. <!-- content -->
  13. <a-layout-content :class="$style.searchcontent">
  14. <km-apply v-if="isApplyFlag" :apply-list="applyList"></km-apply>
  15. <div v-else :class="$style.file">
  16. <!-- 左侧的搜索条件 -->
  17. <km-fullsearch-classify
  18. :class="$style.leftcondition"
  19. @onSearch="onSearch"
  20. ></km-fullsearch-classify>
  21. <!-- 搜索内容及结果展示区 -->
  22. <km-fullsearch-cotent
  23. ref="content"
  24. :class="$style.middleresult"
  25. :search-list="searchList"
  26. :search-val="searchVal"
  27. :total="total"
  28. :params="params"
  29. @onSearch="onSearch"
  30. ></km-fullsearch-cotent>
  31. <!-- 右侧的搜索热度排名 -->
  32. <div :class="$style.rightrate">
  33. <km-fullsearch-rate :class="$style.rate" @onSearch="onSearch"></km-fullsearch-rate>
  34. </div>
  35. </div>
  36. </a-layout-content>
  37. </a-layout>
  38. </div>
  39. </template>
  40. <script>
  41. import moment from 'moment'
  42. import KmKnowledageService from '../km-knowledage-service'
  43. import KmFullsearchHeader from './km-fullsearch-header'
  44. import KmFullsearchClassify from './km-fullsearch-classify'
  45. import KmFullsearchCotent from './km-fullsearch-cotent'
  46. import KmFullsearchRate from './km-fullsearch-rate'
  47. import components from './_import-components/km-knowledge-fullsearch-import'
  48. export default {
  49. name: 'KmKnowledgeFullsearch',
  50. metaInfo: {
  51. title: '全文检索',
  52. },
  53. components: {
  54. ...components,
  55. 'km-fullsearch-header': KmFullsearchHeader,
  56. 'km-fullsearch-classify': KmFullsearchClassify,
  57. 'km-fullsearch-cotent': KmFullsearchCotent,
  58. 'km-fullsearch-rate': KmFullsearchRate,
  59. },
  60. data() {
  61. return {
  62. isApplyFlag: false,
  63. searchList: [],
  64. searchVal: this.$route.query.searchVal || '请输入搜索内容',
  65. total: 0,
  66. params: [
  67. {
  68. searchText: '', // 关键词,对应searchVal
  69. searchDateType: 'all', // 搜索时间
  70. startDate: '', // 开始时间, extra
  71. endDate: '', // 结束时间,extra
  72. typeIds: ['all'], // 知识分类编号
  73. tagNames: ['all'], // 知识标签名称
  74. domainIds: ['all'], // 业务领域
  75. searchFields: ['all'], // 搜索范围
  76. createDeptIds: ['all'], // 创建部门
  77. creatorAccounts: ['all'], // 创建人
  78. searchType: 'splitWrod', // 搜索类型
  79. searchSort: 'score', // 排序,对应this.sort
  80. startPosition: '0', // 分页,默认0
  81. size: 5, // 分页条数
  82. },
  83. ],
  84. applyList: [],
  85. }
  86. },
  87. mounted() {
  88. if (this.searchVal) {
  89. this.params[0].searchText = this.searchVal
  90. }
  91. this.getSearchList()
  92. },
  93. methods: {
  94. // 文件/应用选择
  95. handleSelect(val) {
  96. if (val === 'apply') {
  97. this.isApplyFlag = true
  98. this.getApplyList('')
  99. } else {
  100. this.isApplyFlag = false
  101. }
  102. },
  103. // 获取搜索条件 搜索
  104. onSearch(val, type) {
  105. if (type === 'fileType') {
  106. this.isApplyFlag = true
  107. this.getApplyList(val)
  108. return
  109. }
  110. if (type === 'startDate') {
  111. this.params[0].startDate = val
  112. return
  113. }
  114. this.params.splice(1, 1)
  115. if (type !== 'startPosition' && type !== 'maxResults') {
  116. this.params[0].startPosition = 0
  117. }
  118. if (type === 'searchResult') {
  119. // 按结果搜索
  120. this.params.push(this.params[0])
  121. } else if (type === 'reset') {
  122. // 重置
  123. this.params[0].searchDateType = 'all'
  124. this.params[0].typeIds = ['all']
  125. this.params[0].tagNames = ['all']
  126. this.params[0].domainIds = ['all']
  127. this.params[0].searchFields = ['all']
  128. this.params[0].creatorAccounts = ['all']
  129. this.params[0].createDeptIds = ['all']
  130. } else if (type === 'searchDateType') {
  131. // 创建时间
  132. if (val === 'yourself') {
  133. // 自定义
  134. this.params[0].searchDateType = 'part'
  135. return
  136. } else if (val === 'all') {
  137. // all
  138. this.params[0].searchDateType = 'all'
  139. this.params[0].startDate = ''
  140. this.params[0].endDate = ''
  141. } else {
  142. this.params[0].searchDateType = 'part'
  143. this.params[0].endDate = moment(new Date()) // 结束时间
  144. if (val === 'week') {
  145. this.params[0].startDate = moment(new Date()).subtract(1, 'weeks')
  146. // 开始时间
  147. } else if (val === 'month') {
  148. this.params[0].startDate = moment(new Date()).subtract(1, 'months')
  149. } else if (val === '3') {
  150. this.params[0].startDate = moment(new Date()).subtract(3, 'months')
  151. } else if (val === '6') {
  152. this.params[0].startDate = moment(new Date()).subtract(6, 'months')
  153. } else {
  154. this.params[0].startDate = moment(new Date()).subtract(1, 'years')
  155. }
  156. }
  157. } else {
  158. if (type === 'searchText') {
  159. this.searchVal = val
  160. }
  161. if (Object.keys(this.params[0]).indexOf(type) !== -1) {
  162. this.params[0][type] = val
  163. }
  164. }
  165. if (this.params[0].startDate) {
  166. this.params[0].startDate = moment(this.params[0].startDate).format('YYYY-MM-DD HH:mm:ss')
  167. }
  168. if (this.params[0].endDate) {
  169. if (this.params[0].searchDateType === 'part') {
  170. this.params[0].endDate = moment(this.params[0].endDate)
  171. .add(1, 'days')
  172. .subtract(1, 'seconds')
  173. }
  174. this.params[0].endDate = moment(this.params[0].endDate).format('YYYY-MM-DD HH:mm:ss')
  175. }
  176. this.getSearchList()
  177. },
  178. // 获取搜索结果
  179. getSearchList() {
  180. this.searchList = []
  181. this.$refs.content.loading = true
  182. if (this.params[0].searchText === '请输入搜索内容') this.params[0].searchText = ''
  183. KmKnowledageService.getSearchList(this.params).then((res) => {
  184. this.total = res.data.total
  185. const data = res.data.docs
  186. if (data) {
  187. data.forEach((item, index) => {
  188. this.searchList.push(item.fieldValues)
  189. })
  190. }
  191. this.$refs.content.loading = false
  192. })
  193. },
  194. // 获取应用搜索结果
  195. getApplyList(text) {
  196. KmKnowledageService.applySearch(text).then((res) => {
  197. this.applyList = res.data
  198. })
  199. },
  200. },
  201. }
  202. </script>
  203. <style module lang="scss">
  204. @use '@/common/design' as *;
  205. $line-height: 30px;
  206. .oafullbox {
  207. height: 100%;
  208. background: #f0f2f5;
  209. }
  210. .fullsearch {
  211. width: 100%;
  212. height: 100%;
  213. .searchheader {
  214. width: 100%;
  215. height: 156px;
  216. padding: 0;
  217. background-image: linear-gradient(90deg, #1890ff, #0162eb);
  218. }
  219. .searchcontent {
  220. width: 100%;
  221. height: calc(100% - 64px);
  222. margin-top: 1rem;
  223. overflow: scroll;
  224. .file {
  225. display: flex;
  226. .leftcondition {
  227. width: 300px;
  228. }
  229. .middleresult {
  230. width: calc(100% - 582px);
  231. }
  232. .rightrate {
  233. width: 250px;
  234. .rate {
  235. width: calc(100% - 32px);
  236. }
  237. }
  238. }
  239. }
  240. :global(.ant-tabs) {
  241. display: none;
  242. }
  243. }
  244. </style>