publicfn.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. 
  2. /*
  3. * 爽客邦公用方法
  4. */
  5. // 验证手机号码格式
  6. const verificationphonenumber = (phonenumber) =>{
  7. 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}$/;
  8. return reg.test(phonenumber);
  9. };
  10. // 验证手机号码格式
  11. const verificationIdnumber = (idnumber) =>{
  12. 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)$/;
  13. return reg.test(idnumber);
  14. };
  15. // 验证手机号码格式
  16. const verificationbankcardId = (bankcardId) =>{
  17. const reg = /^[1-9]\d{9,29}$/;
  18. return reg.test(bankcardId);
  19. };
  20. // 提示函数
  21. const tips = (tips,position = "bottom") => {
  22. vant.Toast({message: tips,position});
  23. };
  24. //- 手机号码验证
  25. const verification = (mobilenumber) => {
  26. if(mobilenumber === '') {
  27. tips('请输入手机号码!');
  28. return true;
  29. }
  30. if(!verificationphonenumber(mobilenumber)){
  31. tips('手机号码格式错误!');
  32. return true;
  33. };
  34. };
  35. // 密码校验
  36. const verificationpassword = function(pwd){
  37. if(pwd.length < 6 || pwd.length > 16) {
  38. tips('密码长度应为6~16位');
  39. return true;
  40. }
  41. };
  42. // 验证码校验
  43. const verificationmobilecode = function(code){
  44. if(code.length !== 6) {
  45. tips('短信验证码长度应为6位');
  46. return true;
  47. }
  48. };
  49. // 按钮防抖
  50. const undebounce = function(func,delay = 300) {
  51. let timer;
  52. return function() {
  53. const args = arguments;
  54. const that = this;
  55. if (timer) clearTimeout(timer);
  56. timer = setTimeout(() => {
  57. func.apply(that,args)
  58. }, delay)
  59. }
  60. };
  61. // 保留两位小数
  62. Vue.filter('tofixed2', function (value) {
  63. return value.toFixed(2);
  64. });
  65. const tofixed2 = function (value) {
  66. return value.toFixed(2);
  67. };
  68. // 隐藏中间位
  69. const hidemiddlenum = function (str,frontLen,endLen = 0) {
  70. var len = str.length-frontLen-endLen;
  71. var xing = '';
  72. for (var i=0;i<len;i++) {
  73. xing+='*';
  74. }
  75. return str.substring(0,frontLen)+xing+str.substring(str.length-endLen);
  76. };
  77. // 模拟app方法接口
  78. // const PublicLib = {
  79. // Goto:function(urlobj){
  80. // window.open(`http://192.168.9.69:5757/${urlobj.Url}.html`,"_self");
  81. // },
  82. // putCookieInfo:function(name,val){
  83. // window.localStorage.setItem(name,val);
  84. // },
  85. // getCookieInfo:function(name){
  86. // return window.localStorage.getItem(name);
  87. // },
  88. // GoBack:function(num){
  89. // window.history.back(-num);
  90. // if(num === 0) {
  91. // PublicLib.Goto({Url:'user-center'});
  92. // }
  93. // },
  94. // ClearAppCache:function(){
  95. // vant.Toast('清除了缓存');
  96. // },
  97. // PhoneCall:function(phonenum){
  98. // window.location.href = 'tel:'+ phonenum;
  99. // },
  100. // GetAppVersion(){
  101. // return '1.1.4';
  102. // },
  103. // DataEncrypt({Content:val}){
  104. // return val
  105. // },
  106. // ShowLoading(){
  107. // console.log('等待。。。。。。')
  108. // },
  109. // HideLoading(){
  110. // console.log('隐藏等待。。。。。。')
  111. // },
  112. // };
  113. // PublicLib.Goto({Url:''});
  114. // PublicLib.putCookieInfo('userId', res.data.Id);
  115. // PublicLib.getCookieInfo('userId');
  116. // PublicLib.GoBack({Level:1});
  117. // 补零函数
  118. const fillzero = function(num) {
  119. if(num < 10) {
  120. return '0'+ num;
  121. }else{
  122. return num;
  123. };
  124. };
  125. const formatDate = function(year,mounth,daile = ''){
  126. year = fillzero(year);
  127. mounth = fillzero(mounth);
  128. daile = daile !== '' ? fillzero(daile) : ''
  129. return ''+year + mounth + daile;
  130. };
  131. // 底部导航栏是否显示
  132. const bottomtabisshow = true;
  133. // 顶部标题栏是否显示
  134. const toptitleisshow = true;
  135. /*判断访问终端*/
  136. const browsertype = {
  137. versions:function(){
  138. var u = navigator.userAgent, app = navigator.appVersion;
  139. return {
  140. trident: u.indexOf('Trident') > -1, /*IE内核*/
  141. presto: u.indexOf('Presto') > -1, /*opera内核*/
  142. webKit: u.indexOf('AppleWebKit') > -1, /*苹果、谷歌内核*/
  143. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,/*火狐内核*/
  144. mobile: !!u.match(/AppleWebKit.*Mobile.*/), /*是否为移动终端*/
  145. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), /*ios终端*/
  146. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, /*android终端或者uc浏览器*/
  147. iPhone: u.indexOf('iPhone') > -1 , /*是否为iPhone或者QQHD浏览器*/
  148. iPad: u.indexOf('iPad') > -1, /*是否iPad*/
  149. webApp: u.indexOf('Safari') == -1, /*是否web应该程序,没有头部与底部*/
  150. weixin: u.toLowerCase().indexOf('micromessenger') > -1 /*是否是微信*/
  151. };
  152. }(),
  153. language:(navigator.browserLanguage || navigator.language).toLowerCase()
  154. };
  155. // 扫描二维码函数
  156. const scan = function (value,fn) {
  157. value = PublicLib.getCookieInfo("ScanContent") && JSON.parse(PublicLib.getCookieInfo("ScanContent")).scan
  158. if(value !== '') {
  159. fn();
  160. }
  161. PublicLib.putCookieInfo('ScanContent', '');
  162. };
  163. // 加密函数
  164. const encryption = function(val){
  165. return PublicLib.encryptByDES(val);
  166. };
  167. Host = 'http://test.bs.shuangkebang.com/';
  168. const showHost = 'http://test.bs.shuangkebang.com';
  169. // Host = '/';
  170. isWeb = true;