update.jsp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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="theme"></label>
  13. <input id="theme" type="color" class="form-control" name="theme" maxlength="50" value="${system.theme}">
  14. </div>
  15. <div class="form-group">
  16. <label for="icon">图标</label>
  17. <input id="icon" type="text" class="form-control" name="icon" maxlength="20" value="${system.icon}">
  18. </div>
  19. <div class="form-group">
  20. <label for="title">标题</label>
  21. <input id="title" type="text" class="form-control" name="title" maxlength="20" value="${system.title}" required="true">
  22. </div>
  23. <div class="form-group">
  24. <label for="name">名称</label>
  25. <input id="name" type="text" class="form-control" name="name" maxlength="20" value="${system.name}" required="true">
  26. </div>
  27. <div class="row">
  28. <div class="col-lg-8 form-group">
  29. <label for="name">背景图</label>
  30. <input id="banner" type="text" class="form-control" name="banner" maxlength="150" value="${system.banner}">
  31. </div>
  32. <div class="col-lg-4">
  33. <div id="picker">上传背景图</div>
  34. </div>
  35. </div>
  36. <div class="form-group">
  37. <label for="description">描述</label>
  38. <input id="description" type="text" class="form-control" name="description" maxlength="300" value="${system.description}">
  39. </div>
  40. <div class="form-group">
  41. <label for="basepath">根目录</label>
  42. <input id="basepath" type="text" class="form-control" name="basepath" maxlength="100" value="${system.basepath}">
  43. </div>
  44. <div class="radio">
  45. <div class="radio radio-inline radio-success">
  46. <input id="status_1" type="radio" name="status" value="1" <c:if test="${system.status==1}">checked</c:if>>
  47. <label for="status_1">正常 </label>
  48. </div>
  49. <div class="radio radio-inline">
  50. <input id="status_0" type="radio" name="status" value="-1" <c:if test="${system.status!=1}">checked</c:if>>
  51. <label for="status_0">锁定 </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. $('#banner').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/system/update/${system.systemId}',
  139. data: $('#updateForm').serialize(),
  140. beforeSend: function() {
  141. if ($('#title').val() == '') {
  142. $('#title').focus();
  143. return false;
  144. }
  145. if ($('#name').val() == '') {
  146. $('#name').focus();
  147. return false;
  148. }
  149. },
  150. success: function(result) {
  151. if (result.code != 1) {
  152. if (result.data instanceof Array) {
  153. $.each(result.data, function(index, value) {
  154. $.confirm({
  155. theme: 'dark',
  156. animation: 'rotateX',
  157. closeAnimation: 'rotateX',
  158. title: false,
  159. content: value.errorMsg,
  160. buttons: {
  161. confirm: {
  162. text: '确认',
  163. btnClass: 'waves-effect waves-button waves-light'
  164. }
  165. }
  166. });
  167. });
  168. } else {
  169. $.confirm({
  170. theme: 'dark',
  171. animation: 'rotateX',
  172. closeAnimation: 'rotateX',
  173. title: false,
  174. content: result.data.errorMsg,
  175. buttons: {
  176. confirm: {
  177. text: '确认',
  178. btnClass: 'waves-effect waves-button waves-light'
  179. }
  180. }
  181. });
  182. }
  183. } else {
  184. updateDialog.close();
  185. $table.bootstrapTable('refresh');
  186. }
  187. },
  188. error: function(XMLHttpRequest, textStatus, errorThrown) {
  189. $.confirm({
  190. theme: 'dark',
  191. animation: 'rotateX',
  192. closeAnimation: 'rotateX',
  193. title: false,
  194. content: textStatus,
  195. buttons: {
  196. confirm: {
  197. text: '确认',
  198. btnClass: 'waves-effect waves-button waves-light'
  199. }
  200. }
  201. });
  202. }
  203. });
  204. }
  205. </script>