top.vue 8.2 KB

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