全部效果加载与反馈

文件上传状态

Upload Status

文件条目根据操作显示待上传、上传中、完成或取消。

试着开始或取消模拟上传

适用场景

让上传文件或大型媒体的用户了解进展。 上传的各个阶段都让文件名、当前状态和可操作项留在同一行,批量处理时容易核对。

应用示例

研究档案平台先把选中的访谈录音标为「待上传」,开始后在该行显示进度。研究员中途取消,文件行随即标为「已取消」,状态仍对应这份录音。

AI 提示词

为【文件】显示上传状态。展示文件名、按已发送字节计算的进度、取消操作和明确的成功或失败结果,取消后恢复相应操作。

示例代码

保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。

查看 HTML
<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>文件上传状态</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
    .panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
    .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
    .label { margin: 0; font-size: 13px; font-weight: 650; }
    .detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
    .caption { text-align: center; }
    .control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
    .control:hover { background: #514174; }
    .control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
    .control.primary:hover { background: #e3d8ff; }
    .control:disabled { opacity: .55; cursor: default; }
    .field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
    .field::placeholder { color: #c2abd8; }
    [hidden] { display: none !important; }

    .upload { display: grid; gap: 8px; }
    .upload progress { width: 100%; height: 8px; accent-color: #a9e3d9; }

    @media (prefers-reduced-motion: reduce) {
      .example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="example"><div class="panel upload"><div class="row"><p class="label">palette.png</p><button class="control primary" type="button">模拟上传</button></div><progress max="100" value="0" aria-label="上传进度"></progress><p class="detail" role="status">等待上传</p></div></div>
  </main>
  <script>
    const progress = document.querySelector('progress');
    const status = document.querySelector('[role="status"]');
    const action = document.querySelector('button');
    let timer = 0;
    action.addEventListener('click', () => {
      if (timer) {
        clearInterval(timer);
        timer = 0;
        progress.value = 0;
        status.textContent = "已取消上传";
        action.textContent = "模拟上传";
        return;
      }
      progress.value = 0;
      status.textContent = "上传中 0%";
      action.textContent = "取消";
      timer = setInterval(() => {
        progress.value = Math.min(100, progress.value + 20);
        status.textContent = "上传中" + ' ' + progress.value + '%';
        if (progress.value !== 100) return;
        clearInterval(timer);
        timer = 0;
        status.textContent = "上传完成";
        action.textContent = "重新上传";
      }, 160);
    });
  </script>
</body>
</html>

UI Skills 原创示例