From b33266e162f7c54fe40661edc95d5a16a72cb5cc Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Fri, 12 Oct 2018 14:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=85=AC=E5=85=B1=E8=84=9A=E6=9C=AC=E5=A6=82?= =?UTF-8?q?tooltop/popover/datetimepicker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/wwwroot/js/common-scripts.js | 5 - Bootstrap.Admin/wwwroot/js/exceptions.js | 14 --- Bootstrap.Admin/wwwroot/js/logs.js | 14 --- Bootstrap.Admin/wwwroot/js/longbow.common.js | 41 +++++++ Bootstrap.Client/wwwroot/js/longbow.common.js | 104 ++++-------------- 5 files changed, 65 insertions(+), 113 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index f291af7d..3c5c1134 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -210,11 +210,6 @@ $(function () { $('body').toggleClass('sidebar-open'); }); - $('[data-toggle="dropdown"].dropdown-select').dropdown('select'); - - // tooltip - $('[data-toggle="tooltip"]').tooltip(); - // load widget data $('.header .nav').reloadWidget().notifi({ url: 'NotiHub', diff --git a/Bootstrap.Admin/wwwroot/js/exceptions.js b/Bootstrap.Admin/wwwroot/js/exceptions.js index 58489765..aaaaf6c6 100644 --- a/Bootstrap.Admin/wwwroot/js/exceptions.js +++ b/Bootstrap.Admin/wwwroot/js/exceptions.js @@ -21,20 +21,6 @@ ] }); - $('.date').datetimepicker({ - language: 'zh-CN', - weekStart: 1, - todayBtn: 1, - autoclose: 1, - todayHighlight: 1, - startView: 2, - minView: 2, - forceParse: 0, - format: 'yyyy-mm-dd', - pickerPosition: 'bottom-left', - fontAwesome: true - }); - $('#btn_view').on('click', function (row) { $.bc({ url: Exceptions.url, method: "post", diff --git a/Bootstrap.Admin/wwwroot/js/logs.js b/Bootstrap.Admin/wwwroot/js/logs.js index 87d63907..f463372e 100644 --- a/Bootstrap.Admin/wwwroot/js/logs.js +++ b/Bootstrap.Admin/wwwroot/js/logs.js @@ -15,18 +15,4 @@ { title: "备注", field: "ClientAgent", sortable: false } ] }); - - $('.date').datetimepicker({ - language: 'zh-CN', - weekStart: 1, - todayBtn: 1, - autoclose: 1, - todayHighlight: 1, - startView: 2, - minView: 2, - forceParse: 0, - format: 'yyyy-mm-dd', - pickerPosition: 'bottom-left', - fontAwesome: true - }); }); \ No newline at end of file diff --git a/Bootstrap.Admin/wwwroot/js/longbow.common.js b/Bootstrap.Admin/wwwroot/js/longbow.common.js index a533c6a8..7d8cf621 100644 --- a/Bootstrap.Admin/wwwroot/js/longbow.common.js +++ b/Bootstrap.Admin/wwwroot/js/longbow.common.js @@ -286,6 +286,39 @@ } return this; }, + lgbDatePicker: function (options) { + if (!$.isFunction(this.datetimepicker)) return this; + var option = $.extend({ + language: 'zh-CN', + weekStart: 1, + todayBtn: 1, + autoclose: 1, + todayHighlight: 1, + startView: 2, + minView: 2, + forceParse: 0, + format: 'yyyy-mm-dd', + pickerPosition: 'bottom-left', + fontAwesome: true + }, options); + this.datetimepicker(option); + return this; + }, + lgbInfo: function (option) { + this.each(function () { + var $element = $(this); + $element.append($.format('')); + }); + var container = $(this).parent().attr('data-container') || '#dialogNew'; + this.find('[data-toggle="popover"]').popover($.extend({ + title: function () { + return $(this).parent().text(); + }, content: function () { + return $(this).parent().attr('data-content'); + }, trigger: 'focus', html: true, container: container + }, option)); + return this; + }, notifi: function (options) { var op = $.extend({ url: '', method: 'rev', callback: false }, options); var connection = new signalR.HubConnectionBuilder().withUrl($.formatUrl(op.url)).build(); @@ -319,6 +352,14 @@ } }); + $(function () { + $('[data-toggle="dropdown"].dropdown-select').dropdown('select'); + $('[data-toggle="tooltip"]').tooltip(); + $('[data-toggle="popover"]').popover(); + $('[data-toggle="lgbinfo"]').lgbInfo(); + $('.date').lgbDatePicker(); + }); + // Roles Role = { url: 'api/Roles', diff --git a/Bootstrap.Client/wwwroot/js/longbow.common.js b/Bootstrap.Client/wwwroot/js/longbow.common.js index 82c2f8ff..a14d1064 100644 --- a/Bootstrap.Client/wwwroot/js/longbow.common.js +++ b/Bootstrap.Client/wwwroot/js/longbow.common.js @@ -352,6 +352,19 @@ }); return this; }, + getTextByValue: function (key, value) { + // 通过Key指定一个下拉框,通过value获得下拉框value值的text属性 + if (this.length !== 1) throw 'element must be one'; + var ele = this.get(0); + if (!ele[key]) { + ele[key] = {}; + var that = ele; + $.each($('#' + key).children(), function (index, element) { + that[key][$(element).attr('value')] = $(element).text(); + }); + } + return ele[key][value]; + }, lgbInfo: function (option) { this.each(function () { var $element = $(this); @@ -367,87 +380,18 @@ }, option)); return this; }, - getTextByValue: function (key, value) { - // 通过Key指定一个下拉框,通过value获得下拉框value值的text属性 - if (this.length !== 1) throw 'element must be one'; - var ele = this.get(0); - if (!ele[key]) { - ele[key] = {}; - var that = ele; - $.each($('#' + key).children(), function (index, element) { - that[key][$(element).attr('value')] = $(element).text(); - }); - } - return ele[key][value]; - }, - msgHandler: function (options) { - var settings = { - url: 'api/WS', - interval: 10000, - sendMessage: '', - timerHandler: null, - onopen: function (e) { }, - onmessage: function (e) { }, - onclose: function (e) { }, - errorHandler: function (e) { if (toastr && $.isFunction(toastr.error)) toastr.error("连接服务器失败!", "系统错误"); }, - loop: function () { - var that = this; - var uri = window.location.protocol + "//" + window.location.host + $.formatUrl(settings.url); - $.bc({ - url: uri, - id: this.sendMessage, - method: "post", - callback: function (result) { - if (!result) { - that.errorHandler.call(that.target); - return; - } - that.onmessage.call(that.target, { data: JSON.stringify(result) }); - } - }); - - if (this.timerHandler !== null) clearTimeout(this.timerHandler); - this.timerHandler = setTimeout(function () { that.loop(); }, that.interval); + notifi: function (options) { + var op = $.extend({ url: '', method: 'rev', callback: false }, options); + var connection = new signalR.HubConnectionBuilder().withUrl($.formatUrl(op.url)).build(); + var that = this; + connection.on(op.method, function () { + if ($.isFunction(op.callback)) { + op.callback.apply(that, arguments); } - }; - $.extend(settings, options, { target: this }); - settings.loop(); - return this; - }, - socketHandler: function (options) { - // WebSocket消息处理方法 - var settings = { - url: 'WS', - interval: 30000, - sendMessage: 'keepalive', - timerHandler: null, - onopen: function (e) { }, - onerror: function (e) { }, - errorHandler: function (e) { if (window.toastr && $.isFunction(window.toastr.error)) toastr.error("连接服务器失败!", "系统错误"); }, - onmessage: function (e) { }, - onclose: function (e) { }, - loop: function (socket) { - var that = this; - if (socket.readyState === 1) { - socket.send(this.sendMessage); - if (this.timerHandler !== null) clearTimeout(this.timerHandler); - this.timerHandler = setTimeout(function () { that.loop(socket); }, that.interval); - } - else { - this.errorHandler(); - } - } - }; - $.extend(settings, options, { target: this }); - var uri = "ws://" + window.location.host + $.formatUrl(settings.url); - var socket = new WebSocket(uri); - socket.onopen = function (e) { settings.onopen.call(settings.target, e); settings.loop(socket); }; - socket.onerror = function (e) { - settings.onerror.call(settings.target, e); - settings.target.msgHandler(options); - }; - socket.onmessage = function (e) { settings.onmessage.call(settings.target, e); }; - socket.onclose = function (e) { settings.onclose.call(settings.target, e); }; + }); + connection.start().catch(function (err) { + return console.error(err.toString()); + }); return this; } });