coupon-admin/public/static/manager/js/upload_image.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-11-18 09:57:04 +00:00
/**
* 基于upload.js扩展
*/
layui.use(['jquery', 'upload'], function () {
let $ = layui.jquery, upload = layui.upload;
let url = '/manager/upload/image';
let field = 'image_image';
let multiple = false;
let accept = 'images'; //images图片、file所有文件、video视频、audio音频
let acceptMime = 'images/*';
let exts = 'jpg|png|gif|bmp|jpeg';
let size = 10 * 1024; //size KB
let number = 0;
/*
* 海报上传
*/
let upPorter = upload.render({
elem: '.upload-btn-porter'
, url: url
,data: {"type":"porter"}
, auto: true
, field: field
, accept: accept
, acceptMime: acceptMime
, exts: exts
, size: size
, number: number
, multiple: true
, before: function (obj) {
layer.load(2);
}
, done: function (res, index, upload) {
console.log('上传成功', res);
layer.closeAll('loading'); //关闭loading
let item = this.item;
let div = item.parents('.upload-file-div');
if (res.code === 0 || res.code === 200) {
let inputValue = $(div).find('.upload-file-value').val();
if (inputValue.length > 0) {
inputValue += ',';
}
inputValue += res.data.src;
$(div).find('.upload-file-value').val(inputValue);
initPreviewList();
} else {
layer.msg(res.msg);
}
}
});
});