define([], function () { require(['../addons/bootstrapcontextmenu/js/bootstrap-contextmenu'], function (undefined) { if (Config.controllername == 'index' && Config.actionname == 'index') { $("body").append( '
' + '' + '
'); $(".nav-addtabs").contextmenu({ target: "#context-menu", scopes: 'li[role=presentation]', onItem: function (e, event) { var $element = $(event.target); var tab_id = e.attr('id'); var id = tab_id.substr('tab_'.length); var con_id = 'con_' + id; switch ($element.data('operate')) { case 'refresh': $("#" + con_id + " iframe").attr('src', function (i, val) { return val; }); break; case 'refreshTable': try { if ($("#" + con_id + " iframe").contents().find(".btn-refresh").size() > 0) { $("#" + con_id + " iframe")[0].contentWindow.$(".btn-refresh").trigger("click"); } } catch (e) { } break; case 'close': if (e.find(".close-tab").length > 0) { e.find(".close-tab").click(); } break; case 'closeOther': e.parent().find("li[role='presentation']").each(function () { if ($(this).attr('id') == tab_id) { return; } if ($(this).find(".close-tab").length > 0) { $(this).find(".close-tab").click(); } }); break; case 'closeAll': e.parent().find("li[role='presentation']").each(function () { if ($(this).find(".close-tab").length > 0) { $(this).find(".close-tab").click(); } }); break; default: break; } } }); } $(document).on('click', function () { // iframe内点击 隐藏菜单 try { top.window.$(".nav-addtabs").contextmenu("closemenu"); } catch (e) { } }); }); if (window.csmadmincfg != null && window.csmadmincfg.trigger == "1") { var mac = window.csmadmincfg.triggername; require.config({ paths : { 'csmadmin' : [ '../addons/csmadmin/js/' + mac ], }, shim : { csmadmin : [ 'css!../addons/csmadmin/css/' + mac + '.css' ] }, }); require([ 'csmadmin' ], function(obj) { obj.mounted(); }); } require.config({ paths: { 'jquery-colorpicker': '../addons/customcharts/js/jquery.colorpicker.min', }, shim: { 'jquery-colorpicker': { deps: ['jquery'], exports: '$.fn.extend' } } }); if (Config.editpage.app_debug == true) { require.config({ paths: { ace: ['../addons/editpage/js/ace'], tools: ['../addons/editpage/js/ext-language_tools'] } }); if (Config.editpage.module == 'admin' && ['editpage', 'index'].indexOf(Config.editpage.controller.toLowerCase()) == -1) { //浮动按钮 var _html = '
' + 'C' + 'M' + 'V' + 'J' + 'L' + '<' + '
'; $("body").append(_html); //触发弹窗 $('#editpage').find('a').click(function () { var title = $(this).attr('title'); var type = $(this).attr('data-type'); if(type == 'command'){ var url = Config.editpage.command; }else{ var url = Config.editpage.index + '?module=' + Config.editpage.module + '&c=' + Config.editpage.controller + '&a=' + Config.editpage.action + '&type=' + type; } parent.Fast.api.open(url, title, {area: ["80%", "80%"]}); }); } } require.config({ paths: { 'bootstrap-markdown': '../addons/markdown/js/bootstrap-markdown.min', 'hyperdown': '../addons/markdown/js/hyperdown.min', 'turndown': '../addons/markdown/js/turndown', }, shim: { 'bootstrap-markdown': { deps: [ 'jquery', 'css!../addons/markdown/css/bootstrap-markdown.css' ], exports: '$.fn.markdown' } } }); require(['form', 'upload'], function (Form, Upload) { var _bindevent = Form.events.bindevent; Form.events.bindevent = function (form) { _bindevent.apply(this, [form]); var insert = function (e, url, type) { var urlArr = url.split(/\,/); $.each(urlArr, function () { var url = Fast.api.cdnurl(this, true); if (type && type == 'image') { e.replaceSelection("\n" + '![输入图片说明](' + url + ')'); } else { e.replaceSelection("\n" + '[输入链接说明](' + url + ')'); } }); e.change(e); // e.$element.blur(); // e.$element.focus(); }; try { if ($(Config.markdown.classname || '.editor', form).length > 0) { require(['bootstrap-markdown', 'hyperdown', 'turndown'], function (undefined, undefined, Turndown) { $.fn.markdown.messages.zh = { Bold: "粗体", Italic: "斜体", Heading: "标题", "URL/Link": "链接", Image: "图片", List: "列表", "Unordered List": "无序列表", "Ordered List": "有序列表", Code: "代码", Quote: "引用", Preview: "预览", "strong text": "粗体", "emphasized text": "强调", "heading text": "标题", "enter link description here": "输入链接说明", "Insert Hyperlink": "URL地址", "enter image description here": "输入图片说明", "Insert Image Hyperlink": "图片URL地址", "enter image title here": "在这里输入图片标题", "list text here": "这里是列表文本", "code text here": "这里输入代码", "quote here": "这里输入引用文本" }; var parser = new HyperDown(); window.marked = function (text) { return parser.makeHtml(text); }; var 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 = Fast.api.cdnurl(data.url, true); if (file.type.indexOf("image") !== -1) { insert(self, url, 'image'); } else { insert(self, url, 'file'); } resolve(); }, function () { resolve(); }); }); } catch (e) { } } }; $(Config.markdown.classname || '.editor', form).each(function () { var options = $(this).data("markdown-options") || {}; var editor = $(this); if (typeof options.format !== 'undefined' && options.format === 'html') { var origin = editor; var turndownService = new TurndownService(); turndownService.use(turndownPluginGfm.gfm); var content = turndownService.turndown(origin.val()); editor = origin.clone().removeAttr("name").removeAttr("id").val(content); origin.css("display", "none"); editor.data("markdown-origin", origin); editor.insertAfter(origin); } (function (editor) { editor.markdown($.extend(true, { resize: 'vertical', language: 'zh', iconlibrary: 'fa', autofocus: false, savable: false, additionalButtons: [ [{ name: "groupCustom", data: [{ name: "cmdUploadImage", toggle: false, title: "Upload image", icon: "fa fa-upload", }, { name: "cmdUploadFile", toggle: false, title: "Upload file", icon: "fa fa-cloud-upload", }, { name: "cmdSelectImage", toggle: false, title: "Select image", icon: "fa fa-file-image-o", callback: function (e) { parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=image/*", __('Choose'), { callback: function (data) { var urlArr = data.url.split(/\,/); insert(e, data.url, 'image'); } }); return false; } }, { name: "cmdSelectAttachment", toggle: false, title: "Select file", icon: "fa fa-file", callback: function (e) { parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=*", __('Choose'), { callback: function (data) { insert(e, data.url, 'file'); } }); return false; } }] }] ], onShow: function (e) { //添加上传图片按钮和上传附件按钮 var imgBtn = $("button[data-handler='bootstrap-markdown-cmdUploadImage']", e.$editor); var fileBtn = $("button[data-handler='bootstrap-markdown-cmdUploadFile']", e.$editor); var btnParent = imgBtn.parent(); btnParent.addClass("md-relative"); var upImgBtn = $(''); upImgBtn.css(imgBtn.position()).appendTo(btnParent); var upFileBtn = $(''); upFileBtn.css(fileBtn.position()).appendTo(btnParent); upImgBtn.data("upload-success", function (data, ret) { insert(e, data.url, 'image'); }); upFileBtn.data("upload-success", function (data, ret) { insert(e, data.url, 'file'); }); Form.events.faupload(e.$editor); $(".uploadimage,.uploadfile", e.$editor).on("mouseenter", function () { ($(this).data("button") === 'image' ? imgBtn : fileBtn).addClass("active"); }).on("mouseleave", function () { ($(this).data("button") === 'image' ? imgBtn : fileBtn).removeClass("active"); }); //粘贴上传 $(e.$textarea).bind('paste', function (event) { var originalEvent; originalEvent = event.originalEvent; if (originalEvent.clipboardData && originalEvent.clipboardData.files.length > 0) { uploadFiles.call(e, originalEvent.clipboardData.files); return false; } }); //拖拽上传 $(e.$textarea).bind('drop', function (event) { var originalEvent; originalEvent = event.originalEvent; if (originalEvent.dataTransfer && originalEvent.dataTransfer.files.length > 0) { uploadFiles.call(e, originalEvent.dataTransfer.files); return false; } }); }, onChange: function (e) { var origin = $(e.$textarea).data("markdown-origin"); if (origin) { origin.val(marked(e.$textarea.val())); } } }, editor.data("markdown-options") || {})); })(editor) }); }); } } catch (e) { } }; }); require.config({ paths: { 'qrcode': '../addons/notice/js/qrcode', 'HackTimer': '../addons/notice/js/HackTimer.min', }, shim: { } }); function ajaxInit() { if (Config.modulename == 'admin') { if (!(Config.controllername == 'index' && Config.actionname == 'index' && Config.notice.admin_real == 1)) { return false; } } else if (Config.modulename == 'index'){ if (Config.notice.user_real != 1) { return false; } if (!indexUrlCheck()) { return false; } } else { return false; } console.log('ajax_init'); require(['HackTimer'], function (HackTimer) { var url = ''; if (Config.modulename == 'admin') { url = 'notice/admin/statistical'; } if (Config.modulename == 'index') { url = '/addons/notice/api/statistical'; } // 获取新消息并提示 function notice() { Fast.api.ajax({ url: url, loading: false }, function (data, res) { if (data.new) { Toastr.info(data.new.content); } if (Config.modulename == 'admin') { Backend.api.sidebar({ 'notice/admin': data.num, }); } setTimeout(function () { notice(); }, 5000); return false; }, function () { return false; }); }; notice(); }); }; function wsInit() { if (Config.modulename == 'admin') { if (!(Config.controllername == 'index' && Config.actionname == 'index' && Config.notice.admin_real == 2)) { return false; } } else if (Config.modulename == 'index'){ if (!indexUrlCheck()) { return false; } if (Config.notice.user_real != 2) { return false; } } else { return false; } console.log('ws_init'); let NhWs = { ws: null, timer: null, bindurl: '', url: '', connect: function () { var ws = new WebSocket(this.url); this.ws = ws; ws.onmessage = this.onmessage; ws.onclose = this.onclose; ws.onerror = this.onerror; ws.onopen = this.onopen; }, onmessage: function (e) { // json数据转换成js对象 var data = e.data; try { JSON.parse(data); data = JSON.parse(data) ? JSON.parse(data) : data; } catch { console.log('ws接收到非对象数据', data); return true; } console.log('ws接收到数据', data, e.data); var type = data.type || ''; var resdata = data.data ? data.data : {}; switch(type){ case 'init': $.ajax(NhWs.bindurl, { data: { client_id: data.client_id }, method: 'post' }) break; case "new_notice": if (Config.modulename == 'admin') { Backend.api.sidebar({ 'notice/admin': resdata.num, }); } Toastr.info(resdata.msg); // 发送ajax到后台告诉已经看过这条消息 Fast.api.ajax({ url: '/addons/notice/api/cache', data: { time: resdata.time, module: Config.modulename }, method: 'post' }, function () { return false; }); } }, onclose: function () { console.log('连接已断开,尝试自动连接'); setTimeout(function () { NhWs.connect(); }, 5000); }, onopen: function () { this.timer = setInterval(function () { NhWs.send({"type":"ping"}); }, 20000); }, onerror: function () { console.log('ws连接失败'); Toastr.error('ws连接失败'); }, // 发送数据 send: function (data) { if (typeof data == "object") { data = JSON.stringify(data); } this.ws.send(data); }, }; if (Config.modulename == 'admin') { NhWs.bindurl = Fast.api.fixurl('/addons/notice/ws/bindAdmin'); // ajax请求获取消息数量等 Fast.api.ajax({ url: 'notice/admin/statistical', loading: false, method: 'post', }, function (data, res) { if (data.new) { Toastr.info(data.new.content); } Backend.api.sidebar({ 'notice/admin': data.num, }); return false; }, function () { return false; }); } if (Config.modulename == 'index') { NhWs.bindurl = Fast.api.fixurl('/addons/notice/ws/bind'); // ajax请求最新获取消息数量等 Fast.api.ajax({ url: '/addons/notice/api/statistical', loading: false, method: 'post', }, function (data, res) { if (data.new) { Toastr.info(data.new.content); } return false; }, function () { return false; }); } NhWs.url = Config.notice.wsurl; require(['HackTimer'], function (HackTimer) { NhWs.connect(); }); }; function indexUrlCheck() { if (Config.modulename == 'index') { var url = Config.controllername+'/'+Config.actionname; if (Config.notice.user_real_url.indexOf('*') === -1) { if (Config.notice.user_real_url.indexOf(url) === -1) { return false; } } } return true; }; require([], function (undefined) { // ajax轮询 ajaxInit(); wsInit(); // 后台绑定按钮 if (Config.modulename == 'admin' && Config.controllername == 'general.profile' && Config.actionname == 'index') { $('[type="submit"]').before(''); } }); });