update.jsp 6.4 KB

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