create.jsp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <%@ page contentType="text/html; charset=utf-8"%>
  2. <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
  5. <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
  6. <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
  7. <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
  8. <c:set var="basePath" value="${pageContext.request.contextPath}"/>
  9. <div id="createDialog" class="crudDialog">
  10. <form id="createForm" method="post">
  11. <div class="form-group">
  12. <label for="username">帐号</label>
  13. <input id="username" type="text" class="form-control" name="username" maxlength="20">
  14. </div>
  15. <div class="form-group">
  16. <label for="password">密码</label>
  17. <input id="password" type="text" class="form-control" name="password" maxlength="32">
  18. </div>
  19. <div class="form-group">
  20. <label for="realname">姓名</label>
  21. <input id="realname" type="text" class="form-control" name="realname" maxlength="20">
  22. </div>
  23. <div class="row">
  24. <div class="col-lg-8 form-group">
  25. <label for="avatar">头像</label>
  26. <input id="avatar" type="text" class="form-control" name="avatar" maxlength="150">
  27. </div>
  28. <div class="col-lg-4">
  29. <div id="picker">上传头像</div>
  30. </div>
  31. </div>
  32. <div class="form-group">
  33. <label for="phone">电话</label>
  34. <input id="phone" type="text" class="form-control" name="phone" maxlength="20">
  35. </div>
  36. <div class="form-group">
  37. <label for="email">邮箱</label>
  38. <input id="email" type="text" class="form-control" name="email" maxlength="50">
  39. </div>
  40. <div class="radio">
  41. <div class="radio radio-inline radio-info">
  42. <input id="sex_1" type="radio" name="sex" value="1" checked>
  43. <label for="sex_1">男 </label>
  44. </div>
  45. <div class="radio radio-inline radio-danger">
  46. <input id="sex_0" type="radio" name="sex" value="0">
  47. <label for="sex_0">女 </label>
  48. </div>
  49. <div class="radio radio-inline radio-success">
  50. <input id="locked_0" type="radio" name="locked" value="0" checked>
  51. <label for="locked_0">正常 </label>
  52. </div>
  53. <div class="radio radio-inline">
  54. <input id="locked_1" type="radio" name="locked" value="1">
  55. <label for="locked_1">锁定 </label>
  56. </div>
  57. </div>
  58. <div class="form-group text-right dialog-buttons">
  59. <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
  60. <a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
  61. </div>
  62. </form>
  63. </div>
  64. <script>
  65. function initUploader() {
  66. //百度上传按钮
  67. var uploader = WebUploader.create({
  68. // swf文件路径
  69. swf: '${basePath}/resources/zheng-admin/plugins/webuploader-0.1.5/Uploader.swf',
  70. // 文件接收服务端
  71. method: 'POST',
  72. // 选择文件的按钮。可选。
  73. // 内部根据当前运行是创建,可能是input元素,也可能是flash.
  74. pick: {
  75. "id": '#picker',
  76. "multiple": false
  77. },
  78. // 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
  79. resize: false,
  80. // 选完文件后,是否自动上传。
  81. auto: false,
  82. // 只允许选择图片文件
  83. accept: {
  84. title: '图片文件',
  85. extensions: 'gif,jpg,jpeg,bmp,png',
  86. mimeTypes: 'image/*'
  87. }
  88. });
  89. uploader.on( 'fileQueued', function(file) {
  90. $.ajax({
  91. url: '${ZHENG_OSS_ALIYUN_OSS_POLICY}',
  92. type: 'GET',
  93. dataType: 'jsonp',
  94. jsonp: 'callback',
  95. success: function(result) {
  96. var suffix = get_suffix(file.name);
  97. var random_name = random_string();
  98. uploader.options.formData.key = result.dir + '/' + random_name + suffix;
  99. uploader.options.formData.policy = result.policy;
  100. uploader.options.formData.OSSAccessKeyId = result.OSSAccessKeyId;
  101. uploader.options.formData.success_action_status = 200;
  102. uploader.options.formData.callback = result.callback;
  103. uploader.options.formData.signature = result.signature;
  104. uploader.options.server = result.action;
  105. uploader.upload();
  106. },
  107. error: function(msg) {
  108. console.log(msg);
  109. }
  110. });
  111. });
  112. uploader.on( 'uploadSuccess', function(file, response) {
  113. $('#avatar').val(response.data.filename).focus();
  114. });
  115. uploader.on( 'uploadError', function(file) {
  116. console.log('uploadError', file);
  117. });
  118. }
  119. // 根据路径获取后缀
  120. function get_suffix(filename) {
  121. var pos = filename.lastIndexOf('.');
  122. var suffix = '';
  123. if (pos != -1) {
  124. suffix = filename.substring(pos);
  125. }
  126. return suffix;
  127. }
  128. // 随机字符串
  129. function random_string(len) {
  130. len = len || 32;
  131. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  132. var maxPos = chars.length;
  133. var pwd = '';
  134. for (i = 0; i < len; i++) {
  135. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  136. }
  137. return pwd;
  138. }
  139. function createSubmit() {
  140. $.ajax({
  141. type: 'post',
  142. url: '${basePath}/manage/user/create',
  143. data: $('#createForm').serialize(),
  144. beforeSend: function() {
  145. if ($('#username').val() == '') {
  146. $('#username').focus();
  147. return false;
  148. }
  149. if ($('#password').val() == '' || $('#password').val().length < 5) {
  150. $('#password').focus();
  151. return false;
  152. }
  153. },
  154. success: function(result) {
  155. if (result.code != 1) {
  156. if (result.data instanceof Array) {
  157. $.each(result.data, function(index, value) {
  158. $.confirm({
  159. theme: 'dark',
  160. animation: 'rotateX',
  161. closeAnimation: 'rotateX',
  162. title: false,
  163. content: value.errorMsg,
  164. buttons: {
  165. confirm: {
  166. text: '确认',
  167. btnClass: 'waves-effect waves-button waves-light'
  168. }
  169. }
  170. });
  171. });
  172. } else {
  173. $.confirm({
  174. theme: 'dark',
  175. animation: 'rotateX',
  176. closeAnimation: 'rotateX',
  177. title: false,
  178. content: result.data.errorMsg || result.data,
  179. buttons: {
  180. confirm: {
  181. text: '确认',
  182. btnClass: 'waves-effect waves-button waves-light'
  183. }
  184. }
  185. });
  186. }
  187. } else {
  188. createDialog.close();
  189. $table.bootstrapTable('refresh');
  190. }
  191. },
  192. error: function(XMLHttpRequest, textStatus, errorThrown) {
  193. $.confirm({
  194. theme: 'dark',
  195. animation: 'rotateX',
  196. closeAnimation: 'rotateX',
  197. title: false,
  198. content: textStatus,
  199. buttons: {
  200. confirm: {
  201. text: '确认',
  202. btnClass: 'waves-effect waves-button waves-light'
  203. }
  204. }
  205. });
  206. }
  207. });
  208. }
  209. </script>