rageframe.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. $(document).ready(function () {
  2. if ($(this).width() < 769) {
  3. config.isMobile = true;
  4. }
  5. // 动态改变菜单
  6. autoChangeMenu(true);
  7. // 修改颜色
  8. autoFontColor();
  9. // 初始化表格
  10. initTable();
  11. // 判断默认显示
  12. var isDefaultShow = false;
  13. $('.rfLeftMenu').each(function () {
  14. if ($(this).hasClass('is_default_show')) {
  15. isDefaultShow = true;
  16. }
  17. });
  18. if (isDefaultShow === false) {
  19. var id = $('.rfTopMenu').eq(0).data('id');
  20. if (id) {
  21. $('.rfLeftMenu-' + id).removeClass('hide');
  22. $('.rfTopMenu').eq(0).addClass('rfTopMenuHover');
  23. }
  24. }
  25. });
  26. $(window).resize(function () {
  27. var leftAuto = true;
  28. if (config.isMobile == false) {
  29. leftAuto = false;
  30. }
  31. if ($(this).width() < 769) {
  32. config.isMobile = true;
  33. } else {
  34. config.isMobile = false;
  35. }
  36. if (config.isMobile == false && leftAuto == false) {
  37. autoChangeMenu();
  38. } else {
  39. autoChangeMenu(true);
  40. }
  41. // 初始化table
  42. // initTable();
  43. });
  44. function autoFontColor() {
  45. $("body").find("label").each(function (i, data) {
  46. if ($(data).find('input').length > 0) {
  47. $(data).attr('style', 'color:#636f7a');
  48. }
  49. })
  50. }
  51. function autoChangeMenu(leftAuto = false) {
  52. // 改变框架高度
  53. var mainContent = window.innerHeight - 99;
  54. if (config.tag != true || config.isMobile == true) {
  55. mainContent = mainContent + 40;
  56. }
  57. $(".J_mainContent").height(mainContent);
  58. if (config.isMobile == true) {
  59. // 显示左边菜单
  60. $('.rfLeftMenu').removeClass('hide');
  61. // 隐藏tag
  62. $(".content-tabs").addClass('hide');
  63. // 显示退出
  64. $("#logout").removeClass('hide');
  65. // 隐藏头部菜单栏
  66. $('.rfTopMenu').each(function (i, data) {
  67. var type = $(this).data('type');
  68. if (type) {
  69. $(this).addClass('hide');
  70. }
  71. });
  72. // 增加样式
  73. $(".J_mainContent").addClass('rfMainContent');
  74. // 底部隐藏
  75. $(".main-footer").addClass('hide');
  76. } else {
  77. if (leftAuto == true) {
  78. // 隐藏左边菜单
  79. $('.rfLeftMenu').addClass('hide');
  80. // 默认菜单显示
  81. $('.is_default_show').removeClass('hide');
  82. }
  83. // 头部菜单栏
  84. $('.rfTopMenu').removeClass('hide');
  85. // 显示标签
  86. $('.content-tabs').removeClass('hide');
  87. // 隐藏退出
  88. $("#logout").addClass('hide');
  89. // 移除样式
  90. $(".J_mainContent").removeClass('rfMainContent');
  91. // 底部显示
  92. $(".main-footer").removeClass('hide');
  93. }
  94. if (config.tag != true) {
  95. // 隐藏tag
  96. $(".content-tabs").addClass('hide');
  97. // 显示退出
  98. $("#logout").removeClass('hide');
  99. }
  100. // 判断顶部菜单显示状态
  101. if (config.isMobile == false) {
  102. var allNavWidth = $('.rf-navbar-nav').width();
  103. if (allNavWidth === undefined) {
  104. return false;
  105. }
  106. $('.rf-navbar-nav .rf-navbar-nav-left li').removeClass('hide');
  107. $('.hide-menu div').html('');
  108. var leftWidth = allNavWidth - $('.rf-navbar-nav .ml-auto').width() - 70;
  109. if (leftWidth < $('.rf-navbar-nav-left').width()) {
  110. var tmpWith = 0;
  111. // 移动菜单显示
  112. $('.rf-navbar-nav .rf-navbar-nav-left li').each(function (i, item) {
  113. tmpWith += parseInt($(item).width());
  114. if (tmpWith > leftWidth) {
  115. $(item).addClass('hide');
  116. $('.hide-menu').removeClass('hide');
  117. // 增加一次的菜单
  118. $('.hide-menu > div').append("<li class='rfTopMenu' data-type=" + $(item).data('type') + " data-id=" + $(item).data('id') + ">" + $(item).html() + "</li>")
  119. $('.hide-menu div li').find('a').css({"height": "35px", "line-height": "1.5"});
  120. }
  121. })
  122. } else {
  123. $('.hide-menu').addClass('hide');
  124. }
  125. } else {
  126. $('.hide-menu').addClass('hide');
  127. }
  128. }
  129. /* data-table */
  130. var $table = $('.rf-table');
  131. function buildTable($el, fixedNumber, fixedRightNumber) {
  132. if (fixedNumber <= 0) {
  133. fixedNumber = 0;
  134. }
  135. if (fixedRightNumber <= 0) {
  136. fixedRightNumber = 0;
  137. }
  138. $el.bootstrapTable('destroy').bootstrapTable({
  139. classes: 'table table-hover',
  140. fixedColumns: true,
  141. fixedNumber: fixedNumber,
  142. fixedRightNumber: fixedRightNumber,
  143. showFooter: true
  144. })
  145. }
  146. function initTable() {
  147. var fixedNumber = $($table).attr('fixedNumber');
  148. var fixedRightNumber = $($table).attr('fixedRightNumber');
  149. buildTable($table, fixedNumber, fixedRightNumber);
  150. if ($('.fixed-table-container .fixed-table-body table thead').length > 1) {
  151. $('.fixed-table-container .fixed-table-body table thead').each(function (index, row) {
  152. var length = $(row).find('td').length;
  153. console.log(index)
  154. switch (index) {
  155. // 内容
  156. case 0 :
  157. $(row).find('td').each(function (key, val) {
  158. if (key < fixedNumber || key >= (length - fixedRightNumber)) {
  159. // 去掉input
  160. $(val).find('input').attr('name', '');
  161. $(val).find('select').attr('name', '');
  162. $(val).html('');
  163. }
  164. });
  165. break;
  166. // 头部
  167. case 1 :
  168. $(row).find('td').each(function (key, val) {
  169. if (key >= fixedNumber) {
  170. // 去掉input
  171. $(val).find('input').attr('name', '');
  172. $(val).find('select').attr('name', '');
  173. $(val).html('');
  174. }
  175. });
  176. break;
  177. // 尾部
  178. case 2 :
  179. $(row).find('td').each(function (key, val) {
  180. if (key < (length - fixedRightNumber - 1)) {
  181. // 去掉input
  182. $(val).find('input').attr('name', '');
  183. $(val).find('select').attr('name', '');
  184. $(val).html('');
  185. }
  186. });
  187. break;
  188. }
  189. });
  190. }
  191. $('[data-toggle="tooltip"]').tooltip();
  192. }
  193. /* 导航标签切换 */
  194. $(document).on("click", ".rfTopMenu", function () {
  195. var id = $(this).data('id');
  196. $('.rfTopMenu').removeClass('open');
  197. if (parseInt(id) > 0) {
  198. $('.rfTopMenu').removeClass('rfTopMenuHover');
  199. $('.rfLeftMenu').addClass('hide');
  200. $('.rfLeftMenu-' + id).removeClass('hide');
  201. $(this).addClass('rfTopMenuHover');
  202. }
  203. // 无标签页面
  204. if (config.tag != true) {
  205. // 自动打开菜单二级
  206. $('.rfLeftMenu-' + id).each(function (index, item) {
  207. if (index === 0 && !$(item).hasClass('menu-open')) {
  208. $(item).find('a').eq(0).trigger('click');
  209. // 二级菜单打开
  210. var itemUlTwo = $(item).find('a').eq(0).next('ul');
  211. if (itemUlTwo.length > 0) {
  212. $(itemUlTwo).find('a').eq(0).trigger('click');
  213. }
  214. // 判断三级
  215. var itemThree = $(itemUlTwo).find('a').eq(0).next('ul');
  216. if (itemThree.length > 0) {
  217. $(itemThree).find('a').eq(0).trigger('click');
  218. }
  219. }
  220. });
  221. }
  222. });
  223. /* 打一个新窗口 */
  224. $(document).on("click", ".openUploadIframe", function (e) {
  225. var width = $(this).data('width');
  226. var boxId = $(this).data('boxId');
  227. var height = $(this).data('height');
  228. var offset = $(this).data('offset');
  229. var href = $(this).attr('href');
  230. if (width === undefined) {
  231. width = '92%';
  232. }
  233. if (height === undefined) {
  234. height = '85%';
  235. }
  236. if (offset === undefined) {
  237. offset = "7%";
  238. }
  239. openUploadIframe(width, height, href, offset);
  240. e.preventDefault();
  241. return false;
  242. });
  243. layer.config({
  244. extend: 'style.css', //加载您的扩展样式
  245. });
  246. // 启用状态 status 1:启用;0禁用;
  247. function rfStatus(obj) {
  248. let id = $(obj).attr('data-id');
  249. let status = 0;
  250. self = $(obj);
  251. if (self.hasClass("btn-success")) {
  252. status = 1;
  253. }
  254. if (!id) {
  255. id = $(obj).parent().parent().attr('id');
  256. }
  257. if (!id) {
  258. id = $(obj).parent().parent().attr('data-key');
  259. }
  260. $.ajax({
  261. type: "get",
  262. url: 'ajax-update',
  263. dataType: "json",
  264. data: {
  265. id: id,
  266. status: status
  267. },
  268. success: function (data) {
  269. if (parseInt(data.code) === 200) {
  270. if (self.hasClass("btn-success")) {
  271. self.removeClass("btn-success").addClass("btn-default");
  272. self.attr("data-toggle", 'tooltip');
  273. self.attr("data-original-title", '点击禁用');
  274. self.text('禁用');
  275. } else {
  276. self.removeClass("btn-default").addClass("btn-success");
  277. self.attr("data-toggle", 'tooltip');
  278. self.attr("data-original-title", '点击启用');
  279. self.text('启用');
  280. }
  281. } else {
  282. rfAffirm(data.message);
  283. }
  284. }
  285. });
  286. }
  287. // 排序
  288. function rfSort(obj) {
  289. let id = $(obj).attr('data-id');
  290. if (!id) {
  291. id = $(obj).parent().parent().attr('id');
  292. }
  293. if (!id) {
  294. id = $(obj).parent().parent().attr('data-key');
  295. }
  296. var sort = $(obj).val();
  297. if (isNaN(sort)) {
  298. rfAffirm('排序只能为数字');
  299. return false;
  300. } else {
  301. $.ajax({
  302. type: "get",
  303. url: 'ajax-update',
  304. dataType: "json",
  305. data: {
  306. id: id,
  307. sort: sort
  308. },
  309. success: function (data) {
  310. if (parseInt(data.code) !== 200) {
  311. rfAffirm(data.message);
  312. }
  313. }
  314. });
  315. }
  316. }
  317. // 打一个新窗口
  318. function openUploadIframe(width, height, content, offset) {
  319. layer.open({
  320. type: 2,
  321. title: '素材选择',
  322. shade: 0.3,
  323. offset: offset,
  324. shadeClose: true,
  325. btn: ['确认', '关闭'],
  326. yes: function (index, layero) {
  327. let allData = [];
  328. var body = layer.getChildFrame('body', index);
  329. $(body).find('#rfAttachmentList .active').each(function(i, data){
  330. var tmpData = [];
  331. tmpData['id'] = $(data).data('id');
  332. tmpData['url'] = $(data).data('url');
  333. tmpData['name'] = $(data).data('name');
  334. tmpData['upload_type'] = $(data).data('upload_type');
  335. allData.push(tmpData)
  336. console.log(allData);
  337. });
  338. var boxId = $(body).find('.box-id').data('id');
  339. $(document).trigger('select-file-' + boxId, [boxId, allData]);
  340. layer.closeAll();
  341. },
  342. btn2: function () {
  343. layer.closeAll();
  344. },
  345. area: [width, height],
  346. content: content
  347. });
  348. return false;
  349. }
  350. /* 提示报错弹出框配置 */
  351. toastr.options = {
  352. "closeButton": true,
  353. "debug": false,
  354. "progressBar": true,
  355. "positionClass": "toast-top-right",
  356. "showDuration": "300",
  357. "hideDuration": "1000",
  358. "timeOut": "5000",
  359. "extendedTimeOut": "1000",
  360. "showEasing": "swing",
  361. "hideEasing": "linear",
  362. "showMethod": "fadeIn",
  363. "hideMethod": "fadeOut"
  364. };
  365. /* 打一个新窗口 */
  366. $(document).on("click", ".openIframe", function (e) {
  367. var title = $(this).data('title');
  368. var width = $(this).data('width');
  369. var height = $(this).data('height');
  370. var offset = $(this).data('offset');
  371. var href = $(this).attr('href');
  372. if (title == undefined) {
  373. title = '基本信息';
  374. }
  375. if (width == undefined) {
  376. width = '80%';
  377. }
  378. if (height == undefined) {
  379. height = '80%';
  380. }
  381. if (offset == undefined) {
  382. offset = "10%";
  383. }
  384. openIframe(title, width, height, href, offset);
  385. e.preventDefault();
  386. return false;
  387. });
  388. layer.config({
  389. extend: 'style.css', //加载您的扩展样式
  390. });
  391. // 打一个新窗口
  392. function openIframe(title, width, height, content, offset) {
  393. layer.open({
  394. type: 2,
  395. title: title,
  396. shade: 0.3,
  397. offset: offset,
  398. shadeClose: true,
  399. btn: ['保存', '关闭'],
  400. yes: function (index, layero) {
  401. var body = layer.getChildFrame('body', index);
  402. var form = body.find('#w0');
  403. var postUrl = form.attr('action');
  404. $.ajax({
  405. type: "post",
  406. url: postUrl,
  407. dataType: "json",
  408. data: form.serialize(),
  409. success: function (data) {
  410. if (parseInt(data.code) !== 200) {
  411. rfMsg(data.message);
  412. } else {
  413. layer.close(index);
  414. location.reload();
  415. }
  416. }
  417. });
  418. },
  419. btn2: function () {
  420. layer.closeAll();
  421. },
  422. area: [width, height],
  423. content: content
  424. });
  425. return false;
  426. }
  427. /* 打一个新窗口 */
  428. $(document).on("click", ".openIframeView", function (e) {
  429. var title = $(this).data('title');
  430. var width = $(this).data('width');
  431. var height = $(this).data('height');
  432. var offset = $(this).data('offset');
  433. var href = $(this).attr('href');
  434. var btnHide = $(this).data('btn_hide');
  435. if (title == undefined) {
  436. title = '基本信息';
  437. }
  438. if (width == undefined) {
  439. width = '80%';
  440. }
  441. if (height == undefined) {
  442. height = '80%';
  443. }
  444. if (offset == undefined) {
  445. offset = "10%";
  446. }
  447. openIframeView(title, width, height, href, offset, btnHide);
  448. e.preventDefault();
  449. return false;
  450. });
  451. // 打一个新窗口
  452. function openIframeView(title, width, height, content, offset, btnHide) {
  453. var btn = ['关闭'];
  454. if (btnHide) {
  455. btn = '';
  456. }
  457. console.log(btnHide)
  458. layer.open({
  459. type: 2,
  460. title: title,
  461. shade: 0.3,
  462. offset: offset,
  463. shadeClose: true,
  464. btn: btn,
  465. yes: function (index, layero) {
  466. layer.closeAll();
  467. },
  468. area: [width, height],
  469. content: content
  470. });
  471. return false;
  472. }
  473. /* 在顶部导航栏打开tab */
  474. $(document).on("click", ".openContab", function (e) {
  475. parent.openConTab($(this));
  476. return false;
  477. });
  478. // 关闭当前的标签
  479. $(document).on("click", ".closeCurrentConTab", function (e) {
  480. parent.closeCurrentConTab();
  481. return false;
  482. });
  483. // 另外一种风格提示
  484. function rfMsg(title) {
  485. layer.msg(title);
  486. }
  487. // 错误提示
  488. function rfError(title, text) {
  489. let dialogText = rfText(text);
  490. swal({
  491. title: title,
  492. text: dialogText,
  493. icon: "error",
  494. button: "确定",
  495. });
  496. }
  497. // 警告提示
  498. function rfWarning(title, text) {
  499. let dialogText = rfText(text);
  500. swal({
  501. title: title,
  502. text: dialogText,
  503. icon: "warning",
  504. button: "确定",
  505. });
  506. }
  507. // 普通提示
  508. function rfAffirm(title, text) {
  509. let dialogText = rfText(text);
  510. swal({
  511. title: title,
  512. text: dialogText,
  513. button: "确定",
  514. });
  515. }
  516. // 信息提示
  517. function rfInfo(title, text) {
  518. let dialogText = rfText(text);
  519. swal({
  520. title: title,
  521. text: dialogText,
  522. icon: "info",
  523. button: "确定",
  524. });
  525. }
  526. // 成功提示
  527. function rfSuccess(title, text) {
  528. let dialogText = rfText(text);
  529. swal({
  530. title: title,
  531. text: dialogText,
  532. icon: "success",
  533. button: "确定",
  534. });
  535. }
  536. // 删除提示
  537. function rfDelete(obj, text) {
  538. title = "确定要删除这条记录吗?";
  539. if (!text) {
  540. text = '删除有可能导致数据不可恢复,请谨慎操作。';
  541. }
  542. rfTwiceAffirm(obj, title, text, "")
  543. }
  544. // 二次确认提示
  545. function rfTwiceAffirm(obj, title, text, icon = '') {
  546. var dialogText = rfText(text);
  547. swal(title, {
  548. buttons: {
  549. cancel: "取消",
  550. defeat: '确定',
  551. },
  552. title: title,
  553. text: dialogText,
  554. icon: icon,
  555. }).then(function (value) {
  556. switch (value) {
  557. case "defeat":
  558. window.location = $(obj).attr('href');
  559. break;
  560. default:
  561. }
  562. });
  563. }
  564. // 二次确认返回提示
  565. function rfTwiceAffirmBack(obj, title, text) {
  566. var dialogText = rfText(text);
  567. swal(title, {
  568. buttons: {
  569. cancel: "取消",
  570. defeat: '确定'
  571. },
  572. title: title,
  573. text: dialogText,
  574. // icon: "warning",
  575. }).then(function (value) {
  576. switch (value) {
  577. case "defeat":
  578. history.go(-1);
  579. break;
  580. default:
  581. }
  582. });
  583. }
  584. function rfText(text) {
  585. if (text) {
  586. return text;
  587. }
  588. return '小手一抖就打开了一个框';
  589. }
粤ICP备19079148号