publicfn.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 
  2. /*
  3. * 爽客邦公用方法
  4. */
  5. // 验证HOST合法性
  6. const verificationHost = (host) =>{
  7. const reg = /^https:\/\/ap.kexiaoshuang.com/g;
  8. return reg.test(host);
  9. };
  10. // 验证手机号码格式
  11. const verificationphonenumber = (phonenumber) =>{
  12. const reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
  13. return reg.test(phonenumber);
  14. };
  15. // 验证手机号码格式
  16. const verificationIdnumber = (idnumber) =>{
  17. const reg = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
  18. return reg.test(idnumber);
  19. };
  20. // 验证手机号码格式
  21. const verificationbankcardId = (bankcardId) =>{
  22. const reg = /^[1-9]\d{9,29}$/;
  23. return reg.test(bankcardId);
  24. };
  25. // 提示函数
  26. const tips = (tips,position = "bottom") => {
  27. vant.Toast({message: tips,position});
  28. };
  29. // 非汉字验证
  30. const verificationFront = (name) =>{
  31. const reg = /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/;
  32. return reg.test(name);
  33. }
  34. //- 手机号码验证
  35. const verification = (mobilenumber) => {
  36. if(mobilenumber === '') {
  37. tips('请输入手机号码!');
  38. return true;
  39. }
  40. if(!verificationphonenumber(mobilenumber)){
  41. tips('手机号码格式错误!');
  42. return true;
  43. };
  44. };
  45. // 密码校验
  46. const verificationpassword = function(pwd){
  47. if(pwd.length < 6 || pwd.length > 16) {
  48. tips('密码长度应为6~16位');
  49. return true;
  50. }
  51. };
  52. // 验证码校验
  53. const verificationmobilecode = function(code){
  54. if(code.length !== 6) {
  55. tips('短信验证码长度应为6位');
  56. return true;
  57. }
  58. };
  59. // 按钮防抖
  60. const undebounce = function(func,delay = 300) {
  61. let timer;
  62. return function() {
  63. const args = arguments;
  64. const that = this;
  65. if (timer) clearTimeout(timer);
  66. timer = setTimeout(() => {
  67. func.apply(that,args)
  68. }, delay)
  69. }
  70. };
  71. // 保留两位小数
  72. Vue.filter('tofixed2', function (value) {
  73. return value.toFixed(2);
  74. });
  75. const tofixed2 = function (value) {
  76. return value.toFixed(2);
  77. };
  78. // 隐藏中间位
  79. const hidemiddlenum = function (str,frontLen,endLen = 0) {
  80. var len = str.length-frontLen-endLen;
  81. var xing = '';
  82. for (var i=0;i<len;i++) {
  83. xing+='*';
  84. }
  85. return str.substring(0,frontLen)+xing+str.substring(str.length-endLen);
  86. };
  87. // 模拟app方法接口
  88. // 补零函数
  89. const fillzero = function(num) {
  90. if(num < 10) {
  91. return '0'+ num;
  92. }else{
  93. return num;
  94. };
  95. };
  96. const formatDate = function(year,mounth,daile = ''){
  97. year = fillzero(year);
  98. mounth = fillzero(mounth);
  99. daile = daile !== '' ? fillzero(daile) : ''
  100. return ''+year + mounth + daile;
  101. };
  102. // 底部导航栏是否显示
  103. const bottomtabisshow = false;
  104. // 顶部标题栏是否显示
  105. const toptitleisshow = false;
  106. /*判断访问终端*/
  107. const browsertype = {
  108. versions:function(){
  109. var u = navigator.userAgent, app = navigator.appVersion;
  110. return {
  111. trident: u.indexOf('Trident') > -1, /*IE内核*/
  112. presto: u.indexOf('Presto') > -1, /*opera内核*/
  113. webKit: u.indexOf('AppleWebKit') > -1, /*苹果、谷歌内核*/
  114. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,/*火狐内核*/
  115. mobile: !!u.match(/AppleWebKit.*Mobile.*/), /*是否为移动终端*/
  116. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), /*ios终端*/
  117. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, /*android终端或者uc浏览器*/
  118. iPhone: u.indexOf('iPhone') > -1 , /*是否为iPhone或者QQHD浏览器*/
  119. iPad: u.indexOf('iPad') > -1, /*是否iPad*/
  120. webApp: u.indexOf('Safari') == -1, /*是否web应该程序,没有头部与底部*/
  121. weixin: u.toLowerCase().indexOf('micromessenger') > -1 /*是否是微信*/
  122. };
  123. }(),
  124. language:(navigator.browserLanguage || navigator.language).toLowerCase()
  125. };
  126. // 扫描二维码函数
  127. const scan = function (value,fn) {
  128. value = PublicLib.getCookieInfo("ScanContent") && JSON.parse(PublicLib.getCookieInfo("ScanContent")).scan
  129. if(value !== '') {
  130. fn();
  131. }
  132. PublicLib.putCookieInfo('ScanContent', '');
  133. };
  134. // 加密函数
  135. const encryption = function(val){
  136. return PublicLib.encryptByDES(val);
  137. };
  138. function deviceDetection() {
  139. const ua = navigator.userAgent
  140. let osVersion = ''
  141. let device = ''
  142. try {
  143. if (/android/i.test(ua)) {
  144. device = 'android'
  145. osVersion = ua.match(/Android\s+([\d.]+)/i)[0].replace('Android ', '')
  146. } else if (/ipad|iphone|ipod/i.test(ua)) {
  147. device = 'ios'
  148. osVersion = ua.match(/OS\s+([\d_]+)/i)[0].replace(/_/g, '.').replace('OS ', '')
  149. }
  150. } catch (err) {
  151. /* istanbul ignore next line */
  152. console.error(err)
  153. }
  154. return { osVersion, device }
  155. };
  156. // 判断是否为刘海屏
  157. function isFringe() {
  158. const { device } = deviceDetection()
  159. // const { screen } = global
  160. return device === 'ios' &&
  161. ((screen.width === 375 && screen.height === 812) || (screen.width === 414 && screen.height === 896) || (screen.width === 375 && screen.height === 812) || (screen.width === 390 && screen.height === 844) || (screen.width === 428 && screen.height === 926))
  162. };
  163. if(isFringe()){
  164. if(document.querySelector('.iphonetitle')){
  165. document.querySelector('.iphonetitle').className += ' topBangs';
  166. };
  167. if(document.querySelector('.indexy')){
  168. document.querySelector('.indexy').className += ' topindex';
  169. };
  170. }else{
  171. if(document.querySelector('.iphonetitle')){
  172. document.querySelector('.iphonetitle').className += ' untopBangs';
  173. };
  174. if(document.querySelector('.indexy')){
  175. document.querySelector('.indexy').className += ' untopindex';
  176. };
  177. };
  178. Host = 'https://test.bs.shuangkebang.com/';
  179. const showHost = 'https://test.bs.shuangkebang.com';
  180. // isWeb = true;