1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| let Main = { data(){ return { defaultList: [], videoName: '', previewPath:'', visible: false, uploadList: [], videoIds:[], rtxImgIds:[], } }, methods: { //预览视频 handleView (path, name) { this.videoName = name; this.previewPath = path; this.visible = true; }, //删除视频 handleRemove (file) { const fileList = this.$refs.upload.fileList; this.$refs.upload.fileList.splice(fileList.indexOf(file), 1); this.videoIds.splice(this.videoIds.indexOf(file.videoId), 1); }, //视频上传成功 handleSuccess (res, file) { if (!res.status) { this.$Message.error(res.msg); return false; } file.path = res.data.filePath; file.name = res.data.fileName; this.videoIds.push(res.data.videoId); }, //错误提示 handleFormatError (file) { this.$Notice.warning({ title: '文件格式错误', desc: '文件名为 ' + file.name + '格式错误, 请上传mp4格式.' }); }, //错误提示 handleMaxSize (file) { this.$Notice.warning({ title: '上传文件错误', desc: '文件 ' + file.name + ' 太大了,超过了10M' }); }, //错误提示 handleBeforeUpload () { const check = this.uploadList.length < 5; if (!check) { this.$Notice.warning({ title: '最多只能上传5个视频' }); } return check; },
//初始化quill富文本编辑器 initQuill () { // this.$Message.info('这是一个提示'); const quill = new Quill('#editor-container', { modules: { toolbar: "#toolbar-container", imageResize: { displaySize: true }, }, placeholder: '请输入课程描述...', theme: 'snow' // or 'bubble' }); this.quill = quill; this.quill.getModule("toolbar").addHandler("image", this.uploadImageHandler) }, //quill富文本编辑器上传图片动作 uploadImageHandler() { const input = document.querySelector('#uploadImg'); input.value = ''; input.click(); }, //quill富文本编辑器上传图片请求 async uploadImage (event) { const form = new FormData(); form.append('upload_file', event.target.files[0]); const res = await axios({ url:'?your_uploader_image_url', method:'post', data:form, headers: { 'Content-Type': 'multipart/form-data' }, responseType:'json' }).then((res)=>{ return res.data.data});
const addImageRange = this.quill.getSelection(); const newRange = 0 + (addImageRange !== null ? addImageRange.index : 0); this.rtxImgIds.push(res.image_id); this.quill.insertEmbed(newRange, 'image', res.url); this.quill.setSelection(1 + newRange); }, //编辑页面加载video async renderVideo() { var activityId = "<{$course.course_id ? $course.course_id : ''}>"; var vm = this; await axios.get('index.php?app=activities&ctl=admin_course_manage&act=getVideoList&cid=' + activityId).then(function (response) { // vm.defaultList = response.data; vm.defaultList = response.data.video_list; vm.videoIds = response.data.video_ids; vm.$nextTick(() => { vm.uploadList = vm.$refs.upload.fileList; }); });
} }, computed:{ //视频上传成功后,返回id,push到双向绑定的videoid input的value中 videoInput: function () { return JSON.stringify({ids:this.videoIds}); }, rtxImageIdJson: function () { return JSON.stringify({ids:this.rtxImgIds}); } }, mounted () { this.renderVideo(); // this.uploadList = this.$refs.upload.fileList; this.initQuill() }, beforeDestroy () { this.quill = null; delete this.quill; }, };
var Component = Vue.extend(Main); new Component().$mount('#x-g-basic');
|