util.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. var Namespace = new Object();
  2. Namespace.register = function(path) {
  3. var arr = path.split(".");
  4. var ns = "";
  5. for ( var i = 0; i < arr.length; i++) {
  6. if (i > 0)
  7. ns += ".";
  8. ns += arr[i];
  9. eval("if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");
  10. }
  11. };
  12. jQuery.extend({
  13. /**
  14. * 根据名称全选或反选复选框。
  15. *
  16. * @param name
  17. * @param checked
  18. */
  19. checkAll : function(name, checked) {
  20. $("input[name='" + name + "']").attr("checked", checked);
  21. },
  22. /**
  23. * 根据复选框的名称获取选中值,使用逗号分隔。
  24. *
  25. * @param name
  26. * @returns {String}
  27. */
  28. getChkValue : function(name) {
  29. var str = "";
  30. $('input[type="checkbox"][name=' + name + ']').each(function() {
  31. if ($(this).attr('checked')) {
  32. str += $(this).val() + ",";
  33. }
  34. });
  35. if (str != "")
  36. str = str.substring(0, str.length - 1);
  37. return str;
  38. },
  39. /**
  40. * 根据名称获取下拉框的列表的值,使用逗号分隔。
  41. *
  42. * @param name
  43. * @returns {String}
  44. */
  45. getSelectValue : function(name) {
  46. var str = "";
  47. $('select[name=' + name + '] option').each(function() {
  48. str += $(this).val() + ",";
  49. });
  50. if (str != "")
  51. str = str.substring(0, str.length - 1);
  52. return str;
  53. },
  54. copyToClipboard : function(txt) {
  55. if (window.clipboardData) {
  56. window.clipboardData.clearData();
  57. window.clipboardData.setData("Text", txt);
  58. return true;
  59. } else if (navigator.userAgent.indexOf("Opera") != -1) {
  60. window.location = txt;
  61. return false;
  62. } else if (window.netscape) {
  63. try {
  64. netscape.security.PrivilegeManager
  65. .enablePrivilege("UniversalXPConnect");
  66. } catch (e) {
  67. alert($lang.tip.msg,$lang_js.util.copyToClipboard.netscape);
  68. return false;
  69. }
  70. var clip = Components.classes['@mozilla.org/widget/clipboard;1']
  71. .createInstance(Components.interfaces.nsIClipboard);
  72. if (!clip)
  73. return false;
  74. var trans = Components.classes['@mozilla.org/widget/transferable;1']
  75. .createInstance(Components.interfaces.nsITransferable);
  76. if (!trans)
  77. return false;
  78. trans.addDataFlavor('text/unicode');
  79. var str = Components.classes["@mozilla.org/supports-string;1"]
  80. .createInstance(Components.interfaces.nsISupportsString);
  81. var copytext = txt;
  82. str.data = copytext;
  83. trans.setTransferData("text/unicode", str,
  84. copytext.length * 2);
  85. var clipid = Components.interfaces.nsIClipboard;
  86. if (!clip)
  87. return false;
  88. clip.setData(trans, null, clipid.kGlobalClipboard);
  89. return true;
  90. } else {
  91. alert($lang.tip.msg,$lang_js.util.copyToClipboard.notCopy);
  92. return false;
  93. }
  94. },
  95. /**
  96. * 拷贝指定文本框的值。
  97. *
  98. * @param objId
  99. */
  100. copy : function(objId) {
  101. var str = $("#" + objId).val();
  102. var rtn = jQuery.copyToClipboard(str);
  103. if (rtn) {
  104. alert($lang_js.util.copy.success);
  105. }
  106. },
  107. /**
  108. * 判断是否是IE浏览器
  109. *
  110. * @returns {Boolean}
  111. */
  112. isIE : function() {
  113. if (!!window.ActiveXObject || "ActiveXObject" in window){
  114. return true;
  115. }
  116. else{
  117. return false;
  118. }
  119. },
  120. /**
  121. * 判断是否是IE6浏览器
  122. *
  123. * @returns {Boolean}
  124. */
  125. isIE6 : function() {
  126. if(($.browser.msie && $.browser.version =='6.0') &&!$.support.style)
  127. return true;
  128. return false;
  129. },
  130. /**
  131. * 序列化xmldom节点为一个xml。 用法: var sb=new StringBuffer(); var
  132. * str=jQuery.getChildXml(node,sb);
  133. *
  134. * @param node
  135. * xmldom节点。
  136. * @param sb
  137. * @returns
  138. */
  139. getChildXml : function(node, sb) {
  140. var nodes = node.childNodes;
  141. var len = nodes.length;
  142. for ( var i = 0; i < len; i++) {
  143. var childNode = nodes[i];
  144. if (childNode.nodeType != 1)
  145. continue;
  146. var childNodeName = childNode.nodeName;
  147. sb.append("<" + childNodeName + " ");
  148. var attrs = childNode.attributes;
  149. for ( var k = 0; k < attrs.length; k++) {
  150. var attr = attrs[k];
  151. sb.append(" " + attr.name + "=\"" + attr.value + "\" ");
  152. }
  153. sb.append(">");
  154. $.getChildXml(childNode, sb);
  155. sb.append("</" + childNodeName + ">");
  156. }
  157. },
  158. /**
  159. * 根据xmlnode序列化xml
  160. *
  161. * @param node
  162. * xmldom节点。
  163. * @returns
  164. */
  165. getChildXmlByNode : function(node) {
  166. var sb = new StringBuffer();
  167. jQuery.getChildXml(node, sb);
  168. return sb.toString();
  169. },
  170. /**
  171. * 根据xml节点,返回该节点的xml属性。 返回值通过参数ary获取。 用法: var node; var ary=new
  172. * Array(); $.getAttrXml(node,ary);
  173. *
  174. * @param node
  175. * @param ary
  176. */
  177. getAttrXml : function(node, ary) {
  178. var nodes = node.childNodes;
  179. var len = nodes.length;
  180. for ( var i = 0; i < len; i++) {
  181. var childNode = nodes[i];
  182. if (childNode.nodeType != 1)
  183. continue;
  184. var attrs = childNode.attributes;
  185. var obj = new Object();
  186. for ( var k = 0; k < attrs.length; k++) {
  187. var attr = attrs[k];
  188. obj[attr.name] = attr.value;
  189. }
  190. ary.push(obj);
  191. $.getAttrXml(childNode, ary);
  192. }
  193. },
  194. /**
  195. * <img src="img/logo.png" onload="$.fixPNG(this);"/>
  196. * 解决图片在ie中背景透明的问题。
  197. *
  198. * @param imgObj
  199. */
  200. fixPNG : function(imgObj) {
  201. var arVersion = navigator.appVersion.split("MSIE");
  202. var version = parseFloat(arVersion[1]);
  203. if ((version >= 5.5) && (version < 7)
  204. && (document.body.filters)) {
  205. var imgID = (imgObj.id) ? "id='" + imgObj.id + "' " : "";
  206. var imgClass = (imgObj.className) ? "class='"
  207. + imgObj.className + "' " : "";
  208. var imgTitle = (imgObj.title) ? "title='" + imgObj.title
  209. + "' " : "title='" + imgObj.alt + "' ";
  210. var imgStyle = "display:inline-block;"
  211. + imgObj.style.cssText;
  212. var strNewHTML = "<span "
  213. + imgID
  214. + imgClass
  215. + imgTitle
  216. + " style=\""
  217. + "width:"
  218. + imgObj.width
  219. + "px; height:"
  220. + imgObj.height
  221. + "px;"
  222. + imgStyle
  223. + ";"
  224. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  225. + "(src=\'" + imgObj.src
  226. + "\', sizingMethod='scale');\"></span>";
  227. imgObj.outerHTML = strNewHTML;
  228. }
  229. },
  230. /**
  231. * 获取当前路径中指定键的参数值。
  232. *
  233. * @param key
  234. * @returns
  235. */
  236. getParameter : function(key) {
  237. var parameters = unescape(window.location.search.substr(1))
  238. .split("&");
  239. for ( var i = 0; i < parameters.length; i++) {
  240. var paramCell = parameters[i].split("=");
  241. if (paramCell.length == 2
  242. && paramCell[0].toUpperCase() == key.toUpperCase()) {
  243. return paramCell[1];
  244. }
  245. }
  246. return new String();
  247. },
  248. /**
  249. * 根据年份和月份获取某个月的天数。
  250. *
  251. * @param year
  252. * @param month
  253. * @returns
  254. */
  255. getMonthDays : function(year, month) {
  256. if (month < 0 || month > 11) {
  257. return 30;
  258. }
  259. var arrMon = new Array(12);
  260. arrMon[0] = 31;
  261. if (year % 4 == 0) {
  262. arrMon[1] = 29;
  263. } else {
  264. arrMon[1] = 28;
  265. }
  266. arrMon[2] = 31;
  267. arrMon[3] = 30;
  268. arrMon[4] = 31;
  269. arrMon[5] = 30;
  270. arrMon[6] = 31;
  271. arrMon[7] = 31;
  272. arrMon[8] = 30;
  273. arrMon[9] = 31;
  274. arrMon[10] = 30;
  275. arrMon[11] = 31;
  276. return arrMon[month];
  277. },
  278. /**
  279. * 计算日期为当年的第几周
  280. *
  281. * @param year
  282. * @param month
  283. * @param day
  284. * @returns
  285. */
  286. weekOfYear : function(year, month, day) {
  287. // year 年
  288. // month 月
  289. // day 日
  290. // 每周从周日开始
  291. var date1 = new Date(year, 0, 1);
  292. var date2 = new Date(year, month - 1, day, 1);
  293. var dayMS = 24 * 60 * 60 * 1000;
  294. var firstDay = (7 - date1.getDay()) * dayMS;
  295. var weekMS = 7 * dayMS;
  296. date1 = date1.getTime();
  297. date2 = date2.getTime();
  298. return Math.ceil((date2 - date1 - firstDay) / weekMS) + 1;
  299. },
  300. /**
  301. * 添加书签
  302. *
  303. * @param title
  304. * @param url
  305. * @returns {Boolean}
  306. */
  307. addBookmark : function(title, url) {
  308. if (window.sidebar) {
  309. window.sidebar.addPanel(title, url, "");
  310. } else if (document.all) {
  311. window.external.AddFavorite(url, title);
  312. } else if (window.opera && window.print) {
  313. return true;
  314. }
  315. },
  316. /**
  317. * 设置cookie
  318. *
  319. * @param name
  320. * @param value
  321. */
  322. setCookie : function(name, value) {
  323. var expdate = new Date();
  324. var argv = arguments;
  325. var argc = arguments.length;
  326. var expires = (argc > 2) ? argv[2] : null;
  327. var path = (argc > 3) ? argv[3] : null;
  328. var domain = (argc > 4) ? argv[4] : null;
  329. var secure = (argc > 5) ? argv[5] : false;
  330. if (expires != null)
  331. expdate.setTime(expdate.getTime() + (expires * 1000));
  332. document.cookie = name
  333. + "="
  334. + escape(value)
  335. + ((expires == null) ? "" : ("; expires=" + expdate
  336. .toGMTString()))
  337. + ((path == null) ? "" : ("; path=" + path))
  338. + ((domain == null) ? "" : ("; domain=" + domain))
  339. + ((secure == true) ? "; secure" : "");
  340. },
  341. /**
  342. * 删除cookie
  343. *
  344. * @param name
  345. */
  346. delCookie : function(name) {
  347. var exp = new Date();
  348. exp.setTime(exp.getTime() - 1);
  349. var cval = $.getCookie(name);
  350. document.cookie = name + "=" + cval + "; expires="
  351. + exp.toGMTString();
  352. },
  353. /**
  354. * 读取cookie
  355. *
  356. * @param name
  357. * @returns
  358. */
  359. getCookie : function(name) {
  360. var arg = name + "=";
  361. var alen = arg.length;
  362. var clen = document.cookie.length;
  363. var i = 0;
  364. while (i < clen) {
  365. var j = i + alen;
  366. if (document.cookie.substring(i, j) == arg)
  367. return $.getCookieVal(j);
  368. i = document.cookie.indexOf(" ", i) + 1;
  369. if (i == 0)
  370. break;
  371. }
  372. return null;
  373. },
  374. getCookieVal : function(offset)
  375. {
  376. var endstr = document.cookie.indexOf(";", offset);
  377. if (endstr == -1)
  378. endstr = document.cookie.length;
  379. return unescape(document.cookie.substring(offset, endstr));
  380. },
  381. /**
  382. * 通过js设置表单的值。
  383. *
  384. * @param data
  385. */
  386. setFormByJson : function(data) {
  387. var json = data;
  388. if (typeof (data) == "string") {
  389. json = jQuery.parseJSON(data);
  390. }
  391. for ( var p in json) {
  392. var value = json[p];
  393. var frmElments = $("input[name='" + p+ "'],textarea[name='" + p + "']");
  394. if (frmElments[0]) {
  395. frmElments.val(value);
  396. }
  397. }
  398. },
  399. /**
  400. * 当鼠标移过表格行时,高亮表格行数据
  401. */
  402. highlightTableRows : function() {
  403. $("tr.odd,tr.even").hover(function() {
  404. $(this).addClass("over");
  405. }, function() {
  406. $(this).removeClass("over");
  407. });
  408. },
  409. /**
  410. * 选中行或反选
  411. **/
  412. selectTr:function(){
  413. $("tr.odd,tr.even").each(function(){
  414. $(this).bind("mousedown",function(event){
  415. if(event.target.tagName=="TD")
  416. var strFilter='input:checkbox[class="pk"],input:radio[class="pk"]';
  417. var obj=$(this).find(strFilter);
  418. if(obj.length==1){
  419. var state=obj.attr("checked");
  420. obj.attr("checked",!state);
  421. var isHashCheck = $("chkall");
  422. if(isHashCheck){
  423. obj.trigger("change");
  424. }
  425. }
  426. }
  427. );
  428. });
  429. },
  430. /**
  431. * 在数组中指定的位置插入数据。
  432. * @param aryData
  433. * @param data
  434. * @param index
  435. */
  436. insert : function(aryData,data,index){
  437. if(isNaN(index) || index<0 || index>aryData.length) {
  438. aryData.push(data);
  439. }else{
  440. var temp = aryData.slice(index);
  441. aryData[index]=data;
  442. for (var i=0; i<temp.length; i++){
  443. aryData[index+1+i]=temp[i];
  444. }
  445. }
  446. },
  447. getFirstLower:function(v){
  448. var value="";
  449. if(v.indexOf('_')!=-1){
  450. var ary=v.split('_');
  451. for(var i=0;i<ary.length;i++){
  452. var tmp=ary[i];
  453. if(i==0){
  454. value+=tmp.toLowerCase();
  455. }else{
  456. value+=tmp.substring(0,1).toUpperCase()+tmp.substring(1,tmp.length+1).toLowerCase();
  457. }
  458. }
  459. }else{
  460. value=v.toLowerCase();
  461. }
  462. return value;
  463. },
  464. getFirstUpper:function(v){
  465. var value="";
  466. if(v.indexOf('_')!=-1){
  467. var ary=v.split('_');
  468. for(var i=0;i<ary.length;i++){
  469. var tmp=ary[i];
  470. value+=tmp.substring(0,1).toUpperCase()+tmp.substring(1,tmp.length+1).toLowerCase();
  471. }
  472. }else{
  473. value=v.substring(0,1).toUpperCase()+v.substring(1,v.length+1).toLowerCase();
  474. }
  475. return value;
  476. },
  477. /**
  478. *
  479. * @param url
  480. * @returns
  481. */
  482. openFullWindow:function(url){
  483. var h=screen.availHeight-35;
  484. var w=screen.availWidth-5;
  485. var vars="top=0,left=0,height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizable=1,scrollbars=1";
  486. var win=window.open(url,"",vars,true);
  487. return win;
  488. },
  489. /**
  490. *
  491. * @param url
  492. * @returns
  493. */
  494. openMidWindow:function(url){
  495. var h=350;
  496. var w=560;
  497. var t=(screen.availHeight-h)/2;
  498. var l=(screen.availWidth-w)/2;
  499. var vars="top="+t+",left="+l+",height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizable=1,scrollbars=1";
  500. var win=window.open(url,"",vars,true);
  501. return win;
  502. },
  503. /**
  504. * 刷新父窗口并关闭当前窗口。
  505. */
  506. closeWindow:function(){
  507. if(window.opener){
  508. try{
  509. window.opener.location.href=window.opener.location.href.getNewUrl();
  510. }
  511. catch(e){}
  512. }
  513. window.close();
  514. },
  515. /**
  516. * 如果传入的值是null、undefined或空字符串,则返回true。(可选的)
  517. * @param {Mixed} value 要验证的值。
  518. * @param {Boolean} allowBlank (可选的) 如果该值为true,则空字符串不会当作空而返回true。
  519. * @return {Boolean}
  520. */
  521. isEmpty : function(v, allowBlank){
  522. return v === null || v === undefined || (!allowBlank ? v === '' : false);
  523. },
  524. /**
  525. * 将数字转换成人名币大写。
  526. * @param currencyDigits
  527. * @returns
  528. */
  529. convertCurrency:function(currencyDigits) {
  530. var MAXIMUM_NUMBER = 99999999999.99;
  531. var CN_ZERO = "零";
  532. var CN_ONE = "壹";
  533. var CN_TWO = "贰";
  534. var CN_THREE = "叁";
  535. var CN_FOUR = "肆";
  536. var CN_FIVE = "伍";
  537. var CN_SIX = "陆";
  538. var CN_SEVEN = "柒";
  539. var CN_EIGHT = "捌";
  540. var CN_NINE = "玖";
  541. var CN_TEN = "拾";
  542. var CN_HUNDRED = "佰";
  543. var CN_THOUSAND = "仟";
  544. var CN_TEN_THOUSAND = "万";
  545. var CN_HUNDRED_MILLION = "亿";
  546. var CN_SYMBOL = "";
  547. var CN_DOLLAR = "元";
  548. var CN_TEN_CENT = "角";
  549. var CN_CENT = "分";
  550. var CN_INTEGER = "整";
  551. var integral;
  552. var decimal;
  553. var outputCharacters;
  554. var parts;
  555. var digits, radices, bigRadices, decimals;
  556. var zeroCount;
  557. var i, p, d;
  558. var quotient, modulus;
  559. currencyDigits = currencyDigits.toString();
  560. if (currencyDigits == "") {
  561. return "";
  562. }
  563. if (currencyDigits.match(/[^,.\d]/) != null) {
  564. return "";
  565. }
  566. if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
  567. return "";
  568. }
  569. currencyDigits = currencyDigits.replace(/,/g, "");
  570. currencyDigits = currencyDigits.replace(/^0+/, "");
  571. if (Number(currencyDigits) > MAXIMUM_NUMBER) {
  572. return "";
  573. }
  574. parts = currencyDigits.split(".");
  575. if (parts.length > 1) {
  576. integral = parts[0];
  577. decimal = parts[1];
  578. decimal = decimal.substr(0, 2);
  579. }
  580. else {
  581. integral = parts[0];
  582. decimal = "";
  583. }
  584. digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
  585. radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
  586. bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
  587. decimals = new Array(CN_TEN_CENT, CN_CENT);
  588. outputCharacters = "";
  589. if (Number(integral) > 0) {
  590. zeroCount = 0;
  591. for (i = 0; i < integral.length; i++) {
  592. p = integral.length - i - 1;
  593. d = integral.substr(i, 1);
  594. quotient = p / 4;
  595. modulus = p % 4;
  596. if (d == "0") {
  597. zeroCount++;
  598. }
  599. else {
  600. if (zeroCount > 0) {
  601. outputCharacters += digits[0];
  602. }
  603. zeroCount = 0;
  604. outputCharacters += digits[Number(d)] + radices[modulus];
  605. }
  606. if (modulus == 0 && zeroCount < 4) {
  607. outputCharacters += bigRadices[quotient];
  608. }
  609. }
  610. outputCharacters += CN_DOLLAR;
  611. }
  612. if (decimal != "") {
  613. for (i = 0; i < decimal.length; i++) {
  614. d = decimal.substr(i, 1);
  615. if (d != "0") {
  616. outputCharacters += digits[Number(d)] + decimals[i];
  617. }
  618. }
  619. }
  620. if (outputCharacters == "") {
  621. outputCharacters = CN_ZERO + CN_DOLLAR;
  622. }
  623. if (decimal == "") {
  624. outputCharacters += CN_INTEGER;
  625. }
  626. outputCharacters = CN_SYMBOL + outputCharacters;
  627. return outputCharacters;
  628. },
  629. /**
  630. * 转换节点的tagName
  631. * 示例 var me=$(this); me=$.tagName(me,"span");
  632. * @param self {object} 要转换的单个节点
  633. * @param tag {string} 转换为tag类型节点
  634. * @return {object} 转换后的节点对象
  635. */
  636. tagName:function(self,tag){
  637. var attrs=self.attributes,
  638. newTag=document.createElement(tag);
  639. for(var i=0,c;c=attrs[i++];){
  640. if(!c.value||c.value=='null')continue;
  641. $(newTag).attr(c.name,c.value);
  642. }
  643. $(self).before($(newTag));
  644. $(self).remove();
  645. return $(newTag);
  646. },
  647. /**
  648. * 在文本框指定的地方插入文本
  649. * @param txtarea 文本框对象
  650. * @param tag 文本
  651. */
  652. insertText : function(txtarea, tag) {
  653. // IE
  654. if (document.selection) {
  655. var theSelection = document.selection.createRange().text;
  656. if (!theSelection) {
  657. theSelection = tag;
  658. }
  659. txtarea.focus();
  660. if (theSelection.charAt(theSelection.length - 1) == " ") {
  661. theSelection = theSelection.substring(0,
  662. theSelection.length - 1);
  663. document.selection.createRange().text = theSelection
  664. + " ";
  665. } else {
  666. document.selection.createRange().text = theSelection;
  667. }
  668. // Mozilla
  669. } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
  670. var startPos = txtarea.selectionStart;
  671. var endPos = txtarea.selectionEnd;
  672. var myText = (txtarea.value).substring(startPos, endPos);
  673. if (!myText) {
  674. myText = tag;
  675. }
  676. if (myText.charAt(myText.length - 1) == " ") {
  677. subst = myText.substring(0, (myText.length - 1)) + " ";
  678. } else {
  679. subst = myText;
  680. }
  681. txtarea.value = txtarea.value.substring(0, startPos)+ subst+ txtarea.value.substring(endPos,txtarea.value.length);
  682. txtarea.focus();
  683. var cPos = startPos + (myText.length);
  684. txtarea.selectionStart = cPos;
  685. txtarea.selectionEnd = cPos;
  686. // All others
  687. } else {
  688. txtarea.value += tag;
  689. txtarea.focus();
  690. }
  691. if (txtarea.createTextRange)
  692. txtarea.caretPos = document.selection.createRange().duplicate();
  693. },
  694. confirm:function(selector,message,callback){
  695. $(selector).click(function(){
  696. if($(this).hasClass('disabled')) return false;
  697. var ele=this;
  698. $.ligerDialog.confirm(message,$lang.tip.msg,function(rtn) {
  699. if(rtn){
  700. if($.browser.msie){
  701. $.gotoDialogPage(ele.href);
  702. }
  703. else{
  704. location.href=ele.href;
  705. }
  706. }
  707. });
  708. return false;
  709. });
  710. },
  711. /**
  712. * Dialog窗口跳转
  713. * @param {} url 地址
  714. */
  715. gotoDialogPage: function (url) {
  716. if($.browser.msie){
  717. var a = document.createElement("a");
  718. a.href=url;
  719. document.body.appendChild(a);
  720. a.click();
  721. }
  722. else{
  723. location.href=url;
  724. }
  725. },
  726. /**
  727. * 克隆对象。
  728. */
  729. cloneObject:function(obj){
  730. var o = obj.constructor === Array ? [] : {};
  731. for(var i in obj){
  732. if(obj.hasOwnProperty(i)){
  733. o[i] = typeof obj[i] === "object" ? cloneObject(obj[i]) : obj[i];
  734. }
  735. }
  736. return o;
  737. },
  738. /**
  739. * 清除表单
  740. */
  741. clearQueryForm:function(){
  742. $("input[name^='Q_'],select[name^='Q_']").each(function(){
  743. $(this).val('');
  744. });
  745. },
  746. getFileExtName:function(fileName){
  747. var pos=fileName.lastIndexOf(".");
  748. if(pos==-1) return "";
  749. return fileName.substring(pos +1);
  750. },
  751. //转成千分位。
  752. comdify:function(v){
  753. if(v&&v!=''){
  754. n=v+"";
  755. var re=/\d{1,3}(?=(\d{3})+$)/g;
  756. var n1=n.trim().replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){
  757. return s1.replace(re,"$&,")+s2;
  758. });
  759. return n1;
  760. }
  761. return v;
  762. },
  763. toNumber:function(v){
  764. if(v&&v!=''){
  765. if(v.indexOf(',')==-1)
  766. return v;
  767. var ary=v.split(',');
  768. var val=ary.join("");
  769. return val;
  770. }
  771. return 0;
  772. },
  773. /**
  774. * 上下移动
  775. *
  776. * @param {}
  777. * obj 上移的对象
  778. * @param {}
  779. * isUp 是否上移
  780. */
  781. moveTr : function(obj, isUp) {
  782. var thisTr = $(obj).parents("tr");
  783. if (isUp) {
  784. var prevTr = $(thisTr).prev();
  785. if (prevTr) {
  786. thisTr.insertBefore(prevTr);
  787. }
  788. } else {
  789. var nextTr = $(thisTr).next();
  790. if (nextTr) {
  791. thisTr.insertAfter(nextTr);
  792. }
  793. }
  794. },
  795. getCurrentDate:function(){
  796. var myDate=new Date();
  797. var month=myDate.getMonth()+1;
  798. month=(month<10)?"0" + month:month;
  799. return myDate.getFullYear() +"-" + month + "-"+ myDate.getDate();
  800. },
  801. getPageSize:function() {
  802. var winW, winH;
  803. if(window.innerHeight) {// all except IE
  804. winW = window.innerWidth;
  805. winH = window.innerHeight;
  806. } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
  807. winW = document.documentElement.clientWidth;
  808. winH = document.documentElement.clientHeight;
  809. } else if (document.body) { // other
  810. winW = document.body.clientWidth;
  811. winH = document.body.clientHeight;
  812. } // for small pages with total size less then the viewport
  813. return {width:winW, height:winH};
  814. } ,
  815. isArray : function(v){
  816. return Object.prototype.toString.call(v) === '[object Array]';
  817. }
  818. });
  819. /**
  820. * 功能:给url添加一个当前时间日期数值,使页面不会被缓存。
  821. */
  822. String.prototype.getNewUrl = function() {
  823. // 如果url中没有参数。
  824. var time = new Date().getTime();
  825. var url = this;
  826. //去除‘#’后边的字符
  827. if (url.indexOf("#") != -1) {
  828. var index=url.lastIndexOf("#",url.length-1);
  829. url=url.substring(0, index);
  830. }
  831. while(url.endWith("#")){
  832. url=url.substring(0, url.length-1);
  833. }
  834. url=url.replace(/(\?|&)rand=\d*/g, "");
  835. if (url.indexOf("?") == -1) {
  836. url += "?rand=" + time;
  837. } else {
  838. url += "&rand=" + time;
  839. }
  840. return url;
  841. };
  842. /**
  843. * 功能:给url添加jsessionId 防止session丢失。
  844. * @returns {String}
  845. */
  846. String.prototype.getSessionUrl=function(){
  847. //jsessionid
  848. var url = this;
  849. if(url.indexOf(";jsessionid=")!=-1){
  850. return url;
  851. }
  852. if(url.indexOf("?")==-1){
  853. url+=";jsessionid=" +__jsessionid;
  854. }
  855. else{
  856. var aryUrl=url.split("?");
  857. url=aryUrl[0] +";jsessionid=" +__jsessionId +"?" + aryUrl[1];
  858. }
  859. return url;
  860. };
  861. /**
  862. * 判断字符串是否为空。
  863. *
  864. * @returns {Boolean}
  865. */
  866. String.prototype.isEmpty = function() {
  867. var rtn = (this == null || this == undefined || this.trim() == '');
  868. return rtn;
  869. };
  870. /**
  871. * 功能:移除首尾空格
  872. */
  873. String.prototype.trim = function() {
  874. return this.replace(/(^\s*)|(\s*$)/g, "");
  875. };
  876. /**
  877. * 功能:移除左边空格
  878. */
  879. String.prototype.lTrim = function() {
  880. return this.replace(/(^\s*)/g, "");
  881. };
  882. /**
  883. * 功能:移除右边空格
  884. */
  885. String.prototype.rTrim = function() {
  886. return this.replace(/(\s*$)/g, "");
  887. };
  888. /**
  889. * 判断结束是否相等
  890. *
  891. * @param str
  892. * @param isCasesensitive
  893. * @returns {Boolean}
  894. */
  895. String.prototype.endWith = function(str, isCasesensitive) {
  896. if (str == null || str == "" || this.length == 0
  897. || str.length > this.length)
  898. return false;
  899. var tmp = this.substring(this.length - str.length);
  900. if (isCasesensitive == undefined || isCasesensitive) {
  901. return tmp == str;
  902. } else {
  903. return tmp.toLowerCase() == str.toLowerCase();
  904. }
  905. };
  906. /**
  907. * 判断开始是否相等
  908. *
  909. * @param str
  910. * @param isCasesensitive
  911. * @returns {Boolean}
  912. */
  913. String.prototype.startWith = function(str, isCasesensitive) {
  914. if (str == null || str == "" || this.length == 0
  915. || str.length > this.length)
  916. return false;
  917. var tmp = this.substr(0, str.length);
  918. if (isCasesensitive == undefined || isCasesensitive) {
  919. return tmp == str;
  920. } else {
  921. return tmp.toLowerCase() == str.toLowerCase();
  922. }
  923. };
  924. /**
  925. * 在字符串左边补齐指定数量的字符
  926. *
  927. * @param c
  928. * 指定的字符
  929. * @param count
  930. * 补齐的次数 使用方法: var str="999"; str=str.leftPad("0",3); str将输出 "000999"
  931. * @returns
  932. */
  933. String.prototype.leftPad = function(c, count) {
  934. if (!isNaN(count)) {
  935. var a = "";
  936. for ( var i = this.length; i < count; i++) {
  937. a = a.concat(c);
  938. }
  939. a = a.concat(this);
  940. return a;
  941. }
  942. return null;
  943. };
  944. /**
  945. * 在字符串右边补齐指定数量的字符
  946. *
  947. * @param c
  948. * 指定的字符
  949. * @param count
  950. * 补齐的次数 使用方法: var str="999"; str=str.rightPad("0",3); str将输出
  951. * "999000"
  952. * @returns
  953. */
  954. String.prototype.rightPad = function(c, count) {
  955. if (!isNaN(count)) {
  956. var a = this;
  957. for ( var i = this.length; i < count; i++) {
  958. a = a.concat(c);
  959. }
  960. return a;
  961. }
  962. return null;
  963. };
  964. /**
  965. * 对html字符进行编码 用法: str=str.htmlEncode();
  966. *
  967. * @returns
  968. */
  969. String.prototype.htmlEncode = function() {
  970. return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g,
  971. "&gt;").replace(/\"/g, "&#34;").replace(/\'/g, "&#39;");
  972. };
  973. /**
  974. * 对html字符串解码 用法: str=str.htmlDecode();
  975. *
  976. * @returns
  977. */
  978. String.prototype.htmlDecode = function() {
  979. return this.replace(/\&amp\;/g, '\&').replace(/\&gt\;/g, '\>').replace(
  980. /\&lt\;/g, '\<').replace(/\&quot\;/g, '\'').replace(/\&\#39\;/g,
  981. '\'');
  982. };
  983. /**
  984. * 对json中的特殊字符进行转义
  985. */
  986. String.prototype.jsonEscape = function(){
  987. return this.replace(/\"/g, "&quot;").replace(/\n/g,"&nuot;");
  988. };
  989. /**
  990. * 对json中的特殊字符进行转义
  991. */
  992. String.prototype.jsonUnescape = function(){
  993. return this.replace(/&quot;/g, "\"").replace(/&nuot;/g,"\n");
  994. };
  995. /**
  996. * 字符串替换
  997. *
  998. * @param s1
  999. * 需要替换的字符
  1000. * @param s2
  1001. * 替换的字符。
  1002. * @returns
  1003. */
  1004. String.prototype.replaceAll = function(s1, s2) {
  1005. return this.replace(new RegExp(s1, "gm"), s2);
  1006. };
  1007. /**
  1008. * 获取url参数
  1009. *
  1010. * @returns {object}
  1011. */
  1012. String.prototype.getArgs = function() {
  1013. var args = {};
  1014. if(this.indexOf("?")>-1){
  1015. var argStr = this.split("?")[1],
  1016. argAry = argStr.split("&");
  1017. for(var i=0,c;c=argAry[i++];){
  1018. var pos = c.indexOf("=");
  1019. if(pos==-1)continue;
  1020. var argName = c.substring(0,pos),
  1021. argVal = c.substring(pos+1);
  1022. argVal = decodeURIComponent(argVal);
  1023. args[argName] = argVal;
  1024. }
  1025. }
  1026. return args;
  1027. };
  1028. /**
  1029. * var str=String.format("姓名:{0},性别:{1}","ray","男");
  1030. * alert(str);
  1031. * @returns
  1032. */
  1033. String.format=function(){
  1034. var template=arguments[0];
  1035. var args=arguments;
  1036. var str=template.replace(/\{(\d+)\}/g,function(m,i){
  1037. var k=parseInt(i)+1;
  1038. return args[k];
  1039. });
  1040. return str;
  1041. };
  1042. /**
  1043. * 字符串操作 使用方法: var sb=new StringBuffer(); sb.append("aa"); sb.append("aa"); var
  1044. * str=sb.toString();
  1045. *
  1046. * @returns {StringBuffer}
  1047. */
  1048. function StringBuffer() {
  1049. this.content = new Array;
  1050. }
  1051. StringBuffer.prototype.append = function(str) {
  1052. this.content.push(str);
  1053. };
  1054. StringBuffer.prototype.toString = function() {
  1055. return this.content.join("");
  1056. };
  1057. /**
  1058. * 日期格式化
  1059. * 格式 YYYY/yyyy/YY/yy 表示年份
  1060. * MM/M 月份
  1061. * W/w 星期
  1062. * dd/DD/d/D 日期
  1063. * hh/HH/h/H 时间
  1064. * mm/m 分钟
  1065. * ss/SS/s/S 秒
  1066. */
  1067. Date.prototype.Format = function(formatStr)
  1068. {
  1069. var str = formatStr;
  1070. if(formatStr==undefined || formatStr==null){
  1071. str="yyyy-MM-dd";
  1072. }
  1073. var Week = ['日','一','二','三','四','五','六'];
  1074. str=str.replace(/yyyy|YYYY/,this.getFullYear());
  1075. str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
  1076. str=str.replace(/MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString():'0' + (this.getMonth()+1));
  1077. str=str.replace(/M/g,(this.getMonth()+1));
  1078. str=str.replace(/w|W/g,Week[this.getDay()]);
  1079. str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
  1080. str=str.replace(/d|D/g,this.getDate());
  1081. str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
  1082. str=str.replace(/h|H/g,this.getHours());
  1083. str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
  1084. str=str.replace(/m/g,this.getMinutes());
  1085. str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
  1086. str=str.replace(/s|S/g,this.getSeconds());
  1087. return str;
  1088. };
  1089. /**
  1090. * 求两个时间的天数差 日期格式为 yyyy-MM-dd 或 YYYY-MM-dd HH:mm:ss
  1091. */
  1092. function daysBetween(DateOne,DateTwo)
  1093. {
  1094. var date1 = new Date(DateOne).getTime();
  1095. var date2 = new Date(DateTwo).getTime();;
  1096. if(date1>date2){
  1097. return false;
  1098. }else{
  1099. return true;
  1100. }
  1101. };
  1102. /**
  1103. * 加载多个Script
  1104. * @param resources script file array :['file1.js','file2.js']
  1105. * @param callback function
  1106. * @returns void
  1107. */
  1108. jQuery.getMutilScript = function( resources, callback ) {
  1109. var getScript = function(url,callback){
  1110. $.ajax({
  1111. url: url,
  1112. dataType: "script",
  1113. success: callback,
  1114. async:false
  1115. }).done(function(){
  1116. callback && callback();
  1117. });
  1118. };
  1119. var // reference declaration &amp; localization
  1120. length = resources.length,
  1121. handler = function() { counter++; },
  1122. deferreds = [],
  1123. counter = 0,
  1124. idx = 0;
  1125. for ( ; idx < length; idx++ ) {
  1126. deferreds.push(
  1127. getScript( resources[ idx ], handler )
  1128. );
  1129. }
  1130. jQuery.when(deferreds ).done(function(){
  1131. callback && callback();
  1132. });
  1133. };
  1134. $(function(){
  1135. if($.browser){
  1136. if($.browser.version=='6.0'){
  1137. $("a.tipinfo").each(function(){
  1138. $(this).mouseover(function(){
  1139. $("span",$(this)).show();
  1140. });
  1141. $(this).mouseleave(function(){
  1142. $("span",$(this)).hide();
  1143. });
  1144. });
  1145. }
  1146. }
  1147. });
  1148. jQuery.getWindowRect = function() {
  1149. var myWidth = 0, myHeight = 0;
  1150. if( typeof( window.innerWidth ) == 'number' ) {
  1151. //Non-IE
  1152. myWidth = window.innerWidth;
  1153. myHeight = window.innerHeight;
  1154. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  1155. //IE 6+ in 'standards compliant mode'
  1156. myWidth = document.documentElement.clientWidth;
  1157. myHeight = document.documentElement.clientHeight;
  1158. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  1159. //IE 4 compatible
  1160. myWidth = document.body.clientWidth;
  1161. myHeight = document.body.clientHeight;
  1162. }
  1163. return {
  1164. height:myHeight,
  1165. width:myWidth
  1166. };
  1167. }
  1168. //禁用刷新。通过传入浏览器类型 来指定禁用某个浏览器的刷新
  1169. function forbidF5(exp) {
  1170. var currentExplorer = window.navigator.userAgent;
  1171. //ie "MSIE" ,, firefox "Firefox" ,,Chrome "Chrome",,Opera "Opera",,Safari "Safari"
  1172. if (currentExplorer.indexOf(exp) >= 0) {
  1173. document.onkeydown = function(e) {
  1174. var ev = window.event || e;
  1175. var code = ev.keyCode || ev.which;
  1176. if (code == 116) {
  1177. ev.keyCode ? ev.keyCode = 0 : ev.which = 0;
  1178. cancelBubble = true;
  1179. return false;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. Date.prototype.format = function(format)
  1185. {
  1186. var o = {
  1187. "M+" : this.getMonth()+1, //month
  1188. "d+" : this.getDate(),//day
  1189. "h+" : this.getHours(), //hour
  1190. "m+" : this.getMinutes(), //minute
  1191. "s+" : this.getSeconds(), //second
  1192. "q+" : Math.floor((this.getMonth()+3)/3), //quarter
  1193. "S" : this.getMilliseconds() //millisecond
  1194. }
  1195. if(/(y+)/.test(format))
  1196. format = format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
  1197. for(var k in o)
  1198. if(new RegExp("("+ k +")").test(format))
  1199. format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
  1200. return format;
  1201. }
  1202. /**
  1203. * 调整点击资源菜单时 tab导航栏向上浮动的问题;
  1204. */
  1205. function justifyMargin(height,level,time){
  1206. if(window.navigator.userAgent.indexOf("Chrome")>=0){
  1207. window.setTimeout(function(){
  1208. var tabLinks = "";
  1209. if(level==3){
  1210. tabLinks = $("#framecenter > div.l-tab-links",parent.parent.document);
  1211. if($(".l-layout-left",parent.document)[0] && $("iframe",parent.document).length !=1) return;
  1212. }else{
  1213. tabLinks = $("#framecenter > div.l-tab-links",parent.document)
  1214. }
  1215. tabLinks.css("margin-top",parseInt(tabLinks.css("margin-top"))+ height +"px");
  1216. },time||0)
  1217. }
  1218. }
  1219. /**
  1220. * 修复所有树状结构右键菜单超出屏幕的问题
  1221. * @param e 传入点击事件event
  1222. */
  1223. function justifyRightClickPosition(e){
  1224. var offsetHeight=parseInt($(".l-menu").eq(0).height());
  1225. var ePageY=parseInt(e.pageY);
  1226. var bodyOffsetHeight=parseInt(document.body.offsetHeight);
  1227. var h=$(window).height() ;
  1228. if(offsetHeight+ePageY>=bodyOffsetHeight-10){
  1229. e.pageY=ePageY-offsetHeight;
  1230. }
  1231. }
  1232. /**
  1233. * 修复list页面滚动条的bug ,用法 在对应的页面 的body上面加上 onload事件 如 : <body style="overflow: hidden;" onload="changeHeight()">
  1234. */
  1235. function changeScrollHeight(noNeedFoldHeight,time){
  1236. window.setTimeout(function(){
  1237. $.setCookie("noNeedFoldHeight", noNeedFoldHeight||"");
  1238. if(noNeedFoldHeight) return;
  1239. $("body").css("overflow-y","hidden");
  1240. var currentTable=$(".table-grid.table-list");
  1241. if(! currentTable) return;
  1242. var tableBody=currentTable.parent(),foldHeight=0;
  1243. if(!parent.document.querySelectorAll("#logoImg")[0])foldHeight = $("#searchForm").height();
  1244. var moreHeight = $('.panel-search').attr("moreHeight")||0;
  1245. tableBody.height($(window).height()-tableBody[0].offsetTop-$(".index_menu",$(parent.document)).height()/2-foldHeight-moreHeight);
  1246. tableBody.css("overflow-y","scroll");
  1247. tableBody.css("border","1px solid #A0BDBB");
  1248. currentTable.css("margin-top","0px");
  1249. },time||10)
  1250. }
  1251. /**
  1252. * 获取元素当前页angular的scope by liyj
  1253. * @param obj
  1254. * @returns
  1255. */
  1256. function getScope(obj){
  1257. obj=(obj&&$(obj))||$("[ng-controller]");
  1258. obj=(obj[0]?obj:$("body"));
  1259. return obj.scope();
  1260. }
  1261. /**
  1262. * 将字符串转为json对象。
  1263. * @param jsonStr
  1264. * @param type 可不填写
  1265. * @returns
  1266. */
  1267. function parseToJson(jsonStr,type){
  1268. type=type||1;
  1269. if(jsonStr === "") return;
  1270. try{
  1271. switch(type){
  1272. case 1:
  1273. return eval("("+jsonStr+")");
  1274. break;
  1275. case 2:
  1276. return $.parseJSON(jsonStr);
  1277. break;
  1278. case 3:
  1279. return angular.fromJson(jsonStr);
  1280. break;
  1281. case 4:
  1282. JSON.parse(jsonStr);
  1283. break;
  1284. default:
  1285. console.error("解析json对象错误");
  1286. break;
  1287. }
  1288. }catch(e){
  1289. return parseToJson(jsonStr,type+1);
  1290. }
  1291. }
  1292. //在鼠标停留的地方插入text
  1293. function insertText(obj,str) {
  1294. if (document.selection) {
  1295. var sel = document.selection.createRange();
  1296. sel.text = str;
  1297. } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
  1298. var startPos = obj.selectionStart,
  1299. endPos = obj.selectionEnd,
  1300. cursorPos = startPos,
  1301. tmpStr = obj.value;
  1302. obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
  1303. cursorPos += str.length;
  1304. obj.selectionStart = obj.selectionEnd = cursorPos;
  1305. } else {
  1306. obj.value += str;
  1307. }
  1308. }
  1309. /**
  1310. * 通过scope中取得ng-model对应的属性值
  1311. * @param obj 控件对象
  1312. * @param exp 表示ngModel (可选) 列如 editingField.option.numberFormat.isShowComdify
  1313. * @param scope (可选)
  1314. * @returns
  1315. */
  1316. function getValByScope(obj,exp,scope){
  1317. if(obj) obj=angular.element(obj);
  1318. if(!scope&&!obj) return;
  1319. scope=scope||obj.scope();
  1320. var ngModel=exp||(obj&&(obj.attr("ht-model-true")||obj.attr("ng-model")));
  1321. if(!ngModel) {
  1322. if(obj&&(obj.attr("type")=="checkbox"||obj.attr("type")=="radio")){
  1323. if(obj.is(":checked")) return obj.val();
  1324. else return "";
  1325. }else return obj.val();
  1326. }
  1327. //判断是否是获取复选框的值
  1328. if(ngModel.indexOf("__tempCheckBoxVal")!=-1){
  1329. ngModel=obj.attr("ht-checkbox");
  1330. }
  1331. try{
  1332. if(scope){
  1333. var str="scope."+ngModel;
  1334. return eval("("+str+")");
  1335. }else{
  1336. return obj.val();
  1337. }
  1338. }catch(e){
  1339. return "";
  1340. }
  1341. }
  1342. function delSubRow(){
  1343. $("input:checked").closest("[var='templTr']").remove();
  1344. }
  1345. function checkTr(el){
  1346. var ck = $("input[type='checkbox']",$(el));
  1347. ck.attr("checked",!ck.attr("checked"));
  1348. }
  1349. /**
  1350. * 给控件的scope赋值
  1351. * @param obj 控件对象 (当传入exp时,obj可以传入空值)
  1352. * @param val 值
  1353. * @param time 延迟时间(可选)
  1354. * @param exp 表示ngModel (可选) 列如 editingField.option.numberFormat.isShowComdify
  1355. */
  1356. function setValToScope(obj,val,time,exp,scope){
  1357. __setValTimes = 0;
  1358. if(time){ // 加上时间延迟 是为了处理在easyUI界面没有加载成功的情况下 数据赋值失败的问题
  1359. window.setTimeout(fun,time);
  1360. }else{
  1361. fun();
  1362. }
  1363. function fun(){
  1364. if(obj&&!scope){
  1365. obj=angular.element(obj);
  1366. scope=obj.scope();
  1367. }
  1368. if(!scope) return;
  1369. ngModel=exp||(obj&&(obj.attr("ht-model-true")||obj.attr("ng-model")));
  1370. if(!ngModel) return;
  1371. var exps=ngModel.split("."),tempModel=ngModel;
  1372. if(ngModel.indexOf("data")==0&&ngModel.indexOf(".sub_")>0){
  1373. var sub_model = $.extend([],exps);
  1374. sub_model.splice(exps.length-1,1);
  1375. var subModelVals = getValByScope(null,sub_model.join("."),scope),tempScope = "";
  1376. if(!subModelVals){
  1377. subModelVals = getValByScope(null,sub_model.join("."),scope.$parent);
  1378. tempScope = scope.$parent;
  1379. }else{
  1380. tempScope = scope;
  1381. }
  1382. if(subModelVals){
  1383. if(subModelVals instanceof Array){
  1384. for(var i =0;i<subModelVals.length;i++){
  1385. subModelVals[i][targetParam] = val;
  1386. }
  1387. setValToScope(null,subModelVals,null,sub_model.join("."),tempScope);
  1388. return ;
  1389. }
  1390. }
  1391. }
  1392. setVal();
  1393. __setValTimes = 0;
  1394. function setVal(){
  1395. try{
  1396. eval("("+"scope."+ngModel+"=val"+")");
  1397. obj&&obj.attr("ng-model")&&obj.val(val);
  1398. if(!scope.$$phase){
  1399. scope.$digest();
  1400. }
  1401. }catch(e){
  1402. if(__setValTimes>20) return ;
  1403. setTempVal();
  1404. __setValTimes++;
  1405. tempModel=ngModel;
  1406. exps=ngModel.split(".");
  1407. setVal();
  1408. }
  1409. }
  1410. function setTempVal(){// a.b.c
  1411. try{
  1412. eval("("+"scope."+tempModel+"={}"+")");
  1413. }catch(e){
  1414. tempModel=exps.remove(exps[exps.length-1]).join(".");
  1415. setTempVal();
  1416. }
  1417. }
  1418. }
  1419. }
  1420. /**
  1421. * 序列化查询参数
  1422. * @param {} form
  1423. * @return {}
  1424. */
  1425. function serializeObject(form){
  1426. var o = {};
  1427. var a = $(form).serializeArray();
  1428. $.each(a, function() {
  1429. if (o[this.name]) {
  1430. if (!o[this.name].push) {
  1431. o[this.name] = [o[this.name]];
  1432. }
  1433. o[this.name].push(this.value || '');
  1434. } else {
  1435. o[this.name] = this.value || '';
  1436. }
  1437. });
  1438. return o;
  1439. }
  1440. function renderDtype(type){
  1441. <!--DTYPE(下发状态):0下发,1上报,2省来文,3市来文,4市上报,5县区上报,6乡镇上报-->
  1442. var typeArray=new Array("下发公文","上报公文","省来文","市来文","市上报文件","县区上报文件","乡镇上报文件");
  1443. return typeArray[type];
  1444. }