oa-start-button-loading-demo.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <title>发起审批 · 按钮加载态 Demo</title>
  7. <style>
  8. :root {
  9. --brand: #16a34a;
  10. --brand-dark: #15803d;
  11. --brand-soft: #f0fdf4;
  12. --bg: #f5f8f7;
  13. --ink: #1f2a26;
  14. --muted: #6b7b74;
  15. --border: #dcebe4;
  16. }
  17. * { box-sizing: border-box; }
  18. body {
  19. margin: 0;
  20. font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  21. color: var(--ink);
  22. background:
  23. radial-gradient(900px 480px at 0% -10%, #dcfce7 0%, transparent 50%),
  24. radial-gradient(700px 400px at 100% 0%, #e8f5ee 0%, transparent 45%),
  25. var(--bg);
  26. line-height: 1.45;
  27. }
  28. .wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 96px; }
  29. h1 { margin: 0 0 8px; font-size: 22px; letter-spacing: -0.02em; }
  30. .sub { margin: 0; color: var(--muted); font-size: 14px; max-width: 720px; }
  31. .note {
  32. margin: 14px 0 22px;
  33. padding: 10px 12px;
  34. border-radius: 10px;
  35. background: #fff;
  36. border: 1px solid #e2e8e5;
  37. font-size: 13px;
  38. color: var(--muted);
  39. }
  40. .note strong { color: var(--brand-dark); font-weight: 650; }
  41. .grid {
  42. display: grid;
  43. grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  44. gap: 16px;
  45. }
  46. .card {
  47. background: #fff;
  48. border: 1px solid #e2e8e5;
  49. border-radius: 16px;
  50. padding: 14px;
  51. transition: border-color .15s, box-shadow .15s;
  52. }
  53. .card.is-selected {
  54. border-color: var(--brand);
  55. box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent);
  56. }
  57. .card.is-rec {
  58. outline: 2px dashed color-mix(in srgb, var(--brand) 45%, transparent);
  59. outline-offset: 2px;
  60. }
  61. .badge-row {
  62. display: flex;
  63. align-items: center;
  64. gap: 8px;
  65. margin-bottom: 8px;
  66. flex-wrap: wrap;
  67. }
  68. .letter {
  69. width: 28px; height: 28px;
  70. border-radius: 8px;
  71. background: var(--brand-soft);
  72. color: var(--brand-dark);
  73. display: grid; place-items: center;
  74. font-weight: 700; font-size: 13px;
  75. }
  76. .tag {
  77. font-size: 11px;
  78. padding: 2px 8px;
  79. border-radius: 999px;
  80. background: #f1f5f3;
  81. color: var(--muted);
  82. }
  83. .tag.warn { background: #fff7ed; color: #c2410c; }
  84. .tag.rec { background: var(--brand-soft); color: var(--brand-dark); font-weight: 650; }
  85. .card h2 {
  86. margin: 0 0 4px;
  87. font-size: 15px;
  88. font-weight: 650;
  89. }
  90. .card p {
  91. margin: 0 0 12px;
  92. font-size: 12.5px;
  93. color: var(--muted);
  94. }
  95. .phone {
  96. border: 1px solid var(--border);
  97. border-radius: 14px;
  98. background: var(--bg);
  99. overflow: hidden;
  100. }
  101. .phone-body {
  102. height: 88px;
  103. padding: 12px;
  104. font-size: 12px;
  105. color: var(--muted);
  106. }
  107. .ft {
  108. display: flex;
  109. gap: 10px;
  110. align-items: center;
  111. padding: 10px 12px;
  112. background: #fff;
  113. border-top: 1px solid var(--border);
  114. box-shadow: 0 -4px 16px rgba(31, 42, 38, 0.04);
  115. }
  116. .btn {
  117. margin: 0;
  118. height: 40px;
  119. border-radius: 8px;
  120. font-size: 14px;
  121. font-family: inherit;
  122. cursor: pointer;
  123. display: inline-flex;
  124. align-items: center;
  125. justify-content: center;
  126. gap: 6px;
  127. padding: 0 12px;
  128. transition: opacity .15s, filter .15s;
  129. position: relative;
  130. overflow: hidden;
  131. -webkit-tap-highlight-color: transparent;
  132. }
  133. .btn:disabled { cursor: not-allowed; }
  134. .btn-cancel {
  135. flex: 0 0 64px;
  136. border: none;
  137. background: transparent;
  138. color: var(--muted);
  139. padding: 0;
  140. }
  141. .btn-draft {
  142. flex: 1;
  143. border: 1.5px solid var(--brand);
  144. background: #fff;
  145. color: var(--brand-dark);
  146. font-weight: 600;
  147. }
  148. .btn-submit {
  149. flex: 1.35;
  150. border: none;
  151. background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  152. color: #fff;
  153. font-weight: 700;
  154. box-shadow: 0 6px 14px rgba(22, 163, 74, 0.28);
  155. }
  156. .btn.is-loading { pointer-events: none; }
  157. /* spinner */
  158. .spin {
  159. width: 16px; height: 16px;
  160. border: 2px solid currentColor;
  161. border-right-color: transparent;
  162. border-radius: 50%;
  163. animation: spin .7s linear infinite;
  164. flex-shrink: 0;
  165. }
  166. .spin--lg { width: 18px; height: 18px; }
  167. @keyframes spin { to { transform: rotate(360deg); } }
  168. /* A: 现状 — 文字消失,只剩转圈 */
  169. .a .btn.is-loading .label { display: none; }
  170. .a .btn.is-loading .spin-only { display: block; }
  171. .a .spin-only { display: none; }
  172. /* B: 左侧小转圈 + 文案保留/改为「…中」 */
  173. /* default markup handles it */
  174. /* C: 仅改文案,无转圈 */
  175. /* handled in JS text swap */
  176. /* D: 文案 + 跳动三点 */
  177. .dots span {
  178. display: inline-block;
  179. animation: bounce 1.1s infinite ease-in-out;
  180. opacity: .35;
  181. }
  182. .dots span:nth-child(2) { animation-delay: .15s; }
  183. .dots span:nth-child(3) { animation-delay: .3s; }
  184. @keyframes bounce {
  185. 0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  186. 40% { opacity: 1; transform: translateY(-2px); }
  187. }
  188. /* E: 保留文案 + 按钮内浅色 shimmer */
  189. .e .btn.is-loading::after {
  190. content: "";
  191. position: absolute;
  192. inset: 0;
  193. background: linear-gradient(
  194. 105deg,
  195. transparent 35%,
  196. rgba(255,255,255,.35) 50%,
  197. transparent 65%
  198. );
  199. background-size: 200% 100%;
  200. animation: shimmer 1.1s ease-in-out infinite;
  201. pointer-events: none;
  202. }
  203. .e .btn-draft.is-loading::after {
  204. background: linear-gradient(
  205. 105deg,
  206. transparent 35%,
  207. rgba(22,163,74,.12) 50%,
  208. transparent 65%
  209. );
  210. background-size: 200% 100%;
  211. }
  212. @keyframes shimmer {
  213. 0% { background-position: 100% 0; }
  214. 100% { background-position: -100% 0; }
  215. }
  216. /* F: 保留文案 + 整体脉冲透明度 */
  217. .f .btn.is-loading {
  218. animation: pulse 1s ease-in-out infinite;
  219. }
  220. @keyframes pulse {
  221. 0%, 100% { opacity: 1; }
  222. 50% { opacity: .55; }
  223. }
  224. /* G: 转圈叠在文字上(半透明底)— 接近现状但更差,作对比 */
  225. .g .btn.is-loading .label { opacity: .25; }
  226. .g .btn.is-loading .overlay-spin {
  227. position: absolute;
  228. inset: 0;
  229. display: grid;
  230. place-items: center;
  231. background: rgba(0,0,0,.06);
  232. }
  233. .g .overlay-spin { display: none; }
  234. .g .btn.is-loading .overlay-spin { display: grid; }
  235. .actions {
  236. margin-top: 10px;
  237. display: flex;
  238. gap: 8px;
  239. }
  240. .pick {
  241. flex: 1;
  242. height: 34px;
  243. border-radius: 8px;
  244. border: 1px solid var(--border);
  245. background: #fff;
  246. color: var(--ink);
  247. font-size: 13px;
  248. font-family: inherit;
  249. cursor: pointer;
  250. }
  251. .pick:hover { border-color: var(--brand); color: var(--brand-dark); }
  252. .card.is-selected .pick {
  253. background: var(--brand);
  254. border-color: var(--brand);
  255. color: #fff;
  256. font-weight: 650;
  257. }
  258. .hint {
  259. margin-top: 8px;
  260. font-size: 11px;
  261. color: var(--muted);
  262. text-align: center;
  263. }
  264. .bar {
  265. position: sticky;
  266. bottom: 0;
  267. margin-top: 28px;
  268. padding: 12px 14px;
  269. background: rgba(255,255,255,.92);
  270. backdrop-filter: blur(8px);
  271. border: 1px solid #e2e8e5;
  272. border-radius: 12px;
  273. font-size: 13px;
  274. color: var(--muted);
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. gap: 12px;
  279. flex-wrap: wrap;
  280. }
  281. .bar strong { color: var(--brand-dark); }
  282. </style>
  283. </head>
  284. <body>
  285. <div class="wrap">
  286. <h1>发起审批 · 底栏按钮加载态对比</h1>
  287. <p class="sub">
  288. 模拟「暂存草稿 / 提交」点击后的等待反馈。点任意主按钮可预览约 2 秒加载态;选中喜欢的方案后告诉我编号即可落地。
  289. </p>
  290. <div class="note">
  291. <strong>现状问题:</strong>Vant <code>:loading</code> 默认会把按钮文字藏掉,中间只剩一个转圈,看起来像「按钮坏了 / 内容丢失」,而不是「正在处理」。
  292. 更好的做法一般是:<strong>保留语义文案</strong>(如「提交中…」),转圈可有可无、且应偏小、靠左。
  293. </div>
  294. <div class="grid">
  295. <!-- A -->
  296. <article class="card a" data-id="A" data-name="现状:只剩转圈">
  297. <div class="badge-row">
  298. <span class="letter">A</span>
  299. <span class="tag warn">现状 / 不推荐</span>
  300. </div>
  301. <h2>文字消失 · 中间转圈</h2>
  302. <p>Vant 默认 loading:文案隐藏,只留 spinner。容易误以为按钮空白或出错。</p>
  303. <div class="phone">
  304. <div class="phone-body">表单区占位…</div>
  305. <div class="ft">
  306. <button type="button" class="btn btn-cancel">取消</button>
  307. <button type="button" class="btn btn-draft" data-role="draft">
  308. <span class="spin spin-only" aria-hidden="true"></span>
  309. <span class="label">暂存草稿</span>
  310. </button>
  311. <button type="button" class="btn btn-submit" data-role="submit">
  312. <span class="spin spin-only spin--lg" aria-hidden="true"></span>
  313. <span class="label">提交</span>
  314. </button>
  315. </div>
  316. </div>
  317. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  318. <div class="actions"><button type="button" class="pick">选这个</button></div>
  319. </article>
  320. <!-- B -->
  321. <article class="card b is-rec" data-id="B" data-name="小转圈 + 文案">
  322. <div class="badge-row">
  323. <span class="letter">B</span>
  324. <span class="tag rec">推荐</span>
  325. </div>
  326. <h2>左侧小转圈 +「…中」文案</h2>
  327. <p>保留可读语义:暂存中… / 提交中…。转圈提示进度,文案说明在做什么。行业常见做法。</p>
  328. <div class="phone">
  329. <div class="phone-body">表单区占位…</div>
  330. <div class="ft">
  331. <button type="button" class="btn btn-cancel">取消</button>
  332. <button type="button" class="btn btn-draft" data-role="draft"
  333. data-idle="暂存草稿" data-busy="暂存中…">
  334. <span class="spin" hidden aria-hidden="true"></span>
  335. <span class="label">暂存草稿</span>
  336. </button>
  337. <button type="button" class="btn btn-submit" data-role="submit"
  338. data-idle="提交" data-busy="提交中…">
  339. <span class="spin" hidden aria-hidden="true"></span>
  340. <span class="label">提交</span>
  341. </button>
  342. </div>
  343. </div>
  344. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  345. <div class="actions"><button type="button" class="pick">选这个</button></div>
  346. </article>
  347. <!-- C -->
  348. <article class="card c" data-id="C" data-name="仅改文案">
  349. <div class="badge-row">
  350. <span class="letter">C</span>
  351. <span class="tag">轻量</span>
  352. </div>
  353. <h2>只改文案 · 无转圈</h2>
  354. <p>「提交」→「提交中…」,按钮禁用。最干净,但进度感稍弱;短请求时够用。</p>
  355. <div class="phone">
  356. <div class="phone-body">表单区占位…</div>
  357. <div class="ft">
  358. <button type="button" class="btn btn-cancel">取消</button>
  359. <button type="button" class="btn btn-draft" data-role="draft"
  360. data-idle="暂存草稿" data-busy="暂存中…">
  361. <span class="label">暂存草稿</span>
  362. </button>
  363. <button type="button" class="btn btn-submit" data-role="submit"
  364. data-idle="提交" data-busy="提交中…">
  365. <span class="label">提交</span>
  366. </button>
  367. </div>
  368. </div>
  369. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  370. <div class="actions"><button type="button" class="pick">选这个</button></div>
  371. </article>
  372. <!-- D -->
  373. <article class="card d" data-id="D" data-name="跳动三点">
  374. <div class="badge-row">
  375. <span class="letter">D</span>
  376. <span class="tag">活泼</span>
  377. </div>
  378. <h2>文案 + 跳动三点</h2>
  379. <p>「提交中···」三点依次闪动。无转圈、有动效,适合品牌感稍强的场景。</p>
  380. <div class="phone">
  381. <div class="phone-body">表单区占位…</div>
  382. <div class="ft">
  383. <button type="button" class="btn btn-cancel">取消</button>
  384. <button type="button" class="btn btn-draft" data-role="draft"
  385. data-idle="暂存草稿" data-busy-html='暂存中<span class="dots"><span>·</span><span>·</span><span>·</span></span>'>
  386. <span class="label">暂存草稿</span>
  387. </button>
  388. <button type="button" class="btn btn-submit" data-role="submit"
  389. data-idle="提交" data-busy-html='提交中<span class="dots"><span>·</span><span>·</span><span>·</span></span>'>
  390. <span class="label">提交</span>
  391. </button>
  392. </div>
  393. </div>
  394. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  395. <div class="actions"><button type="button" class="pick">选这个</button></div>
  396. </article>
  397. <!-- E -->
  398. <article class="card e" data-id="E" data-name="光带扫描">
  399. <div class="badge-row">
  400. <span class="letter">E</span>
  401. <span class="tag">动感</span>
  402. </div>
  403. <h2>保留文案 · 光带扫描</h2>
  404. <p>文字不变(或改为「…中」),按钮表面扫光。进度感强,实现稍重一点。</p>
  405. <div class="phone">
  406. <div class="phone-body">表单区占位…</div>
  407. <div class="ft">
  408. <button type="button" class="btn btn-cancel">取消</button>
  409. <button type="button" class="btn btn-draft" data-role="draft"
  410. data-idle="暂存草稿" data-busy="暂存中…">
  411. <span class="label">暂存草稿</span>
  412. </button>
  413. <button type="button" class="btn btn-submit" data-role="submit"
  414. data-idle="提交" data-busy="提交中…">
  415. <span class="label">提交</span>
  416. </button>
  417. </div>
  418. </div>
  419. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  420. <div class="actions"><button type="button" class="pick">选这个</button></div>
  421. </article>
  422. <!-- F -->
  423. <article class="card f" data-id="F" data-name="透明度脉冲">
  424. <div class="badge-row">
  425. <span class="letter">F</span>
  426. <span class="tag">极简</span>
  427. </div>
  428. <h2>保留文案 · 整体脉冲</h2>
  429. <p>文字改为「…中」,按钮透明度呼吸。实现最简单,但不够「明确在请求」。</p>
  430. <div class="phone">
  431. <div class="phone-body">表单区占位…</div>
  432. <div class="ft">
  433. <button type="button" class="btn btn-cancel">取消</button>
  434. <button type="button" class="btn btn-draft" data-role="draft"
  435. data-idle="暂存草稿" data-busy="暂存中…">
  436. <span class="label">暂存草稿</span>
  437. </button>
  438. <button type="button" class="btn btn-submit" data-role="submit"
  439. data-idle="提交" data-busy="提交中…">
  440. <span class="label">提交</span>
  441. </button>
  442. </div>
  443. </div>
  444. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  445. <div class="actions"><button type="button" class="pick">选这个</button></div>
  446. </article>
  447. <!-- G -->
  448. <article class="card g" data-id="G" data-name="转圈压字">
  449. <div class="badge-row">
  450. <span class="letter">G</span>
  451. <span class="tag warn">对比用</span>
  452. </div>
  453. <h2>转圈压在字上</h2>
  454. <p>文字半透明仍在,转圈居中覆盖。比 A 稍好但仍挤、难读,一般不建议。</p>
  455. <div class="phone">
  456. <div class="phone-body">表单区占位…</div>
  457. <div class="ft">
  458. <button type="button" class="btn btn-cancel">取消</button>
  459. <button type="button" class="btn btn-draft" data-role="draft">
  460. <span class="label">暂存草稿</span>
  461. <span class="overlay-spin"><span class="spin"></span></span>
  462. </button>
  463. <button type="button" class="btn btn-submit" data-role="submit">
  464. <span class="label">提交</span>
  465. <span class="overlay-spin"><span class="spin" style="border-color:#fff;border-right-color:transparent"></span></span>
  466. </button>
  467. </div>
  468. </div>
  469. <p class="hint">点「暂存草稿」或「提交」试效果</p>
  470. <div class="actions"><button type="button" class="pick">选这个</button></div>
  471. </article>
  472. </div>
  473. <div class="bar">
  474. <span>当前选择:<strong id="choice">未选</strong></span>
  475. <span>建议优先试 <strong>B</strong>(小转圈 + 文案),短接口也可考虑 <strong>C</strong>。</span>
  476. </div>
  477. </div>
  478. <script>
  479. const timers = new WeakMap()
  480. function setLoading(card, btn, on) {
  481. const id = card.dataset.id
  482. const label = btn.querySelector('.label')
  483. const spin = btn.querySelector('.spin:not(.spin-only)')
  484. btn.classList.toggle('is-loading', on)
  485. btn.disabled = on
  486. if (id === 'A') {
  487. // CSS handles hide label / show spin-only
  488. return
  489. }
  490. if (id === 'G') {
  491. return
  492. }
  493. if (spin) spin.hidden = !on
  494. if (btn.dataset.busyHtml) {
  495. if (on) label.innerHTML = btn.dataset.busyHtml
  496. else label.textContent = btn.dataset.idle || label.textContent
  497. return
  498. }
  499. if (btn.dataset.busy) {
  500. if (on) label.textContent = btn.dataset.busy
  501. else label.textContent = btn.dataset.idle || label.textContent
  502. }
  503. }
  504. document.querySelectorAll('.card').forEach((card) => {
  505. card.querySelectorAll('[data-role]').forEach((btn) => {
  506. btn.addEventListener('click', () => {
  507. if (btn.classList.contains('is-loading')) return
  508. // clear sibling loading in same footer
  509. card.querySelectorAll('[data-role]').forEach((b) => {
  510. clearTimeout(timers.get(b))
  511. setLoading(card, b, false)
  512. })
  513. setLoading(card, btn, true)
  514. const t = setTimeout(() => setLoading(card, btn, false), 2000)
  515. timers.set(btn, t)
  516. })
  517. })
  518. card.querySelector('.pick').addEventListener('click', () => {
  519. document.querySelectorAll('.card').forEach((c) => c.classList.remove('is-selected'))
  520. card.classList.add('is-selected')
  521. document.getElementById('choice').textContent =
  522. card.dataset.id + ' · ' + card.dataset.name
  523. })
  524. })
  525. </script>
  526. </body>
  527. </html>