index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-model="show"
  5. append-to-body
  6. width="1200px"
  7. :close-on-click-modal="false"
  8. @close="close"
  9. @closed="closed"
  10. >
  11. <div class="content">
  12. <div class="search flex flex-center">
  13. <div class="icon flex flex-center main-bg-color">
  14. <el-icon size="30px">
  15. <Search />
  16. </el-icon>
  17. </div>
  18. <el-input
  19. v-model="keyword"
  20. placeholder="搜索"
  21. @keyup.enter="search"
  22. ></el-input>
  23. <el-button type="primary" class="ml-20" @click="search"
  24. >搜 索</el-button
  25. >
  26. </div>
  27. <div class="mt-20 padding">
  28. <span class="bold font-16">文档({{ count }})</span>
  29. <div class="flex mt-20">
  30. <div
  31. v-if="list.length > 0"
  32. class="flex flex-align-start flex-justify-between full-width"
  33. >
  34. <div class="full-width mt-10 list">
  35. <div v-for="(i, index) in list" :key="i">
  36. <div
  37. class="padding border-bottom pointer"
  38. @click="changeDoc(i, index)"
  39. >
  40. <div :class="fileIndex === index ? 'bold' : ''">
  41. {{ i.fileName }}
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div>
  47. <div
  48. class="full-height full-width preview flex flex-center pointer"
  49. v-if="current"
  50. @click="showImage = true"
  51. >
  52. <el-tooltip placement="right">
  53. <template #content>
  54. <div
  55. style="width: 200px"
  56. v-html="current.contents[pageIndex].content"
  57. ></div>
  58. </template>
  59. <img
  60. class="img"
  61. :src="current.contents[pageIndex].imagePath"
  62. alt="img"
  63. />
  64. </el-tooltip>
  65. </div>
  66. <div class="flex flex-center flex-justify-between padding">
  67. <div>
  68. <el-button
  69. type="primary"
  70. icon="ArrowLeftBold"
  71. circle
  72. @click="pageChange(1)"
  73. />
  74. <el-button
  75. type="primary"
  76. icon="ArrowRightBold"
  77. circle
  78. @click="pageChange(2)"
  79. />
  80. </div>
  81. <el-button type="primary" @click="goDoc">查看</el-button>
  82. </div>
  83. <div
  84. class="full-width flex flex-justify-start flex-col"
  85. style="width: 360px"
  86. >
  87. <span class="lines-1"
  88. >名称:{{ current.contents[pageIndex].fileName }}</span
  89. >
  90. <span class="lines-1"
  91. >所属项目:{{ current.projectName }}</span
  92. >
  93. <span class="lines-1"
  94. >所属文件夹:{{ current.stageName }}</span
  95. >
  96. </div>
  97. </div>
  98. </div>
  99. <div v-else class="full-width full-height">
  100. <el-empty
  101. :description="
  102. loading ? '请稍后,加载中' : '请输入关键词进行搜索'
  103. "
  104. >
  105. </el-empty>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </el-dialog>
  111. <el-image-viewer
  112. v-if="showImage"
  113. :url-list="imgList"
  114. @close="showImage = false"
  115. :initial-index="pageIndex"
  116. />
  117. </div>
  118. </template>
  119. <script>
  120. export default {
  121. props: {
  122. show: {
  123. type: Boolean,
  124. default: true
  125. }
  126. },
  127. data() {
  128. return {
  129. keyword: '',
  130. showImage: false,
  131. imgList: [],
  132. page: { current: 1, size: 10 },
  133. list: [],
  134. current: null,
  135. count: '',
  136. loading: '333',
  137. fileIndex: 0,
  138. pageIndex: 0,
  139. pageList: []
  140. }
  141. },
  142. methods: {
  143. search() {
  144. if (this.keyword.length === 0) {
  145. return
  146. }
  147. this.loading = true
  148. const data = Object.assign(this.page, { keyword: this.keyword })
  149. this.$api.search.searchList(data).then(res => {
  150. this.loading = false
  151. if (res.code === 200) {
  152. this.list = res.data.records
  153. this.count = res.data.total
  154. if (this.list.length > 0) {
  155. this.current = this.list[0]
  156. this.fetchData()
  157. } else {
  158. this.$message.error('暂无数据')
  159. }
  160. } else {
  161. this.$message.error(res.msg)
  162. }
  163. })
  164. },
  165. /**
  166. * 对数据进行初始化
  167. */
  168. fetchData() {
  169. this.current.contents.map(sub => {
  170. sub.content = sub.content.replace(
  171. this.keyword,
  172. `<span
  173. style="color: red"
  174. >` +
  175. this.keyword +
  176. `</span
  177. >`
  178. )
  179. return sub
  180. })
  181. this.pageList = this.current.contents.map(sub => sub.currentPage)
  182. this.imgList = this.current.contents.map(sub => sub.imagePath)
  183. },
  184. closed() {
  185. this.keyword = ''
  186. this.$emit('close', false)
  187. },
  188. /**
  189. * type 1 前一页 后一页
  190. */
  191. pageChange(type) {
  192. console.log(type)
  193. if (type === 1) {
  194. if (this.pageIndex === 0) {
  195. return
  196. }
  197. this.pageIndex = this.pageIndex - 1
  198. } else {
  199. if (this.pageIndex < this.pageList.length) {
  200. this.pageIndex = this.pageIndex + 1
  201. }
  202. }
  203. },
  204. /**
  205. * 查看文档
  206. * */
  207. goDoc() {
  208. const routeData = this.$router.resolve({
  209. path: '/home/file_detail',
  210. query: { id: this.current.fileId }
  211. })
  212. window.open(routeData.href, '_blank')
  213. },
  214. changeDoc(item, index) {
  215. this.current = item
  216. this.pageIndex = 0
  217. this.fileIndex = index
  218. this.fetchData()
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .content {
  225. .search {
  226. .icon {
  227. width: 80px;
  228. height: 50px;
  229. border-radius: 4px;
  230. color: #343434;
  231. }
  232. }
  233. }
  234. .list {
  235. height: 560px;
  236. overflow-y: scroll;
  237. overflow: hidden;
  238. }
  239. .preview-content {
  240. width: 360px;
  241. background-color: aqua;
  242. }
  243. .preview {
  244. width: 260px;
  245. height: 460px;
  246. border: #eeeeee solid 1px;
  247. padding: 10px;
  248. margin: 10px;
  249. border-radius: 8px;
  250. .img {
  251. width: auto;
  252. height: 420px;
  253. }
  254. }
  255. .tips {
  256. width: 260px;
  257. }
  258. </style>