| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <html>
- <head>
- <style type="text/css">
- .uploadingPlayer-list .el-link{
- float: left;
- }
-
- .uploadingPlayer-list .el-link--inner{
- line-height: normal;
- }
- .uploadingPlayer-list .icon-img {
- vertical-align: middle;
- width: 24px;
- }
-
- </style>
- </head>
- <body>
- <div id="space-content" style="position: relative;">
- <div class="uploadingPlayer">
- <!-- 页面左边 -->
- <div class="uploadingPlayer-left">
- <!-- 上传按钮 -->
- <div class="uploadingPlayer-uploadingBtn">
- <el-button size="mini" icon="el-icon-upload" @click="onUpload">上传</el-button>
- <input type="file" id="cmsFile" style="display: none;" v-model="cmsFile" />
- </div>
- <!-- 文件列表 -->
- <div class="uploadingPlayer-list">
- <ul>
- <li v-for="(item,index) in obj" :key="index" :class="activeClass == index?'current':''" @mouseout="btnMouseOut(index)" @click="preview(item,index)">
- <img :src="item.icon" class="icon-img">
- <p :title="item.fileName">
- {{item.fileName}}
- </p>
- <i class="moreBtn spaceicon icon-more3a" @mouseover="btnMouseOver(index)"></i>
- <!-- 按钮组 -->
- <div @mouseover="btnMouseOver(index)" @mouseout="btnMouseOut(index)">
- <el-button-group v-show="showGroupBtn[index]">
- <el-button size="mini" type="danger" @click="removeFile(item,index)">删除</el-button>
- <el-button size="mini" type="primary" @click="openFileDetail(item,index)">属性</el-button>
- <el-link :href="item.downloadToken" :download="item.filename" :underline="false">
- <el-button size="mini" type="primary">
- 下载
- </el-button>
- </el-link>
- </el-button-group>
- </div>
- </li>
- </ul>
- </div>
- </div>
- <!-- 页面右边 -->
- <div class="uploadingPlayer-right">
- <div class="no-choose" v-if="!iframeSrc && !obj.length>0"><p>请在左侧上传文件</p></div>
- <div class="no-choose" v-if="!iframeSrc && obj.length>0"><p>请点击左侧预览文件</p></div>
- <iframe :src="iframeSrc" v-if="iframeSrc"></iframe>
- </div>
- </div>
- <!-- 进度条框 -->
- <div class="pop-progress" v-show="progress.loading">
- <div class="pop-progress-left">
- <i class="el-icon-upload"></i>
- </div>
- <div class="pop-progress-right">
- <p>正在上传“<span>{{progress.fileName}}</span>”</p>
- <el-progress :percentage="progress.percentage"></el-progress>
- </div>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- space.vue = new Vue({
- el: space.appContent,
- data() {
- return {
- serviceURI: {
- initURL: "@service{ name:'cmsFileList' }@",
- uploadFile: "@service{ name:'cmsUploadAjax' }@",
- removeFileURI: "@service{ name:'removeUploadFileAjax' }@"
- },
- cmsFile: undefined,
- cmsId: null,
- showGroupBtn: [], //保存按钮显示与否
- obj: [],
- winInterval: undefined,
- progress: {
- loading: false,
- percentage: 0,
- fileName: ''
- },
- iframeSrc: undefined,
- activeClass: -1
- };
- },
- created: function() {
-
- var _this = this;
- this.winInterval = setInterval(function() {
- if(!window.CMS) {
- return;
- }
-
- window.clearInterval(_this.winInterval);
-
- if (!window.CMS.id) {
- return;
- }
-
- _this.cmsId = window.CMS.id;
-
- space.utils.ajax({
- url: _this.serviceURI.initURL,
- dataType: 'json',
- data: {
- "contentId": _this.cmsId
- },
- callback: function(data) {
- _this.obj = data.data;
- for(var i = 0; i < _this.obj.length; i++) {
- _this.showGroupBtn.push(false);
- }
- }
- })
- }, 100);
- },
- watch: {
- cmsFile: 'cmsFileChange' // 监听 image,改变时执行 cmsFileChange 方法
- },
- methods: {
- btnMouseOver: function(index) {
- Vue.set(this.showGroupBtn, index, true)
- },
- btnMouseOut: function(index) {
- Vue.set(this.showGroupBtn, index, false)
- },
- removeFile: function(item, index) {
- var _this = this;
- this.$confirm('此操作将删除已上传的文件, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- space.utils.ajax({
- url: _this.serviceURI.removeFileURI,
- data: {
- "id": _this.cmsId,
- "fileId": item.id
- },
- dataType: 'json',
- callback: function(data) {
- if(data.code == "success") {
- space.message.success("删除成功");
- _this.obj.splice(index, 1)
- _this.setFileCount();
- _this.iframeSrc = "";
- } else {
- space.message.error("系统繁忙,请稍后再试");
- }
- }
- })
- space.forms.submit();
- }).catch(() => {});
- },
- openFileDetail: function(item, index) {
-
- var _this = this;
- var winSetting = {
- "title": "文件属性",
- "width": "520",
- "height": "500",
- "url": "@service{ page:'upload_file_change' }@"
- };
-
- var callback = function(name) {
- item.fileName = name;
- }
-
- space.plugins.layer.openPredefinePage(winSetting, {
- success: function(win) {
- win.CMS = {
- contentId : _this.cmsId,
- fileId : item.id,
- success : callback
- }
-
- },
- end: function() {
-
- }
- });
- },
- onUpload: function() {
- $('#cmsFile').click()
- },
- cmsFileChange: function(curVal, oldVal) {
- if(curVal) {
- var files = $('#cmsFile')[0].files;
- // if(!this.verifySize($('#cmsFile')[0], 1024)) {
- // this.cmsFile = ''; // 清空文件选择
- // space.message.warning("文件大小不能超过1G,请重新选择");
- // return;
- // }
- if(files && files.length) {
- var URL = window.URL || window.webkitURL;
- var file = files[0];
- const formData = new FormData();
- formData.append('cmsFile', file);
- formData.append('contentId', this.cmsId);
- var _this = this;
- $.ajax(_this.serviceURI.uploadFile, {
- method: "POST",
- data: formData,
- processData: false,
- contentType: false,
- dataType: 'json',
- xhr: function() {
- _this.progress.loading = true
- _this.progress.fileName = file.name
- myXhr = $.ajaxSettings.xhr();
- if(myXhr.upload) {
- myXhr.upload.addEventListener('progress', function(e) {
- var loaded = e.loaded; //已经上传大小情
- var total = e.total; //附件总大
- var percent = Math.floor(100 * loaded / total) + "%"; //已经上传的百分比
- _this.progress.percentage = Math.floor(100 * loaded / total)
- }, false);
- }
- return myXhr;
- },
- success(data) {
- var retData = data.data;
- if(data.code == "success" && retData.data[0].code == "success") {
- _this.cmsId = retData.id;
- _this.obj.push(retData.data[0].data);
- _this.setFileCount();
- space.message.success("上传成功");
- } else {
- space.message.error(retData.msg);
- }
- _this.initProgress();
- },
- error() {
- _this.initProgress();
- space.message.error("系统繁忙,请稍后再试");
- }
- });
- }
- this.cmsFile = '';
- }
- },
- verifySize: function(fileEl, maxSize) {
- // 判断是否为IE浏览器: /msie/i.test(navigator.userAgent) 为一个简单正则
- var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
- var fileSize = 0;
- if(isIE && !fileEl.files) { // IE浏览器
- var filePath = fileEl.value; // 获得上传文件的绝对路径
- var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
- var file = fileSystem.GetFile(filePath);
- fileSize = file.Size; // 文件大小,单位:b
- } else { // 非IE浏览器
- fileSize = fileEl.files[0].size;
- }
- var size = fileSize / 1024 / 1024;
- return !(size > maxSize);
- },
- setFileCount: function() {
- window.parentWin.CMS = {
- fileCount: this.obj.length,
- id: this.cmsId
- }
- },
- initProgress: function() {
- this.progress = {
- loading: false,
- percentage: 0,
- fileName: ''
- }
- },
- preview: function(item,index) {
- if (item.token) {
- this.iframeSrc = item.token + "&rn=" + space.utils.random(6);
- this.activeClass = index;
- }
-
- }
- }
- })
- </script>
- </html>
|