1001910526_edit.jsp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="/css/cms.css">
  4. </head>
  5. <body>
  6. <div id="space-content">
  7. <div class="space-wrap">
  8. <div class="area-btn">
  9. <el-button-group>
  10. <el-button size="small" icon="el-icon-download" :disabled="checkList.length <= 0"
  11. @click="downloadCMSFile">下载</el-button>
  12. </el-button-group>
  13. <div class="upload-btn">
  14. <el-button-group>
  15. <el-button size="small" @click="checkAllClick">全选</el-button>
  16. <el-button size="small" @click="checkInvertClick">反选</el-button>
  17. </el-button-group>
  18. </div>
  19. </div>
  20. <div class="area-list">
  21. <el-checkbox-group v-model="checkList">
  22. <el-checkbox :label="item.idcard" v-for="item in CMSFiles" :disabled="!item.fileExist">
  23. <div class="area-list-wrap" @click.prevent="previewClick(item)" :title="item.source_file_name">
  24. <div class="area-list-img">
  25. <el-image :src="item.thumbnail" fit="contain"></el-image>
  26. </div>
  27. <p>{{item.source_file_name}}</p>
  28. <p class="file-size">{{item.file_size_unit}}</p>
  29. </div>
  30. </el-checkbox>
  31. </el-checkbox-group>
  32. </div>
  33. <div class="area-list-count">
  34. 共 {{CMSFiles.length}} 项
  35. </div>
  36. </div>
  37. <!-- 文件数为0显示 -->
  38. <div class="result" v-if="CMSFiles.length<=0">
  39. <div class="no-data">
  40. </div>
  41. <p class="result-msg" style="font-size: 16px;color: #999;margin-top: 0px;">
  42. 空空如也~
  43. </p>
  44. </div>
  45. </div>
  46. </body>
  47. <script type="text/javascript">
  48. var whiteDomAry = ["area-list-count", "el-checkbox-group", "space-wrap"];
  49. const imgTypesAry = ['png', 'jpg', 'jpeg', 'gif', 'bmp']; // 图片类型
  50. /** 点击空白区域取消选中所有 */
  51. $(document).on("click", function (e) {
  52. // 取消选中
  53. if (e.target.id == 'space-content' || whiteDomAry.indexOf(e.target.className) != -1) {
  54. space.vue.$data.checkList = [];
  55. }
  56. });
  57. space.vue = new Vue({
  58. el: space.appContent,
  59. data: function () {
  60. return {
  61. serviceURI: {
  62. initURL: "@service{ name: 'cms_file_list' }@",
  63. CMSFilePreview: '@service{ name: "getCMSData" }@',
  64. downloadCMSFileURI: '@service{ name: "downloadCMSData" }@',
  65. packageToZipFiles: '@service{ name: "packageToZipFiles" }@',
  66. },
  67. cms: {},
  68. CMSFiles: [],
  69. checkList: [], //选中的列表
  70. imgFileAry: [], // 图片文件,预览时用
  71. previewModel: [], // 文件预览模型
  72. defaultPreviewViewObj: undefined, // 默认的预览对象
  73. }
  74. },
  75. methods: {
  76. // 预览
  77. previewClick: function (file) {
  78. // 如果只有选中一个,替换选中项;否则累计选中项
  79. if(file.fileExist) {
  80. if (this.checkList.length <= 1) {
  81. this.checkList = [];
  82. this.checkList.push(file.idcard);
  83. } else {
  84. this.checkList.indexOf(file.idcard) > -1 ? "" : this.checkList.push(file.idcard);
  85. }
  86. }
  87. if (!file.fileExist) {
  88. space.message.warning("文件不存在或已被删除,无法预览和下载");
  89. return;
  90. }
  91. // 图片类型,特殊处理,调用系统的预览插件
  92. if (this.isImgFile(file.file_type)) {
  93. space.plugins.elPreview.show(this.generateImgPreviewURI(file.idcard), this.imgFileAry);
  94. return;
  95. }
  96. var previewObj = this.getPreviewViewObj(file);
  97. space.plugins.layer.openPage({ open: true, title: file.file_name, width: previewObj.width, height: previewObj.height, url: previewObj.url, refresh: false });
  98. },
  99. // 全选
  100. checkAllClick: function () {
  101. var temporary = [];
  102. this.CMSFiles.forEach(function (item) {
  103. if (item.fileExist) {
  104. temporary.push(item.idcard);
  105. }
  106. });
  107. this.checkList = temporary;
  108. },
  109. // 反选
  110. checkInvertClick: function () {
  111. var that = this;
  112. var temporary = [];
  113. if (this.checkList.length == this.CMSFiles.length) {
  114. this.checkList = [];
  115. } else {
  116. this.CMSFiles.forEach(function (item) {
  117. if (that.checkList.indexOf(item.idcard) < 0) {
  118. if (item.fileExist) {
  119. temporary.push(item.idcard);
  120. }
  121. }
  122. });
  123. that.checkList = temporary;
  124. }
  125. },
  126. /**
  127. * 初始化 cms 文件列表
  128. */
  129. initCMSFileList: function () {
  130. if (!this.cms.idcard) {
  131. return;
  132. }
  133. var _this = this;
  134. space.utils.ajax({
  135. url: _this.serviceURI.initURL,
  136. dataType: 'json',
  137. data: {
  138. "idcard": _this.cms.idcard
  139. },
  140. callback: function (data) {
  141. if (data.code == "success") {
  142. _this.CMSFiles = data.data.cmsFileList;
  143. _this.previewModel = data.data.previewModeList;
  144. _this.defaultPreviewViewObj = _this.getDefaultPreviewViewObj();
  145. // 初始化图片类型的文件数组
  146. _this.initImgFileAry();
  147. }
  148. }
  149. })
  150. },
  151. /**
  152. * 下载文件
  153. */
  154. downloadCMSFile: function () {
  155. // 单文件
  156. if (this.checkList.length == 1) {
  157. window.open(space.utils.appendRandom(this.serviceURI.downloadCMSFileURI + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + this.checkList.join(',')))
  158. }
  159. // 多文件
  160. else {
  161. var _this = this;
  162. space.utils.ajax({
  163. url: _this.serviceURI.packageToZipFiles,
  164. dataType: 'json',
  165. timeout: 60000, // 60 秒
  166. loadMsg: '正在打包,请稍后',
  167. data: {
  168. "cmsid": _this.cms.idcard,
  169. "cmsfileid": _this.checkList.join(',')
  170. },
  171. callback: function (data) {
  172. if (data.code == "success") {
  173. window.open(space.utils.appendRandom(_this.serviceURI.downloadCMSFileURI + "&type=zip&cmsid=" + _this.cms.idcard + "&cmsfileid=" + data.data))
  174. }
  175. }
  176. })
  177. }
  178. },
  179. /* 将所有的图片记录成数组 */
  180. initImgFileAry: function () {
  181. this.imgFileAry = [];
  182. for (let index = 0; index < this.CMSFiles.length; index++) {
  183. const element = this.CMSFiles[index];
  184. if (element.fileExist && imgTypesAry.indexOf(element.file_type) != -1) {
  185. this.imgFileAry.push(this.generateImgPreviewURI(element.idcard));
  186. }
  187. }
  188. },
  189. // 判断是否为图片类型的文件
  190. isImgFile: function (filetype) {
  191. return imgTypesAry.indexOf(filetype) != -1;
  192. },
  193. // 生成图片预览的URI
  194. generateImgPreviewURI: function (idcard) {
  195. return this.serviceURI.CMSFilePreview + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + idcard
  196. },
  197. // 生成文件预览的URI
  198. generateFilePreivewURI: function (element, idcard) {
  199. return "/apps?ark=" + (space.utils.isNull(element.service) ? "" : element.service) + "&destination="
  200. + (space.utils.isNull(element.destination) ? "" : element.destination) + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + idcard
  201. },
  202. // 获取预览的路径
  203. getPreviewViewObj: function (file) {
  204. for (let index = 0; index < this.previewModel.length; index++) {
  205. const element = this.previewModel[index];
  206. if (element.model.indexOf(file.file_type) != -1) {
  207. return {
  208. "url": this.generateFilePreivewURI(element, file.idcard),
  209. "width": element.width,
  210. "height": element.height
  211. }
  212. }
  213. }
  214. // 默认预览
  215. return {
  216. "url": this.generateFilePreivewURI(this.defaultPreviewViewObj, file.idcard),
  217. "width": this.defaultPreviewViewObj.width,
  218. "height": this.defaultPreviewViewObj.height
  219. }
  220. },
  221. /* 找默认的预览对象 */
  222. getDefaultPreviewViewObj: function () {
  223. for (let index = 0; index < this.previewModel.length; index++) {
  224. const element = this.previewModel[index];
  225. if (element.model.indexOf("*") != -1) {
  226. return element;
  227. }
  228. }
  229. }
  230. },
  231. })
  232. /**
  233. * 初始化 CMS
  234. */
  235. function initCms(cms) {
  236. space.vue.$data.cms = {
  237. "idcard": cms.cmsid
  238. };
  239. space.vue.initCMSFileList();
  240. }
  241. </script>
  242. </html>