| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <div class="adm-page-header">
- <div class="adm-page-header__main">
- <div class="adm-page-header__title-row">
- <el-button
- v-if="back"
- class="adm-page-header__back"
- type="text"
- icon="el-icon-arrow-left"
- @click="handleBack"
- >返回</el-button>
- <h2 class="adm-page-header__title">{{ title }}</h2>
- <span v-if="count !== null && count !== undefined" class="adm-page-header__count">共 {{ count }} 条</span>
- </div>
- <p v-if="subtitle" class="adm-page-header__subtitle">{{ subtitle }}</p>
- </div>
- <div class="adm-page-header__extra">
- <slot />
- </div>
- </div>
- </template>
- <script>
- /**
- * PageHeader —— 统一页头
- *
- * 设计目的:后台 47 个页面各自手写
- * <div class="admin-page-header"><span class="admin-page-title">标题</span><el-button>...</el-button></div>
- * 结构/间距/字号不统一。本组件把「标题 + 副标题 + 右侧操作区」收敛为一处。
- *
- * 用法:
- * <PageHeader title="会员管理" subtitle="等级与权益配置">
- * <el-button size="small" icon="el-icon-refresh">刷新</el-button>
- * </PageHeader>
- *
- * 也可作为卡片 header 内容:
- * <el-card><div slot="header"><PageHeader title="编辑商品" /></div> ... </el-card>
- */
- export default {
- name: 'PageHeader',
- props: {
- /** 页面标题 */
- title: { type: String, required: true },
- /** 副标题/说明 */
- subtitle: { type: String, default: '' },
- /** 列表总数,传入则在标题后展示「共 N 条」 */
- count: { type: [Number, String], default: null },
- /** 是否展示返回按钮 */
- back: { type: Boolean, default: false }
- },
- methods: {
- handleBack() {
- // 默认回退一级;页面可通过 @back 覆盖(本组件派发 back 事件)
- this.$emit('back')
- if (!this.$listeners || !this.$listeners.back) {
- this.$router && this.$router.back()
- }
- }
- }
- }
- </script>
- <style scoped>
- .adm-page-header {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- gap: 16px;
- margin-bottom: 16px;
- flex-wrap: wrap;
- }
- .adm-page-header__main {
- min-width: 0;
- flex: 1 1 auto;
- }
- .adm-page-header__title-row {
- display: flex;
- align-items: center;
- gap: 8px;
- min-width: 0;
- }
- .adm-page-header__back {
- padding: 0;
- margin-right: -2px;
- }
- .adm-page-header__title {
- margin: 0;
- font-size: 20px;
- font-weight: 600;
- line-height: 28px;
- color: #262626;
- }
- .adm-page-header__count {
- font-size: 12px;
- color: #8c8c8c;
- font-variant-numeric: tabular-nums;
- }
- .adm-page-header__subtitle {
- margin: 4px 0 0;
- font-size: 12px;
- line-height: 20px;
- color: #8c8c8c;
- }
- .adm-page-header__extra {
- flex: 0 0 auto;
- display: flex;
- align-items: center;
- gap: 8px;
- }
- /* 窄屏下操作区换行,避免挤压标题 */
- @media (max-width: 768px) {
- .adm-page-header__extra {
- width: 100%;
- flex-wrap: wrap;
- }
- }
- </style>
|