wizard.html 14 KB

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