1001910083_edit.jsp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <style type="text/css">
  5. .uploadingPlayer-list .el-link{
  6. float: left;
  7. }
  8. .uploadingPlayer-list .el-link--inner{
  9. line-height: normal;
  10. }
  11. .uploadingPlayer-list .icon-img {
  12. vertical-align: middle;
  13. width: 24px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="space-content" style="position: relative;">
  19. <div class="uploadingPlayer">
  20. <!-- 页面左边 -->
  21. <div class="uploadingPlayer-left">
  22. <!-- 上传按钮 -->
  23. <div class="uploadingPlayer-uploadingBtn">
  24. <el-button size="mini" icon="el-icon-upload" @click="onUpload">上传</el-button>
  25. <input type="file" id="cmsFile" style="display: none;" v-model="cmsFile" />
  26. </div>
  27. <!-- 文件列表 -->
  28. <div class="uploadingPlayer-list">
  29. <ul>
  30. <li v-for="(item,index) in obj" :key="index" :class="activeClass == index?'current':''" @mouseout="btnMouseOut(index)" @click="preview(item,index)">
  31. <img :src="item.icon" class="icon-img">
  32. <p :title="item.fileName">
  33. {{item.fileName}}
  34. </p>
  35. <i class="moreBtn spaceicon icon-more3a" @mouseover="btnMouseOver(index)"></i>
  36. <!-- 按钮组 -->
  37. <div @mouseover="btnMouseOver(index)" @mouseout="btnMouseOut(index)">
  38. <el-button-group v-show="showGroupBtn[index]">
  39. <el-button size="mini" type="danger" @click="removeFile(item,index)">删除</el-button>
  40. <el-button size="mini" type="primary" @click="openFileDetail(item,index)">属性</el-button>
  41. <el-link :href="item.downloadToken" :download="item.filename" :underline="false">
  42. <el-button size="mini" type="primary">
  43. 下载
  44. </el-button>
  45. </el-link>
  46. </el-button-group>
  47. </div>
  48. </li>
  49. </ul>
  50. </div>
  51. </div>
  52. <!-- 页面右边 -->
  53. <div class="uploadingPlayer-right">
  54. <div class="no-choose" v-if="!iframeSrc && !obj.length>0"><p>请在左侧上传文件</p></div>
  55. <div class="no-choose" v-if="!iframeSrc && obj.length>0"><p>请点击左侧预览文件</p></div>
  56. <iframe :src="iframeSrc" v-if="iframeSrc"></iframe>
  57. </div>
  58. </div>
  59. <!-- 进度条框 -->
  60. <div class="pop-progress" v-show="progress.loading">
  61. <div class="pop-progress-left">
  62. <i class="el-icon-upload"></i>
  63. </div>
  64. <div class="pop-progress-right">
  65. <p>正在上传“<span>{{progress.fileName}}</span>”</p>
  66. <el-progress :percentage="progress.percentage"></el-progress>
  67. </div>
  68. </div>
  69. </div>
  70. </body>
  71. <script type="text/javascript">
  72. space.vue = new Vue({
  73. el: space.appContent,
  74. data() {
  75. return {
  76. serviceURI: {
  77. initURL: "@service{ name:'cmsFileList' }@",
  78. uploadFile: "@service{ name:'cmsUploadAjax' }@",
  79. removeFileURI: "@service{ name:'removeUploadFileAjax' }@"
  80. },
  81. cmsFile: undefined,
  82. cmsId: null,
  83. showGroupBtn: [], //保存按钮显示与否
  84. obj: [],
  85. winInterval: undefined,
  86. progress: {
  87. loading: false,
  88. percentage: 0,
  89. fileName: ''
  90. },
  91. iframeSrc: undefined,
  92. activeClass: -1
  93. };
  94. },
  95. created: function() {
  96. var _this = this;
  97. this.winInterval = setInterval(function() {
  98. if(!window.CMS) {
  99. return;
  100. }
  101. window.clearInterval(_this.winInterval);
  102. if (!window.CMS.id) {
  103. return;
  104. }
  105. _this.cmsId = window.CMS.id;
  106. space.utils.ajax({
  107. url: _this.serviceURI.initURL,
  108. dataType: 'json',
  109. data: {
  110. "contentId": _this.cmsId
  111. },
  112. callback: function(data) {
  113. _this.obj = data.data;
  114. for(var i = 0; i < _this.obj.length; i++) {
  115. _this.showGroupBtn.push(false);
  116. }
  117. }
  118. })
  119. }, 100);
  120. },
  121. watch: {
  122. cmsFile: 'cmsFileChange' // 监听 image,改变时执行 cmsFileChange 方法
  123. },
  124. methods: {
  125. btnMouseOver: function(index) {
  126. Vue.set(this.showGroupBtn, index, true)
  127. },
  128. btnMouseOut: function(index) {
  129. Vue.set(this.showGroupBtn, index, false)
  130. },
  131. removeFile: function(item, index) {
  132. var _this = this;
  133. this.$confirm('此操作将删除已上传的文件, 是否继续?', '提示', {
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning'
  137. }).then(() => {
  138. space.utils.ajax({
  139. url: _this.serviceURI.removeFileURI,
  140. data: {
  141. "id": _this.cmsId,
  142. "fileId": item.id
  143. },
  144. dataType: 'json',
  145. callback: function(data) {
  146. if(data.code == "success") {
  147. space.message.success("删除成功");
  148. _this.obj.splice(index, 1)
  149. _this.setFileCount();
  150. _this.iframeSrc = "";
  151. } else {
  152. space.message.error("系统繁忙,请稍后再试");
  153. }
  154. }
  155. })
  156. space.forms.submit();
  157. }).catch(() => {});
  158. },
  159. openFileDetail: function(item, index) {
  160. var _this = this;
  161. var winSetting = {
  162. "title": "文件属性",
  163. "width": "520",
  164. "height": "500",
  165. "url": "@service{ page:'upload_file_change' }@"
  166. };
  167. var callback = function(name) {
  168. item.fileName = name;
  169. }
  170. space.plugins.layer.openPredefinePage(winSetting, {
  171. success: function(win) {
  172. win.CMS = {
  173. contentId : _this.cmsId,
  174. fileId : item.id,
  175. success : callback
  176. }
  177. },
  178. end: function() {
  179. }
  180. });
  181. },
  182. onUpload: function() {
  183. $('#cmsFile').click()
  184. },
  185. cmsFileChange: function(curVal, oldVal) {
  186. if(curVal) {
  187. var files = $('#cmsFile')[0].files;
  188. // if(!this.verifySize($('#cmsFile')[0], 1024)) {
  189. // this.cmsFile = ''; // 清空文件选择
  190. // space.message.warning("文件大小不能超过1G,请重新选择");
  191. // return;
  192. // }
  193. if(files && files.length) {
  194. var URL = window.URL || window.webkitURL;
  195. var file = files[0];
  196. const formData = new FormData();
  197. formData.append('cmsFile', file);
  198. formData.append('contentId', this.cmsId);
  199. var _this = this;
  200. $.ajax(_this.serviceURI.uploadFile, {
  201. method: "POST",
  202. data: formData,
  203. processData: false,
  204. contentType: false,
  205. dataType: 'json',
  206. xhr: function() {
  207. _this.progress.loading = true
  208. _this.progress.fileName = file.name
  209. myXhr = $.ajaxSettings.xhr();
  210. if(myXhr.upload) {
  211. myXhr.upload.addEventListener('progress', function(e) {
  212. var loaded = e.loaded; //已经上传大小情
  213. var total = e.total; //附件总大
  214. var percent = Math.floor(100 * loaded / total) + "%"; //已经上传的百分比
  215. _this.progress.percentage = Math.floor(100 * loaded / total)
  216. }, false);
  217. }
  218. return myXhr;
  219. },
  220. success(data) {
  221. var retData = data.data;
  222. if(data.code == "success" && retData.data[0].code == "success") {
  223. _this.cmsId = retData.id;
  224. _this.obj.push(retData.data[0].data);
  225. _this.setFileCount();
  226. space.message.success("上传成功");
  227. } else {
  228. space.message.error(retData.msg);
  229. }
  230. _this.initProgress();
  231. },
  232. error() {
  233. _this.initProgress();
  234. space.message.error("系统繁忙,请稍后再试");
  235. }
  236. });
  237. }
  238. this.cmsFile = '';
  239. }
  240. },
  241. verifySize: function(fileEl, maxSize) {
  242. // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
  243. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  244. var fileSize = 0;
  245. if(isIE && !fileEl.files) { // IE浏览器
  246. var filePath = fileEl.value; // 获得上传文件的绝对路径
  247. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  248. var file = fileSystem.GetFile(filePath);
  249. fileSize = file.Size; // 文件大小,单位:b
  250. } else { // 非IE浏览器
  251. fileSize = fileEl.files[0].size;
  252. }
  253. var size = fileSize / 1024 / 1024;
  254. return !(size > maxSize);
  255. },
  256. setFileCount: function() {
  257. window.parentWin.CMS = {
  258. fileCount: this.obj.length,
  259. id: this.cmsId
  260. }
  261. },
  262. initProgress: function() {
  263. this.progress = {
  264. loading: false,
  265. percentage: 0,
  266. fileName: ''
  267. }
  268. },
  269. preview: function(item,index) {
  270. if (item.token) {
  271. this.iframeSrc = item.token + "&rn=" + space.utils.random(6);
  272. this.activeClass = index;
  273. }
  274. }
  275. }
  276. })
  277. </script>
  278. </html>