Keine Beschreibung

framework-ui.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. $(function () {
  2. //document.body.className = localStorage.getItem('config-skin');
  3. $("[data-toggle='tooltip']").tooltip();
  4. })
  5. $.reload = function () {
  6. location.reload();
  7. return false;
  8. }
  9. $.loading = function (bool, text) {
  10. var $loadingpage = top.$("#loadingPage");
  11. var $loadingtext = $loadingpage.find('.loading-content');
  12. if (bool) {
  13. $loadingpage.show();
  14. } else {
  15. if ($loadingtext.attr('istableloading') == undefined) {
  16. $loadingpage.hide();
  17. }
  18. }
  19. if (!!text) {
  20. $loadingtext.html(text);
  21. } else {
  22. $loadingtext.html("数据加载中,请稍后…");
  23. }
  24. $loadingtext.css("left", (top.$('body').width() - $loadingtext.width()) / 2 - 50);
  25. $loadingtext.css("top", (top.$('body').height() - $loadingtext.height()) / 2);
  26. }
  27. $.request = function (name) {
  28. var search = location.search.slice(1);
  29. var arr = search.split("&");
  30. for (var i = 0; i < arr.length; i++) {
  31. var ar = arr[i].split("=");
  32. if (ar[0] == name) {
  33. if (unescape(ar[1]) == 'undefined') {
  34. return "";
  35. } else {
  36. return unescape(ar[1]);
  37. }
  38. }
  39. }
  40. return "";
  41. }
  42. $.currentWindow = function () {
  43. var iframeId = top.$(".NFine_iframe:visible").attr("id");
  44. return top.frames[iframeId];
  45. }
  46. $.browser = function () {
  47. var userAgent = navigator.userAgent;
  48. var isOpera = userAgent.indexOf("Opera") > -1;
  49. if (isOpera) {
  50. return "Opera"
  51. };
  52. if (userAgent.indexOf("Firefox") > -1) {
  53. return "FF";
  54. }
  55. if (userAgent.indexOf("Chrome") > -1) {
  56. if (window.navigator.webkitPersistentStorage.toString().indexOf('DeprecatedStorageQuota') > -1) {
  57. return "Chrome";
  58. } else {
  59. return "360";
  60. }
  61. }
  62. if (userAgent.indexOf("Safari") > -1) {
  63. return "Safari";
  64. }
  65. if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
  66. return "IE";
  67. };
  68. }
  69. $.download = function (url, data, method) {
  70. if (url && data) {
  71. data = typeof data == 'string' ? data : jQuery.param(data);
  72. var inputs = '';
  73. $.each(data.split('&'), function () {
  74. var pair = this.split('=');
  75. inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
  76. });
  77. $('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>').appendTo('body').submit().remove();
  78. };
  79. };
  80. $.modalOpen = function (options) {
  81. var defaults = {
  82. id: null,
  83. title: '系统窗口',
  84. width: "100px",
  85. height: "100px",
  86. url: '',
  87. shade: 0.3,
  88. btn: ['确认', '关闭'],
  89. btnclass: ['btn btn-primary', 'btn btn-danger'],
  90. callBack: null
  91. };
  92. var options = $.extend(defaults, options);
  93. var _width = top.$(window).width() > parseInt(options.width.replace('px', '')) ? options.width : top.$(window).width() + 'px';
  94. var _height = top.$(window).height() > parseInt(options.height.replace('px', '')) ? options.height : top.$(window).height() + 'px';
  95. top.layer.open({
  96. id: options.id,
  97. type: 2,
  98. shade: options.shade,
  99. title: options.title,
  100. fix: false,
  101. area: [_width, _height],
  102. content: options.url,
  103. btn: options.btn,
  104. btnclass: options.btnclass,
  105. yes: function () {
  106. options.callBack(options.id)
  107. }, cancel: function () {
  108. return true;
  109. }
  110. });
  111. }
  112. $.modalConfirm = function (content, callBack) {
  113. top.layer.confirm(content, {
  114. icon: "fa-exclamation-circle",
  115. title: "系统提示",
  116. btn: ['确认', '取消'],
  117. btnclass: ['btn btn-primary', 'btn btn-danger'],
  118. }, function () {
  119. callBack(true);
  120. }, function () {
  121. callBack(false)
  122. });
  123. }
  124. $.modalAlert = function (content, type) {
  125. var icon = "";
  126. if (type == 'success') {
  127. icon = "fa-check-circle";
  128. }
  129. if (type == 'error') {
  130. icon = "fa-times-circle";
  131. }
  132. if (type == 'warning') {
  133. icon = "fa-exclamation-circle";
  134. }
  135. top.layer.alert(content, {
  136. icon: icon,
  137. title: "系统提示",
  138. btn: ['确认'],
  139. btnclass: ['btn btn-primary'],
  140. });
  141. }
  142. $.modalMsg = function (content, type) {
  143. if (type != undefined) {
  144. var icon = "";
  145. if (type == 'success') {
  146. icon = "fa-check-circle";
  147. }
  148. if (type == 'error') {
  149. icon = "fa-times-circle";
  150. }
  151. if (type == 'warning') {
  152. icon = "fa-exclamation-circle";
  153. }
  154. top.layer.msg(content, { icon: icon, time: 4000, shift: 5 });
  155. top.$(".layui-layer-msg").find('i.' + icon).parents('.layui-layer-msg').addClass('layui-layer-msg-' + type);
  156. } else {
  157. top.layer.msg(content);
  158. }
  159. }
  160. $.modalClose = function () {
  161. var index = top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  162. var $IsdialogClose = top.$("#layui-layer" + index).find('.layui-layer-btn').find("#IsdialogClose");
  163. var IsClose = $IsdialogClose.is(":checked");
  164. if ($IsdialogClose.length == 0) {
  165. IsClose = true;
  166. }
  167. if (IsClose) {
  168. top.layer.close(index);
  169. } else {
  170. location.reload();
  171. }
  172. }
  173. $.submitForm = function (options) {
  174. var defaults = {
  175. url: "",
  176. param: [],
  177. loading: "正在提交数据...",
  178. success: null,
  179. close: true
  180. };
  181. var options = $.extend(defaults, options);
  182. $.loading(true, options.loading);
  183. window.setTimeout(function () {
  184. if ($('[name=__RequestVerificationToken]').length > 0) {
  185. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  186. }
  187. $.ajax({
  188. url: options.url,
  189. data: options.param,
  190. type: "post",
  191. dataType: "json",
  192. success: function (data) {
  193. if (data.state == "success") {
  194. options.success(data);
  195. $.modalMsg(data.message, data.state);
  196. if (options.close == true) {
  197. $.modalClose();
  198. }
  199. } else {
  200. $.modalAlert(data.message, data.state);
  201. }
  202. },
  203. error: function (XMLHttpRequest, textStatus, errorThrown) {
  204. $.loading(false);
  205. $.modalMsg(errorThrown, "error");
  206. },
  207. beforeSend: function () {
  208. $.loading(true, options.loading);
  209. },
  210. complete: function () {
  211. $.loading(false);
  212. }
  213. });
  214. }, 500);
  215. }
  216. $.deleteForm = function (options) {
  217. var defaults = {
  218. prompt: "注:您确定要删除该项数据吗?",
  219. url: "",
  220. param: [],
  221. loading: "正在删除数据...",
  222. success: null,
  223. close: true
  224. };
  225. var options = $.extend(defaults, options);
  226. if ($('[name=__RequestVerificationToken]').length > 0) {
  227. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  228. }
  229. $.modalConfirm(options.prompt, function (r) {
  230. if (r) {
  231. $.loading(true, options.loading);
  232. window.setTimeout(function () {
  233. $.ajax({
  234. url: options.url,
  235. data: options.param,
  236. type: "post",
  237. dataType: "json",
  238. success: function (data) {
  239. if (data.state == "success") {
  240. options.success(data);
  241. $.modalMsg(data.message, data.state);
  242. } else {
  243. $.modalAlert(data.message, data.state);
  244. }
  245. },
  246. error: function (XMLHttpRequest, textStatus, errorThrown) {
  247. $.loading(false);
  248. $.modalMsg(errorThrown, "error");
  249. },
  250. beforeSend: function () {
  251. $.loading(true, options.loading);
  252. },
  253. complete: function () {
  254. $.loading(false);
  255. }
  256. });
  257. }, 500);
  258. }
  259. });
  260. }
  261. $.jsonWhere = function (data, action) {
  262. if (action == null) return;
  263. var reval = new Array();
  264. $(data).each(function (i, v) {
  265. if (action(v)) {
  266. reval.push(v);
  267. }
  268. })
  269. return reval;
  270. }
  271. $.fn.jqGridRowValue = function () {
  272. var $grid = $(this);
  273. var selectedRowIds = $grid.jqGrid("getGridParam", "selarrrow");
  274. if (selectedRowIds != "") {
  275. var json = [];
  276. var len = selectedRowIds.length;
  277. for (var i = 0; i < len ; i++) {
  278. var rowData = $grid.jqGrid('getRowData', selectedRowIds[i]);
  279. json.push(rowData);
  280. }
  281. return json;
  282. } else {
  283. return $grid.jqGrid('getRowData', $grid.jqGrid('getGridParam', 'selrow'));
  284. }
  285. }
  286. $.fn.formValid = function () {
  287. return $(this).valid({
  288. errorPlacement: function (error, element) {
  289. element.parents('.formValue').addClass('has-error');
  290. element.parents('.has-error').find('i.error').remove();
  291. element.parents('.has-error').append('<i class="form-control-feedback fa fa-exclamation-circle error" data-placement="left" data-toggle="tooltip" title="' + error + '"></i>');
  292. $("[data-toggle='tooltip']").tooltip();
  293. if (element.parents('.input-group').hasClass('input-group')) {
  294. element.parents('.has-error').find('i.error').css('right', '33px')
  295. }
  296. },
  297. success: function (element) {
  298. element.parents('.has-error').find('i.error').remove();
  299. element.parent().removeClass('has-error');
  300. }
  301. });
  302. }
  303. $.fn.formSerialize = function (formdate) {
  304. var element = $(this);
  305. if (!!formdate) {
  306. for (var key in formdate) {
  307. var $id = element.find('#' + key);
  308. var value = $.trim(formdate[key]).replace(/&nbsp;/g, '');
  309. var type = $id.attr('type');
  310. if ($id.hasClass("select2-hidden-accessible")) {
  311. type = "select";
  312. }
  313. switch (type) {
  314. case "checkbox":
  315. if (value == "true") {
  316. $id.attr("checked", 'checked');
  317. } else {
  318. $id.removeAttr("checked");
  319. }
  320. break;
  321. case "select":
  322. $id.val(value).trigger("change");
  323. break;
  324. default:
  325. $id.val(value);
  326. break;
  327. }
  328. };
  329. return false;
  330. }
  331. var postdata = {};
  332. element.find('input,select,textarea').each(function (r) {
  333. var $this = $(this);
  334. var id = $this.attr('id');
  335. var type = $this.attr('type');
  336. switch (type) {
  337. case "checkbox":
  338. postdata[id] = $this.is(":checked");
  339. break;
  340. default:
  341. var value = $this.val() == "" ? "&nbsp;" : $this.val();
  342. if (!$.request("keyValue")) {
  343. value = value.replace(/&nbsp;/g, '');
  344. }
  345. postdata[id] = value;
  346. break;
  347. }
  348. });
  349. if ($('[name=__RequestVerificationToken]').length > 0) {
  350. postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  351. }
  352. return postdata;
  353. };
  354. $.fn.bindSelect = function (options) {
  355. var defaults = {
  356. id: "id",
  357. text: "text",
  358. search: false,
  359. url: "",
  360. param: [],
  361. change: null
  362. };
  363. var options = $.extend(defaults, options);
  364. var $element = $(this);
  365. if (options.url != "") {
  366. $.ajax({
  367. url: options.url,
  368. data: options.param,
  369. dataType: "json",
  370. //async: false,
  371. success: function (data) {
  372. $.each(data, function (i) {
  373. $element.append($("<option></option>").val(data[i][options.id]).html(data[i][options.text]));
  374. });
  375. $element.select2({
  376. minimumResultsForSearch: options.search == true ? 0 : -1
  377. });
  378. $element.on("change", function (e) {
  379. if (options.change != null) {
  380. options.change(data[$(this).find("option:selected").index()]);
  381. }
  382. $("#select2-" + $element.attr('id') + "-container").html($(this).find("option:selected").text().replace(/  /g, ''));
  383. });
  384. }
  385. });
  386. } else {
  387. $element.select2({
  388. minimumResultsForSearch: -1
  389. });
  390. }
  391. }
  392. $.fn.authorizeButton = function () {
  393. var moduleId = top.$(".J_iframe:visible").attr("id") && top.$(".J_iframe:visible").attr("id").substr(5);
  394. var dataJson = top.clients.authorizeButton[moduleId];
  395. var $element = $(this);
  396. $element.find('[authorize=yes]').attr('authorize', 'no');
  397. console.log("authorizeButton===="+moduleId);
  398. console.log(dataJson);
  399. if (dataJson != undefined) {
  400. $.each(dataJson, function (i) {
  401. $element.find("#" + dataJson[i].encode).attr('authorize', 'yes');
  402. });
  403. }
  404. $element.find("[authorize=no]").remove();
  405. }
  406. $.fn.authorizeOperateButton = function () {
  407. var moduleId = top.$(".J_iframe:visible").attr("id") && top.$(".J_iframe:visible").attr("id").substr(5);
  408. var dataJson = top.clients.authorizeButton[moduleId];
  409. console.log("authorizeOperateButton===="+moduleId);
  410. console.log(dataJson);
  411. var $element = $(this);
  412. $element.find('[authorize=yes]').attr('authorize', 'no');
  413. if (dataJson != undefined) {
  414. $.each(dataJson, function (i) {
  415. $element.find("[id*='" + dataJson[i].encode + "']").attr('authorize', 'yes');
  416. });
  417. }
  418. if(dataJson && dataJson.length == 0){
  419. $element.find("[authorize=no]").parents('.task_tools').html('-');
  420. $element.find("[authorize=no]").parents('ul').html('-');
  421. }
  422. //行内编辑的情况去掉编辑(注意类名为 editValue)
  423. if($element.find('a[authorize=no]').hasClass('editValue')){
  424. $element.find('a[authorize=no]').removeClass('editValue');
  425. $element.find('a[authorize=no]').attr('title', '');
  426. }else{
  427. $element.find('a[authorize=no]').parents('li').remove();
  428. $element.find('a[authorize=no]').remove();
  429. }
  430. }
  431. $.fn.dataGrid = function (options) {
  432. var defaults = {
  433. datatype: "json",
  434. autowidth: true,
  435. rownumbers: true,
  436. shrinkToFit: false,
  437. gridview: true
  438. };
  439. var options = $.extend(defaults, options);
  440. var $element = $(this);
  441. options["onSelectRow"] = function (rowid) {
  442. var length = $(this).jqGrid("getGridParam", "selrow").length;
  443. var $operate = $(".operate");
  444. if (length > 0) {
  445. $operate.animate({ "left": 0 }, 200);
  446. } else {
  447. $operate.animate({ "left": '-100.1%' }, 200);
  448. }
  449. $operate.find('.close').click(function () {
  450. $operate.animate({ "left": '-100.1%' }, 200);
  451. })
  452. };
  453. $element.jqGrid(options);
  454. };