| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <html>
- <head>
- <link rel="stylesheet" href="/css/cms.css">
- </head>
- <body>
- <div id="space-content">
- <div class="space-wrap">
- <div class="area-btn">
- <el-button-group>
- <el-button size="small" icon="el-icon-download" :disabled="checkList.length <= 0"
- @click="downloadCMSFile">下载</el-button>
- </el-button-group>
- <div class="upload-btn">
- <el-button-group>
- <el-button size="small" @click="checkAllClick">全选</el-button>
- <el-button size="small" @click="checkInvertClick">反选</el-button>
- </el-button-group>
- </div>
- </div>
- <div class="area-list">
- <el-checkbox-group v-model="checkList">
- <el-checkbox :label="item.idcard" v-for="item in CMSFiles" :disabled="!item.fileExist">
- <div class="area-list-wrap" @click.prevent="previewClick(item)" :title="item.source_file_name">
- <div class="area-list-img">
- <el-image :src="item.thumbnail" fit="contain"></el-image>
- </div>
- <p>{{item.source_file_name}}</p>
- <p class="file-size">{{item.file_size_unit}}</p>
- </div>
- </el-checkbox>
- </el-checkbox-group>
- </div>
- <div class="area-list-count">
- 共 {{CMSFiles.length}} 项
- </div>
- </div>
- <!-- 文件数为0显示 -->
- <div class="result" v-if="CMSFiles.length<=0">
- <div class="no-data">
- </div>
- <p class="result-msg" style="font-size: 16px;color: #999;margin-top: 0px;">
- 空空如也~
- </p>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- var whiteDomAry = ["area-list-count", "el-checkbox-group", "space-wrap"];
- const imgTypesAry = ['png', 'jpg', 'jpeg', 'gif', 'bmp']; // 图片类型
- /** 点击空白区域取消选中所有 */
- $(document).on("click", function (e) {
- // 取消选中
- if (e.target.id == 'space-content' || whiteDomAry.indexOf(e.target.className) != -1) {
- space.vue.$data.checkList = [];
- }
- });
- space.vue = new Vue({
- el: space.appContent,
- data: function () {
- return {
- serviceURI: {
- initURL: "@service{ name: 'cms_file_list' }@",
- CMSFilePreview: '@service{ name: "getCMSData" }@',
- downloadCMSFileURI: '@service{ name: "downloadCMSData" }@',
- packageToZipFiles: '@service{ name: "packageToZipFiles" }@',
- },
- cms: {},
- CMSFiles: [],
- checkList: [], //选中的列表
- imgFileAry: [], // 图片文件,预览时用
- previewModel: [], // 文件预览模型
- defaultPreviewViewObj: undefined, // 默认的预览对象
- }
- },
- methods: {
- // 预览
- previewClick: function (file) {
- // 如果只有选中一个,替换选中项;否则累计选中项
- if(file.fileExist) {
- if (this.checkList.length <= 1) {
- this.checkList = [];
- this.checkList.push(file.idcard);
- } else {
- this.checkList.indexOf(file.idcard) > -1 ? "" : this.checkList.push(file.idcard);
- }
- }
- if (!file.fileExist) {
- space.message.warning("文件不存在或已被删除,无法预览和下载");
- return;
- }
- // 图片类型,特殊处理,调用系统的预览插件
- if (this.isImgFile(file.file_type)) {
- space.plugins.elPreview.show(this.generateImgPreviewURI(file.idcard), this.imgFileAry);
- return;
- }
- var previewObj = this.getPreviewViewObj(file);
- space.plugins.layer.openPage({ open: true, title: file.file_name, width: previewObj.width, height: previewObj.height, url: previewObj.url, refresh: false });
- },
- // 全选
- checkAllClick: function () {
- var temporary = [];
- this.CMSFiles.forEach(function (item) {
- if (item.fileExist) {
- temporary.push(item.idcard);
- }
- });
- this.checkList = temporary;
- },
- // 反选
- checkInvertClick: function () {
- var that = this;
- var temporary = [];
- if (this.checkList.length == this.CMSFiles.length) {
- this.checkList = [];
- } else {
- this.CMSFiles.forEach(function (item) {
- if (that.checkList.indexOf(item.idcard) < 0) {
- if (item.fileExist) {
- temporary.push(item.idcard);
- }
- }
- });
- that.checkList = temporary;
- }
- },
- /**
- * 初始化 cms 文件列表
- */
- initCMSFileList: function () {
- if (!this.cms.idcard) {
- return;
- }
- var _this = this;
- space.utils.ajax({
- url: _this.serviceURI.initURL,
- dataType: 'json',
- data: {
- "idcard": _this.cms.idcard
- },
- callback: function (data) {
- if (data.code == "success") {
- _this.CMSFiles = data.data.cmsFileList;
- _this.previewModel = data.data.previewModeList;
- _this.defaultPreviewViewObj = _this.getDefaultPreviewViewObj();
- // 初始化图片类型的文件数组
- _this.initImgFileAry();
- }
- }
- })
- },
- /**
- * 下载文件
- */
- downloadCMSFile: function () {
- // 单文件
- if (this.checkList.length == 1) {
- window.open(space.utils.appendRandom(this.serviceURI.downloadCMSFileURI + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + this.checkList.join(',')))
- }
- // 多文件
- else {
- var _this = this;
- space.utils.ajax({
- url: _this.serviceURI.packageToZipFiles,
- dataType: 'json',
- timeout: 60000, // 60 秒
- loadMsg: '正在打包,请稍后',
- data: {
- "cmsid": _this.cms.idcard,
- "cmsfileid": _this.checkList.join(',')
- },
- callback: function (data) {
- if (data.code == "success") {
- window.open(space.utils.appendRandom(_this.serviceURI.downloadCMSFileURI + "&type=zip&cmsid=" + _this.cms.idcard + "&cmsfileid=" + data.data))
- }
- }
- })
- }
- },
- /* 将所有的图片记录成数组 */
- initImgFileAry: function () {
- this.imgFileAry = [];
- for (let index = 0; index < this.CMSFiles.length; index++) {
- const element = this.CMSFiles[index];
- if (element.fileExist && imgTypesAry.indexOf(element.file_type) != -1) {
- this.imgFileAry.push(this.generateImgPreviewURI(element.idcard));
- }
- }
- },
- // 判断是否为图片类型的文件
- isImgFile: function (filetype) {
- return imgTypesAry.indexOf(filetype) != -1;
- },
- // 生成图片预览的URI
- generateImgPreviewURI: function (idcard) {
- return this.serviceURI.CMSFilePreview + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + idcard
- },
- // 生成文件预览的URI
- generateFilePreivewURI: function (element, idcard) {
- return "/apps?ark=" + (space.utils.isNull(element.service) ? "" : element.service) + "&destination="
- + (space.utils.isNull(element.destination) ? "" : element.destination) + "&cmsid=" + this.cms.idcard + "&cmsfileid=" + idcard
- },
- // 获取预览的路径
- getPreviewViewObj: function (file) {
- for (let index = 0; index < this.previewModel.length; index++) {
- const element = this.previewModel[index];
- if (element.model.indexOf(file.file_type) != -1) {
- return {
- "url": this.generateFilePreivewURI(element, file.idcard),
- "width": element.width,
- "height": element.height
- }
- }
- }
- // 默认预览
- return {
- "url": this.generateFilePreivewURI(this.defaultPreviewViewObj, file.idcard),
- "width": this.defaultPreviewViewObj.width,
- "height": this.defaultPreviewViewObj.height
- }
- },
- /* 找默认的预览对象 */
- getDefaultPreviewViewObj: function () {
- for (let index = 0; index < this.previewModel.length; index++) {
- const element = this.previewModel[index];
- if (element.model.indexOf("*") != -1) {
- return element;
- }
- }
- }
- },
- })
- /**
- * 初始化 CMS
- */
- function initCms(cms) {
- space.vue.$data.cms = {
- "idcard": cms.cmsid
- };
- space.vue.initCMSFileList();
- }
- </script>
- </html>
|