PageHeader.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="page-header">
  3. <div class="page-header-index-wide">
  4. <a-breadcrumb class="breadcrumb">
  5. <a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
  6. <router-link
  7. v-if="item.name != name && index != 1"
  8. :to="{ path: item.path === '' ? '/' : item.path }"
  9. >{{ item.meta.title }}</router-link>
  10. <span v-else>{{ item.meta.title }}</span>
  11. </a-breadcrumb-item>
  12. </a-breadcrumb>
  13. <div class="detail">
  14. <div class="main" v-if="!$route.meta.hiddenHeaderContent">
  15. <div class="row">
  16. <img v-if="logo" :src="logo" class="logo"/>
  17. <h1 v-if="title" class="title">{{ title }}</h1>
  18. <div class="action">
  19. <slot name="action"></slot>
  20. </div>
  21. </div>
  22. <div class="row">
  23. <div v-if="avatar" class="avatar">
  24. <a-avatar :src="avatar"/>
  25. </div>
  26. <div v-if="this.$slots.content" class="headerContent">
  27. <slot name="content"></slot>
  28. </div>
  29. <div v-if="this.$slots.extra" class="extra">
  30. <slot name="extra"></slot>
  31. </div>
  32. </div>
  33. <div>
  34. <slot name="pageMenu"></slot>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import Breadcrumb from '@/components/tools/Breadcrumb'
  43. export default {
  44. name: 'PageHeader',
  45. components: {
  46. 's-breadcrumb': Breadcrumb
  47. },
  48. props: {
  49. title: {
  50. type: String,
  51. default: '',
  52. required: false
  53. },
  54. breadcrumb: {
  55. type: Array,
  56. default: null,
  57. required: false
  58. },
  59. logo: {
  60. type: String,
  61. default: '',
  62. required: false
  63. },
  64. avatar: {
  65. type: String,
  66. default: '',
  67. required: false
  68. }
  69. },
  70. data () {
  71. return {
  72. name: '',
  73. breadList: []
  74. }
  75. },
  76. created () {
  77. this.getBreadcrumb()
  78. },
  79. methods: {
  80. getBreadcrumb () {
  81. this.breadList = []
  82. // this.breadList.push({name: 'index', path: '/dashboard/', meta: {title: '首页'}})
  83. this.name = this.$route.name
  84. this.$route.matched.forEach((item) => {
  85. // item.name !== 'index' && this.breadList.push(item)
  86. this.breadList.push(item)
  87. })
  88. }
  89. },
  90. watch: {
  91. $route () {
  92. this.getBreadcrumb()
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="less" scoped>
  98. .page-header {
  99. background: #fff;
  100. padding: 16px 32px 0;
  101. border-bottom: 1px solid #e8e8e8;
  102. .breadcrumb {
  103. margin-bottom: 16px;
  104. }
  105. .detail {
  106. display: flex;
  107. /*margin-bottom: 16px;*/
  108. .avatar {
  109. flex: 0 1 72px;
  110. margin: 0 24px 8px 0;
  111. & > span {
  112. border-radius: 72px;
  113. display: block;
  114. width: 72px;
  115. height: 72px;
  116. }
  117. }
  118. .main {
  119. width: 100%;
  120. flex: 0 1 auto;
  121. .row {
  122. display: flex;
  123. width: 100%;
  124. .avatar {
  125. margin-bottom: 16px;
  126. }
  127. }
  128. .title {
  129. font-size: 20px;
  130. font-weight: 500;
  131. font-size: 20px;
  132. line-height: 28px;
  133. font-weight: 500;
  134. color: rgba(0,0,0,.85);
  135. margin-bottom: 16px;
  136. flex: auto;
  137. }
  138. .logo {
  139. width: 28px;
  140. height: 28px;
  141. border-radius: 4px;
  142. margin-right: 16px;
  143. }
  144. .content, .headerContent {
  145. flex: auto;
  146. color: rgba(0,0,0,.45);
  147. line-height: 22px;
  148. .link {
  149. margin-top: 16px;
  150. line-height: 24px;
  151. a {
  152. font-size: 14px;
  153. margin-right: 32px;
  154. }
  155. }
  156. }
  157. .extra {
  158. flex: 0 1 auto;
  159. margin-left: 88px;
  160. min-width: 242px;
  161. text-align: right;
  162. }
  163. .action {
  164. margin-left: 56px;
  165. min-width: 266px;
  166. flex: 0 1 auto;
  167. text-align: right;
  168. &:empty {
  169. display: none;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. .mobile .page-header {
  176. .main {
  177. .row {
  178. flex-wrap: wrap;
  179. .avatar {
  180. flex: 0 1 25%;
  181. margin: 0 2% 8px 0;
  182. }
  183. .content, .headerContent {
  184. flex: 0 1 70%;
  185. .link {
  186. margin-top: 16px;
  187. line-height: 24px;
  188. a {
  189. font-size: 14px;
  190. margin-right: 10px;
  191. }
  192. }
  193. }
  194. .extra {
  195. flex: 1 1 auto;
  196. margin-left: 0;
  197. min-width: 0;
  198. text-align: right;
  199. }
  200. .action {
  201. margin-left: unset;
  202. min-width: 266px;
  203. flex: 0 1 auto;
  204. text-align: left;
  205. margin-bottom: 12px;
  206. &:empty {
  207. display: none;
  208. }
  209. }
  210. }
  211. }
  212. </style>