Feng.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. var Feng = {
  2. ctxPath: "",
  3. addCtx: function (ctx) {
  4. if (this.ctxPath == "") {
  5. this.ctxPath = ctx;
  6. }
  7. },
  8. confirm: function (tip, ensure) {//询问框
  9. parent.layer.confirm(tip, {
  10. btn: ['确定', '取消']
  11. }, function (index,layero) {
  12. var btn = layero.find(".layui-layer-btn0");
  13. btn.css("pointer-events","none")
  14. ensure();
  15. parent.layer.close(index);
  16. }, function (index) {
  17. parent.layer.close(index);
  18. });
  19. },
  20. log: function (info) {
  21. console.log(info);
  22. },
  23. alert: function (info, iconIndex) {
  24. parent.layer.msg(info, {
  25. icon: iconIndex
  26. });
  27. },
  28. info: function (info) {
  29. Feng.alert(info, 0);
  30. },
  31. success: function (info) {
  32. Feng.alert(info, 1);
  33. },
  34. error: function (info) {
  35. Feng.alert(info, 2);
  36. },
  37. infoDetail: function (title, info) {
  38. var display = "";
  39. if (typeof info == "string") {
  40. display = info;
  41. } else {
  42. if (info instanceof Array) {
  43. for (var x in info) {
  44. display = display + info[x] + "<br/>";
  45. }
  46. } else {
  47. display = info;
  48. }
  49. }
  50. parent.layer.open({
  51. title: title,
  52. type: 1,
  53. skin: 'layui-layer-rim', //加上边框
  54. area: ['950px', '600px'], //宽高
  55. content: '<div style="padding: 20px;">' + display + '</div>'
  56. });
  57. },
  58. writeObj: function (obj) {
  59. var description = "";
  60. for (var i in obj) {
  61. var property = obj[i];
  62. description += i + " = " + property + ",";
  63. }
  64. layer.alert(description, {
  65. skin: 'layui-layer-molv',
  66. closeBtn: 0
  67. });
  68. },
  69. showInputTree: function (inputId, inputTreeContentId, leftOffset, rightOffset) {
  70. var onBodyDown = function (event) {
  71. if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
  72. $("#" + inputTreeContentId).fadeOut("fast");
  73. $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发,不用弹起
  74. }
  75. };
  76. if (leftOffset == undefined && rightOffset == undefined) {
  77. var inputDiv = $("#" + inputId);
  78. var inputDivOffset = $("#" + inputId).offset();
  79. $("#" + inputTreeContentId).css({
  80. left: inputDivOffset.left + "px",
  81. top: inputDivOffset.top + inputDiv.outerHeight() + "px"
  82. }).slideDown("fast");
  83. } else {
  84. $("#" + inputTreeContentId).css({
  85. left: leftOffset + "px",
  86. top: rightOffset + "px"
  87. }).slideDown("fast");
  88. }
  89. $("body").bind("mousedown", onBodyDown);
  90. },
  91. baseAjax: function (url, tip) {
  92. var ajax = new $ax(Feng.ctxPath + url, function (data) {
  93. Feng.success(tip + "成功!");
  94. }, function (data) {
  95. Feng.error(tip + "失败!" + data.responseJSON.message + "!");
  96. });
  97. return ajax;
  98. },
  99. changeAjax: function (url) {
  100. return Feng.baseAjax(url, "修改");
  101. },
  102. zTreeCheckedNodes: function (zTreeId) {
  103. var zTree = $.fn.zTree.getZTreeObj(zTreeId);
  104. var nodes = zTree.getCheckedNodes();
  105. var ids = "";
  106. for (var i = 0, l = nodes.length; i < l; i++) {
  107. ids += "," + nodes[i].id;
  108. }
  109. return ids.substring(1);
  110. },
  111. eventParseObject: function (event) {//获取点击事件的源对象
  112. event = event ? event : window.event;
  113. var obj = event.srcElement ? event.srcElement : event.target;
  114. return $(obj);
  115. },
  116. sessionTimeoutRegistry: function () {
  117. $.ajaxSetup({
  118. contentType: "application/x-www-form-urlencoded;charset=utf-8",
  119. complete: function (XMLHttpRequest, textStatus) {
  120. //通过XMLHttpRequest取得响应头,sessionstatus,
  121. var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
  122. if (sessionstatus == "timeout") {
  123. //如果超时就处理 ,指定要跳转的页面
  124. window.location = Feng.ctxPath + "/global/sessionError";
  125. }
  126. }
  127. });
  128. },
  129. initValidator: function (formId, fields) {
  130. $('#' + formId).bootstrapValidator({
  131. feedbackIcons: {
  132. valid: 'glyphicon glyphicon-ok',
  133. invalid: 'glyphicon glyphicon-remove',
  134. validating: 'glyphicon glyphicon-refresh'
  135. },
  136. fields: fields,
  137. live: 'enabled',
  138. message: '该字段不能为空'
  139. });
  140. },
  141. initValidatorTip: function (formId, fields) {
  142. $('#' + formId).bootstrapValidator({
  143. feedbackIcons: {
  144. valid: 'glyphicon glyphicon-ok',
  145. invalid: 'glyphicon glyphicon-remove',
  146. validating: 'glyphicon glyphicon-refresh'
  147. },
  148. container: 'tooltip',
  149. group:'.rowGroup',
  150. fields:fields,
  151. live: 'enabled',
  152. message: '该字段不能为空'
  153. }).on('error.field.bv', function(e, data) {
  154. var $parent = data.element.parents('.form-group-sm'),
  155. $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + data.field + '"]'),
  156. title = $icon.data('bs.tooltip').getTitle();
  157. $icon.tooltip('destroy').tooltip({
  158. html: true,
  159. placement: 'right',
  160. title: title,
  161. container: 'body'
  162. });
  163. });
  164. },
  165. underLineToCamel: function (str) {
  166. var strArr = str.split('_');
  167. for (var i = 1; i < strArr.length; i++) {
  168. strArr[i] = strArr[i].charAt(0).toUpperCase() + strArr[i].substring(1);
  169. }
  170. var result = strArr.join('');
  171. return result.charAt(0).toUpperCase() + result.substring(1);
  172. },
  173. randomNum: function (minNum, maxNum) {
  174. switch (arguments.length) {
  175. case 1:
  176. return parseInt(Math.random() * minNum + 1, 10);
  177. break;
  178. case 2:
  179. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
  180. break;
  181. default:
  182. return 0;
  183. break;
  184. }
  185. },
  186. newCrontab: function (href, menuName) {
  187. var dataUrl = href;
  188. var needCreateCrontab = true;
  189. // 轮询已有的标签,判断是否已经存在标签
  190. parent.$('.J_menuTab').each(function () {
  191. if ($(this).data('id') == dataUrl) {
  192. if (!$(this).hasClass('active')) {
  193. $(this).addClass('active').siblings('.J_menuTab').removeClass('active');
  194. parent.MyCrontab.scrollToTab(this);
  195. parent.MyCrontab.$('.J_mainContent .J_iframe').each(function () {
  196. if ($(this).data('id') == dataUrl) {
  197. $(this).show().siblings('.J_iframe').hide();
  198. $(this).attr('src', $(this).attr('src'));
  199. return false;
  200. }
  201. });
  202. }
  203. needCreateCrontab = false;
  204. return false;
  205. }
  206. });
  207. //创建标签
  208. if (needCreateCrontab) {
  209. var tabLink = '<a href="javascript:;" class="active J_menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
  210. parent.$('.J_menuTab').removeClass('active');
  211. parent.$('.J_menuTabs .page-tabs-content').append(tabLink);
  212. var iframeContent = '<iframe class="J_iframe" name="iframe' + Feng.randomNum(100,999) + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
  213. parent.$('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(iframeContent);
  214. parent.MyCrontab.scrollToTab($('.J_menuTab.active'));
  215. }
  216. },
  217. endWith: function(str, val){
  218. if (str==null || val==null) {
  219. return false;
  220. }
  221. if (str.length < val.length) {
  222. return false;
  223. }
  224. var temp = str.substring(str.length - val.length);
  225. if(temp == val){
  226. return true;
  227. }else{
  228. return false;
  229. }
  230. },
  231. setUrlParam: function(url, jsonObj){
  232. for(var temp in jsonObj){
  233. var key = temp;
  234. var value = jsonObj[temp];
  235. if (value!=null && value!='') {
  236. if (url.indexOf("?")!=-1) {
  237. url = url + "&" + key + "=" + encodeURI(encodeURI(value));
  238. } else {
  239. url = url + "?" + key + "=" + encodeURI(encodeURI(value));
  240. }
  241. }
  242. }
  243. return url
  244. },
  245. getUrlValue : function(name){
  246. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  247. var r = window.location.search.substr(1).match(reg);
  248. if(r!=null)return decodeURI(r[2]); return null;
  249. },
  250. addAjaxSelect: function (val) {
  251. var id = val.id; //下拉框对象的id
  252. var url = val.url; //请求地址
  253. var displayCode = val.displayCode; //下拉框实际值名称
  254. var displayName = val.displayName; //下拉框显示值名称
  255. var type = val.type; //请求方式 GET 或者 POST, 默认POST
  256. var async = val.async; //同步方式 {异步--falae, 同步--true}, 默认为同步
  257. if (async == null){
  258. async = false;
  259. }
  260. if (type==null){
  261. type == "POST";
  262. }
  263. var select = $("#"+id);
  264. select.empty();
  265. var ajax = new $ax(url, function(data){
  266. var length = data.length;
  267. var html = "<option value=''>---请选择---</option>";
  268. for(var i=0; i<length; i++){
  269. if (length == 1){
  270. html = html+ "<option value=\""+data[i][displayCode]+"\">"+data[i][displayName]+"</option>";
  271. }else{
  272. if(data[i][displayCode]==select.attr("defval")){
  273. html += "<option selected='selected' value=\""+data[i][displayCode]+"\">"+data[i][displayName]+"</option>";
  274. }else{
  275. html += "<option value=\""+data[i][displayCode]+"\">"+data[i][displayName]+"</option>";
  276. }
  277. }
  278. }
  279. select.append(html);
  280. if (length == 1){ //如果只有一个选项,需要触发select的onchange方法
  281. select.change();
  282. }
  283. },function(data){
  284. Feng.error("操作失败!");
  285. });
  286. ajax.async = async;
  287. ajax.type = type;
  288. ajax.set({});
  289. ajax.start();
  290. },
  291. acceptImg:function (){
  292. return {
  293. title : 'Images',
  294. extensions : 'gif,jpg,jpeg,bmp,png',
  295. mimeTypes : 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
  296. };
  297. },
  298. acceptWord:function (){
  299. return {
  300. title: 'word',
  301. extensions: 'rar,zip,doc,xls,docx,xlsx,pdf',
  302. mimeTypes: '.rar,.zip,.doc,.xls,.docx,.xlsx,.pdf'
  303. };
  304. },
  305. acceptWord_Img:function (){
  306. return {
  307. title: 'word_img',
  308. extensions: 'doc,xls,docx,xlsx,pdf,gif,jpg,jpeg,bmp,png',
  309. mimeTypes: '.doc,.xls,.docx,.xlsx,.pdf,image/gif,image/jpg,image/jpeg,image/bmp,image/png'
  310. };
  311. },
  312. resetSelect: function(id){
  313. var options = $("#"+id).children();
  314. if (options.length > 1){
  315. $("#"+id).val("");
  316. }
  317. },
  318. dictFormatter: function(code,type){
  319. var result = "";
  320. var ajax = new $ax(Feng.ctxPath + "/dict/findDetailByCode/"+type+"/"+code, function(data){
  321. result=data.name;
  322. },function(data){
  323. Feng.error("操作失败!");
  324. });
  325. ajax.start();
  326. return result;
  327. },
  328. showImg: function(context) { //传一个<img>对像
  329. var pic = $(context);
  330. var src = pic.attr("src");
  331. var sbp = window.top.$("#showBigPic");
  332. sbp.empty();
  333. sbp.append("<img id=\"_pic0001\" src=\""+src+"\" style=\"width:1px; height:1px; margin:0px;padding:0px;\"/>");
  334. window.top.$("#_pic0001").viewer({
  335. toolbar:true,
  336. fullscreen:false
  337. });
  338. window.top.$("#_pic0001").click();
  339. },
  340. findChildDictBatch : function (data) {
  341. var ajax = new $ax(Feng.ctxPath + "/common/tool/findChildDictBatch", function (res) {
  342. var data = res.obj;
  343. for(var i in data){
  344. var html = "<option value=''>---请选择---</option>";
  345. for(var j in data[i]){
  346. html = html + '<option value="'+data[i][j].code+'">'+data[i][j].name+'</option>';
  347. }
  348. $("#"+i).empty().append(html);
  349. }
  350. }, function (data) {
  351. Feng.error("初始化失败!" + data.responseJSON.message + "!");
  352. });
  353. ajax.setData(data);
  354. ajax.setcontentType('application/json;charset=utf-8');
  355. ajax.start();
  356. },
  357. checkMobilePhoneNum: function(num) {
  358. var telReg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  359. if (!telReg.test(num)) {
  360. return false;
  361. } else {
  362. return true;
  363. }
  364. },
  365. getCheckLog : function (id,data) {
  366. //初始化日志
  367. $('#'+id).bootstrapTable({
  368. url: Feng.ctxPath + "/common/api/getCheckLog",
  369. method: 'POST',
  370. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  371. search: false, // 是否显示表格搜索,此搜索是客户端搜索,不会进服务端
  372. showRefresh: false, // 是否显示刷新按钮
  373. clickToSelect: true, // 是否启用点击选中行
  374. singleSelect: true, // 设置True 将禁止多选
  375. striped: true, // 是否显示行间隔色
  376. pagination: false, // 设置为 true 会在表格底部显示分页条
  377. paginationHAlign: "left",
  378. paginationDetailHAlign: "right",
  379. sidePagination: "server", // 设置在哪里进行分页,可选值为 'client' 或者 'server'
  380. showColumns: false,
  381. queryParams: function (params) {
  382. return data;
  383. },
  384. rowStyle : function(row,index){
  385. return {
  386. css: {
  387. "word-break": "break-word",
  388. "white-space": "inherit"
  389. }
  390. }
  391. },
  392. columns:
  393. [
  394. {title: '步骤', field: 'stepName', visible: true, align: 'center', valign: 'middle',width:"10%",'class':'uitd_showTip',
  395. formatter : function (value,row,index) {
  396. return ""+value;
  397. }
  398. },
  399. {title: '审核状态', field: 'stateName', visible: true, align: 'center', valign: 'middle',width:"10%",'class':'uitd_showTip'},
  400. {title: '状态变更', field: 'stateChange', visible: true, align: 'center', valign: 'middle',width:"20%",'class':'uitd_showTip'},
  401. {title: '审核意见/备注', field: 'description', visible: true, align: 'center', valign: 'middle',width:"30%",'class':'uitd_showTip',
  402. formatter : function (value,row,index) {
  403. return '<span data-toggle="tooltip" title="'+ value +'">"'+value+'"</span>';
  404. }
  405. },
  406. {title: '操作人', field: 'createUser', visible: true, align: 'center', valign: 'middle',width:"15%",'class':'uitd_showTip'},
  407. {title: '操作时间', field: 'createTime', visible: true, align: 'center', valign: 'middle',width:"15%",'class':'uitd_showTip'},
  408. ]
  409. ,
  410. onPostBody: function () {
  411. $('#'+id+"td.uitd_showTip").bind("mouseover", function () {
  412. var htm = $(this).html();
  413. $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
  414. });
  415. }
  416. });
  417. },
  418. getCheckLogModel : function (id,type,fileType) {
  419. layer.open({
  420. type: 1,
  421. title:"日志",
  422. fixed:false,
  423. content: '<table id="'+id+'"></table>',
  424. area: ['80%', '80%'],
  425. maxmin: true,
  426. success :function (layero, index) {
  427. //初始化日志
  428. $('#'+id).bootstrapTable({
  429. url: Feng.ctxPath + "/api/talentInfo/getCheckLog",
  430. method: 'POST',
  431. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  432. search: false, // 是否显示表格搜索,此搜索是客户端搜索,不会进服务端
  433. showRefresh: false, // 是否显示刷新按钮
  434. clickToSelect: true, // 是否启用点击选中行
  435. singleSelect: true, // 设置True 将禁止多选
  436. striped: true, // 是否显示行间隔色
  437. pagination: false, // 设置为 true 会在表格底部显示分页条
  438. paginationHAlign: "left",
  439. paginationDetailHAlign: "right",
  440. sidePagination: "server", // 设置在哪里进行分页,可选值为 'client' 或者 'server'
  441. showColumns: false,
  442. queryParams: function (params) {
  443. if(Feng.isEmptyStr(fileType)){
  444. fileType = "";
  445. }
  446. return {"type":type,"mainId":id,"typeFileId":fileType,"active":1};
  447. },
  448. rowStyle : function(row,index){
  449. return {
  450. css: {
  451. "word-break": "break-word",
  452. "white-space": "inherit"
  453. }
  454. }
  455. },
  456. columns:
  457. [
  458. {title: '步骤', field: 'stepName', visible: true, align: 'center', valign: 'middle',width:"10%",'class':'uitd_showTip',
  459. formatter : function (value,row,index) {
  460. return ""+value;
  461. }
  462. },
  463. {title: '审核状态', field: 'stateName', visible: true, align: 'center', valign: 'middle',width:"10%",'class':'uitd_showTip'},
  464. {title: '状态变更', field: 'stateChange', visible: true, align: 'center', valign: 'middle',width:"20%",'class':'uitd_showTip'},
  465. {title: '审核意见/备注', field: 'description', visible: true, align: 'center', valign: 'middle',width:"30%",'class':'uitd_showTip',
  466. formatter : function (value,row,index) {
  467. return '<span data-toggle="tooltip" title="'+ value +'">"'+value+'"</span>';
  468. }
  469. },
  470. {title: '操作人', field: 'createUser', visible: true, align: 'center', valign: 'middle',width:"15%",'class':'uitd_showTip'},
  471. {title: '操作时间', field: 'createTime', visible: true, align: 'center', valign: 'middle',width:"15%",'class':'uitd_showTip'},
  472. ]
  473. ,
  474. onPostBody: function () {
  475. $('#'+id+"td.uitd_showTip").bind("mouseover", function () {
  476. var htm = $(this).html();
  477. $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
  478. });
  479. }
  480. });
  481. }
  482. });
  483. },
  484. showPdf : function(url,id,title){
  485. if(Feng.isEmptyStr(id)){
  486. id = "id";
  487. }
  488. if(Feng.isEmptyStr(title)){
  489. title = "预览";
  490. }
  491. let origin = window.location.origin;
  492. //let full_url = "https://fileview.jinjianghc.com/onlinePreview?url=" + encodeURIComponent(Base64.encode(url));
  493. var index = layer.open({
  494. id:id,
  495. type: 2,
  496. shade: 0,
  497. title: title,
  498. area: ['600px', '350px'], //宽高
  499. fix: false, //不固定
  500. maxmin: true,
  501. content: url,
  502. });
  503. // layer.full(index);
  504. },
  505. showExcel:function(url,id,title){
  506. window.location.href = url;
  507. },
  508. showFile:function(url,id,title){
  509. if(Feng.isEmptyStr(id)){
  510. id = "id";
  511. }
  512. if(Feng.isEmptyStr(title)){
  513. title = "预览";
  514. }
  515. var index = layer.open({
  516. id:id,
  517. type: 2,
  518. shade: 0,
  519. title: title,
  520. area: ['600px', '350px'], //宽高
  521. fix: false, //不固定
  522. maxmin: true,
  523. content: url,
  524. });
  525. },
  526. isEmptyStr:function(str) {
  527. if(str == null || str == ''){
  528. return true;
  529. }else{
  530. return false;
  531. }
  532. },
  533. isNotEmptyStr:function (str) {
  534. if(str!=null && str != ''){
  535. return true;
  536. }else{
  537. return false;
  538. }
  539. },
  540. checkAll:function (id) {
  541. $("#"+id+" input").each(function () {
  542. this.checked = true;
  543. })
  544. },
  545. unCheckAll :function(id) {
  546. $("#"+id+" input").each(function () {
  547. if(this.checked){
  548. this.checked = false;
  549. }else{
  550. this.checked = true;
  551. }
  552. })
  553. },
  554. showMiniFileModal:function (project,type,id) {
  555. layer.open({
  556. type: 2,
  557. title: "附件",
  558. shade: 0,
  559. resize:true,
  560. maxmin:true,
  561. // moveOut:true,
  562. id:"file",
  563. area: ['800px', '500px'],
  564. offset: 'rb', //右下角弹出content:
  565. shift: 2,
  566. content: Feng.ctxPath + "/api/common/gotoFileShow",
  567. zIndex: layer.zIndex,
  568. success:function (layero,index) {
  569. layer.setTop(layero);
  570. //按钮【按钮一】的回调
  571. var iframeWin = window[layero.find('iframe')[0]['name']];
  572. iframeWin.getFile(project,type,id);
  573. }
  574. });
  575. },
  576. getCheckBoxValues:function (str) { //获取checkbox值
  577. var val = "";
  578. $("#"+str+" input[name='"+str+"']").each(function () {
  579. if (this.checked) {
  580. val = val + $(this).val() + ",";
  581. }
  582. });
  583. return val.substring(0,val.length-1);
  584. },
  585. initDate:function () {
  586. $(".date").removeAttr('lay-key');
  587. $(".date").each(function(){
  588. laydate.render({
  589. elem: this
  590. ,type: 'date'
  591. ,trigger: 'click'
  592. });
  593. });
  594. },
  595. downloadFile:function (id,type) {
  596. window.location.href = Feng.ctxPath + "/api/common/downloadFile?id=" + id + "&type="+type;
  597. },
  598. bankChange:function (val,target){
  599. var bank = $("#"+val).val();
  600. if($.trim(bank)=='中国工商银行'){
  601. $("#"+target).val('102391050013');
  602. }else {
  603. $("#"+target).val('');
  604. }
  605. }
  606. };