123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- define([], function () {
- require(['../addons/bootstrapcontextmenu/js/bootstrap-contextmenu'], function (undefined) {
- if (Config.controllername == 'index' && Config.actionname == 'index') {
- $("body").append(
- '<div id="context-menu">' +
- '<ul class="dropdown-menu" role="menu">' +
- '<li><a tabindex="-1" data-operate="refresh"><i class="fa fa-refresh fa-fw"></i>刷新</a></li>' +
- '<li><a tabindex="-1" data-operate="refreshTable"><i class="fa fa-table fa-fw"></i>刷新表格</a></li>' +
- '<li><a tabindex="-1" data-operate="close"><i class="fa fa-close fa-fw"></i>关闭</a></li>' +
- '<li><a tabindex="-1" data-operate="closeOther"><i class="fa fa-window-close-o fa-fw"></i>关闭其他</a></li>' +
- '<li class="divider"></li>' +
- '<li><a tabindex="-1" data-operate="closeAll"><i class="fa fa-power-off fa-fw"></i>关闭全部</a></li>' +
- '</ul>' +
- '</div>');
- $(".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 = '<div id="editpage" style="position: fixed;right: 0;top: 20%;z-index: 999;flex-flow: column;right: 5px;">' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="c" class="btn btn-primary" title="控制器">C</a>' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="m" class="btn btn-info" title="模型">M</a>' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="v" class="btn btn-success" title="视图">V</a>' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="j" class="btn btn-danger" title="JS">J</a>' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="l" class="btn btn-warning" title="Lang">L</a>' +
- '<a style="display: flex;margin-bottom: 2px;" href="javascript:;" data-type="command" class="btn btn-primary" title="命令行"><</a>' +
- '</div>';
- $("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 = $('<button type="button" class="uploadimage faupload" data-button="image" title="点击上传图片" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="true">点击上传图片</button>');
- upImgBtn.css(imgBtn.position()).appendTo(btnParent);
- var upFileBtn = $('<button type="button" class="uploadfile faupload" data-button="file" title="点击上传附件" data-multiple="true">点击上传附件</button>');
- 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('<button style="margin-right: 5px;" type="button" class="btn btn-primary btn-dialog" data-url="notice/admin_mptemplate/bind">模版消息(公众号)</button>');
- }
- });
- });
|