define([], function () { require([], function () { //绑定data-toggle=addresspicker属性点击事件 $(document).on('click', "[data-toggle='addresspicker']", function () { var that = this; var callback = $(that).data('callback'); var input_id = $(that).data("input-id") ? $(that).data("input-id") : ""; var lat_id = $(that).data("lat-id") ? $(that).data("lat-id") : ""; var lng_id = $(that).data("lng-id") ? $(that).data("lng-id") : ""; var zoom_id = $(that).data("zoom-id") ? $(that).data("zoom-id") : ""; var lat = lat_id ? $("#" + lat_id).val() : ''; var lng = lng_id ? $("#" + lng_id).val() : ''; var zoom = zoom_id ? $("#" + zoom_id).val() : ''; var url = "/addons/address/index/select"; url += (lat && lng) ? '?lat=' + lat + '&lng=' + lng + (input_id ? "&address=" + $("#" + input_id).val() : "") + (zoom ? "&zoom=" + zoom : "") : ''; Fast.api.open(url, '位置选择', { callback: function (res) { input_id && $("#" + input_id).val(res.address).trigger("change"); lat_id && $("#" + lat_id).val(res.lat).trigger("change"); lng_id && $("#" + lng_id).val(res.lng).trigger("change"); zoom_id && $("#" + zoom_id).val(res.zoom).trigger("change"); try { //执行回调函数 if (typeof callback === 'function') { callback.call(that, res); } } catch (e) { } } }); }); }); require(['fast', 'layer'], function (Fast, Layer) { var _fastOpen = Fast.api.open; Fast.api.open = function (url, title, options) { options = options || {}; options.area = Config.betterform.area; options.offset = Config.betterform.offset; options.anim = Config.betterform.anim; options.shadeClose = Config.betterform.shadeClose; options.shade = Config.betterform.shade; return _fastOpen(url, title, options); }; if (isNaN(Config.betterform.dialoganim)) { var _layerOpen = Layer.open; Layer.open = function (options) { var classNameArr = {slideDown: "layer-anim-slide-down", slideLeft: "layer-anim-slide-left", slideUp: "layer-anim-slide-up", slideRight: "layer-anim-slide-right"}; var animClass = "layer-anim " + classNameArr[options.anim] || "layer-anim-fadein"; var index = _layerOpen(options); var layero = $('#layui-layer' + index); layero.addClass(classNameArr[options.anim] + "-custom"); layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () { $(this).removeClass(animClass); }); return index; } } }); require.config({ paths: { 'clicaptcha': '../addons/clicaptcha/js/clicaptcha' }, shim: { 'clicaptcha': { deps: [ 'jquery', 'css!../addons/clicaptcha/css/clicaptcha.css' ], exports: '$.fn.clicaptcha' } } }); require(['form'], function (Form) { window.clicaptcha = function (captcha) { require(['clicaptcha'], function (undefined) { captcha = captcha ? captcha : $("input[name=captcha]"); if (captcha.length > 0) { var form = captcha.closest("form"); var parentDom = captcha.parent(); // 非文本验证码 if ($("a[data-event][data-url]", parentDom).length > 0) { return; } if (captcha.parentsUntil(form, "div.form-group").length > 0) { captcha.parentsUntil(form, "div.form-group").addClass("hidden"); } else if (parentDom.is("div.input-group")) { parentDom.addClass("hidden"); } captcha.attr("data-rule", "required"); // 验证失败时进行操作 captcha.on('invalid.field', function (e, result, me) { //必须删除errors对象中的数据,否则会出现Layer的Tip delete me.errors['captcha']; captcha.clicaptcha({ src: '/addons/clicaptcha/index/start', success_tip: '验证成功!', error_tip: '未点中正确区域,请重试!', callback: function (captchainfo) { form.trigger("submit"); return false; } }); }); // 监听表单错误事件 form.on("error.form", function (e, data) { captcha.val(''); }); } }); }; // clicaptcha($("input[name=captcha]")); if (typeof Frontend !== 'undefined') { Frontend.api.preparecaptcha = function (btn, type, data) { require(['form'], function (Form) { $("#clicaptchacontainer").remove(); $("
").attr("id", "clicaptchacontainer").addClass("hidden").html(Template("captchatpl", {})).appendTo("body"); var form = $("#clicaptchacontainer form"); form.data("validator-options", { valid: function (ret) { data.captcha = $("input[name=captcha]", form).val(); Frontend.api.sendcaptcha(btn, type, data, function (data, ret) { console.log("ok"); }); return true; } }) Form.api.bindevent(form); }); }; } var _bindevent = Form.events.bindevent; Form.events.bindevent = function (form) { _bindevent.apply(this, [form]); var captchaObj = $("input[name=captcha]", form); if (captchaObj.length > 0) { clicaptcha(captchaObj); if ($(form).attr("name") === 'captcha-form') { setTimeout(function () { captchaObj.trigger("invalid.field", [{key: 'captcha'}, {errors: {}}]); }, 100); } } } }); require(['form', 'upload'], function (Form, Upload) { var _bindevent = Form.events.bindevent; Form.events.bindevent = function (form) { _bindevent.apply(this, [form]); if ($("#croppertpl").length == 0) { var allowAttr = [ 'aspectRatio', 'autoCropArea', 'cropBoxMovable', 'cropBoxResizable', 'minCropBoxWidth', 'minCropBoxHeight', 'minContainerWidth', 'minContainerHeight', 'minCanvasHeight', 'minCanvasWidth', 'croppedWidth', 'croppedHeight', 'croppedMinWidth', 'croppedMinHeight', 'croppedMaxWidth', 'croppedMaxHeight', 'fillColor', 'containerMinHeight', 'containerMaxHeight', 'customWidthHeight', 'customAspectRatio' ]; String.prototype.toLineCase = function () { return this.replace(/[A-Z]/g, function (match) { return "-" + match.toLowerCase(); }); }; var btnAttr = []; $.each(allowAttr, function (i, j) { btnAttr.push('data-' + j.toLineCase() + '="<%=data.' + j + '%>"'); }); var btn = ''; var insertBtn = function () { return arguments[0].replace(arguments[2], btn + arguments[2]); }; $("").appendTo("body"); } $(".plupload[data-preview-id],.faupload[data-preview-id]").each(function () { var preview_id = $(this).data("preview-id"); var previewObj = $("#" + preview_id); var tpl = previewObj.length > 0 ? previewObj.data("template") : ''; if (!tpl) { if (!$(this).hasClass("cropper")) { $(this).addClass("cropper"); } previewObj.data("template", "croppertpl"); } }); //图片裁剪 $(document).off('click', '.btn-cropper').on('click', '.btn-cropper', function () { var image = $(this).closest("li").find('.thumbnail').data('url'); var input = $("#" + $(this).data("input-id")); var url = image; var data = $(this).data(); var params = []; $.each(allowAttr, function (i, j) { if (typeof data[j] !== 'undefined' && data[j] !== '') { params.push(j + '=' + data[j]); } }); try { var parentWin = (parent ? parent : window); parentWin.Fast.api.open('/addons/cropper/index/cropper?url=' + image + (params.length > 0 ? '&' + params.join('&') : ''), '裁剪', { callback: function (data) { if (typeof data !== 'undefined') { var arr = data.dataURI.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } var urlArr = url.split('.'); var suffix = 'png'; url = urlArr.join(''); var filename = url.substr(url.lastIndexOf('/') + 1); var exp = new RegExp("\\." + suffix + "$", "i"); filename = exp.test(filename) ? filename : filename + "." + suffix; var file = new File([u8arr], filename, {type: mime}); Upload.api.send(file, function (data) { input.val(input.val().replace(image, data.url)).trigger("change"); }, function (data) { }); } }, area: [Math.min(parentWin.$(parentWin.window).width(), Config.cropper.dialogWidth) + "px", Math.min(parentWin.$(parentWin.window).height(), Config.cropper.dialogHeight) + "px"], }); } catch (e) { console.error(e); } return false; }); } }); require.config({ paths: { 'csmtable_xcore': '../addons/csmtable/library/xcore/js/xcore', 'csmtable_csminputstyle': '../addons/csmtable/library/xcore/js/csminputstyle', 'jquery.simple-color': '../addons/csmtable/library/xcore/js/jquery.simple-color', 'csmtable': '../addons/csmtable/js/csmtable', 'fixedcolumns': '../addons/csmtable/js/bootstrap-table-fixed-columns', 'tablereorderrows': '../addons/csmtable/js/bootstrap-table-reorder-rows', 'tablestickyheader': '../addons/csmtable/js/bootstrap-table-sticky-header', 'tabletreegrid': '../addons/csmtable/js/bootstrap-table-treegrid', 'jquerytablednd': '../addons/csmtable/js/jquery.tablednd.min', 'jquerytreegrid': '../addons/csmtable/js/jquery.treegrid.min', 'xeditable2': '../addons/csmtable/js/select2', }, shim: { 'csmtable_xcore': { deps: ["css!../addons/csmtable/library/xcore/css/xcore.css"] }, 'csmtable_csminputstyle': { deps: ["css!../addons/csmtable/library/xcore/css/csminputstyle.css"] }, 'csmtable': { deps: ["css!../addons/csmtable/css/csmtable.css", 'bootstrap-table'] }, 'fixedcolumns': { deps: ["css!../addons/csmtable/css/bootstrap-table-fixed-columns.css", 'bootstrap-table'] }, 'tablereorderrows':{ deps: ["css!../addons/csmtable/css/bootstrap-table-reorder-rows.css",'jquerytablednd', 'bootstrap-table'] }, 'tablestickyheader':{ deps: ["css!../addons/csmtable/css/bootstrap-table-sticky-header.css", 'bootstrap-table'] }, 'tabletreegrid':{ deps: ["css!../addons/csmtable/css/jquery.treegrid.min.css",'jquerytreegrid', 'bootstrap-table'] }, 'xeditable2':{ deps: ["css!../addons/csmtable/css/select2.css","css!../addons/csmtable/css/select2-bootstrap.css",'bootstrap-table','editable'] }, } }); //判断系统深色模式变化,修改切换按钮 var matchMedia = window.matchMedia(('(prefers-color-scheme: dark)')); matchMedia.addEventListener('change', function () { var mode = this.matches ? 'dark' : 'light'; //只有当cookie中无手动定义值时才进行操作 if (document.cookie.indexOf("thememode=") === -1 && Config.darktheme.mode === 'auto') { $("body").toggleClass("darktheme", mode === "dark"); } }); if (typeof Config.darktheme !== 'undefined' && Config.darktheme.switchbtn) { // 切换模式 var switchMode = function (mode) { // 获取当前深色模式 if (mode === 'auto') { var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; mode = isDarkMode ? 'dark' : 'light'; } if (mode === 'auto') { } else if (mode === 'dark') { $("body").addClass("darktheme"); $(".darktheme-link").removeAttr("media"); } else { $("body").removeClass("darktheme"); $(".darktheme-link").attr("media", "(prefers-color-scheme: dark)"); } }; // 创建Cookie var createCookie = function (name, value) { var date = new Date(); date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000)); var url = Config.moduleurl.replace(location.origin, ""); var path = url ? url.substring(url.lastIndexOf("/")) : "/"; document.cookie = encodeURIComponent(Config.cookie.prefix + name) + "=" + encodeURIComponent(value) + "; path=" + path + "; expires=" + date.toGMTString(); }; if (Config.controllername === 'index' && Config.actionname === 'index') { var mode = Config.darktheme.mode; if (mode === 'auto') { var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; mode = isDarkMode ? 'dark' : 'light'; } var html = '
  • ' + '' + '
  • '; $(html).prependTo("#firstnav > div > ul"); //点击切换按钮 $(document).on("click", ".theme-toggle", function () { var mode = $(this).attr("data-mode"); switchMode(mode); createCookie("thememode", mode); $("iframe").each(function () { try { $(this)[0].contentWindow.$("body").trigger("swithmode", [mode]); } catch (e) { } }); $(this).attr("data-mode", mode === 'dark' ? 'light' : 'dark').attr("title", '切换' + (mode === 'dark' ? '浅色' : '深色') + '模式'); }); //判断系统深色模式变化,修改切换按钮 var matchMedia = window.matchMedia(('(prefers-color-scheme: dark)')); matchMedia.addEventListener('change', function () { var mode = this.matches ? 'dark' : 'light'; //只有当cookie中无手动定义值时才切换 if (document.cookie.indexOf("thememode=") === -1 && Config.darktheme.mode === 'auto') { $(".theme-toggle").attr("data-mode", mode === 'dark' ? 'light' : 'dark').attr("title", '切换' + (mode === 'dark' ? '浅色' : '深色') + '模式'); } }); } else { //添加事件 $("body").on("swithmode", function (e, mode) { switchMode(mode); $("iframe").each(function () { try { $(this)[0].contentWindow.$("body").trigger("swithmode", [mode]); } catch (e) { } }); }); } } require.config({ paths: { 'editable': '../libs/bootstrap-table/dist/extensions/editable/bootstrap-table-editable.min', 'x-editable': '../addons/editable/js/bootstrap-editable.min', }, shim: { 'editable': { deps: ['x-editable', 'bootstrap-table'] }, "x-editable": { deps: ["css!../addons/editable/css/bootstrap-editable.css"], } } }); if ($("table.table").length > 0) { require(['editable', 'table'], function (Editable, Table) { $.fn.bootstrapTable.defaults.onEditableSave = function (field, row, oldValue, $el) { var data = {}; data["row[" + field + "]"] = row[field]; Fast.api.ajax({ url: this.extend.edit_url + "/ids/" + row[this.pk], data: data }); }; }); } require.config({ paths: { 'nkeditor': '../addons/nkeditor/js/customplugin', 'nkeditor-core': '../addons/nkeditor/nkeditor', 'nkeditor-lang': '../addons/nkeditor/lang/zh-CN', }, shim: { 'nkeditor': { deps: [ 'nkeditor-core', 'nkeditor-lang' ] }, 'nkeditor-core': { deps: [ 'css!../addons/nkeditor/themes/black/editor.min.css', 'css!../addons/nkeditor/css/common.css' ], exports: 'window.KindEditor' }, 'nkeditor-lang': { deps: [ 'nkeditor-core' ] } } }); require(['form'], function (Form) { var _bindevent = Form.events.bindevent; Form.events.bindevent = function (form) { _bindevent.apply(this, [form]); if ($(Config.nkeditor.classname || '.editor', form).length > 0) { require(['nkeditor', 'upload'], function (Nkeditor, Upload) { var getFileFromBase64, uploadFiles; uploadFiles = async function (files) { var self = this; for (var i = 0; i < files.length; i++) { try { await new Promise((resolve) => { var url, html, file; file = files[i]; Upload.api.send(file, function (data) { url = Config.nkeditor.fullmode ? Fast.api.cdnurl(data.url, true) : Fast.api.cdnurl(data.url); if (file.type.indexOf("image") !== -1) { self.exec("insertimage", url); } else { html = '' + (file.name || url) + ''; self.exec("inserthtml", html); } resolve(); }, function () { resolve(); }); }); } catch (e) { } } }; getFileFromBase64 = function (data, url) { var arr = data.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } var filename, suffix; if (typeof url != 'undefined') { var urlArr = url.split('.'); filename = url.substr(url.lastIndexOf('/') + 1); suffix = urlArr.pop(); } else { filename = Math.random().toString(36).substring(5, 15); } if (!suffix) { suffix = data.substring("data:image/".length, data.indexOf(";base64")); } var exp = new RegExp("\\." + suffix + "$", "i"); filename = exp.test(filename) ? filename : filename + "." + suffix; var file = new File([u8arr], filename, {type: mime}); return file; }; $(Config.nkeditor.classname || '.editor', form).each(function () { var that = this; var options = $(this).data("nkeditor-options"); var editor = Nkeditor.create(that, $.extend({}, { width: '100%', filterMode: false, wellFormatMode: false, allowMediaUpload: true, //是否允许媒体上传 allowFileManager: true, allowImageUpload: true, baiduMapKey: Config.nkeditor.baidumapkey || '', baiduMapCenter: Config.nkeditor.baidumapcenter || '', fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '21px', '24px', '32px'], formulaPreviewUrl: typeof Config.nkeditor != 'undefined' && Config.nkeditor.formulapreviewurl ? Config.nkeditor.formulapreviewurl : "", //数学公式的预览地址 cssPath: Config.site.cdnurl + '/assets/addons/nkeditor/plugins/code/prism.css', cssData: "body {font-size: 13px}", fillDescAfterUploadImage: false, //是否在上传后继续添加描述信息 themeType: typeof Config.nkeditor != 'undefined' ? Config.nkeditor.theme : 'black', //编辑器皮肤,这个值从后台获取 fileManagerJson: Fast.api.fixurl("/addons/nkeditor/index/attachment/module/" + Config.modulename), items: [ 'source', 'undo', 'redo', 'preview', 'print', 'template', 'code', 'quote', 'cut', 'copy', 'paste', 'plainpaste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', 'formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', 'image', 'multiimage', 'graft', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', 'remoteimage', 'search', 'math', 'about', 'fullscreen' ], afterCreate: function () { var self = this; //Ctrl+回车提交 Nkeditor.ctrl(document, 13, function () { self.sync(); $(that).closest("form").submit(); }); Nkeditor.ctrl(self.edit.doc, 13, function () { self.sync(); $(that).closest("form").submit(); }); //粘贴上传 $("body", self.edit.doc).bind('paste', function (event) { var originalEvent; originalEvent = event.originalEvent; if (originalEvent.clipboardData && originalEvent.clipboardData.files.length > 0) { uploadFiles.call(self, originalEvent.clipboardData.files); return false; } }); //拖拽上传 $("body", self.edit.doc).bind('drop', function (event) { var originalEvent; originalEvent = event.originalEvent; if (originalEvent.dataTransfer && originalEvent.dataTransfer.files.length > 0) { uploadFiles.call(self, originalEvent.dataTransfer.files); return false; } }); }, afterChange: function () { $(this.srcElement[0]).trigger("change"); }, //自定义处理 beforeUpload: function (callback, file) { var file = file ? file : $("input.ke-upload-file", this.form).prop('files')[0]; Upload.api.send(file, function (data) { var data = {code: '000', data: {url: Config.nkeditor.fullmode ? Fast.api.cdnurl(data.url, true) : Fast.api.cdnurl(data.url)}, title: '', width: '', height: '', border: '', align: ''}; callback(data); }); }, //错误处理 handler errorMsgHandler: function (message, type) { try { Fast.api.msg(message); console.log(message, type); } catch (Error) { alert(message); } }, uploadFiles: uploadFiles }, options || {})); $(this).data("nkeditor", editor); }); }); } } }); if (Config.modulename === 'index' && Config.controllername === 'user' && ['login', 'register'].indexOf(Config.actionname) > -1 && $("#register-form,#login-form").length > 0 && $(".social-login").length == 0) { $("#register-form,#login-form").append(Config.third.loginhtml || ''); } // 手机端左右滑动切换菜单栏 if ('ontouchstart' in document.documentElement) { var startX, startY, moveEndX, moveEndY, relativeX, relativeY, element; element = $('body', top.document); $("body").on("touchstart", function (e) { startX = e.originalEvent.changedTouches[0].pageX; startY = e.originalEvent.changedTouches[0].pageY; }); $("body").on("touchend", function (e) { moveEndX = e.originalEvent.changedTouches[0].pageX; moveEndY = e.originalEvent.changedTouches[0].pageY; relativeX = moveEndX - startX; relativeY = moveEndY - startY; // 判断标准 //右滑 if (relativeX > 45) { if ((Math.abs(relativeX) - Math.abs(relativeY)) > 50) { element.addClass("sidebar-open"); } } //左滑 else if (relativeX < -45) { if ((Math.abs(relativeX) - Math.abs(relativeY)) > 50) { element.removeClass("sidebar-open"); } } }); } });