更新同步插件代码

This commit is contained in:
邹景立 2023-03-10 16:42:42 +08:00
parent 161b05ce61
commit c36ae62bf4
8 changed files with 276 additions and 268 deletions

View File

@ -16,6 +16,7 @@
namespace app\admin\controller\api;
use Error;
use Exception;
use think\admin\Controller;
use think\admin\service\AdminService;
@ -90,7 +91,7 @@ class Queue extends Controller
} else {
echo "<span class='color-red pointer' data-tips-text='{$message}'>未启动</span>";
}
} catch (Exception $exception) {
} catch (Error|Exception $exception) {
echo "<span class='color-red pointer' data-tips-text='{$exception->getMessage()}'>异 常</span>";
} else {
echo "<span class='color-red pointer' data-tips-text='只有超级管理员才能操作!'>无权限</span>";

View File

@ -5,7 +5,7 @@
<a data-table-id="FileTable" data-load='{:url("distinct")}' class='layui-btn layui-btn-sm layui-btn-primary'>清理重复</a>
<!--{/if}-->
<!--{if auth("remove")}-->
<a data-confirm="确定永久删除这些账号吗?" data-table-id="FileTable" data-action='{:url("remove")}' data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</a>
<a data-confirm="确定删除这些记录吗?" data-table-id="FileTable" data-action='{:url("remove")}' data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</a>
<!--{/if}-->
{/block}

View File

@ -257,11 +257,8 @@ $(function () {
};
/*! 内容区域动态加载后初始化 */
this.reInit = function ($dom) {
$dom = $dom || $(this.selecter);
layui.form.render(), layui.element.render(), $(window).trigger('scroll');
require(['ThinkAdmin'], function () {
$.vali.listen($dom) && $body.trigger('reInit', $dom);
});
layui.form.render() && layui.element.render() && $(window).trigger('scroll');
$.vali.listen($dom = $dom || $(this.selecter)) && $body.trigger('reInit', $dom);
return $dom.find('[required]').map(function () {
this.$parent = $(this).parent();
if (this.$parent.is('label')) this.$parent.addClass('label-required-prev'); else this.$parent.prevAll('label.layui-form-label').addClass('label-required-next');
@ -739,17 +736,28 @@ $(function () {
layer.style(layer.open({type: true, resize: false, scrollbar: false, area: ['320px', '600px'], title: false, closeBtn: true, shadeClose: false, skin: 'layui-layer-nobg', content: laytpl(template).render({title: title || '公众号', url: href})}), {boxShadow: 'none'});
};
/*! 注册 ThinkAdmin 组件及标签行为 */
define('ThinkAdmin', ['require', 'queue', 'validate'], function (require, Queue, Validate) {
/*! 显示任务进度 */
$.loadQueue = function (code, doScript, element) {
require(['queue'], function (Queue) {
return new Queue(code, doScript, element);
});
};
/*! 注册JqFn函数 */
$.fn.vali = function (done, init) {
return this.each(function () {
$.vali(this, done, init);
});
};
/*! 创建表单验证 */
$.vali = function (form, callable) {
return $(form).data('validate') || new Validate(form, callable, onConfirm);
$.vali = function (form, done, init) {
require(['validate'], function (Validate) {
/** @type {import("./plugs/admin/validate")|Validate} */
var vali = $(form).data('validate') || new Validate(form, onConfirm);
typeof init === 'function' && init.call(vali, $(form).formToJson());
typeof done === 'function' && vali.addDoneEvent(done);
});
};
/*! 自动监听表单 */
@ -775,13 +783,6 @@ $(function () {
});
};
/*! 注册对象到JqFn */
$.fn.vali = function (callable) {
return this.each(function () {
$.vali(this, callable);
});
};
/*! 注册 data-search 表单搜索行为 */
onEvent('submit', 'form.form-search', function () {
if (this.dataset.tableId) return $('table#' + this.dataset.tableId).trigger('reload', {
@ -871,6 +872,7 @@ $(function () {
/*! 注册 data-open 事件行为 */
onEvent('click', '[data-open]', function () {
layui.sessionData('pages', null);
if (this.dataset.open.match(/^https?:/)) {
$.form.goto(this.dataset.open);
} else {
@ -976,14 +978,14 @@ $(function () {
/*! 注册 data-target-submit 事件行为 */
onEvent('click', '[data-target-submit]', function () {
$(this.dataset.targetSubmit || this).submit();
$(this.dataset.targetSubmit || 'form:last').submit();
});
/*! 表单编辑返回操作 */
onEvent('click', '[data-history-back]', function () {
$.msg.confirm(this.dataset.historyBack || '确定要返回吗?', function () {
onEvent('click', '[data-target-backup],[data-history-back]', function () {
onConfirm(this.dataset.historyBack || this.dataset.targetBackup || '确定要返回上个页面吗?', function () {
history.back();
})
});
});
/*! 图片加载异常处理 */
@ -992,10 +994,6 @@ $(function () {
event.target.src = baseRoot + 'theme/img/404_icon.png';
}, true);
});
/*! 系统菜单表单页面初始化 */
require(['ThinkAdmin'], function () {
/*! 初始化系统菜单及表单验证 */
$.menu.listen() && $.form.reInit($body);
});
});

View File

@ -12,7 +12,7 @@
// | github 代码仓库https://github.com/zoujingli/think-plugs-static
// +----------------------------------------------------------------------
require(['ThinkAdmin'], function () {
$(function () {
window.$body = $('body');

View File

@ -17,7 +17,9 @@ define(function () {
var doAjax = true, doReload = false;
var template = '<div class="padding-30 padding-bottom-0" data-queue-load="{{d.code}}"><div class="layui-elip notselect nowrap" data-message-title><b class="color-desc">...</b></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" style="resize:none;overflow:hidden;height:190px"></code></div></div>';
return function (code, doScript, element) {
return Queue;
function Queue(code, doScript, element) {
layer.open({
type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () {
doAjax = doReload && doScript && $.layTable.reload(((element || {}).dataset || {}).tableId || true)

View File

@ -14,7 +14,9 @@
define(function () {
return function (form, callable, onConfirm) {
return Validate;
function Validate(form, onConfirm) {
var that = this;
// 绑定表单元素
this.form = $(form);
@ -22,17 +24,23 @@ define(function () {
this.evts = 'blur change';
// 检测表单元素
this.tags = 'input,textarea';
// 验证成功回调
this.dones = [];
// 预设检测规则
this.patterns = {
qq: '^[1-9][0-9]{4,11}$',
ip: '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
url: '^((https?|ftp|file):\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$',
url: '^https?://([a-zA-Z0-9]+\\.)+[a-zA-Z0-9]+',
phone: '^1[3-9][0-9]{9}$',
email: '^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$',
email: '^([a-zA-Z0-9_\\.\\-])+@(([a-zA-Z0-9\-])+\\.)+([a-zA-Z0-9]{2,4})+$',
wechat: '^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$',
cardid: '^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$',
cardid: '^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$',
userame: '^[a-zA-Z0-9_-]{4,16}$',
};
// 设置完成回调
this.addDoneEvent = function (done) {
if (typeof done === 'function') this.dones.push(done);
};
this.isRegex = function (el, value, pattern) {
pattern = pattern || el.getAttribute('pattern');
if ((value = value || $.trim($(el).val())) === '') return true;
@ -43,7 +51,7 @@ define(function () {
var attrProp = el.getAttribute(prop);
return typeof attrProp !== 'undefined' && attrProp !== null && attrProp !== false;
};
this.needCheck = function (el, type) {
this.hasCheck = function (el, type) {
if (this.hasProp(el, 'data-auto-none')) return false;
type = (el.getAttribute('type') || '').replace(/\W+/, '').toLowerCase();
return $.inArray(type, ['file', 'reset', 'image', 'radio', 'checkbox', 'submit', 'hidden']) < 0;
@ -55,7 +63,7 @@ define(function () {
}) && status;
};
this.checkInput = function (el) {
if (!this.needCheck(el)) return true;
if (!this.hasCheck(el = typeof el === 'string' ? form[el] : el)) return true;
if (this.hasProp(el, 'required') && $.trim($(el).val()) === '') return this.remind(el, 'required');
return this.isRegex(el) ? !!this.hideError(el) : this.remind(el, 'pattern');
};
@ -80,33 +88,32 @@ define(function () {
};
/*! 预埋异常标签*/
this.form.find(this.tags).each(function (i, el) {
that.needCheck(this) && setTimeout(function () {
that.hasCheck(this) && setTimeout(function () {
that.hideError(el, '');
}, 500);
}, 250);
});
/*! 表单元素验证 */
this.form.attr({onsubmit: 'return false', novalidate: 'novalidate', autocomplete: 'off'}).on('keydown', this.tags, function () {
that.hideError(this)
}).off(this.evts, this.tags).on(this.evts, this.tags, function () {
that.checkInput(this);
}).data('validate', this).bind('submit', function (event) {
event.preventDefault();
}).data('validate', this).bind('submit', function (evt) {
evt.preventDefault();
/* 检查所有表单元素是否通过H5的规则验证 */
if (that.checkAllInput() && typeof callable === 'function') {
if (that.checkAllInput() && that.dones.length > 0) {
if (typeof CKEDITOR === 'object' && typeof CKEDITOR.instances === 'object') {
for (var i in CKEDITOR.instances) CKEDITOR.instances[i].updateElement();
}
/* 触发表单提交后,锁定三秒不能再次提交表单 */
if (that.form.attr('submit-locked')) return false;
var submit = that.form.find('button[type=submit],button:not([type=button])');
onConfirm(submit.attr('data-confirm'), function () {
that.form.attr('submit-locked', 1);
submit.addClass('submit-button-loading');
callable.call(form, that.form.formToJson(), []);
evt.submit = that.form.find('button[type=submit],button:not([type=button])');
onConfirm(evt.submit.attr('data-confirm'), function () {
that.form.attr('submit-locked', 1) && evt.submit.addClass('submit-button-loading');
setTimeout(function () {
that.form.removeAttr('submit-locked');
submit.removeClass('submit-button-loading');
}, 3000);
that.form.removeAttr('submit-locked') && evt.submit.removeClass('submit-button-loading');
}, 3000) && that.dones.forEach(function (done) {
done.call(form, that.form.formToJson(), []);
});
});
}
}).find('[data-form-loaded]').map(function () {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long