common.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. var priceshow = false;
  2. var timeshow = false;
  3. function priceTime(){
  4. $(".pricefat").mouseover(function(){
  5. if(!$(".pricefat").hasClass("active")){
  6. $("#minprice").css({"border-color":"#2cb7ca"});
  7. $("#maxprice").css({"border-color":"#2cb7ca"});
  8. $(".pricebut").show();
  9. $(".pricefat").addClass("customtime-active");
  10. }
  11. }).mouseout(function(){
  12. if(!$(".pricefat").hasClass("active")){
  13. if(!priceshow){
  14. $("#minprice").css({"border-color":""});
  15. $("#maxprice").css({"border-color":""});
  16. $(".pricebut").hide();
  17. $(".pricefat").removeClass("customtime-active");
  18. }
  19. }
  20. })
  21. $("#minprice,#maxprice").blur(function(){
  22. if(!priceshow&&!$(".pricefat").hasClass("active")){
  23. $("#minprice").css({"border-color":""});
  24. $("#maxprice").css({"border-color":""});
  25. $(".pricebut").hide();
  26. $(".pricefat").removeClass("customtime-active");
  27. }
  28. })
  29. $("#minprice").click(function(){
  30. priceshow=true;
  31. $(".pricebut").show();
  32. $(".pricefat").addClass("customtime-active");
  33. })
  34. $("#maxprice").click(function(){
  35. priceshow=true;
  36. $(".pricebut").show();
  37. $(".pricefat").addClass("customtime-active");
  38. })
  39. //
  40. $(".timerInput").mouseover(function(){
  41. if(!$(".timerInput").hasClass("active")){
  42. $("#starttime").css({"border-color":"#2cb7ca"});
  43. $("#endtime").css({"border-color":"#2cb7ca"});
  44. $("#timebut").show();
  45. $(".timerInput").addClass("customtime-active");
  46. }
  47. }).mouseout(function(){
  48. if(!$(".timerInput").hasClass("active")){
  49. if(!timeshow){
  50. $("#starttime").css({"border-color":""});
  51. $("#endtime").css({"border-color":""});
  52. $("#timebut").hide();
  53. $(".timerInput").removeClass("customtime-active");
  54. }
  55. }
  56. })
  57. //
  58. $("#starttime").click(function(){
  59. timeshow = true;
  60. $("#timebut").show();
  61. $(".timerInput").addClass("customtime-active");
  62. $('.custom-select').css("border-color", '#e0e0e0').children('.icon-arrow').removeClass('up')
  63. $('.custom-select').siblings().hide()
  64. })
  65. $("#endtime").click(function(){
  66. timeshow = true;
  67. $("#timebut").show();
  68. $(".timerInput").addClass("customtime-active");
  69. $('.custom-select').css("border-color", '#e0e0e0').children('.icon-arrow').removeClass('up')
  70. $('.custom-select').siblings().hide()
  71. })
  72. }
  73. function showToast (text, duration) {
  74. if (!text) return
  75. duration = duration || 2000
  76. var _html = ""
  77. _html+='<div id="j-toast"><div class="mask" style="background-color: transparent;"></div><div class="toast-container">'
  78. _html+='<span>' + text + '</span></div></div>'
  79. $('body').append(_html)
  80. setTimeout(function(){
  81. $('#j-toast').fadeOut().remove();
  82. }, duration)
  83. }
  84. var EasyAlert = {
  85. timeout: null,
  86. waitTime: 1000,
  87. show: function(text,css,waitTime){
  88. if(this.timeout != null){
  89. clearTimeout(this.timeout);
  90. this.hide();
  91. this.timeout = null;
  92. }
  93. var thisClass = this;
  94. this.timeout = setTimeout(function(){
  95. thisClass.hide();
  96. thisClass.timeout = null;
  97. },waitTime?waitTime:this.waitTime);
  98. $("body").append('<div class="easyalert" id="easyAlert">'+text+'</div>');
  99. if(typeof(css) != "undefined"&&css!=""){
  100. $("#easyAlert").css(css);
  101. }
  102. $("#easyAlert").css({"left":"50%","margin-top":-($("#easyAlert").outerHeight()/2),"margin-left":-($("#easyAlert").outerWidth()/2)}).show();
  103. },
  104. hide: function(){
  105. $("#easyAlert").remove();
  106. }
  107. }
  108. var EasyPopup = function(id){
  109. this.id = id;
  110. var thisClass = this;
  111. document.getElementById(id).ontap = function(e){
  112. if(e.target.id == id){
  113. thisClass.hide();
  114. }
  115. }
  116. this.show = function(){
  117. $("#"+this.id).fadeIn();
  118. var mainObj = $("#"+id+">div:first");
  119. mainObj.css({"margin-top":-(mainObj.outerHeight()/2 + 35)});
  120. },
  121. this.hide = function(){
  122. $("#"+this.id).fadeOut();
  123. }
  124. }
  125. // 部分页面没有全局工具函数
  126. if (typeof utils !== 'object') {
  127. utils = {}
  128. }
  129. Date.prototype.pattern = function (fmt) {
  130. if (!fmt) return ''
  131. var o = {
  132. 'y+': this.getFullYear(),
  133. 'M+': this.getMonth() + 1, // 月份
  134. 'd+': this.getDate(), // 日
  135. // 12小时制
  136. 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时
  137. // 24小时制
  138. 'H+': this.getHours(), // 小时
  139. 'm+': this.getMinutes(), // 分
  140. 's+': this.getSeconds(), // 秒
  141. 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
  142. 'S': this.getMilliseconds(), // 毫秒
  143. 'E+': this.getDay(), // 周
  144. };
  145. var week = {
  146. '0': '日',
  147. '1': '一',
  148. '2': '二',
  149. '3': '三',
  150. '4': '四',
  151. '5': '五',
  152. '6': '六'
  153. };
  154. if (/(y+)/.test(fmt)) {
  155. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  156. }
  157. if (/(E+)/.test(fmt)) {
  158. fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '星期' : '周') : '') + week[
  159. this.getDay() + '']);
  160. }
  161. for (var k in o) {
  162. if (new RegExp('(' + k + ')').test(fmt)) {
  163. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k])
  164. .length)));
  165. }
  166. }
  167. return fmt;
  168. }
  169. utils.dateFromNow = function (originTime, useOld) {
  170. if (!originTime) return
  171. // 原始时间 - 传入的时间戳
  172. var originTimeStamp = +new Date(originTime)
  173. // 当前时间戳
  174. var nowTimeStamp = +new Date()
  175. // 时间戳相差多少
  176. var diffTimeStamp = nowTimeStamp - originTimeStamp
  177. var postfix = diffTimeStamp > 0 ? '前' : '后'
  178. // 求绝对值 ms(毫秒)
  179. var diffTimeStampAbsMs = Math.abs(diffTimeStamp)
  180. var diffTimeStampAbsS = Math.round(diffTimeStampAbsMs / 1000)
  181. // 10天的秒数
  182. var days11 = 11 * 24 * 60 * 60
  183. // var dataMap = {
  184. // zh: ['年', '个月', '星期', '天', '小时', '分钟', '秒'],
  185. // number: [365*24*60*60, 30*24*60*60, 7*24*60*60, 24*60*60, 60*60, 60, 1]
  186. // }
  187. var dataMap = {
  188. zh: ['天', '小时', '分钟', '秒'],
  189. number: [24 * 60 * 60, 60 * 60, 60, 1]
  190. }
  191. var timeString = ''
  192. // 10天前
  193. var tenDaysAgo = diffTimeStampAbsS > days11
  194. // 是否是当天
  195. var isCurrentDay = new Date(originTimeStamp).pattern('yyyy.MM.dd') === new Date().pattern('yyyy.MM.dd')
  196. var condition = !isCurrentDay
  197. if (useOld) {
  198. condition = tenDaysAgo
  199. }
  200. if (condition) {
  201. // 不是当天,则使用正常日期显示
  202. var originDate = new Date(originTimeStamp)
  203. var nowDate = new Date()
  204. // 是否同年
  205. var sameYear = originDate.getFullYear() === nowDate.getFullYear()
  206. // 如果是当年,则不显示年
  207. var patternString = sameYear ? 'MM-dd' : 'yyyy-MM-dd'
  208. timeString = originDate.pattern(patternString)
  209. } else {
  210. for (var i = 0; i < dataMap.number.length; i++) {
  211. var inm = Math.floor(diffTimeStampAbsS / dataMap.number[i])
  212. if (inm != 0) {
  213. timeString = inm + dataMap.zh[i] + postfix
  214. break
  215. }
  216. }
  217. }
  218. return timeString
  219. }
  220. //计算时差
  221. function timeDiff(date){
  222. var date1 = date;//开始时间
  223. var date2 = new Date();//结束时间
  224. var date3 = date2.getTime()-date1.getTime();//时间差的毫秒数
  225. //计算出相差天数
  226. var days = Math.floor(date3/(24*3600*1000));
  227. //计算出小时数
  228. var leave1 = date3%(24*3600*1000);//计算天数后剩余的毫秒数
  229. var hours = Math.floor(leave1/(3600*1000));
  230. //计算相差分钟数
  231. var leave2 = leave1%(3600*1000);//计算小时数后剩余的毫秒数
  232. var minutes = Math.floor(leave2/(60*1000));
  233. //计算相差秒数
  234. var td = "30秒前";
  235. if(days > 0){
  236. if (days > 10) {
  237. var date1year = date1.getFullYear();
  238. var date2year = date2.getFullYear();
  239. var date1month = date1.getMonth()+1;
  240. var date1day = date1.getDate();
  241. if(date1month < 10){
  242. date1month ="0"+date1month;
  243. }
  244. if(date1day < 10){
  245. date1day ="0"+date1day;
  246. }
  247. if (date1year<date2year){
  248. td = date1.getFullYear()+"-"+date1month+"-"+date1day;
  249. }else{
  250. td = date1month+"-"+date1day;
  251. }
  252. } else {
  253. td = days+"天前"
  254. }
  255. }else if(hours > 0){
  256. td = hours+"小时前";
  257. }else if(minutes > 0){
  258. td = minutes+"分钟前";
  259. }
  260. return td;
  261. }
  262. function redirect(zbadd,link,sid,sds){
  263. if(link != null && typeof(link) != "undefined"){
  264. link = link.replace(/\n/g,"");
  265. if(!/^http/.test(link)){
  266. link="http://"+link
  267. }
  268. }
  269. if(sds){
  270. window.location.href="/article/content/"+sid+".html?keywords="+encodeURIComponent(sds);
  271. }else{
  272. window.location.href="/article/content/"+sid+".html";
  273. }
  274. }
  275. function newredirect(zbadd,link,sid,sds,index){
  276. if(link != null && typeof(link) != "undefined"){
  277. link = link.replace(/\n/g,"");
  278. if(!/^http/.test(link)){
  279. link="http://"+link
  280. }
  281. }
  282. var pt = ""
  283. if (index==1){
  284. pt="projectMatch=项目匹配"
  285. }
  286. if(sds){
  287. pt = "&"+pt
  288. window.location.href="/article/content/"+sid+".html?keywords="+encodeURIComponent(sds)+pt;
  289. }else{
  290. window.location.href="/article/content/"+sid+".html"+pt;
  291. }
  292. }
  293. function pcredirect(link,sid){
  294. window.open("/pcdetail/"+sid+".html");
  295. }
  296. var isNumber = /^[0-9]+$/
  297. var isLetter = /^[a-zA-Z]+$/
  298. function isRegExp (value) {
  299. return Object.prototype.toString.call(value) === '[object RegExp]'
  300. }
  301. function keyWordHighlight (value, oldChars, newChar) {
  302. if(typeof(oldChars) == "undefined" || oldChars == null || typeof(newChar) == "undefined" || newChar == null || newChar == "" || oldChars == '略'){
  303. return value;
  304. }
  305. var array = [];
  306. if(oldChars instanceof Array){
  307. array = oldChars.concat();
  308. }else{
  309. array.push(oldChars);
  310. }
  311. // 非字符串替换集合
  312. var notStrReplacer = []
  313. for (var i = 0; i < array.length; i++) {
  314. if (!array[i]) {
  315. continue
  316. } else {
  317. if (isRegExp(array[i])) {
  318. // 正则直接替换
  319. // 注意:该正则中必须包含至少一个分组匹配,分组中的内容用来替换
  320. notStrReplacer.push(array[i])
  321. array[i] = ''
  322. } else {
  323. // 字符串替换
  324. array[i] = array[i].replace(/([\$\(\)\*\+\.\[\]\?\/\\\^\{\}\|])/g, '\\$1').replace(/\s+/g, '')
  325. }
  326. // array[i] = array[i].replace(/\$/g,"\\$");
  327. // array[i] = array[i].replace(/\(/g,"\\(");
  328. // array[i] = array[i].replace(/\)/g,"\\)");
  329. // array[i] = array[i].replace(/\*/g,"\\*");
  330. // array[i] = array[i].replace(/\+/g,"\\+");
  331. // array[i] = array[i].replace(/\./g,"\\.");
  332. // array[i] = array[i].replace(/\[/g,"\\[");
  333. // array[i] = array[i].replace(/\]/g,"\\]");
  334. // array[i] = array[i].replace(/\?/g,"\\?");
  335. // array[i] = array[i].replace(/\\/g,"\\");
  336. // array[i] = array[i].replace(/\//g,"\\/");
  337. // array[i] = array[i].replace(/\^/g,"\\^");
  338. // array[i] = array[i].replace(/\{/g,"\\{");
  339. // array[i] = array[i].replace(/\}/g,"\\}");
  340. // array[i] = array[i].replace(/\|/g,"\\|");
  341. }
  342. }
  343. // 数组去空
  344. var lastArr = []
  345. array.forEach(function (item) {
  346. if (item) {
  347. lastArr.push(item)
  348. }
  349. })
  350. if (lastArr.length === 0 && notStrReplacer.length === 0) {
  351. return value
  352. }
  353. lastArr = lastArr.sort(function (a, b) {
  354. return b.length - a.length
  355. })
  356. if (notStrReplacer.length) {
  357. for (var j = 0; j < notStrReplacer.length; j++) {
  358. // 正则替换
  359. value = value.replace(notStrReplacer[j], newChar)
  360. }
  361. }
  362. if (lastArr.length) {
  363. value = value.replace(new RegExp('(' + lastArr.join('|') + ')', 'gmi'), newChar)
  364. }
  365. return value
  366. }
  367. function getWxVersion(){
  368. var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
  369. if(!wechatInfo) {
  370. return null;
  371. }
  372. return wechatInfo[1];
  373. }
  374. /**
  375. * 设置光标在短连接输入框中的位置
  376. * @param inpObj 输入框
  377. * @param pos
  378. */
  379. function setCursorPos(inpObj, pos){
  380. if(navigator.userAgent.indexOf("MSIE") > -1){
  381. var range = document.selection.createRange();
  382. var textRange = inpObj.createTextRange();
  383. textRange.moveStart('character',pos);
  384. textRange.collapse();
  385. textRange.select();
  386. }else{
  387. inpObj.setSelectionRange(pos,pos);
  388. }
  389. }
  390. /**
  391. * 获取光标在短连接输入框中的位置
  392. * @param inpObj 输入框
  393. */
  394. function getCursorPos(inpObj){
  395. if(navigator.userAgent.indexOf("MSIE") > -1) { // IE
  396. var range = document.selection.createRange();
  397. range.text = '';
  398. range.setEndPoint('StartToStart',inpObj.createTextRange());
  399. return range.text.length;
  400. } else {
  401. return inpObj.selectionStart;
  402. }
  403. }
  404. //获取url中参数
  405. function getUrlParam(name){
  406. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  407. var r = window.location.search.substr(1).match(reg);
  408. if(r != null)
  409. return unescape(r[2]);
  410. return null;
  411. }
  412. /******* 获取url参数(正则)********/
  413. function getParam(name) {
  414. var search = document.location.search;
  415. // alert(search);
  416. var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
  417. var matcher = pattern.exec(search);
  418. var items = null;
  419. if (null != matcher) {
  420. try {
  421. items = decodeURIComponent(decodeURIComponent(matcher[1]));
  422. } catch (e) {
  423. try {
  424. items = decodeURIComponent(matcher[1]);
  425. } catch (e) {
  426. items = matcher[1];
  427. }
  428. }
  429. }
  430. return items;
  431. };
  432. //获取滚动条宽度
  433. function getScrollWidth() {
  434. var noScroll, scroll, oDiv = document.createElement("DIV");
  435. oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
  436. noScroll = document.body.appendChild(oDiv).clientWidth;
  437. oDiv.style.overflowY = "scroll";
  438. scroll = oDiv.clientWidth;
  439. document.body.removeChild(oDiv);
  440. return noScroll-scroll;
  441. }
  442. //表头固定
  443. var TableHeadFixed = function(className,isminus,flag,pageName, callback){
  444. if (typeof callback !== 'function') {
  445. callback = function () {}
  446. }
  447. if(typeof(className) == "undefined"){
  448. className = "tabContainer-2";
  449. }
  450. if(typeof(isminus) == "undefined"){
  451. isminus = true;
  452. }
  453. if(typeof(flag) == "undefined"){
  454. flag = true;
  455. }
  456. var cHeight = document.body.clientHeight;
  457. if(cHeight <= 0){
  458. cHeight = 500;
  459. }
  460. var thisFlag = false;
  461. var prevSelectType = null;
  462. $(window).scroll(function(event){
  463. if(!$("#right-table").hasClass("active") && flag){
  464. return;
  465. }
  466. //超级搜索页面增加处理逻辑
  467. if(pageName == "supsearch"){
  468. if(prevSelectType != selectType){
  469. thisFlag = false;
  470. }
  471. prevSelectType = selectType;
  472. if(selectType == "all"){
  473. className = "tabContainer"
  474. }else{
  475. className = "tabContainer-2";
  476. }
  477. }
  478. var tableHeight = $("."+className).outerHeight();
  479. if(tableHeight <= cHeight){
  480. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  481. $("."+className+" .lucene-table>table:first").css("top",'64px');
  482. callback(false)
  483. thisFlag = false;
  484. return;
  485. }
  486. var offsetTop = $("."+className).offset().top;
  487. var scrollTop = $(this).scrollTop();
  488. var oTop = offsetTop;
  489. var ooTop = offsetTop;
  490. if(isminus){
  491. oTop+=20;
  492. ooTop-=20;
  493. }
  494. if(scrollTop >= (oTop-64)){
  495. if(ooTop + tableHeight - scrollTop -20 <= cHeight){
  496. if(!thisFlag){
  497. $("."+className+" .lucene-table").addClass("tababsolute");
  498. $("."+className+" .lucene-table>table:first").css("top",scrollTop);
  499. }
  500. thisFlag = true;
  501. }else{
  502. if(thisFlag){
  503. $("."+className+" .lucene-table").removeClass("tababsolute");
  504. $("."+className+" .lucene-table>table:first").css("top",'64px');
  505. }
  506. callback(false)
  507. thisFlag = false;
  508. }
  509. $("."+className+" .lucene-table").addClass("tabfixed");
  510. callback(true)
  511. }else{
  512. $("."+className+" .lucene-table").removeClass("tabfixed tababsolute");
  513. $("."+className+" .lucene-table>table:first").css("top",'64px');
  514. callback(false)
  515. thisFlag = false;
  516. }
  517. });
  518. }
  519. //页面跳转输入框光标位置
  520. function moveEnd(obj) {
  521. obj.focus();
  522. var len = obj.value.length;
  523. if (document.selection) {
  524. var sel = obj.createTextRange();
  525. sel.moveStart('character', len);
  526. sel.collapse();
  527. sel.select();
  528. } else if (typeof obj.selectionStart == 'number'
  529. && typeof obj.selectionEnd == 'number') {
  530. obj.selectionStart = obj.selectionEnd = len;
  531. }
  532. }
  533. function mySysIsIos(){
  534. return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  535. }
  536. // 金额转换
  537. function moneyUnit(num, type, lv) {
  538. if (num === '' || num == null || num == undefined || isNaN(num)) return ''
  539. var levelArr = ['元', '万元', '亿元', '万亿元']
  540. if (type === void 0) {
  541. type = 'string';
  542. }
  543. if (lv === void 0) {
  544. lv = 0;
  545. }
  546. if (num === 0) {
  547. if (type === 'string') {
  548. return '0';
  549. }
  550. if (type === 'lv') {
  551. return levelArr[lv];
  552. }
  553. if (type === 'number') {
  554. return 0;
  555. }
  556. if (type === 'index') {
  557. return lv;
  558. }
  559. }
  560. var result = num / Math.pow(10000, lv);
  561. if (result > 10000 && lv < 2) {
  562. return this.moneyUnit(num, type, lv + 1)
  563. } else {
  564. if (type === 'string') {
  565. return String(Math.floor(result * 100) / 100).replace('.00', '') + levelArr[lv];
  566. }
  567. if (type === 'lv') {
  568. return levelArr[lv];
  569. }
  570. if (type === 'index') {
  571. return lv;
  572. }
  573. if (type === 'number') {
  574. return String(Math.floor(result * 100) / 100).replace('.00', '');
  575. }
  576. }
  577. }
  578. /*
  579. * 时间格式化函数(将时间格式化为,2019年08月12日,2019-08-12,2019/08/12的形式)
  580. *
  581. *
  582. * pattern参数(想要什么格式的数据就传入什么格式的数据)
  583. * · 'yyyy-MM-dd' ---> 输出如2019-09-20
  584. * · 'yyyy-MM-dd hh:mm' ---> 输出如2019-09-20 08:20
  585. * · 'yyyy-MM-dd HH:mm:ss' ---> 输出如2019-09-20 18:20:23
  586. * · 'yyyy/MM/dd' ---> 输出如2019/09/20
  587. * · 'yyyy年MM月dd日' ---> 输出如2019年09月20日
  588. * · 'yyyy年MM月dd日 hh时mm分' ---> 输出如2019年09月20日 08时20分
  589. * · 'yyyy年MM月dd日 hh时mm分ss秒' ---> 输出如2019年09月20日 08时20分23秒
  590. * · 'yyyy年MM月dd日 hh时mm分ss秒 EE' ---> 输出如2019年09月20日 08时20分23秒 周二
  591. * · 'yyyy年MM月dd日 hh时mm分ss秒 EEE' ---> 输出如2019年09月20日 08时20分23秒 星期二
  592. *
  593. * 参考: https://www.cnblogs.com/mr-wuxiansheng/p/6296646.html
  594. */
  595. Date.prototype.pattern = function (fmt) {
  596. if (!fmt) return ''
  597. var o = {
  598. 'y+': this.getFullYear(),
  599. 'M+': this.getMonth() + 1, // 月份
  600. 'd+': this.getDate(), // 日
  601. // 12小时制
  602. 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时
  603. // 24小时制
  604. 'H+': this.getHours(), // 小时
  605. 'm+': this.getMinutes(), // 分
  606. 's+': this.getSeconds(), // 秒
  607. 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
  608. 'S': this.getMilliseconds(), // 毫秒
  609. 'E+': this.getDay(), // 周
  610. };
  611. var week = {
  612. '0': '日',
  613. '1': '一',
  614. '2': '二',
  615. '3': '三',
  616. '4': '四',
  617. '5': '五',
  618. '6': '六'
  619. };
  620. if (/(y+)/.test(fmt)) {
  621. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  622. }
  623. if (/(E+)/.test(fmt)) {
  624. fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '星期' : '周') : '') + week[
  625. this.getDay() + '']);
  626. }
  627. for (var k in o) {
  628. if (new RegExp('(' + k + ')').test(fmt)) {
  629. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k])
  630. .length)));
  631. }
  632. }
  633. return fmt;
  634. }
  635. $(function(){
  636. //自定义tap
  637. if("ontouchend" in document){
  638. $(document).on("touchstart", function(e) {
  639. var $target = $(e.target);
  640. $target.data("isMoved", 0);
  641. $target.data("startTime", Date.now());
  642. });
  643. $(document).on("touchmove", function(e) {
  644. var $target = $(e.target);
  645. $target.data("isMoved", 1);
  646. });
  647. $(document).on("touchend", function(e) {
  648. var $target = $(e.target);
  649. var startTime = $target.data("startTime");
  650. if(Date.now()-startTime>200){
  651. return;
  652. }
  653. if($target.data("isMoved") == 1){
  654. return;
  655. }
  656. $target.trigger("tap");
  657. });
  658. }else{
  659. $(document).on("click", function(e) {
  660. var $target = $(e.target);
  661. $target.trigger("tap");
  662. });
  663. }
  664. });
  665. /**
  666. * 根据keys校验object必填项
  667. * @param {Array} keys - 待校验字段keys
  668. * @param {Object} target - 待校验object
  669. * @returns {boolean} - 是否通过
  670. */
  671. function checkRequiredKeys (keys, target) {
  672. try {
  673. // 职位/部门特殊处理, 满足时移除部门校验
  674. if (keys.indexOf('branch') !== -1 && keys.indexOf('position') !== -1) {
  675. if (target['position'] === '总裁' || target['position'] === '总经理') {
  676. keys.splice(keys.indexOf('branch'), 1)
  677. }
  678. }
  679. return !keys.some(function (k) {
  680. var tempValue = target[k]
  681. var result = false
  682. if (typeof tempValue === 'number') {
  683. tempValue = tempValue.toString()
  684. }
  685. if (typeof tempValue === 'string') {
  686. result = tempValue.trim() !== ''
  687. }
  688. if (typeof tempValue === 'boolean') {
  689. result = true
  690. }
  691. return !result
  692. })
  693. } catch (e) {
  694. console.warn(e)
  695. return false
  696. }
  697. }
  698. /**
  699. * 根据keys覆盖object必填项
  700. * @param {Object}target - 指定需替换的object
  701. * @param {Object}now - 数据来源object
  702. * @param {Array}[keys] - 指定需替换的keys
  703. * @returns {Object} - 替换后的object,需注意target已被替换
  704. */
  705. function echoRequiredValues (target, now, keys) {
  706. try {
  707. Object.keys(now).forEach(function (k) {
  708. if (keys && keys.indexOf(k) === -1) {
  709. return
  710. }
  711. if (target.hasOwnProperty(k)) {
  712. target[k] = JSON.parse(JSON.stringify(now[k]))
  713. }
  714. })
  715. return target
  716. } catch (e) {
  717. console.warn(e)
  718. return {}
  719. }
  720. }
  721. /**
  722. * ----S 金额转换 ---
  723. * @desc 同步金额转换函数-与PC、MOBILE 端其他项目保持一致,经过 babel 转化,原始代码参照其他项目
  724. * @date 2022-10-08 目前用于表格中预算、中标金额字段展示格式化
  725. */
  726. /**
  727. * 金额转换
  728. * @param money 金额
  729. * @param config
  730. * @param config.type 类型 full | number | unit
  731. * @param config.level 初始单位索引
  732. * @param config.levelArr 单位数组 ['元', '万', '亿', '万亿']
  733. * @param config.unit 计算单位 10000
  734. * @param config.digit 精度,保留小数位数 2
  735. * @param config.degrade 指定单位索引时,所需精度不够是否降级单位 false
  736. * @returns {*|string|string|number}
  737. */
  738. function recursiveCalculationMoney(money, config, start) {
  739. if (config === void 0) {
  740. config = {};
  741. }
  742. if (start === void 0) {
  743. start = false;
  744. }
  745. var _Object$assign = Object.assign({
  746. type: 'full',
  747. level: 0,
  748. levelArr: ['元', '万元', '亿元', '万亿元'],
  749. digit: 2,
  750. degrade: false,
  751. unit: 10000
  752. }, config),
  753. type = _Object$assign.type,
  754. level = _Object$assign.level,
  755. levelArr = _Object$assign.levelArr,
  756. unit = _Object$assign.unit,
  757. digit = _Object$assign.digit,
  758. degrade = _Object$assign.degrade; // 提取纯数字
  759. var computMoney = String(money).match(/^\d+(\.\d+)?/g) || [0];
  760. computMoney = Number(computMoney[0]); // 是否指定单位索引
  761. var lockUnit = start && level > 0; // 判断是否需要递归单位
  762. if (!lockUnit) {
  763. var canNext = computMoney / Math.pow(unit, level + 1) >= 1 && level + 1 < levelArr.length;
  764. if (canNext) {
  765. return recursiveCalculationMoney(computMoney, {
  766. type: type,
  767. level: level + 1,
  768. levelArr: levelArr,
  769. digit: digit,
  770. degrade: degrade,
  771. unit: unit
  772. });
  773. }
  774. } // 浮点数精度
  775. var digitNumber = Math.pow(10, digit); // 指定单位索引时,如不满足精度要求,是否需要降级单位处理
  776. var computLevel = level;
  777. var needDegrade = degrade && computMoney * digitNumber < Math.pow(unit, level);
  778. if (lockUnit && needDegrade) {
  779. computLevel--;
  780. } // 计算金额
  781. computMoney = Number(String(Math.floor(computMoney / Math.pow(unit, computLevel) * digitNumber) / digitNumber)); // 返回结果
  782. switch (type) {
  783. case 'full':
  784. {
  785. if (computMoney === 0) {
  786. return '';
  787. } else {
  788. return computMoney + levelArr[computLevel];
  789. }
  790. }
  791. case 'unit':
  792. {
  793. return levelArr[computLevel];
  794. }
  795. case 'number':
  796. {
  797. return computMoney;
  798. }
  799. }
  800. }
  801. function tableFormatMoney(money, config) {
  802. if (config === void 0) {
  803. config = {};
  804. }
  805. return recursiveCalculationMoney(money, config, true);
  806. }
  807. /**
  808. * ----E 金额转换 ---
  809. */
  810. // 元素是否在视口中
  811. function isElementVisible (el) {
  812. var rect = el.getBoundingClientRect()
  813. var vWidth = window.innerWidth || document.documentElement.clientWidth
  814. var vHeight = window.innerHeight || document.documentElement.clientHeight
  815. if (
  816. rect.right < 0 ||
  817. rect.bottom < 0 ||
  818. rect.left > vWidth ||
  819. rect.top > vHeight
  820. ) {
  821. return false
  822. }
  823. return true
  824. }