提交 c98d27d5 作者: dingtalk_nnkplh

修改上传图片的bug

上级 334d93d5
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<input type="hidden" class="form-control" th:field="*{atlasCover}"> <input type="hidden" class="form-control" th:field="*{atlasCover}">
<div class="file-loading"> <div class="file-loading">
<input id="singleFile" name="files" type="file"> <input id="singleFile" name="file" type="file">
</div> </div>
</div> </div>
</div> </div>
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
</form> </form>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<!-- <th:block th:include="include :: summernote-js" />-->
<th:block th:include="include :: bootstrap-fileinput-js" /> <th:block th:include="include :: bootstrap-fileinput-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "system/atlas"; var prefix = ctx + "system/atlas";
...@@ -104,38 +103,6 @@ ...@@ -104,38 +103,6 @@
}); });
} }
// 多图上传
$("#multipleFile").on('fileuploaded', function (event, data, previewId, index) {
var rsp = data.response;
var imgPath = $("#atlasContent").val();
if(imgPath != null && imgPath != ''){
$("#atlasContent").val(imgPath+","+rsp.fileNames);
}else{
$("#atlasContent").val(rsp.fileNames);
}
$("#multipleFile").fileinput('destroy');//销毁fileUploadFileInput
initUpload();//重新初始化文件预览数据和文件上传附件
$('#multipleFile').fileinput('enable');//enable作用:destroy并重新初始化fileinput插件后,插件会处于disable状态
});
//删除方法
$('#multipleFile').on('filepredelete', function(event, key, jqXHR, data) { //就是在删除原图片之前触发,而新选择的图片不会触发。能满足我们的要求。
console.log('Key = ' + key);
var logoUrl = $("#atlasContent").val();
var urlLinkNew = '';
var imgArr = logoUrl.split(",");
for ( var i = 0; i < imgArr.length; i++) {
if (i == key) continue;
if (urlLinkNew !=''){
urlLinkNew = urlLinkNew + "," + imgArr[i];
}else{
urlLinkNew = imgArr[i];
}
}
$("#atlasContent").val(urlLinkNew);
console.log($("#atlasContent").val())
});
function initUpload1() { function initUpload1() {
var logoUrl = $("#atlasCover").val();//拿到图片路径 var logoUrl = $("#atlasCover").val();//拿到图片路径
var preList = new Array(); var preList = new Array();
...@@ -202,6 +169,37 @@ ...@@ -202,6 +169,37 @@
}); });
} }
// 多图上传
$("#multipleFile").on('fileuploaded', function (event, data, previewId, index) {
var rsp = data.response;
var imgPath = $("#atlasContent").val();
if(imgPath != null && imgPath != ''){
$("#atlasContent").val(imgPath+","+rsp.fileNames);
}else{
$("#atlasContent").val(rsp.fileNames);
}
$("#multipleFile").fileinput('destroy');//销毁fileUploadFileInput
initUpload();//重新初始化文件预览数据和文件上传附件
$('#multipleFile').fileinput('enable');//enable作用:destroy并重新初始化fileinput插件后,插件会处于disable状态
});
//删除方法
$('#multipleFile').on('filepredelete', function(event, key, jqXHR, data) { //就是在删除原图片之前触发,而新选择的图片不会触发。能满足我们的要求。
console.log('Key = ' + key);
var logoUrl = $("#atlasContent").val();
var urlLinkNew = '';
var imgArr = logoUrl.split(",");
for ( var i = 0; i < imgArr.length; i++) {
if (i == key) continue;
if (urlLinkNew !=''){
urlLinkNew = urlLinkNew + "," + imgArr[i];
}else{
urlLinkNew = imgArr[i];
}
}
$("#atlasContent").val(urlLinkNew);
console.log($("#atlasContent").val())
});
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论