mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-21 06:19:16 +08:00
修改支付处理及资源同步
This commit is contained in:
parent
ac58ece305
commit
322e8d9ffc
@ -14,9 +14,9 @@ define(['md5'], function (SparkMD5, allowMime) {
|
||||
opt.elem.data('input', $input.size() > 0 ? $input.get(0) : null);
|
||||
}
|
||||
|
||||
/*! 文件选择筛选 */
|
||||
$((opt.elem.data('type') || '').split(',')).map(function (i, ext) {
|
||||
if (allowMime[ext]) opt.exts.push(ext), opt.mimes.push(allowMime[ext]);
|
||||
/*! 文件选择筛选,使用 MIME 规则过滤文件列表 */
|
||||
$((opt.elem.data('type') || '').split(',')).map(function (i, e) {
|
||||
if (allowMime[e]) opt.exts.push(e), opt.mimes.push(allowMime[e]);
|
||||
});
|
||||
|
||||
/*! 初始化上传组件 */
|
||||
@ -67,29 +67,27 @@ define(['md5'], function (SparkMD5, allowMime) {
|
||||
});
|
||||
});
|
||||
}, progress: function (number) {
|
||||
|
||||
/*! 文件上传进度处理 */
|
||||
$('[data-upload-progress]').html(number + '%');
|
||||
opt.elem.triggerHandler('upload.progress', {number: number, event: arguments[2], file: arguments[3]});
|
||||
|
||||
if (opt.count.total > 1) {
|
||||
$('[data-upload-progress]').html(number + '%' + ' ' + (opt.count.uploaded + 1) + '/' + opt.count.total);
|
||||
} else {
|
||||
$('[data-upload-progress]').html(number + '%');
|
||||
}
|
||||
}, done: function (ret, idx) {
|
||||
|
||||
/*! 检查单个文件上传返回的结果 */
|
||||
if (ret.code < 1) return $.msg.tips(ret.info || '文件上传失败!');
|
||||
if (typeof opt.cache[idx].xurl !== 'string') return $.msg.tips('无效的文件上传对象!');
|
||||
|
||||
/*! 单个文件上传成功结果处理 */
|
||||
if (typeof callable === 'function') {
|
||||
callable.call(opt.elem, opt.cache[idx].xurl, opt.cache['id']);
|
||||
} else if (opt.mult < 1 && opt.elem.data('input')) {
|
||||
$(opt.elem.data('input')).val(opt.cache[idx].xurl).trigger('change', opt.cache[idx]);
|
||||
}
|
||||
|
||||
(opt.hide || $.msg.close(opt.load)), opt.elem.html(opt.elem.data('html'));
|
||||
opt.elem.triggerHandler('upload.done', {file: opt.cache[idx], data: ret});
|
||||
|
||||
opt.elem.html(opt.elem.data('html')).triggerHandler('upload.done', {file: opt.cache[idx], data: ret});
|
||||
/*! 所有文件上传完成后结果处理 */
|
||||
if (++opt.count.uploaded >= opt.count.total) {
|
||||
opt.hide || $.msg.close(opt.load);
|
||||
if (opt.mult > 0 && opt.elem.data('input')) {
|
||||
var urls = opt.elem.data('input').value || [];
|
||||
if (typeof urls === 'string') urls = urls.split('|');
|
||||
@ -97,7 +95,7 @@ define(['md5'], function (SparkMD5, allowMime) {
|
||||
$(opt.elem.data('input')).val(urls.join('|')).trigger('change', opt.cache);
|
||||
}
|
||||
opt.elem.triggerHandler('upload.complete', {file: opt.cache});
|
||||
(opt.cache = [], opt.files = []), opt.uploader.reload();
|
||||
(opt.cache = [], opt.files = [], opt.count = {uploaded: 0, total: 0}), opt.uploader.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -67,7 +67,7 @@ class JoinpayPaymentService extends PaymentService
|
||||
'p0_Version' => '1.0',
|
||||
'p1_MerchantNo' => $this->mchid,
|
||||
'p2_OrderNo' => $orderNo,
|
||||
'p3_Amount' => $paymentAmount * 100,
|
||||
'p3_Amount' => $paymentAmount,
|
||||
'p4_Cur' => '1',
|
||||
'p5_ProductName' => $paymentTitle,
|
||||
'p6_ProductDesc' => $paymentRemark,
|
||||
|
@ -174,13 +174,13 @@ $(function () {
|
||||
$body: $('body>.think-page-loader'),
|
||||
$main: $('.think-page-body+.think-page-loader'),
|
||||
show: function () {
|
||||
if (that.page.$body.is(':hidden')) that.page.$main.removeClass('layui-hide').show();
|
||||
that.page.$body.is(':visible') || that.page.$main.removeClass('layui-hide').show();
|
||||
},
|
||||
hide: function () {
|
||||
if (that.page.time) clearTimeout(that.page.time);
|
||||
that.page.time = setTimeout(function () {
|
||||
(delete that.page.time), that.page.$main.fadeOut();
|
||||
}, 500);
|
||||
(that.page.time = 0) || that.page.$main.fadeOut();
|
||||
}, 200);
|
||||
},
|
||||
};
|
||||
/*! 确认对话框 */
|
||||
@ -238,8 +238,6 @@ $(function () {
|
||||
$(this.elem).val(value).trigger('change');
|
||||
}
|
||||
});
|
||||
}), $dom.find('[data-file]:not([data-inited])').map(function () {
|
||||
$(this).uploadFile();
|
||||
}), $dom.find('[data-lazy-src]:not([data-lazy-loaded])').each(function () {
|
||||
if (this.dataset.lazyLoaded !== 'true') {
|
||||
this.dataset.lazyLoaded = "true";
|
||||
@ -551,9 +549,9 @@ $(function () {
|
||||
};
|
||||
|
||||
/*! 注册对象到JqFn */
|
||||
$.fn.vali = function (callable, options) {
|
||||
$.fn.vali = function (callable) {
|
||||
return this.each(function () {
|
||||
$.vali(this, callable, options);
|
||||
$.vali(this, callable);
|
||||
});
|
||||
};
|
||||
|
||||
@ -581,57 +579,54 @@ $(function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
/*! 全局文件上传 */
|
||||
$.fn.uploadFile = function (callable) {
|
||||
/*! 全局文件上传插件 */
|
||||
$.fn.uploadFile = function (callable, initialize) {
|
||||
return this.each(function () {
|
||||
if ($(this).data('inited')) return false;
|
||||
var that = $(this), mult = '|one|btn|'.indexOf(that.data('file') || 'one') ? 0 : 1;
|
||||
var that = $(this), mult = '|one|btn|'.indexOf(that.data('file') || 'one') > -1 ? 0 : 1;
|
||||
that.data('inited', true).data('multiple', mult), require(['upload'], function (apply) {
|
||||
apply.call(this, that, callable);
|
||||
apply(that, callable), (typeof initialize === 'function' && setTimeout(initialize, 100));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/*! 上传单张图片 */
|
||||
$.fn.uploadOneImage = function () {
|
||||
return this.each(function ($in, $bt) {
|
||||
$in = $(this), $bt = $('<a data-file="one" class="uploadimage transition"><span class="layui-icon">ဆ</span></a>');
|
||||
$bt.attr('data-size', $in.data('size') || 0).attr('data-file', 'one').attr('data-type', $in.data('type') || 'png,jpg,gif');
|
||||
$bt.data('input', this).find('span').on('click', function (event) {
|
||||
return this.each(function () {
|
||||
if ($(this).data('inited')) return true; else $(this).data('inited', true);
|
||||
var $in = $(this), $bt = $('<a data-file class="uploadimage transition"><span class="layui-icon">ဆ</span></a>').data('input', this);
|
||||
$bt.attr('data-size', $in.data('size') || 0).attr('data-type', $in.data('type') || 'png,jpg,gif').find('span').on('click', function (event) {
|
||||
event.stopPropagation(), $bt.attr('style', ''), $in.val('');
|
||||
});
|
||||
$in.attr('name', $bt.attr('data-field')).after($bt).on('change', function () {
|
||||
}), $in.on('change', function () {
|
||||
if (this.value) $bt.css('backgroundImage', 'url(' + encodeURI(this.value) + ')');
|
||||
}).trigger('change');
|
||||
}), this;
|
||||
}).after($bt).trigger('change');
|
||||
});
|
||||
};
|
||||
|
||||
/*! 上传多张图片 */
|
||||
$.fn.uploadMultipleImage = function () {
|
||||
return this.each(function () {
|
||||
var $in = $(this), $bt = $('<a class="uploadimage"></a>'), imgs = this.value ? this.value.split('|') : [];
|
||||
$bt.attr('data-size', $in.data('size') || 0).attr('data-file', 'mut').attr('data-type', $in.data('type') || 'png,jpg,gif');
|
||||
$in.after($bt), $bt.uploadFile(function (src) {
|
||||
if ($(this).data('inited')) return true; else $(this).data('inited', true);
|
||||
var $in = $(this), $bt = $('<a data-file="mul" class="uploadimage"></a>'), imgs = this.value ? this.value.split('|') : []
|
||||
$in.after($bt.attr('data-size', $in.data('size') || 0).attr('data-type', $in.data('type') || 'png,jpg,gif').uploadFile(function (src) {
|
||||
imgs.push(src), $in.val(imgs.join('|')), showImageContainer([src]);
|
||||
});
|
||||
if (imgs.length > 0) showImageContainer(imgs);
|
||||
})), (imgs.length > 0 && showImageContainer(imgs));
|
||||
|
||||
function showImageContainer(srcs) {
|
||||
$(srcs).each(function (idx, src, $image) {
|
||||
$image = $('<div class="uploadimage uploadimagemtl transition"><div><a class="layui-icon"></a><a class="layui-icon">ဆ</a><a class="layui-icon"></a></div></div>');
|
||||
$image.attr('data-tips-image', encodeURI(src)).css('backgroundImage', 'url(' + encodeURI(src) + ')').on('click', 'a', function (event, index, prevs, $item) {
|
||||
event.stopPropagation(), $item = $(this).parent().parent(), index = $(this).index(), prevs = $bt.prevAll('div.uploadimage').length;
|
||||
if (index === 2 && $item.index() !== prevs) $item.next().after($item);
|
||||
else if (index === 0 && $item.index() > 1) $item.prev().before($item);
|
||||
else if (index === 1) $item.remove();
|
||||
event.stopPropagation(), $item = $(this).parent().parent(), index = $(this).index();
|
||||
if (index === 2 && $item.index() !== $bt.prevAll('div.uploadimage').length) $item.next().after($item);
|
||||
else if (index === 0 && $item.index() > 1) $item.prev().before($item); else if (index === 1) $item.remove();
|
||||
imgs = [], $bt.prevAll('.uploadimage').map(function () {
|
||||
imgs.push($(this).attr('data-tips-image'));
|
||||
});
|
||||
imgs.reverse(), $in.val(imgs.join('|'));
|
||||
}), $bt.before($image);
|
||||
});
|
||||
};
|
||||
}), this;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*! 标签输入插件 */
|
||||
@ -679,7 +674,7 @@ $(function () {
|
||||
});
|
||||
}
|
||||
|
||||
/*! 组件 LayUI table 功能封装 */
|
||||
/*! 组件 layui.table 封装 */
|
||||
$.fn.layTable = function (params) {
|
||||
return this.each(function (idx, elem) {
|
||||
// 动态初始化数据表
|
||||
@ -738,6 +733,102 @@ $(function () {
|
||||
});
|
||||
}
|
||||
|
||||
/*! 弹出图片层 */
|
||||
$.previewImage = function (src, area) {
|
||||
var img = new Image(), defer = $.Deferred(), loaded = $.msg.loading();
|
||||
img.style.background = '#FFF', img.referrerPolicy = 'no-referrer';
|
||||
img.style.height = 'auto', img.style.width = area || '100%', img.style.display = 'none';
|
||||
document.body.appendChild(img), img.onerror = function () {
|
||||
$.msg.close(loaded), defer.reject();
|
||||
}, img.onload = function () {
|
||||
layer.open({
|
||||
type: 1, title: false, shadeClose: true, content: $(img), success: function ($elem, idx) {
|
||||
$.msg.close(loaded), defer.notify($elem, idx);
|
||||
}, area: area || '480px', skin: 'layui-layer-nobg', closeBtn: 1, end: function () {
|
||||
document.body.removeChild(img), defer.resolve()
|
||||
}
|
||||
});
|
||||
};
|
||||
return (img.src = src), defer.resolve();
|
||||
};
|
||||
|
||||
/*! 以手机模式显示内容 */
|
||||
$.previewPhonePage = function (href, title, template) {
|
||||
template = '<div><div class="mobile-preview pull-left"><div class="mobile-header">_TITLE_</div><div class="mobile-body"><iframe id="phone-preview" src="_URL_" frameborder="0" marginheight="0" marginwidth="0"></iframe></div></div></div>';
|
||||
layer.style(layer.open({type: true, scrollbar: false, area: ['320px', '600px'], title: false, closeBtn: true, shadeClose: false, skin: 'layui-layer-nobg', content: $(template.replace('_TITLE_', title || '公众号').replace('_URL_', href)).html()}), {boxShadow: 'none'});
|
||||
};
|
||||
|
||||
/*! 显示任务进度消息 */
|
||||
$.loadQueue = function (code, doScript, element) {
|
||||
var doAjax = true, doReload = false;
|
||||
layui.layer.open({
|
||||
type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () {
|
||||
doAjax = false;
|
||||
if (doReload && doScript) {
|
||||
if (element && element.dataset && element.dataset.tableId) {
|
||||
$('#' + element.dataset.tableId).trigger('reload');
|
||||
} else {
|
||||
$.form.reload();
|
||||
}
|
||||
}
|
||||
}, content: '' +
|
||||
'<div class="padding-30 padding-bottom-0" data-queue-load="' + code + '">' +
|
||||
' <div class="layui-elip notselect nowrap" data-message-title></div>' +
|
||||
' <div class="margin-top-15 layui-progress layui-progress-big" lay-showPercent="yes"><div class="layui-progress-bar transition" lay-percent="0.00%"></div></div>' +
|
||||
' <div class="margin-top-15"><code class="layui-textarea layui-bg-black border-0" disabled style="resize:none;overflow:hidden;height:190px"></code></div>' +
|
||||
'</div>',
|
||||
success: function ($elem) {
|
||||
new function () {
|
||||
var that = this;
|
||||
this.$box = $elem.find('[data-queue-load=' + code + ']');
|
||||
if (doAjax === false || this.$box.length < 1) return false;
|
||||
this.$coder = this.$box.find('code'), this.$name = this.$box.find('[data-message-title]');
|
||||
this.$percent = this.$box.find('.layui-progress div'), this.SetCache = function (code, index, value) {
|
||||
var ckey = code + '_' + index, ctype = 'admin-queue-script';
|
||||
return value !== undefined ? layui.data(ctype, {key: ckey, value: value}) : layui.data(ctype)[ckey] || 0;
|
||||
}, this.SetState = function (status, message) {
|
||||
if (message.indexOf('javascript:') === -1) if (status === 1) {
|
||||
that.$name.html('<b class="color-text">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
|
||||
} else if (status === 2) {
|
||||
if (message.indexOf('>>>') > -1) {
|
||||
that.$name.html('<b class="color-blue">' + message + '</b>').addClass('text-center');
|
||||
} else {
|
||||
that.$name.html('<b class="color-blue">正在处理:</b>' + message).removeClass('text-center');
|
||||
}
|
||||
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
|
||||
} else if (status === 3) {
|
||||
doReload = true;
|
||||
that.$name.html('<b class="color-green">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-green').removeClass('layui-bg-blue layui-bg-red');
|
||||
} else if (status === 4) {
|
||||
that.$name.html('<b class="color-red">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-red').removeClass('layui-bg-blue layui-bg-green');
|
||||
}
|
||||
}, (this.LoadProgress = function () {
|
||||
if (doAjax === false || that.$box.length < 1) return false;
|
||||
$.form.load(tapiRoot + '/api.queue/progress', {code: code}, 'post', function (ret) {
|
||||
if (ret.code) {
|
||||
var lines = [];
|
||||
for (var idx in ret.data.history) {
|
||||
var line = ret.data.history[idx], percent = '[ ' + line.progress + '% ] ';
|
||||
if (line.message.indexOf('javascript:') === -1) lines.push(line.message.indexOf('>>>') > -1 ? line.message : percent + line.message);
|
||||
else if (!that.SetCache(code, idx) && doScript !== false) that.SetCache(code, idx, 1), location.href = line.message;
|
||||
}
|
||||
if (ret.data.status > 0) {
|
||||
that.SetState(parseInt(ret.data.status), ret.data.message);
|
||||
that.$percent.attr('lay-percent', (parseFloat(ret.data.progress || '0.00').toFixed(2)) + '%'), layui.element.render();
|
||||
that.$coder.html('<p class="layui-elip">' + lines.join('</p><p class="layui-elip">') + '</p>').animate({scrollTop: that.$coder[0].scrollHeight + 'px'}, 200);
|
||||
return parseInt(ret.data.status) === 3 || parseInt(ret.data.status) === 4 || setTimeout(that.LoadProgress, Math.floor(Math.random() * 200)), false;
|
||||
} else return setTimeout(that.LoadProgress, Math.floor(Math.random() * 500) + 200), false;
|
||||
}
|
||||
}, false);
|
||||
})();
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*! 注册 data-search 表单搜索行为 */
|
||||
onEvent('submit', 'form.form-search', function () {
|
||||
var tableId = this.dataset.tableId;
|
||||
@ -753,6 +844,15 @@ $(function () {
|
||||
return $.form.load(url, this, 'post');
|
||||
});
|
||||
|
||||
/*! 注册 data-file 事件行为 */
|
||||
onEvent('click', '[data-file]', function () {
|
||||
if ($(this).data('inited') !== true) (function (that) {
|
||||
that.uploadFile(undefined, function () {
|
||||
that.trigger('upload.start');
|
||||
});
|
||||
})($(this));
|
||||
});
|
||||
|
||||
/*! 注册 data-load 事件行为 */
|
||||
onEvent('click', '[data-load]', function () {
|
||||
var emap = this.dataset, data = {};
|
||||
@ -874,6 +974,7 @@ $(function () {
|
||||
$textarea.remove();
|
||||
})(this.dataset.copy, $('<textarea style="position:fixed;top:-500px"></textarea>'));
|
||||
});
|
||||
|
||||
/*! 异步任务状态监听与展示 */
|
||||
onEvent('click', '[data-queue]', function (e) {
|
||||
(function (confirm, callable) {
|
||||
@ -886,72 +987,6 @@ $(function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
$.loadQueue = function (code, doScript, element) {
|
||||
var doAjax = true;
|
||||
layui.layer.open({
|
||||
type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () {
|
||||
doAjax = false;
|
||||
if (element && element.dataset && element.dataset.tableId) {
|
||||
$('#' + element.dataset.tableId).trigger('reload');
|
||||
} else {
|
||||
$.form.reload();
|
||||
}
|
||||
}, content: '' +
|
||||
'<div class="padding-30 padding-bottom-0" data-queue-load="' + code + '">' +
|
||||
' <div class="layui-elip notselect nowrap" data-message-title></div>' +
|
||||
' <div class="margin-top-15 layui-progress layui-progress-big" lay-showPercent="yes"><div class="layui-progress-bar transition" lay-percent="0.00%"></div></div>' +
|
||||
' <div class="margin-top-15"><code class="layui-textarea layui-bg-black border-0" disabled style="resize:none;overflow:hidden;height:190px"></code></div>' +
|
||||
'</div>',
|
||||
success: function ($elem) {
|
||||
new function () {
|
||||
var that = this;
|
||||
this.$box = $elem.find('[data-queue-load=' + code + ']');
|
||||
if (doAjax === false || this.$box.length < 1) return false;
|
||||
this.$coder = this.$box.find('code'), this.$name = this.$box.find('[data-message-title]');
|
||||
this.$percent = this.$box.find('.layui-progress div'), this.SetCache = function (code, index, value) {
|
||||
var ckey = code + '_' + index, ctype = 'admin-queue-script';
|
||||
return value !== undefined ? layui.data(ctype, {key: ckey, value: value}) : layui.data(ctype)[ckey] || 0;
|
||||
}, this.SetState = function (status, message) {
|
||||
if (message.indexOf('javascript:') === -1) if (status === 1) {
|
||||
that.$name.html('<b class="color-text">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
|
||||
} else if (status === 2) {
|
||||
if (message.indexOf('>>>') > -1) {
|
||||
that.$name.html('<b class="color-blue">' + message + '</b>').addClass('text-center');
|
||||
} else {
|
||||
that.$name.html('<b class="color-blue">正在处理:</b>' + message).removeClass('text-center');
|
||||
}
|
||||
that.$percent.addClass('layui-bg-blue').removeClass('layui-bg-green layui-bg-red');
|
||||
} else if (status === 3) {
|
||||
that.$name.html('<b class="color-green">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-green').removeClass('layui-bg-blue layui-bg-red');
|
||||
} else if (status === 4) {
|
||||
that.$name.html('<b class="color-red">' + message + '</b>').addClass('text-center');
|
||||
that.$percent.addClass('layui-bg-red').removeClass('layui-bg-blue layui-bg-green');
|
||||
}
|
||||
}, (this.LoadProgress = function () {
|
||||
if (doAjax === false || that.$box.length < 1) return false;
|
||||
$.form.load(tapiRoot + '/api.queue/progress', {code: code}, 'post', function (ret) {
|
||||
if (ret.code) {
|
||||
var lines = [];
|
||||
for (var idx in ret.data.history) {
|
||||
var line = ret.data.history[idx], percent = '[ ' + line.progress + '% ] ';
|
||||
if (line.message.indexOf('javascript:') === -1) lines.push(line.message.indexOf('>>>') > -1 ? line.message : percent + line.message);
|
||||
else if (!that.SetCache(code, idx) && doScript !== false) that.SetCache(code, idx, 1), location.href = line.message;
|
||||
}
|
||||
if (ret.data.status > 0) {
|
||||
that.SetState(parseInt(ret.data.status), ret.data.message);
|
||||
that.$percent.attr('lay-percent', (parseFloat(ret.data.progress || '0.00').toFixed(2)) + '%'), layui.element.render();
|
||||
that.$coder.html('<p class="layui-elip">' + lines.join('</p><p class="layui-elip">') + '</p>').animate({scrollTop: that.$coder[0].scrollHeight + 'px'}, 200);
|
||||
return parseInt(ret.data.status) === 3 || parseInt(ret.data.status) === 4 || setTimeout(that.LoadProgress, Math.floor(Math.random() * 200)), false;
|
||||
} else return setTimeout(that.LoadProgress, Math.floor(Math.random() * 500) + 200), false;
|
||||
}
|
||||
}, false);
|
||||
})();
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*! 注册 data-tips-text 事件行为 */
|
||||
onEvent('mouseenter', '[data-tips-text]', function () {
|
||||
@ -964,10 +999,6 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
/*! 注册 data-tips-image 事件行为 */
|
||||
onEvent('click', '[data-tips-image]', function () {
|
||||
$.previewImage(this.dataset.tipsImage || this.dataset.lazySrc || this.src, this.dataset.with);
|
||||
});
|
||||
/*! 注册 data-tips-image Hover 事件 */
|
||||
onEvent('mouseenter', '[data-tips-image][data-tips-hover]', function () {
|
||||
var img = new Image(), that = this;
|
||||
@ -981,32 +1012,16 @@ $(function () {
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
$.previewImage = function (src, area) {
|
||||
var img = new Image(), defer = $.Deferred(), loaded = $.msg.loading();
|
||||
img.style.background = '#FFF', img.referrerPolicy = 'no-referrer';
|
||||
img.style.height = 'auto', img.style.width = area || '480px', img.style.display = 'none';
|
||||
document.body.appendChild(img), img.onerror = function () {
|
||||
$.msg.close(loaded), defer.reject();
|
||||
}, img.onload = function () {
|
||||
layer.open({
|
||||
type: 1, title: false, shadeClose: true, content: $(img), success: function ($elem, idx) {
|
||||
$.msg.close(loaded), defer.notify($elem, idx);
|
||||
}, area: area || '480px', skin: 'layui-layer-nobg', closeBtn: 1, end: function () {
|
||||
document.body.removeChild(img), defer.resolve()
|
||||
}
|
||||
});
|
||||
};
|
||||
return (img.src = src), defer.resolve();
|
||||
};
|
||||
|
||||
/*! 注册 data-tips-image 事件行为 */
|
||||
onEvent('click', '[data-tips-image]', function () {
|
||||
$.previewImage(this.dataset.tipsImage || this.dataset.lazySrc || this.src, this.dataset.with);
|
||||
});
|
||||
|
||||
/*! 注册 data-phone-view 事件行为 */
|
||||
onEvent('click', '[data-phone-view]', function () {
|
||||
$.previewPhonePage(this.dataset.phoneView || this.href);
|
||||
});
|
||||
$.previewPhonePage = function (href, title, template) {
|
||||
template = '<div><div class="mobile-preview pull-left"><div class="mobile-header">_TITLE_</div><div class="mobile-body"><iframe id="phone-preview" src="_URL_" frameborder="0" marginheight="0" marginwidth="0"></iframe></div></div></div>';
|
||||
layer.style(layer.open({type: true, scrollbar: false, area: ['320px', '600px'], title: false, closeBtn: true, shadeClose: false, skin: 'layui-layer-nobg', content: $(template.replace('_TITLE_', title || '公众号').replace('_URL_', href)).html()}), {boxShadow: 'none'});
|
||||
};
|
||||
|
||||
/*! 表单编辑返回操作 */
|
||||
onEvent('click', '[data-history-back]', function () {
|
||||
|
@ -1,22 +1,26 @@
|
||||
define(function () {
|
||||
|
||||
/*! 下载 Excel 文件 */
|
||||
function excel(data, name) {
|
||||
if (name.substr(-5).toLowerCase() !== '.xlsx') {
|
||||
name += '.xlsx';
|
||||
}
|
||||
layui.excel.exportExcel(data, name, 'xlsx')
|
||||
/*! 定义构造函数 */
|
||||
function Excel(data, name) {
|
||||
if (data && name) this.export(data, name);
|
||||
}
|
||||
|
||||
/*! 导入 Excel 文件 */
|
||||
Excel.prototype.export = function (data, name) {
|
||||
if (name.substr(-5).toLowerCase() !== '.xlsx') name += '.xlsx';
|
||||
layui.excel.exportExcel(data, name, 'xlsx', {writeOpt: {bookSST: true}});
|
||||
}
|
||||
|
||||
/*! 绑定导出的事件 */
|
||||
excel.bind = function (done, filename) {
|
||||
Excel.prototype.bind = function (done, filename) {
|
||||
var that = this;
|
||||
$('body').off('click', '[data-form-export]').on('click', '[data-form-export]', function () {
|
||||
var form = $(this).parents('form');
|
||||
var name = this.dataset.filename || filename;
|
||||
var method = this.dataset.method || form.attr('method') || 'get';
|
||||
var location = this.dataset.excel || this.dataset.formExport || form.attr('action') || '';
|
||||
excel.load(location, form.serialize(), method).then(function (ret) {
|
||||
excel(done(ret), name);
|
||||
that.load(location, form.serialize(), method).then(function (ret) {
|
||||
that.export(done(ret), name);
|
||||
}).fail(function (ret) {
|
||||
$.msg.tips(ret || '文件导出失败');
|
||||
});
|
||||
@ -24,7 +28,7 @@ define(function () {
|
||||
};
|
||||
|
||||
/*! 加载导出的文档 */
|
||||
excel.load = function (url, data, method) {
|
||||
Excel.prototype.load = function (url, data, method) {
|
||||
return (function (defer, lists, loaded) {
|
||||
loaded = $.msg.loading("正在加载 <span data-upload-count>0.00</span>%");
|
||||
return (lists = []), LoadNextPage(1, 1), defer;
|
||||
@ -48,115 +52,83 @@ define(function () {
|
||||
})($.Deferred());
|
||||
};
|
||||
|
||||
/*! 读取本地的表格文件 */
|
||||
excel.read = function (file, filterCallback) {
|
||||
return (function (defer, reader, loaded, Work) {
|
||||
reader.onload = function (event) {
|
||||
Work = XLSX.read(event.target.result, {type: 'binary'});
|
||||
for (var sheet in Work.Sheets) if (Work.Sheets.hasOwnProperty(sheet)) {
|
||||
var object = {}, data = Work.Sheets[sheet], k = '', as = '';
|
||||
for (k in data) if ((as = k.match(/^([A-Z]+)(\d+)$/i))) {
|
||||
object[as[2]] = object[as[2]] || {};
|
||||
object[as[2]][as[1]] = excel.read.CellToValue(data[k].v);
|
||||
}
|
||||
$.msg.close(loaded);
|
||||
return defer.resolve(filterCallback ? excel.read.filter(object, filterCallback) : object);
|
||||
}
|
||||
$.msg.close(loaded)
|
||||
};
|
||||
reader.onerror = function () {
|
||||
defer.reject('读取文件失败');
|
||||
};
|
||||
reader.onprogress = function (event) {
|
||||
defer.notify((event.loaded / event.total).toFixed(4) * 100);
|
||||
};
|
||||
if (typeof file === 'object') {
|
||||
return reader.readAsBinaryString(file), defer.promise();
|
||||
} else {
|
||||
defer.reject('只能读取 file 文件对象');
|
||||
return defer.promise();
|
||||
}
|
||||
})($.Deferred(), new FileReader());
|
||||
};
|
||||
|
||||
/*! 直接推送表格内容 */
|
||||
excel.read.push = function (url, filterCf, filterFn) {
|
||||
return (function (defer, $input, loaded) {
|
||||
$input.appendTo($('body')).click();
|
||||
$input.on('change', function (event) {
|
||||
if (!event.target.files || event.target.files.length < 1) return $.msg.tips('没有可操作文件');
|
||||
loaded = $.msg.loading('<span data-load-name>读取</span> <span data-load-count>0.00%</span>');
|
||||
excel.read(event.target.files[0], filterCf).then(function (items, total, ers, oks, idx) {
|
||||
if ((total = items.length) < 1) return cleanAll(), $.msg.tips('未读取到有效数据');
|
||||
return (ers = 0, oks = 0, idx = 0), $('[data-load-name]').html('更新'), doPostItem(idx, items[idx]);
|
||||
|
||||
/*! 执行导入的数据 */
|
||||
function doPostItem(idx, item, data) {
|
||||
if (idx >= total) {
|
||||
return cleanAll(), $.msg.success('共处理' + total + '条记录( 成功 ' + oks + ' 条, 失败 ' + ers + ' 条 )', 3, function () {
|
||||
$.form.reload();
|
||||
});
|
||||
} else {
|
||||
$('[data-load-count]').html((idx * 100 / total).toFixed(2) + '%( 成功 ' + oks + ' 条, 失败 ' + ers + ' 条 )');
|
||||
/*! 单元数据过滤 */
|
||||
data = item;
|
||||
if (filterFn && (data = filterFn(item)) === false) {
|
||||
return (ers++), doPostItem(idx + 1, items[idx + 1]);
|
||||
}
|
||||
/*! 提交单个数据 */
|
||||
doUpdate(url, data).then(function (ret) {
|
||||
(ret.code ? oks++ : ers++), doPostItem(idx + 1, items[idx + 1]);
|
||||
});
|
||||
}
|
||||
Excel.prototype.push = function (url, sheet, cols, filter) {
|
||||
var loaded, $input;
|
||||
$input = $('<input class="layui-hide" type="file" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">');
|
||||
$input.appendTo($('body')).click().on('change', function (event) {
|
||||
if (!event.target.files || event.target.files.length < 1) return $.msg.tips('没有可操作文件');
|
||||
loaded = $.msg.loading('<span data-load-name>读取</span> <span data-load-count>0.00%</span>');
|
||||
try {
|
||||
// 导入Excel数据,并逐行上传处理
|
||||
layui.excel.importExcel(event.target.files, {}, function (data) {
|
||||
if (!data[0][sheet]) return $.msg.tips('未读取到表[' + sheet + ']的数据');
|
||||
var _cols = {}, _data = data[0][sheet], items = [], row, col, key, item;
|
||||
for (row in _data) if (parseInt(row) + 1 === parseInt(cols._ || '1')) {
|
||||
for (col in _data[row]) for (key in cols) if (_data[row][col] === cols[key]) _cols[key] = col;
|
||||
} else if (parseInt(row) + 1 > cols._ || 1) {
|
||||
item = {};
|
||||
for (key in _cols) item[key] = CellToValue(_data[row][_cols[key]]);
|
||||
items.push(item);
|
||||
}
|
||||
}).progress(function (progress) {
|
||||
$('[data-load-count]').html(progress + '%')
|
||||
}).fail(function () {
|
||||
cleanAll();
|
||||
PushQueue(items, items.length, 0, 0, 1);
|
||||
});
|
||||
});
|
||||
return defer;
|
||||
|
||||
/*! 清理文件选择器 */
|
||||
function cleanAll() {
|
||||
$input.remove(), $.msg.close(loaded);
|
||||
} catch (e) {
|
||||
$.msg.error('读取 Excel 文件失败!')
|
||||
}
|
||||
});
|
||||
|
||||
/*! 队列方式上传数据 */
|
||||
function doUpdate(url, item) {
|
||||
return (function (defer) {
|
||||
return $.form.load(url, item, 'post', function (ret) {
|
||||
return defer.resolve(ret), false;
|
||||
}, false), defer.promise();
|
||||
})($.Deferred());
|
||||
}
|
||||
})($.Deferred(), $('<input class="layui-hide" type="file" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">'));
|
||||
}
|
||||
/*! 单项推送数据 */
|
||||
function PushQueue(items, total, ers, oks, idx) {
|
||||
if ((total = items.length) < 1) return cleanAll(), $.msg.tips('未读取到有效数据');
|
||||
return (ers = 0, oks = 0, idx = 0), $('[data-load-name]').html('更新'), doPostItem(idx, items[idx]);
|
||||
|
||||
/*! 解析读取的数据 */
|
||||
excel.read.filter = function (data, cols) {
|
||||
return (function (items, item, r, c, k) {
|
||||
for (r in data) if (r <= 1) {
|
||||
for (c in data[r]) for (k in cols) {
|
||||
if (data[r][c] === cols[k].name && !cols[k].bind) cols[k].bind = c;
|
||||
/*! 执行导入的数据 */
|
||||
function doPostItem(idx, item, data) {
|
||||
if (idx >= total) {
|
||||
return cleanAll(), $.msg.success('共处理' + total + '条记录( 成功 ' + oks + ' 条, 失败 ' + ers + ' 条 )', 3, function () {
|
||||
$.form.reload();
|
||||
});
|
||||
} else {
|
||||
$('[data-load-count]').html((idx * 100 / total).toFixed(2) + '%( 成功 ' + oks + ' 条, 失败 ' + ers + ' 条 )');
|
||||
/*! 单元数据过滤 */
|
||||
data = item;
|
||||
if (filter && (data = filter(item)) === false) {
|
||||
return (ers++), doPostItem(idx + 1, items[idx + 1]);
|
||||
}
|
||||
/*! 提交单个数据 */
|
||||
doUpdate(url, data).then(function (ret) {
|
||||
(ret.code ? oks++ : ers++), doPostItem(idx + 1, items[idx + 1]);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
item = {};
|
||||
for (k in cols) item[k] = excel.read.CellToValue(data[r][cols[k].bind]);
|
||||
items.push(item);
|
||||
}
|
||||
return items
|
||||
})([]);
|
||||
}
|
||||
}
|
||||
|
||||
/*! 表格单元内容转换 */
|
||||
excel.read.CellToValue = function (v) {
|
||||
if (typeof v !== 'undefined' && /^\d+\.\d{12}$/.test(v)) {
|
||||
return LAY_EXCEL.dateCodeFormat(v, 'YYYY-MM-DD HH:ii:ss');
|
||||
} else {
|
||||
return typeof v !== 'undefined' ? v : '';
|
||||
/*! 清理文件选择器 */
|
||||
function cleanAll() {
|
||||
$input.remove();
|
||||
if (loaded) $.msg.close(loaded);
|
||||
}
|
||||
|
||||
/*! 表格单元内容转换 */
|
||||
function CellToValue(v) {
|
||||
if (typeof v !== 'undefined' && /^\d+\.\d{12}$/.test(v)) {
|
||||
return LAY_EXCEL.dateCodeFormat(v, 'YYYY-MM-DD HH:ii:ss');
|
||||
} else {
|
||||
return typeof v !== 'undefined' ? v : '';
|
||||
}
|
||||
}
|
||||
|
||||
/*! 队列方式上传数据 */
|
||||
function doUpdate(url, item) {
|
||||
return (function (defer) {
|
||||
return $.form.load(url, item, 'post', function (ret) {
|
||||
return defer.resolve(ret), false;
|
||||
}, false), defer.promise();
|
||||
})($.Deferred());
|
||||
}
|
||||
}
|
||||
|
||||
return excel;
|
||||
/*! 返回对象实例 */
|
||||
return new Excel;
|
||||
});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -223,10 +223,7 @@
|
||||
|
||||
.uploadimagemtl {
|
||||
> div {
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: none;
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
|
@ -43,8 +43,9 @@
|
||||
|
||||
&.layui-layout-right {
|
||||
.headimg {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user