PageHeader.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="page-header">
  3. <a-breadcrumb class="breadcrumb">
  4. <a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
  5. <router-link v-if="item.name != name" :to="{ path: item.path }">
  6. {{ item.meta.title }}
  7. </router-link>
  8. <span v-else>{{ item.meta.title }}</span>
  9. </a-breadcrumb-item>
  10. </a-breadcrumb>
  11. <div class="detail">
  12. <div v-if="avatar" class="avatar">
  13. <a-avatar :src="avatar"/>
  14. </div>
  15. <div class="main">
  16. <div class="row">
  17. <img v-if="logo" :src="logo" class="logo"/>
  18. <h1 v-if="title" class="title">{{ title }}</h1>
  19. <div class="action">
  20. <slot name="action"></slot>
  21. </div>
  22. </div>
  23. <div class="row">
  24. <div v-if="this.$slots.content" class="content">
  25. <slot name="content"></slot>
  26. </div>
  27. <div v-if="this.$slots.extra" class="extra">
  28. <slot name="extra"></slot>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import Breadcrumb from '@/components/tools/Breadcrumb'
  37. export default {
  38. name: "PageHeader",
  39. components: {
  40. "s-breadcrumb": Breadcrumb
  41. },
  42. props: {
  43. title: {
  44. type: String,
  45. required: false
  46. },
  47. breadcrumb: {
  48. type: Array,
  49. required: false
  50. },
  51. logo: {
  52. type: String,
  53. required: false
  54. },
  55. avatar: {
  56. type: String,
  57. required: false
  58. }
  59. },
  60. data() {
  61. return {
  62. name: '',
  63. breadList: [],
  64. }
  65. },
  66. created() {
  67. this.getBreadcrumb()
  68. },
  69. methods: {
  70. getBreadcrumb() {
  71. this.breadList = []
  72. this.breadList.push({name: 'index', path: '/dashboard/', meta: {title: '首页'}})
  73. this.name = this.$route.name
  74. this.$route.matched.forEach((item) => {
  75. // item.meta.name === 'dashboard' ? item.path = '/dashboard' : this.$route.path === item.path
  76. this.breadList.push(item)
  77. })
  78. }
  79. },
  80. watch: {
  81. $route() {
  82. this.getBreadcrumb()
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .page-header {
  89. background: #fff;
  90. padding: 16px 32px 0;
  91. border-bottom: 1px solid #e8e8e8;
  92. .breadcrumb {
  93. margin-bottom: 16px;
  94. }
  95. .detail {
  96. display: flex;
  97. margin-bottom: 16px;
  98. .avatar {
  99. flex: 0 1 72px;
  100. margin: 0 24px 8px 0;
  101. & > span {
  102. border-radius: 72px;
  103. display: block;
  104. width: 72px;
  105. height: 72px;
  106. }
  107. }
  108. .main {
  109. width: 100%;
  110. flex: 0 1 auto;
  111. .row {
  112. display: flex;
  113. width: 100%;
  114. }
  115. .title {
  116. font-size: 20px;
  117. font-weight: 500;
  118. font-size: 20px;
  119. line-height: 28px;
  120. font-weight: 500;
  121. color: rgba(0,0,0,.85);
  122. margin-bottom: 16px;
  123. flex: auto;
  124. }
  125. .logo {
  126. width: 28px;
  127. height: 28px;
  128. border-radius: 4px;
  129. margin-right: 16px;
  130. }
  131. .content {
  132. margin-bottom: 16px;
  133. flex: auto;
  134. color: rgba(0,0,0,.45);
  135. line-height: 22px;
  136. }
  137. .extra {
  138. flex: 0 1 auto;
  139. margin-left: 88px;
  140. min-width: 242px;
  141. text-align: right;
  142. }
  143. .action {
  144. margin-left: 56px;
  145. min-width: 266px;
  146. flex: 0 1 auto;
  147. text-align: right;
  148. &:empty {
  149. display: none;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. </style>