wizard.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <th:block th:include="include :: header('表单向导')" />
  5. <th:block th:include="include :: jquery-smartwizard-css" />
  6. <style type="text/css">
  7. /* 如果要让工具栏固定在页面底部,使用下面的样式,不需要的可以注释 */
  8. .sw>.toolbar-bottom{
  9. z-index: 100;
  10. bottom: 0px;
  11. left: 0;
  12. width: 100%;
  13. position: fixed;
  14. text-align: right;
  15. background: #fff;
  16. box-shadow: 0 -2px 6px 1px hsla(223,8%,83%,.5);
  17. border-top: 1px solid #e3e4e8;
  18. }
  19. /* 如果设置了是否自动调节高度为false,需要加滚动条 */
  20. .sw>.tab-content{
  21. overflow-x: hidden;
  22. overflow-y: auto;
  23. }
  24. /* 解决工具栏无法固定底部的问题(如果页面没有animated类可以不写这部分代码) */
  25. .animated {
  26. animation-fill-mode: none;
  27. -webkit-animation-fill-mode: none;
  28. -moz-animation-fill-mode: none;
  29. -o-animation-fill-mode: none;
  30. }
  31. </style>
  32. </head>
  33. <body class="gray-bg">
  34. <div class="wrapper wrapper-content animated fadeInRight" style="height: 100%;">
  35. <div class="row">
  36. <div class="col-sm-12">
  37. <div class="ibox">
  38. <div class="ibox-title">
  39. <h5>
  40. 表单向导
  41. <small>https://github.com/techlab/jquery-smartwizard</small>
  42. </h5>
  43. </div>
  44. <div class="ibox-content">
  45. <div class="row select-list" style="padding-left: 15px; margin-bottom: 10px;">
  46. <ul>
  47. <li>
  48. 选择样式:
  49. <select id="theme-selector">
  50. <option value="default">Default</option>
  51. <option value="arrows" selected>Arrows</option>
  52. <option value="dots">Dots</option>
  53. <option value="progress">Progress</option>
  54. </select>
  55. </li>
  56. <!-- 快速操作栏按钮 -->
  57. <li>
  58. <div class="btn-group-sm" role="group">
  59. <a class="btn btn-info" id="prev-btn"> 上一步 </a>
  60. <a class="btn btn-success" id="next-btn"> 下一步 </a>
  61. <a class="btn btn-danger" id="reset-btn"> 重置 </a>
  62. </div>
  63. </li>
  64. </ul>
  65. </div>
  66. <div id="smartwizard">
  67. <ul class="nav">
  68. <li class="nav-item">
  69. <a class="nav-link" href="#step-1"> 第一步 </a>
  70. </li>
  71. <li class="nav-item">
  72. <a class="nav-link" href="#step-2"> 第二步 </a>
  73. </li>
  74. <li class="nav-item">
  75. <a class="nav-link" href="#step-3"> 第三步 </a>
  76. </li>
  77. <li class="nav-item">
  78. <a class="nav-link" href="#step-4"> 第四步 </a>
  79. </li>
  80. </ul>
  81. <div class="tab-content">
  82. <div id="step-1" class="tab-pane" role="tabpanel" aria-labelledby="step-1">
  83. <div>
  84. <form class="form form-horizontal m-t">
  85. <div class="form-group">
  86. <label class="col-sm-3 control-label">姓氏:</label>
  87. <div class="col-sm-8">
  88. <input id="firstname" name="firstname" class="form-control" type="text">
  89. <span class="help-block m-b-none">
  90. <i class="fa fa-info-circle"></i>
  91. 这里写点提示的内容
  92. </span>
  93. </div>
  94. </div>
  95. <div class="form-group">
  96. <label class="col-sm-3 control-label is-required">名字:</label>
  97. <div class="col-sm-8">
  98. <input id="lastname" name="lastname" class="form-control" type="text" required>
  99. </div>
  100. </div>
  101. <div class="form-group">
  102. <label class="col-sm-3 control-label is-required">用户名:</label>
  103. <div class="col-sm-8">
  104. <input id="username" name="username" class="form-control" type="text" required>
  105. </div>
  106. </div>
  107. <div class="form-group">
  108. <label class="col-sm-3 control-label">密码:</label>
  109. <div class="col-sm-8">
  110. <input id="password" name="password" class="form-control" type="password">
  111. </div>
  112. </div>
  113. <div class="form-group">
  114. <label class="col-sm-3 control-label">确认密码:</label>
  115. <div class="col-sm-8">
  116. <input id="confirm_password" name="confirm_password" class="form-control" type="password">
  117. <span class="help-block m-b-none">
  118. <i class="fa fa-info-circle"></i>
  119. 请再次输入您的密码
  120. </span>
  121. </div>
  122. </div>
  123. <div class="form-group">
  124. <label class="col-sm-3 control-label">E-mail:</label>
  125. <div class="col-sm-8">
  126. <input id="email" name="email" class="form-control" type="email">
  127. </div>
  128. </div>
  129. </form>
  130. </div>
  131. </div>
  132. <div id="step-2" class="tab-pane" role="tabpanel" aria-labelledby="step-2">
  133. <div>
  134. <form class="form form-horizontal m-t">
  135. <div class="form-group">
  136. <label class="col-sm-3 control-label">性别:</label>
  137. <div class="col-sm-8">
  138. <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
  139. <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
  140. </select>
  141. </div>
  142. </div>
  143. <div class="form-group">
  144. <label class="col-sm-3 control-label">时间:</label>
  145. <div class="col-sm-8">
  146. <input id="time" name="time" class="form-control time-input" type="text">
  147. </div>
  148. </div>
  149. <div class="form-group">
  150. <label class="col-sm-3 control-label">状态:</label>
  151. <div class="col-sm-8">
  152. <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
  153. <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
  154. <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
  155. </div>
  156. </div>
  157. </div>
  158. </form>
  159. </div>
  160. </div>
  161. <div id="step-3" class="tab-pane" role="tabpanel" aria-labelledby="step-3">
  162. <div class="m-t-md">
  163. <p>1、如果需要工具栏在页面底部显示, 将style中下面的部分取消注释<blockquote>.sw>.toolbar-bottom </blockquote></p>
  164. <p>2、如果设置了自动调节高度为false, 将style中下面的部分取消注释<blockquote>.sw>.tab-content </blockquote></p>
  165. <p>3、工具栏的按钮样式会被表单插件中.btn样式覆盖导致bootstrap中的按钮样式无效, 如果需要改变按钮样式可以自己定义并提高优先级</blockquote></p>
  166. </div>
  167. </div>
  168. <div id="step-4" class="tab-pane" role="tabpanel" aria-labelledby="step-4">
  169. <div class="m-t-md">
  170. <h3>测试多行显示</h3>
  171. <pre style="overflow-x: hidden;">
  172. $('#smartwizard').smartWizard({
  173. selected: 0, // Initial selected step, 0 = first step
  174. theme: 'default', // theme for the wizard, related css need to include for other than default theme
  175. justified: true, // Nav menu justification. true/false
  176. darkMode:false, // Enable/disable Dark Mode if the theme supports. true/false
  177. autoAdjustHeight: true, // Automatically adjust content height
  178. cycleSteps: false, // Allows to cycle the navigation of steps
  179. backButtonSupport: true, // Enable the back button support
  180. enableURLhash: true, // Enable selection of the step based on url hash
  181. transition: {
  182. animation: 'none', // Effect on navigation, none/fade/slide-horizontal/slide-vertical/slide-swing
  183. speed: '400', // Transion animation speed
  184. easing:'' // Transition animation easing. Not supported without a jQuery easing plugin
  185. },
  186. toolbarSettings: {
  187. toolbarPosition: 'bottom', // none, top, bottom, both
  188. toolbarButtonPosition: 'right', // left, right, center
  189. showNextButton: true, // show/hide a Next button
  190. showPreviousButton: true, // show/hide a Previous button
  191. toolbarExtraButtons: [] // Extra buttons to show on toolbar, array of jQuery input/buttons elements
  192. },
  193. anchorSettings: {
  194. anchorClickable: true, // Enable/Disable anchor navigation
  195. enableAllAnchors: false, // Activates all anchors clickable all times
  196. markDoneStep: true, // Add done state on navigation
  197. markAllPreviousStepsAsDone: true, // When a step selected by url hash, all previous steps are marked done
  198. removeDoneStepOnNavigateBack: false, // While navigate back done step after active step will be cleared
  199. enableAnchorOnDoneStep: true // Enable/Disable the done steps navigation
  200. },
  201. keyboardSettings: {
  202. keyNavigation: true, // Enable/Disable keyboard navigation(left and right keys are used if enabled)
  203. keyLeft: [37], // Left key code
  204. keyRight: [39] // Right key code
  205. },
  206. lang: { // Language variables for button
  207. next: 'Next',
  208. previous: 'Previous'
  209. },
  210. disabledSteps: [], // Array Steps disabled
  211. errorSteps: [], // Highlight step with errors
  212. hiddenSteps: [] // Hidden steps
  213. });
  214. </pre>
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <th:block th:include="include :: footer" />
  225. <th:block th:include="include :: jquery-smartwizard-js" />
  226. <script>
  227. $(document).ready(function() {
  228. // 工具栏按钮
  229. var btnFinish = $('<a id="btn-finish"></a>').text('完成')
  230. .addClass('btn btn-info')
  231. .on('click', function(){ submit(); });
  232. var btnCancel = $('<a id="btn-cancel"></a>').text('取消')
  233. .addClass('btn btn-danger')
  234. .on('click', function(){ $('#smartwizard').smartWizard("reset"); });
  235. // 下面两个按钮是为了因为插件默认的是botton,这里换成<a>,也可以选择用样式替换,或者不替换
  236. var btnNext = $('<a id="btn-next"></a>').text('下一步')
  237. .addClass('btn btn-info')
  238. .on('click', function(){ $('#smartwizard').smartWizard("next");});
  239. var btnPrev = $('<a id="btn-prev"></a>').text('上一步')
  240. .addClass('btn btn-success disabled')
  241. .on('click', function(){ $('#smartwizard').smartWizard("prev"); });
  242. // 初始化表单向导组件
  243. $('#smartwizard').smartWizard({
  244. theme: 'arrows', // default, arrows, dots, progress
  245. autoAdjustHeight : false, // 自动调整高度, 默认true
  246. enableURLhash:false, //开启URL hash,开启后点击浏览器前进后退按钮会执行下一步和上一步操作
  247. transition: {
  248. animation: 'slide-horizontal', // Effect on navigation, none/fade/slide-horizontal/slide-vertical/slide-swing
  249. },
  250. toolbarSettings: {
  251. showNextButton: false,// 因为上面自定义了下一步按钮, 所以隐藏掉插件自带的按钮, 如果不使用自定义按钮, 需要改为true或者去掉该属性
  252. showPreviousButton: false,// 因为上面自定义了上一步按钮, 所以隐藏掉插件自带的按钮, 如果不使用自定义按钮, 需要改为true或者去掉该属性
  253. toolbarExtraButtons: [btnCancel,btnPrev,btnNext,btnFinish]// 扩展的按钮集合
  254. }
  255. });
  256. });
  257. function submit(){
  258. var data = {};
  259. $('.form').each(function (index, form){
  260. // 这里可以使用$.common.formToJSON(formId); 需要在form上加id
  261. $.each($(form).serializeArray(), function(i, field) {
  262. if(data[field.name]) {
  263. data[field.name] += ("," + field.value);
  264. } else {
  265. data[field.name] = field.value;
  266. }
  267. });
  268. });
  269. alert(JSON.stringify(data))
  270. }
  271. // 显示步骤时将触发事件
  272. $("#smartwizard").on("showStep", function(e, anchorObject, stepNumber, stepDirection, stepPosition) {
  273. // 下面按钮是快速操作栏的
  274. $("#prev-btn").removeClass('disabled');
  275. $("#next-btn").removeClass('disabled');
  276. // 下面按钮是工具栏的
  277. $("#btn-prev").removeClass('disabled');
  278. $("#btn-next").removeClass('disabled');
  279. $("#btn-finish").removeClass('disabled');
  280. if(stepPosition === 'first') {
  281. $("#prev-btn").addClass('disabled');// 快速操作栏(演示用)
  282. $("#btn-prev").addClass('disabled');
  283. $("#btn-finish").addClass('disabled');
  284. } else if(stepPosition === 'last') {
  285. $("#next-btn").addClass('disabled');// 快速操作栏(演示用)
  286. $("#btn-next").addClass('disabled');
  287. } else {
  288. $("#prev-btn").removeClass('disabled');// 快速操作栏(演示用)
  289. $("#next-btn").removeClass('disabled');// 快速操作栏(演示用)
  290. $("#btn-prev").removeClass('disabled');
  291. $("#btn-next").removeClass('disabled');
  292. $("#btn-finish").addClass('disabled');
  293. }
  294. });
  295. // 该事件在离开某个步骤之前触发
  296. $("#smartwizard").on("leaveStep", function(e, anchorObject, currentStepNumber, nextStepNumber, stepDirection) {
  297. if(stepDirection == 'forward'){
  298. var form = $("#step-" + (currentStepNumber + 1)).find('.form');
  299. if(form.length > 0){
  300. return form.validate().form();
  301. }
  302. return true;
  303. }
  304. return true;
  305. });
  306. $("#theme-selector").on("change", function() {
  307. // Change theme
  308. var options = {
  309. theme : $(this).val()
  310. };
  311. $('#smartwizard').smartWizard("setOptions", options);
  312. return true;
  313. });
  314. $("#reset-btn").on("click", function() {
  315. // Reset wizard
  316. $('#smartwizard').smartWizard("reset");
  317. return true;
  318. });
  319. $("#prev-btn").on("click", function() {
  320. // Navigate previous
  321. $('#smartwizard').smartWizard("prev");
  322. return true;
  323. });
  324. $("#next-btn").on("click", function() {
  325. // Navigate next
  326. $('#smartwizard').smartWizard("next");
  327. return true;
  328. });
  329. </script>
  330. </body>
  331. </html>