test_confirm_flow.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Layer Confirm Flow - Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <style>
  9. .row {
  10. display: flex;
  11. flex-wrap: wrap;
  12. gap: 10px;
  13. align-items: center;
  14. }
  15. .btn {
  16. appearance: none;
  17. border: 1px solid rgba(255,255,255,0.12);
  18. background: rgba(255,255,255,0.04);
  19. color: #fff;
  20. border-radius: 999px;
  21. padding: 10px 14px;
  22. font-weight: 650;
  23. cursor: pointer;
  24. transition: border-color 0.15s ease, background 0.15s ease;
  25. }
  26. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  27. .btn.danger { border-color: rgba(255,75,75,0.55); background: rgba(255,75,75,0.12); }
  28. .btn.danger:hover { border-color: rgba(255,75,75,0.7); background: rgba(255,75,75,0.18); }
  29. .demo-visual { padding: 22px 24px; }
  30. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="container">
  35. <div class="page-top">
  36. <div class="crumb">UI › LAYER</div>
  37. <div class="since">CONFIRM FLOW</div>
  38. </div>
  39. <h1>Confirm flow</h1>
  40. <p class="description">
  41. The promise resolves with <code class="inline">{ isConfirmed, isDismissed, dismiss }</code>. This page shows how to chain a follow-up popup (success / info / error).
  42. </p>
  43. <div class="box-container">
  44. <div class="box-header">
  45. <div class="box-title">Example</div>
  46. <div class="tabs">
  47. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  48. <div class="tab" onclick="switchTab('html')">HTML</div>
  49. <div class="tab" onclick="switchTab('css')">CSS</div>
  50. </div>
  51. </div>
  52. <pre id="js-code" class="code-view active">xjs.layer({
  53. title: 'Delete item?',
  54. text: 'This action cannot be undone.',
  55. icon: 'warning',
  56. showCancelButton: true,
  57. confirmButtonText: 'Delete',
  58. cancelButtonText: 'Cancel'
  59. }).then((res) => {
  60. if (res.isConfirmed) {
  61. xjs.layer({ title: 'Deleted', icon: 'success' });
  62. } else {
  63. xjs.layer({ title: 'Cancelled', icon: 'info' });
  64. }
  65. });</pre>
  66. <pre id="html-code" class="html-view">&lt;button class="btn danger"&gt;Open confirm&lt;/button&gt;</pre>
  67. <pre id="css-code" class="css-view">/* Local styles for buttons only */</pre>
  68. <div class="feature-desc">
  69. <strong>功能说明:</strong>验证 Layer 的 Promise 结果结构,以及多弹窗串联时的体验(warning → success/info)。
  70. </div>
  71. <div class="demo-visual">
  72. <div class="row">
  73. <button class="btn danger" onclick="openConfirm()">Open confirm</button>
  74. <button class="btn" onclick="openError()">Open error</button>
  75. </div>
  76. <div class="hint">
  77. “Open error” shows the staggered X mark animation.
  78. </div>
  79. </div>
  80. </div>
  81. <div class="doc-nav" aria-label="Previous and next navigation">
  82. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  83. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  84. <span aria-hidden="true">←</span>
  85. </a>
  86. <div class="nav-center" id="navCenter">Layer</div>
  87. <a href="#" id="nextLink" onclick="goNext(); return false;">
  88. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  89. <span aria-hidden="true">→</span>
  90. </a>
  91. </div>
  92. </div>
  93. <script src="../highlight_css.js"></script>
  94. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  95. <script>
  96. (function () {
  97. var b = Date.now();
  98. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  99. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  100. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  101. })();
  102. </script>
  103. <script>
  104. const CURRENT = 'layer/test_confirm_flow.html';
  105. function switchTab(tab) {
  106. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  107. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  108. if (tab === 'js') {
  109. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  110. document.getElementById('js-code')?.classList.add('active');
  111. } else if (tab === 'html') {
  112. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  113. document.getElementById('html-code')?.classList.add('active');
  114. } else {
  115. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  116. document.getElementById('css-code')?.classList.add('active');
  117. }
  118. }
  119. function openConfirm() {
  120. xjs.layer({
  121. title: 'Delete item?',
  122. text: 'This action cannot be undone.',
  123. icon: 'question',
  124. popupAnimation: true,
  125. showCancelButton: true,
  126. confirmButtonText: 'Delete',
  127. cancelButtonText: 'Cancel',
  128. confirmButtonColor: '#d33',
  129. cancelButtonColor: '#444'
  130. }).then((res) => {
  131. if (res.isConfirmed) {
  132. xjs.layer({ title: 'Deleted', text: 'Done', icon: 'success' });
  133. } else if (res.dismiss === 'cancel') {
  134. xjs.layer({ title: 'Cancelled', text: 'No changes', icon: 'info' });
  135. } else {
  136. xjs.layer({ title: 'Dismissed', text: 'Backdrop / ESC', icon: 'info' });
  137. }
  138. });
  139. }
  140. function openError() {
  141. xjs.layer({ title: 'Error', text: 'Example error popup', icon: 'error', popupAnimation: true });
  142. }
  143. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  144. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  145. function syncNavLabels() {
  146. const api = window.parent?.docGetPrevNext;
  147. if (typeof api !== 'function') return;
  148. const { prev, next, current } = api(CURRENT) || {};
  149. const prevLink = document.getElementById('prevLink');
  150. const nextLink = document.getElementById('nextLink');
  151. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  152. else { prevLink.style.visibility = 'hidden'; }
  153. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  154. else { nextLink.style.visibility = 'hidden'; }
  155. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  156. }
  157. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  158. syncNavLabels();
  159. </script>
  160. </body>
  161. </html>