top.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div>
  3. <el-row class='flex flex-align-center flex-justify-between top'>
  4. <el-col :span='12'>
  5. <div class='flex flex-justify-start flex-align-center padding'>
  6. <img class="ml-10" src="../assets/svg/top.svg"/>
  7. <el-breadcrumb class='ml-10' separator="/">
  8. <el-breadcrumb-item v-for='item in nav.menus' :key='item.id'>
  9. <a :href="item.fullPath">{{ item.name }}</a>
  10. </el-breadcrumb-item>
  11. </el-breadcrumb>
  12. </div>
  13. </el-col>
  14. <el-col :span='12'>
  15. <div class='flex-child-average flex-justify-end flex padding-right'>
  16. <div class="padding flex flex-align-center pointer" @click="show = true">
  17. <el-icon class="mr-5">
  18. <Search/>
  19. </el-icon>
  20. <span>搜索</span>
  21. </div>
  22. <div class='padding flex flex-align-center pointer'>
  23. <el-avatar class='mr-10' :size="30"
  24. :src="user.info.avatarUrl && user.info.avatarUrl.length > 0 ? user.info.avatarUrl : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'"/>
  25. <el-dropdown @command='dropDown'>
  26. <span class="flex flex-center">
  27. {{ user.info.name }} / {{ user.info.deptName }}
  28. <el-icon class="el-icon--right">
  29. <arrow-down/>
  30. </el-icon>
  31. </span>
  32. <template #dropdown>
  33. <el-dropdown-menu>
  34. <el-dropdown-item command='info'>个人中心</el-dropdown-item>
  35. <el-dropdown-item command='logout'>退出登录</el-dropdown-item>
  36. </el-dropdown-menu>
  37. </template>
  38. </el-dropdown>
  39. </div>
  40. </div>
  41. </el-col>
  42. </el-row>
  43. <el-dialog v-model='show' append-to-body width='40%'>
  44. <div class="flex flex-col">
  45. <div class="flex flex-center">
  46. <div class="mr-5">
  47. <el-dropdown @command='dropDown'>
  48. <div class="flex flex-center">
  49. <el-icon size="25px">
  50. <Search/>
  51. </el-icon>
  52. <span style='width: 40px' class='text-center'> {{filterTypeName}}</span>
  53. <el-icon size="20px">
  54. <CaretBottom/>
  55. </el-icon>
  56. </div>
  57. <template #dropdown>
  58. <el-dropdown-menu>
  59. <el-dropdown-item command='全部'>全部</el-dropdown-item>
  60. <el-dropdown-item command='项目'>项目</el-dropdown-item>
  61. <el-dropdown-item command='文档'>文档</el-dropdown-item>
  62. <el-dropdown-item command='图片'>图片</el-dropdown-item>
  63. </el-dropdown-menu>
  64. </template>
  65. </el-dropdown>
  66. </div>
  67. <div class="full-width flex flex-center">
  68. <el-input
  69. clearable
  70. v-model='params.keyword'
  71. class='append'
  72. placeholder="输入关键字搜索"
  73. @keydown="searchTotal"
  74. >
  75. </el-input>
  76. <el-button type='primary' class='ml-20' @click='searchTotal(1)'>搜 索</el-button>
  77. </div>
  78. </div>
  79. <!-- 结果展示-->
  80. <div v-if="isAll === 1" class="flex flex-justify-center flex-align-start mt-15">
  81. <div v-for="(item,index) in type" :key='item.key' class="flex flex-center tab" @click="change(index,item.key)">
  82. <el-badge :value='item.count' :hidden='item.count === 0'>
  83. <div :class="active === index ? 'tab-active' : ''" class="pointer">{{item.value }}
  84. </div>
  85. </el-badge>
  86. </div>
  87. </div>
  88. <el-empty v-if="data && data.length === 0" description='暂无数据'/>
  89. <div v-else style='min-height: 300px'>
  90. <div class="mt-10 border-bottom padding flex flex-center flex-justify-between" v-for="sub in data" :key='sub.id'>
  91. <span v-if='params.searchType === "project" '>{{ sub.projectName }}</span>
  92. <span v-else>{{ sub.title }}</span>
  93. <el-button text type='primary' @click='detail(sub)'>详情</el-button>
  94. </div>
  95. </div>
  96. <div class="full-width mt-10 flex flex-justify-end">
  97. <el-pagination small layout="prev, pager, next" :total="total"/>
  98. </div>
  99. </div>
  100. </el-dialog>
  101. <el-image-viewer
  102. v-if='showImage'
  103. :url-list="imgList"
  104. @close='showImage = false'
  105. />
  106. </div>
  107. </template>
  108. <script>
  109. import navStore from '../store/nav.js'
  110. import { useStore } from '../store/user.js'
  111. import permissionStore from '@/store/permission.js'
  112. export default {
  113. name: 'top',
  114. setup () {
  115. const nav = navStore()
  116. const user = useStore()
  117. const permission = permissionStore()
  118. return { nav, user, permission }
  119. },
  120. data () {
  121. return {
  122. showImage: false,
  123. imgList: [],
  124. show: false,
  125. keywords: '',
  126. active: 0,
  127. type: [
  128. {
  129. key: 'project',
  130. value: '项目',
  131. count: 0
  132. },
  133. {
  134. key: 'file',
  135. value: '文档',
  136. count: 0
  137. },
  138. {
  139. key: 'picture',
  140. value: '图片',
  141. count: 0
  142. }
  143. ],
  144. params: {
  145. keyword: '',
  146. searchType: 'project',
  147. pages: 1,
  148. size: 10
  149. },
  150. data: [],
  151. total: '',
  152. isAll: 1,
  153. filterTypeName: '全部',
  154. resultCount: 0
  155. }
  156. },
  157. created () {
  158. },
  159. methods: {
  160. dropDown (res) {
  161. if (res === 'info') {
  162. this.$router.push('/user')
  163. } else if (res === 'logout') {
  164. this.$api.login.logout().then(res => {
  165. if (res.success === 'true') {
  166. this.nav.cleanMenu()
  167. try {
  168. // this.permission.cleanPermission()
  169. } catch (err) {
  170. console.log(err)
  171. }
  172. this.$message.success('退出登录')
  173. this.$router.replace('/login')
  174. } else {
  175. this.$message.error(res.msg)
  176. }
  177. })
  178. } else if (res === '全部') {
  179. this.filterTypeName = res
  180. this.params.searchType = 'all'
  181. this.isAll = 1
  182. this.searchTotal()
  183. } else if (res === '项目') {
  184. this.filterTypeName = res
  185. this.isAll = 0
  186. this.params.searchType = 'project'
  187. this.searchTotal()
  188. } else if (res === '文档') {
  189. this.filterTypeName = res
  190. this.isAll = 0
  191. this.params.searchType = 'file'
  192. this.searchTotal()
  193. } else if (res === '图片') {
  194. this.filterTypeName = res
  195. this.isAll = 0
  196. this.params.searchType = 'picture'
  197. this.searchTotal()
  198. }
  199. },
  200. change (index, key) {
  201. this.active = index
  202. this.params.searchType = key
  203. if (this.params.searchType === 'all') {
  204. this.isAll = 1
  205. this.getTotal()
  206. this.$api.project.totalSearch(this.params).then(res => {
  207. if (res.code === 200) {
  208. this.data = res.data.result
  209. this.total = res.data.total
  210. }
  211. })
  212. } else {
  213. this.getTotal()
  214. this.$api.project.totalSearch(this.params).then(res => {
  215. if (res.code === 200) {
  216. this.data = res.data.result
  217. this.total = res.data.total
  218. }
  219. })
  220. }
  221. },
  222. searchTotal (res) {
  223. if (res.key === 'Enter' || res === 1) {
  224. this.getTotal()
  225. this.$api.project.totalSearch(this.params).then(res => {
  226. if (res.code === 200) {
  227. this.data = res.data.result
  228. this.total = res.data.total
  229. }
  230. })
  231. }
  232. },
  233. getTotal () {
  234. this.resultCount = 0
  235. this.$api.project.total({ keyword: this.params.keyword }).then(res => {
  236. if (res.code === 200) {
  237. this.type[0].count = res.data.projectTotal
  238. this.type[1].count = res.data.fileTotal
  239. this.type[2].count = res.data.pictureTotal
  240. this.type.forEach(sub => {
  241. this.resultCount = this.resultCount + sub.count
  242. })
  243. }
  244. })
  245. },
  246. detail (res) {
  247. if (this.params.searchType === 'project') {
  248. this.$api.project.projectInfo(res.projectId).then(res => {
  249. if (res.code === 200) {
  250. console.log(res)
  251. this.$router.push({
  252. path: '/home/details',
  253. query: { id: res.data.id, type: '0', ownerId: res.data.createUser }
  254. })
  255. }
  256. })
  257. this.show = false
  258. } else if (this.params.searchType === 'file') {
  259. const routeData = this.$router.resolve({ path: '/home/file_detail', query: { id: res.fileId.replace('fileid-', '') } })
  260. window.open(routeData.href, '_blank')
  261. } else if (this.params.searchType === 'picture') {
  262. this.imgList = [res.url]
  263. this.showImage = true
  264. }
  265. }
  266. }
  267. }
  268. </script>
  269. <style lang='scss' scoped>
  270. .top {
  271. height: 60px;
  272. z-index: 1;
  273. background-color: white;
  274. top: 0;
  275. left: 200px;
  276. right: 0;
  277. position: fixed;
  278. border-bottom: whitesmoke solid 1px;
  279. box-shadow: 0 5px 10px -5px rgba(0, 0, 0, 0.1);
  280. }
  281. .avatar {
  282. background-color: #c4c3c3;
  283. width: 30px;
  284. height: 30px;
  285. border-radius: 15px;
  286. }
  287. .tab {
  288. width: 238px;
  289. height: 38px;
  290. background-color: #EDF0F3;
  291. padding: 2px 10px;
  292. color: #707070;
  293. font-size: 13px;
  294. }
  295. .tab-active {
  296. width: 160px;
  297. flex-wrap: nowrap;
  298. color: white;
  299. font-size: 15px;
  300. background-color: #AB7630;
  301. font-weight: 500;
  302. padding: 4px 10px;
  303. border-radius: 20px;
  304. text-align: center;
  305. }
  306. </style>