workbench-card.vue 4.08 KB
<template>
  <div
    class="wb-card"
    :class="[
      `wb-card--${tone}`,
      { 'wb-card--flush': variant === 'banner', 'wb-card--compact': compact }
    ]"
  >
    <div v-if="variant !== 'banner'" class="wb-card__head">
      <div class="wb-card__title-row">
        <span v-if="icon" class="wb-card__icon" aria-hidden="true">
          <i :class="icon" />
        </span>
        <div class="wb-card__titles">
          <span class="wb-card__title">{{ title }}</span>
          <span v-if="subtitle" class="wb-card__subtitle">{{ subtitle }}</span>
        </div>
      </div>
      <div class="wb-card__extra">
        <slot name="extra" />
      </div>
    </div>
    <div class="wb-card__body" :class="{ 'is-banner': variant === 'banner' }" v-loading="loading">
      <slot />
    </div>
  </div>
</template>

<script>
export default {
  name: 'WorkbenchCard',
  props: {
    title: { type: String, default: '' },
    subtitle: { type: String, default: '' },
    icon: { type: String, default: '' },
    loading: { type: Boolean, default: false },
    editMode: { type: Boolean, default: false },
    tone: {
      type: String,
      default: 'blue',
      validator: v => ['blue', 'orange', 'green', 'purple', 'red', 'cyan', 'neutral'].includes(v)
    },
    variant: {
      type: String,
      default: 'default',
      validator: v => ['default', 'banner'].includes(v)
    },
    compact: { type: Boolean, default: false }
  }
}
</script>

<style lang="scss" scoped>
$primary: #409eff;
$surface: #fff;
$text: #1e293b;
$muted: #64748b;
$border: #e8eef5;
$radius: 12px;
$shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.04);
$shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.05), 0 10px 28px rgba(64, 158, 255, 0.12);

.wb-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: $surface;
  border-radius: $radius;
  border: 1px solid $border;
  box-shadow: $shadow;
  overflow: hidden;
  transition: box-shadow 200ms ease, border-color 200ms ease;

  &:hover {
    box-shadow: $shadow-hover;
    border-color: #dbe7f5;
  }

  &--flush {
    border: none;
    box-shadow: none;
    background: transparent;

    &:hover { box-shadow: none; }
  }
}

.wb-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 0;
  min-height: 40px;
  flex-shrink: 0;
}

.wb-card__title-row {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  gap: 10px;
}

.wb-card__icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: #ecf5ff;
  color: $primary;
}

.wb-card--orange .wb-card__icon { background: #fff7ed; color: #f59e0b; }
.wb-card--green .wb-card__icon { background: #ecfdf5; color: #10b981; }
.wb-card--purple .wb-card__icon { background: #f5f3ff; color: #8b5cf6; }
.wb-card--red .wb-card__icon { background: #fef2f2; color: #ef4444; }
.wb-card--cyan .wb-card__icon { background: #ecfeff; color: #06b6d4; }
.wb-card--neutral .wb-card__icon { background: #f1f5f9; color: #64748b; }

.wb-card__titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.wb-card__title {
  font-size: 14px;
  font-weight: 600;
  color: $text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

.wb-card__subtitle {
  margin-top: 1px;
  font-size: 11px;
  color: $muted;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wb-card__extra {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;

  >>> .el-button--text {
    color: $muted;
    font-size: 12px;
    padding: 0 4px;
    &:hover { color: $primary; }
  }
}

.wb-card__body {
  flex: 1;
  padding: 10px 14px 12px;
  /* 默认不出现滚动条,内容在卡片高度内自适应 */
  overflow: hidden;
  min-height: 0;

  &.is-banner {
    padding: 0;
    overflow: hidden;
  }
}

.wb-card--compact .wb-card__head { padding: 12px 14px 0; }
.wb-card--compact .wb-card__body { padding: 10px 14px 14px; }

@media (prefers-reduced-motion: reduce) {
  .wb-card { transition: none; }
}
</style>