1007610532_edit.jsp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <div id="space-content">
  6. <div class="content-wrap">
  7. <div class="CMS-file">
  8. <div class="CMS-btn-top">
  9. <span @click="checkAll">
  10. 全选
  11. </span>
  12. <div class="CMS-btn-right">
  13. <span @click="toggleAll">
  14. 反选
  15. </span>
  16. </div>
  17. </div>
  18. <div class="CMS-file-list">
  19. <van-checkbox-group v-model="checkList" direction="horizontal" ref="checkboxGroup" icon-size="22">
  20. <van-checkbox :name="item.idcard" v-for="item in CMSFiles" :key="item.idcard"
  21. :disabled="!item.fileExist">
  22. <div class="CMS-file-wrap" @click.stop="previewClick(item)">
  23. <div class="CMS-file-img">
  24. <van-image fit="contain" :src="item.thumbnail"></van-image>
  25. </div>
  26. <p>{{item.source_file_name}}</p>
  27. <p class="file-size">{{item.file_size_unit}}</p>
  28. </div>
  29. </van-checkbox>
  30. </van-checkbox-group>
  31. <div class="CMS-file-count" v-if="CMSFiles.length != 0">
  32. 共 {{CMSFiles.length}} 项
  33. </div>
  34. <!-- 文件数为0显示 -->
  35. <div class="no-data" v-if="CMSFiles.length == 0">
  36. <p>空空如也~</p>
  37. </div>
  38. </div>
  39. <div class="CMS-btn-bottom">
  40. <van-button type="info" block :disabled="checkList.length < 1" @click="downloadCMSFile">下载
  41. </van-button>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </body>
  47. <script type="text/javascript">
  48. var whiteDomAry = ["CMS-btn-bottom", "CMS-btn-top", "van-checkbox-group", "van-checkbox-group van-checkbox-group--horizontal", "CMS-file-count", "CMS-file-list"];
  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. curCmsidObj: {}, //当前的cmsid
  68. CMSFiles: [], //所有文件
  69. checkList: [], //选中的文件列表
  70. imgFileAry: [], // 所有图片预览数组
  71. previewModel: [], // 文件预览模型
  72. defaultPreviewViewObj: undefined, // 默认的预览对象
  73. }
  74. },
  75. mounted: function () {
  76. },
  77. methods: {
  78. // 全选
  79. checkAll: function () {
  80. this.$refs.checkboxGroup.toggleAll({
  81. checked: true,
  82. skipDisabled: true,
  83. });
  84. },
  85. // 反选
  86. toggleAll: function () {
  87. this.$refs.checkboxGroup.toggleAll({
  88. skipDisabled: true,
  89. });
  90. },
  91. // 预览
  92. previewClick: function (file) {
  93. // 如果只有选中一个,替换选中项;否则累计选中项
  94. if (file.fileExist) {
  95. if (this.checkList.length <= 1) {
  96. this.checkList = [];
  97. this.checkList.push(file.idcard);
  98. } else {
  99. this.checkList.indexOf(file.idcard) > -1 ? "" : this.checkList.push(file.idcard);
  100. }
  101. }
  102. if (!file.fileExist) {
  103. this.$toast.fail('文件不存在或已被删除,无法预览和下载');
  104. return;
  105. }
  106. // 图片类型,特殊处理,调用图片预览插件
  107. if (this.isImgFile(file.file_type)) {
  108. var index = this.imgFileAry.indexOf(this.generateImgPreviewURI(file.idcard));
  109. vant.ImagePreview({
  110. images: this.imgFileAry,
  111. startPosition: index,
  112. });
  113. return;
  114. }
  115. // 其他类型
  116. var previewObj = this.getPreviewViewObj(file);
  117. space.plugin.layer.open({
  118. url: previewObj.url,
  119. refresh: false,
  120. size: 'mini',
  121. anim: 5,
  122. shade: [0.8, '#393D49'],
  123. shadeClose: true,
  124. success: function (win) {
  125. win.initFileInfo(file);
  126. }
  127. });
  128. },
  129. /**
  130. * 初始化 cms 文件列表
  131. */
  132. initCMSFileList: function () {
  133. if (!this.curCmsidObj.idcard) {
  134. return;
  135. }
  136. var _this = this;
  137. space.utils.ajax({
  138. url: _this.serviceURI.initURL,
  139. dataType: 'json',
  140. data: {
  141. "idcard": _this.curCmsidObj.idcard
  142. },
  143. callback: function (data) {
  144. if (data.code == "success") {
  145. _this.CMSFiles = data.data.cmsFileList;
  146. _this.previewModel = data.data.previewModeList;
  147. _this.defaultPreviewViewObj = _this.getDefaultPreviewViewObj();
  148. // 初始化图片类型的文件数组
  149. _this.initImgFileAry();
  150. }
  151. }
  152. })
  153. },
  154. /* 将所有的图片记录成数组 */
  155. initImgFileAry: function () {
  156. this.imgFileAry = [];
  157. for (let index = 0; index < this.CMSFiles.length; index++) {
  158. const element = this.CMSFiles[index];
  159. if (element.fileExist && imgTypesAry.indexOf(element.file_type) != -1) {
  160. this.imgFileAry.push(this.generateImgPreviewURI(element.idcard));
  161. }
  162. }
  163. },
  164. // 生成图片预览的URI
  165. generateImgPreviewURI: function (idcard) {
  166. return this.serviceURI.CMSFilePreview + "&cmsid=" + this.curCmsidObj.idcard + "&cmsfileid=" + idcard
  167. },
  168. // 判断是否为图片类型的文件
  169. isImgFile: function (filetype) {
  170. return imgTypesAry.indexOf(filetype) != -1;
  171. },
  172. // 获取预览的路径
  173. getPreviewViewObj: function (file) {
  174. for (let index = 0; index < this.previewModel.length; index++) {
  175. const element = this.previewModel[index];
  176. if (element.model.indexOf(file.file_type) != -1) {
  177. return {
  178. "url": this.generateFilePreivewURI(element, file.idcard),
  179. "width": element.width,
  180. "height": element.height
  181. }
  182. }
  183. }
  184. // 默认预览
  185. return {
  186. "url": this.generateFilePreivewURI(this.defaultPreviewViewObj, file.idcard),
  187. "width": this.defaultPreviewViewObj.width,
  188. "height": this.defaultPreviewViewObj.height
  189. }
  190. },
  191. /* 找默认的预览对象 */
  192. getDefaultPreviewViewObj: function () {
  193. for (let index = 0; index < this.previewModel.length; index++) {
  194. const element = this.previewModel[index];
  195. if (element.model.indexOf("*") != -1) {
  196. return element;
  197. }
  198. }
  199. },
  200. // 生成文件预览的URI
  201. generateFilePreivewURI: function (element, idcard) {
  202. return "/apps?ark=" + (space.utils.isNull(element.service) ? "" : element.service) + "&destination="
  203. + (space.utils.isNull(element.destination) ? "" : element.destination) + "&cmsid=" + this.curCmsidObj.idcard + "&cmsfileid=" + idcard
  204. },
  205. /**
  206. * 下载文件
  207. */
  208. downloadCMSFile: function () {
  209. // 单文件
  210. if (this.checkList.length == 1) {
  211. window.open(space.utils.appendRandom(this.serviceURI.downloadCMSFileURI + "&cmsid=" + this.curCmsidObj.idcard + "&cmsfileid=" + this.checkList.join(',')))
  212. }
  213. // 多文件
  214. else {
  215. var _this = this;
  216. space.utils.ajax({
  217. url: _this.serviceURI.packageToZipFiles,
  218. dataType: 'json',
  219. timeout: 60000, // 60 秒
  220. loadMsg: '正在打包,请稍后',
  221. data: {
  222. "cmsid": _this.curCmsidObj.idcard,
  223. "cmsfileid": _this.checkList.join(',')
  224. },
  225. callback: function (data) {
  226. if (data.code == "success") {
  227. window.open(space.utils.appendRandom(_this.serviceURI.downloadCMSFileURI + "&type=zip&cmsid=" + _this.curCmsidObj.idcard + "&cmsfileid=" + data.data))
  228. }
  229. }
  230. })
  231. }
  232. },
  233. },
  234. })
  235. /**
  236. * 初始化 CMS
  237. */
  238. function initCms(cms) {
  239. space.vue.$data.curCmsidObj = {
  240. "idcard": cms.cmsid
  241. };
  242. space.vue.initCMSFileList();
  243. }
  244. </script>
  245. </html>