修改图片和视频上传版本

This commit is contained in:
Renpc-kilig 2024-08-05 10:55:05 +08:00
parent cf50164cdd
commit 066e5b0dc2
6 changed files with 775 additions and 716 deletions

View File

@ -58,36 +58,16 @@
<input type="text" id="identifying" name="identifying" class="layui-input" value="" placeholder="请输入分组标识" maxlength="50">
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">视频</label>
<div class="layui-input-block">
@ -138,12 +118,13 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var wangEditor = window.wangEditor;
var upload = layui.upload;
var wangEditorObj = {};
var viewerObj = {};
@ -237,55 +218,58 @@
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
var photosArray = [];
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
function renderPhoto() {
var $previewImgsFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
function initEvent() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
},
error: function(){
top.dialog.msg('上传异常');
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
$(document).on('click', '.img-remove-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 9) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化视频视频上传
@ -337,7 +321,7 @@
// 初始化内容
function initData() {
initContentRichText();
initPhotoUploadFile();
initEvent();
initVideoUploadFile();
initDictIdSelect();
}

View File

@ -58,34 +58,12 @@
<input type="text" id="identifying" name="identifying" class="layui-input" value="" placeholder="请输入分组标识" maxlength="50">
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
@ -138,7 +116,7 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
@ -148,6 +126,7 @@
var wangEditor = window.wangEditor;
var wangEditorObj = {};
var viewerObj = {};
var upload = layui.upload;
function initDictIdSelect(selectValue) {
top.restAjax.get(top.restAjax.path('api/data/listallbyparentid/b6144a18-c5ea-4286-89fb-441172803d07', []), {}, null, function(code, data, args) {
@ -243,56 +222,60 @@
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
var photosArray = [];
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
function renderPhoto() {
var $photoFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$photoFileBox.empty();
$photoFileBox.append(imgs);
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
function initEvent() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 1) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
},
error: function(){
top.dialog.msg('上传异常');
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
$(document).on('click', '.img-remove-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 1) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化视频视频上传
function initVideoUploadFile() {
@ -352,8 +335,11 @@
form.render(null, 'dataForm');
initContentRichText(data['content']);
initDictIdSelect(data['dictId']);
initPhotoUploadFile();
initVideoUploadFile();
photosArray = data.photo.split(',');
renderPhoto();
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
@ -363,6 +349,7 @@
});
}
initData();
initEvent();
// 提交表单
form.on('submit(saveForm)', function(formData) {

View File

@ -28,64 +28,25 @@
<input type="text" id="title" name="title" class="layui-input" value="" placeholder="请输入标题" maxlength="255">
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">视频</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="videoBtn"><i class="fa fa-upload"></i> 上传视频</button>
<input type="hidden" id="video" name="video">
<div class="layui-btn-container" id="videoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="videoFileDownload" type="text/html">
{{# var fileName = 'video' }}
{{# if(d[fileName] != '') { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-video-box">
<div id="{{fileName}}{{i}}" style="width:300px; height:200px;"></div>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-video" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="videoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 1) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="视频" data-name="video" lay-filter="videoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="videoFileBox">最多可上传一个视频</div>
</div>
</div>
<!--<div class="layui-form-item layui-form-text">
<label class="layui-form-label">内容</label>
<div class="layui-input-block">
@ -119,16 +80,130 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var wangEditor = window.wangEditor;
var upload = layui.upload;
var wangEditorObj = {};
var viewerObj = {};
var helpTypeId = top.restAjax.params(window.location.href).helpTypeId;
// 初始化视频上传
var videosArray = [];
function renderVideo() {
var $previewImgsFileBox = $('#videoFileBox');
var imgs = '';
$.each(videosArray, function(index, item) {
imgs += `
<div class="img">
<video style="width: 100px;" controls>
<source src="route/file/download/true/${item}">
</video>
<!--<video src="route/file/download/true/${item}" style="width: 100px;">-->
<a href="javascript:void(0);" class="img-remove-video-btn" data-type="video" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventVideo() {
upload.render({
elem: '#videoBtn',
url: top.restAjax.path('api/file/uploadvideo', []),
field: 'video',
accept: 'video',
acceptMime: 'video/*',
done: function(res) {
top.dialog.msg('上传成功');
videosArray.push(res.data);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-video-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'video') {
videosArray.splice(index, 1);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length < 9) {
var $uploadLogoBtn = $('#videoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var photosArray = [];
function renderPhotos() {
var $previewImgsFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEvent() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhotos();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhotos();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 9) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
function closeBox() {
parent.layer.close(parent.layer.getFrameIndex(window.name));
}
@ -183,58 +258,6 @@
}
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化视频视频上传
function initVideoUploadFile() {
var files = $('#video').val();
@ -306,8 +329,8 @@
// 初始化内容
function initData() {
initPhotoUploadFile();
initVideoUploadFile();
initEventVideo();
initEvent();
initRichContentRichText();
}
initData();

View File

@ -28,64 +28,24 @@
<input type="text" id="title" name="title" class="layui-input" value="" placeholder="请输入标题" maxlength="255">
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">视频</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="videoBtn"><i class="fa fa-upload"></i> 上传视频</button>
<input type="hidden" id="video" name="video">
<div class="layui-btn-container" id="videoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="videoFileDownload" type="text/html">
{{# var fileName = 'video' }}
{{# if(d[fileName] != '') { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-video-box">
<div id="{{fileName}}{{i}}" style="width:300px; height:200px;"></div>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-video" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="videoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 1) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="视频" data-name="video" lay-filter="videoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="videoFileBox">最多可上传一个视频</div>
</div>
</div>
<!--<div class="layui-form-item layui-form-text">
<label class="layui-form-label">内容</label>
<div class="layui-input-block">
@ -119,17 +79,132 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var upload = layui.upload;
var helpDetailId = top.restAjax.params(window.location.href).helpDetailId;
var wangEditor = window.wangEditor;
var wangEditorObj = {};
var viewerObj = {};
// 初始化视频上传
var videosArray = [];
function renderVideo() {
var $previewImgsFileBox = $('#videoFileBox');
var imgs = '';
$.each(videosArray, function(index, item) {
imgs += `
<div class="img">
<video style="width: 100px;" controls>
<source src="route/file/download/true/${item}">
</video>
<a href="javascript:void(0);" class="img-remove-video-btn" data-type="video" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventVideo() {
upload.render({
elem: '#videoBtn',
url: top.restAjax.path('api/file/uploadvideo', []),
field: 'video',
accept: 'video',
acceptMime: 'video/*',
done: function(res) {
top.dialog.msg('上传成功');
videosArray.push(res.data);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-video-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'video') {
videosArray.splice(index, 1);
renderVideo();
console.log(videosArray)
$('#video').val(videosArray.join(','));
if(videosArray.length < 9) {
var $uploadLogoBtn = $('#videoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var photosArray = [];
function renderPhoto() {
var $photoFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$photoFileBox.empty();
$photoFileBox.append(imgs);
}
function initEvent() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 1) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 1) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
function closeBox() {
parent.layer.close(parent.layer.getFrameIndex(window.name));
}
@ -184,58 +259,6 @@
}
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化视频视频上传
function initVideoUploadFile() {
var files = $('#video').val();
@ -310,15 +333,31 @@
function initData() {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/help-detail/get/{helpDetailId}', [helpDetailId]), {}, null, function(code, data) {
var videoValue = data.video;
delete data.video;
var dataFormData = {};
for(var i in data) {
dataFormData[i] = data[i] +'';
}
console.log(videoValue)
if (videoValue) {
alert()
videosArray = videoValue.split(',');
renderVideo();
}
form.val('dataForm', dataFormData);
form.render(null, 'dataForm');
initPhotoUploadFile();
initVideoUploadFile();
initRichContentRichText(data['richContent']);
if (data.photo) {
photosArray = data.photo.split(',');
renderPhoto();
}
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
@ -328,6 +367,8 @@
});
}
initData();
initEvent();
initEventVideo();
// 提交表单
form.on('submit(submitForm)', function(formData) {

View File

@ -87,94 +87,34 @@
<div id="content"></div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">封面图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="coverPhotoBtn"><i class="fa fa-upload"></i> 上传封面图片</button>
<input type="hidden" id="coverPhoto" name="coverPhoto">
<div class="layui-btn-container" id="coverPhotoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="coverPhotoFileDownload" type="text/html">
{{# var fileName = 'coverPhoto'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="coverPhotoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="封面图片" data-name="coverPhoto" lay-filter="coverPhotoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="coverPhotoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">视频</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="videoBtn"><i class="fa fa-upload"></i> 上传视频</button>
<input type="hidden" id="video" name="video">
<div class="layui-btn-container" id="videoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="videoFileDownload" type="text/html">
{{# var fileName = 'video' }}
{{# if(d[fileName] != '') { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-video-box">
<div id="{{fileName}}{{i}}" style="width:300px; height:200px;"></div>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-video" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="videoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 1) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="视频" data-name="video" lay-filter="videoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="videoFileBox">最多可上传一个视频</div>
</div>
</div>
<div class="layui-form-item layui-layout-admin">
<div class="layui-input-block">
<div class="layui-footer" style="left: 0;">
@ -197,15 +137,184 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var wangEditor = window.wangEditor;
var upload = layui.upload;
var wangEditorObj = {};
var viewerObj = {};
// 初始化视频上传
var videosArray = [];
function renderVideo() {
var $previewImgsFileBox = $('#videoFileBox');
var imgs = '';
$.each(videosArray, function(index, item) {
imgs += `
<div class="img">
<video style="width: 100px;" controls>
<source src="route/file/download/true/${item}">
</video>
<!--<video src="route/file/download/true/${item}" style="width: 100px;">-->
<a href="javascript:void(0);" class="img-remove-video-btn" data-type="video" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventVideo() {
upload.render({
elem: '#videoBtn',
url: top.restAjax.path('api/file/uploadvideo', []),
field: 'video',
accept: 'video',
acceptMime: 'video/*',
done: function(res) {
top.dialog.msg('上传成功');
videosArray.push(res.data);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-video-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'video') {
videosArray.splice(index, 1);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length < 9) {
var $uploadLogoBtn = $('#videoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var photosArray = [];
function renderPhoto() {
var $previewImgsFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-photo-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventPhoto() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-photo-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 9) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var coverPhotosArray = [];
function renderCoverPhoto() {
var $previewImgsFileBox = $('#coverPhotoFileBox');
var imgs = '';
$.each(coverPhotosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-cover-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventCoverPhoto() {
upload.render({
elem: '#coverPhotoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
coverPhotosArray.push(res.data);
renderCoverPhoto();
$('#coverPhoto').val(coverPhotosArray.join(','));
if(coverPhotosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-cover-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
coverPhotosArray.splice(index, 1);
renderCoverPhoto();
$('#coverPhoto').val(coverPhotosArray.join(','));
if(coverPhotosArray.length < 9) {
var $uploadLogoBtn = $('#coverPhotoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
function initNewsTypeSelect() {
top.restAjax.get(top.restAjax.path('api/data/listallbyparentid/827dbe5f-10ad-4d89-8d01-894513ba109e', []), {}, null, function(code, data, args) {
console.log(data)
@ -295,110 +404,6 @@
wangEditorObj['content'] = editor;
}
// 初始化封面图片图片上传
function initCoverPhotoUploadFile() {
var files = $('#coverPhoto').val();
initFileList('coverPhoto', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(coverPhotoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(coverPhotoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化视频视频上传
function initVideoUploadFile() {
var files = $('#video').val();
@ -467,9 +472,9 @@
// 初始化内容
function initData() {
initContentRichText();
initCoverPhotoUploadFile();
initPhotoUploadFile();
initVideoUploadFile();
initEventVideo();
initEventPhoto();
initEventCoverPhoto();
initNewsTypeSelectDepartment();
initPublishTimeDate();
initNewsTypeSelect();

View File

@ -87,94 +87,34 @@
<div id="content"></div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">封面图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="coverPhotoBtn"><i class="fa fa-upload"></i> 上传封面图片</button>
<input type="hidden" id="coverPhoto" name="coverPhoto">
<div class="layui-btn-container" id="coverPhotoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="coverPhotoFileDownload" type="text/html">
{{# var fileName = 'coverPhoto'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="coverPhotoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="封面图片" data-name="coverPhoto" lay-filter="coverPhotoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="coverPhotoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="photoBtn"><i class="fa fa-upload"></i> 上传图片</button>
<input type="hidden" id="photo" name="photo">
<div class="layui-btn-container" id="photoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="photoFileDownload" type="text/html">
{{# var fileName = 'photo'; }}
{{# if(d[fileName].length > 0) { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-image-box">
<span class="upload-image-span">
<img src="route/file/download/false/{{item.fileId}}" align="加载失败">
</span>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="photoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 9) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="图片" data-name="photo" lay-filter="photoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="photoFileBox">最多可上传九张图片</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<div class="layui-form-item">
<label class="layui-form-label">视频</label>
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" id="videoBtn"><i class="fa fa-upload"></i> 上传视频</button>
<input type="hidden" id="video" name="video">
<div class="layui-btn-container" id="videoFileBox" style="border: 1px solid #e6e6e6;"></div>
<script id="videoFileDownload" type="text/html">
{{# var fileName = 'video' }}
{{# if(d[fileName] != '') { }}
{{# var files = d[fileName];}}
{{# for(var i = 0, item = files[i]; item = files[i++];) { }}
<div class="upload-video-box">
<div id="{{fileName}}{{i}}" style="width:300px; height:200px;"></div>
<a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-video" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" lay-filter="videoRemoveFile">
<i class="fa fa-trash-o"></i>
</a>
</div>
{{# } }}
{{# } }}
{{# if(d[fileName].length < 1) { }}
<div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
<a href="javascript:void(0);" lay-form-button data-explain="视频" data-name="video" lay-filter="videoUploadFile">
<i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
</a>
</div>
{{# } }}
</script>
<div class="img-container" id="videoFileBox">最多可上传一个视频</div>
</div>
</div>
<div class="layui-form-item layui-layout-admin">
<div class="layui-input-block">
<div class="layui-footer" style="left: 0;">
@ -197,17 +137,186 @@
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
}).use(['index', 'form', 'laydate', 'laytpl', 'upload'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
var newsId = top.restAjax.params(window.location.href).newsId;
var upload = layui.upload;
var wangEditor = window.wangEditor;
var wangEditorObj = {};
var viewerObj = {};
// 初始化视频上传
var videosArray = [];
function renderVideo() {
var $previewImgsFileBox = $('#videoFileBox');
var imgs = '';
$.each(videosArray, function(index, item) {
imgs += `
<div class="img">
<video style="width: 100px;" controls>
<source src="route/file/download/true/${item}">
</video>
<!--<video src="route/file/download/true/${item}" style="width: 100px;">-->
<a href="javascript:void(0);" class="img-remove-video-btn" data-type="video" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventVideo() {
upload.render({
elem: '#videoBtn',
url: top.restAjax.path('api/file/uploadvideo', []),
field: 'video',
accept: 'video',
acceptMime: 'video/*',
done: function(res) {
top.dialog.msg('上传成功');
videosArray.push(res.data);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-video-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'video') {
videosArray.splice(index, 1);
renderVideo();
$('#video').val(videosArray.join(','));
if(videosArray.length < 9) {
var $uploadLogoBtn = $('#videoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var photosArray = [];
function renderPhoto() {
var $previewImgsFileBox = $('#photoFileBox');
var imgs = '';
$.each(photosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-photo-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventPhoto() {
upload.render({
elem: '#photoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
photosArray.push(res.data);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-photo-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
photosArray.splice(index, 1);
renderPhoto();
$('#photo').val(photosArray.join(','));
if(photosArray.length < 9) {
var $uploadLogoBtn = $('#photoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
// 初始化图片图片上传
var coverPhotosArray = [];
function renderCoverPhoto() {
var $previewImgsFileBox = $('#coverPhotoFileBox');
var imgs = '';
$.each(coverPhotosArray, function(index, item) {
imgs += `
<div class="img">
<img src="route/file/download/true/${item}" style="width: 100px;">
<a href="javascript:void(0);" class="img-remove-cover-btn" data-type="photo" data-index="${index}"><i class="fa fa-remove"></i></a>
</div>
`
})
$previewImgsFileBox.empty();
$previewImgsFileBox.append(imgs);
}
function initEventCoverPhoto() {
upload.render({
elem: '#coverPhotoBtn',
url: top.restAjax.path('api/file/uploadimage', []),
field: 'image',
accept: 'images',
acceptMime: 'image/*',
done: function(res) {
top.dialog.msg('上传成功');
coverPhotosArray.push(res.data);
renderCoverPhoto();
$('#coverPhoto').val(coverPhotosArray.join(','));
if(coverPhotosArray.length >= 9) {
this.elem.attr('disabled', 'disabled');
this.elem.addClass('layui-disabled')
}
},
error: function(){
top.dialog.msg('上传异常');
}
});
$(document).on('click', '.img-remove-cover-btn', function() {
var index = this.dataset.index;
var type = this.dataset.type;
if(type === 'photo') {
coverPhotosArray.splice(index, 1);
renderCoverPhoto();
$('#coverPhoto').val(coverPhotosArray.join(','));
if(coverPhotosArray.length < 9) {
var $uploadLogoBtn = $('#coverPhotoBtn');
$uploadLogoBtn.removeAttr('disabled', 'disabled');
$uploadLogoBtn.removeClass('layui-disabled');
}
}
})
}
function initNewsTypeSelect(selectValue) {
top.restAjax.get(top.restAjax.path('api/data/listallbyparentid/827dbe5f-10ad-4d89-8d01-894513ba109e', []), {}, null, function(code, data, args) {
laytpl(document.getElementById('newsTypeSelectTemplate').innerHTML).render(data, function(html) {
@ -301,110 +410,6 @@
wangEditorObj['content'] = editor;
}
// 初始化封面图片图片上传
function initCoverPhotoUploadFile() {
var files = $('#coverPhoto').val();
initFileList('coverPhoto', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(coverPhotoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(coverPhotoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化图片图片上传
function initPhotoUploadFile() {
var files = $('#photo').val();
initFileList('photo', files, function(fileName) {
var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
viewerObj[fileName] = viewer;
});
form.on('button(photoUploadFile)', function(obj) {
var name = this.dataset.name;
var explain = this.dataset.explain;
top.dialog.file({
type: 'image',
title: '上传'+ explain,
width: '400px',
height: '420px',
maxFileCount: '1',
onClose: function() {
var uploadFileArray = top.dialog.dialogData.uploadFileArray;
if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
var files = $('#'+ name).val();
for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
if(files.length > 0) {
files += ',';
}
files += file.data;
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
}
}
});
});
form.on('button(photoRemoveFile)', function(obj) {
var name = this.dataset.name;
var id = this.dataset.id;
var files = $('#'+ name).val().replace(id, '');
files = files.replace(/\,+/g, ',');
if(files.charAt(0) == ',') {
files = files.substring(1);
}
if(files.charAt(files.length - 1) == ',') {
files = files.substring(0, files.length - 1);
}
initFileList(name, files, function(fileName) {
viewerObj[fileName].update();
});
});
}
// 初始化视频视频上传
function initVideoUploadFile() {
var files = $('#video').val();
@ -474,18 +479,28 @@
function initData() {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/news/get/{newsId}', [newsId]), {}, null, function(code, data) {
var videoValue = data.video;
delete data.video;
var dataFormData = {};
for(var i in data) {
dataFormData[i] = data[i] +'';
}
coverPhotosArray = data.photo.split(',');
renderCoverPhoto();
photosArray = data.photo.split(',');
renderPhoto();
videosArray = videoValue.split(',');
renderVideo();
form.val('dataForm', dataFormData);
form.render(null, 'dataForm');
initContentRichText(data['content']);
initCoverPhotoUploadFile();
initPhotoUploadFile();
initVideoUploadFile();
initPublishTimeDate();
initNewsTypeSelect(data['newsType']);
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
@ -496,6 +511,10 @@
}
initData();
initEventVideo();
initEventPhoto();
initEventCoverPhoto();
// 提交表单
form.on('submit(saveForm)', function(formData) {
formData.field.sendStatus = 'save';