You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
7.2 KiB

2 years ago
  1. /** layui-v2.1.5 MIT License By http://www.layui.com */
  2. ; layui.define("layer", function (e) { "use strict"; var i = layui.$, t = layui.layer, n = layui.hint(), a = layui.device(), o = { config: {}, set: function (e) { var t = this; return t.config = i.extend({}, t.config, e), t }, on: function (e, i) { return layui.onevent.call(this, r, e, i) } }, l = function () { var e = this; return { upload: function (i) { e.upload.call(e, i) }, config: e.config } }, r = "upload", u = "layui-upload-file", c = "layui-upload-form", s = "layui-upload-iframe", f = "layui-upload-choose", p = function (e) { var t = this; t.config = i.extend({}, t.config, o.config, e), t.render() }; p.prototype.config = { accept: "images", exts: "", auto: !0, bindAction: "", url: "", field: "file", method: "post", data: {}, drag: !0, size: 0, multiple: !1 }, p.prototype.render = function (e) { var t = this, e = t.config; e.elem = i(e.elem), e.bindAction = i(e.bindAction), t.file(), t.events() }, p.prototype.file = function () { var e = this, t = e.config, n = e.elemFile = i(['<input class="' + u + '" type="file" name="' + t.field + '"', t.multiple ? " multiple" : "", ">"].join("")), o = t.elem.next(); (o.hasClass(u) || o.hasClass(c)) && o.remove(), a.ie && a.ie < 10 && t.elem.wrap('<div class="layui-upload-wrap"></div>'), e.isFile() ? (e.elemFile = t.elem, t.field = t.elem[0].name) : t.elem.after(n), a.ie && a.ie < 10 && e.initIE() }, p.prototype.initIE = function () { var e = this, t = e.config, n = i('<iframe id="' + s + '" class="' + s + '" name="' + s + '" frameborder="0"></iframe>'), a = i(['<form target="' + s + '" class="' + c + '" method="' + t.method, '" key="set-mine" enctype="multipart/form-data" action="' + t.url + '">', "</form>"].join("")); i("#" + s)[0] || i("body").append(n), t.elem.next().hasClass(s) || (e.elemFile.wrap(a), t.elem.next("." + s).append(function () { var e = []; return layui.each(t.data, function (i, t) { e.push('<input type="hidden" name="' + i + '" value="' + t + '">') }), e.join("") }())) }, p.prototype.msg = function (e) { return t.msg(e, { icon: 2, shift: 6 }) }, p.prototype.isFile = function () { var e = this.config.elem[0]; if (e) return "input" === e.tagName.toLocaleLowerCase() && "file" === e.type }, p.prototype.preview = function (e) { var i = this; window.FileReader && layui.each(i.chooseFiles, function (i, t) { var n = new FileReader; n.readAsDataURL(t), n.onload = function () { e && e(i, t, this.result) } }) }, p.prototype.upload = function (e, t) { var n, o = this, l = o.config, r = o.elemFile[0], u = function () { layui.each(e || o.files || o.chooseFiles || r.files, function (e, t) { var n = new FormData; n.append(l.field, t), layui.each(l.data, function (e, i) { n.append(e, i) }), i.ajax({ url: l.url, type: l.method, data: n, contentType: !1, processData: !1, dataType: "json", success: function (i) { d(e, i) }, error: function () { o.msg("请求上传接口出现异常"), m(e) } }) }) }, c = function () { var e = i("#" + s); o.elemFile.parent().submit(), clearInterval(p.timer), p.timer = setInterval(function () { var i, t = e.contents().find("body"); try { i = t.text() } catch (n) { o.msg("获取上传后的响应信息出现异常"), clearInterval(p.timer), m() } i && (clearInterval(p.timer), t.html(""), d(0, i)) }, 30) }, d = function (e, i) { if (o.elemFile.next("." + f).remove(), r.value = "", "object" != typeof i) try { i = JSON.parse(i) } catch (t) { return i = {}, o.msg("请对上传接口返回有效JSON") } "function" == typeof l.done && l.done(i, e || 0, function (e) { o.upload(e) }) }, m = function (e) { l.auto && (r.value = ""), "function" == typeof l.error && l.error(e || 0, function (e) { o.upload(e) }) }, v = l.exts, h = function () { var i = []; return layui.each(e || o.chooseFiles, function (e, t) { i.push(t.name) }), i }(), g = { preview: function (e) { o.preview(e) }, upload: function (e, i) { var t = {}; t[e] = i, o.upload(t) }, pushFile: function () { return o.files = o.files || {}, layui.each(o.chooseFiles, function (e, i) { o.files[e] = i }), o.files } }, y = function () { return "choose" === t ? l.choose && l.choose(g) : (l.before && l.bef