publicfn.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. 
  2. /*
  3. * 创业帮公用方法
  4. */
  5. // 验证手机号码格式
  6. const verificationphonenumber = (phonenumber) =>{
  7. const reg = /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\d{8}$/;
  8. return reg.test(phonenumber);
  9. };
  10. // 验证邮箱格式
  11. const verificationemail = (email) =>{
  12. const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  13. return reg.test(email);
  14. };
  15. // 社会信用代码
  16. const verificationCreditCode = (creditCode) =>{
  17. const reg = /^(([0-9A-Za-z]{15})|([0-9A-Za-z]{18})|([0-9A-Za-z]{20}))$/;
  18. return reg.test(creditCode);
  19. }
  20. // 身份证号验证
  21. const verificationIdCardNumber = (idNumber) =>{
  22. const reg = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
  23. return reg.test(idNumber);
  24. }
  25. // 中文姓名验证
  26. const verificationName = (name) =>{
  27. const reg = /^(?:[\u4e00-\u9fa5·]{2,16})$/;
  28. return reg.test(name);
  29. }
  30. // // 验证手机号码格式
  31. // const verificationIdnumber = (idnumber) =>{
  32. // 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)$/;
  33. // return reg.test(idnumber);
  34. // };
  35. // 验证银行卡格式
  36. const verificationbankcardId = (bankcardId) =>{
  37. const reg = /^[1-9]\d{9,29}$/;
  38. return reg.test(bankcardId);
  39. };
  40. // 提示函数
  41. const tips = (tips,position = "bottom") => {
  42. vant.Toast({message: tips,position});
  43. };
  44. //- 手机号码验证
  45. const verification = (mobilenumber) => {
  46. if(mobilenumber === '') {
  47. tips('请输入手机号码!');
  48. return true;
  49. }
  50. if(!verificationphonenumber(mobilenumber)){
  51. tips('手机号码格式错误!');
  52. return true;
  53. };
  54. };
  55. // 密码校验
  56. const verificationpassword = function(pwd){
  57. if(pwd.length < 6 || pwd.length > 16) {
  58. tips('密码长度应为6~16位');
  59. return true;
  60. }
  61. };
  62. // 验证码校验
  63. const verificationmobilecode = function(code){
  64. if(code.length !== 6) {
  65. tips('短信验证码长度应为6位');
  66. return true;
  67. }
  68. };
  69. // 按钮防抖
  70. const undebounce = function(func,delay = 300) {
  71. let timer;
  72. return function() {
  73. const args = arguments;
  74. const that = this;
  75. if (timer) clearTimeout(timer);
  76. timer = setTimeout(() => {
  77. func.apply(that,args)
  78. }, delay)
  79. }
  80. };
  81. // 保留两位小数
  82. Vue.filter('tofixed2', function (value) {
  83. return value.toFixed(2);
  84. });
  85. const tofixed2 = function (value) {
  86. return value.toFixed(2);
  87. };
  88. // 隐藏中间位
  89. const hidemiddlenum = function (str,frontLen,endLen = 0) {
  90. var len = str.length-frontLen-endLen;
  91. var xing = '';
  92. for (var i=0;i<len;i++) {
  93. xing+='*';
  94. }
  95. return str.substring(0,frontLen)+xing+str.substring(str.length-endLen);
  96. };
  97. // 模拟app方法接口
  98. // 补零函数
  99. const fillzero = function(num) {
  100. if(num < 10) {
  101. return '0'+ num;
  102. }else{
  103. return num;
  104. };
  105. };
  106. const formatDate = function(year,mounth,daile = ''){
  107. year = fillzero(year);
  108. mounth = fillzero(mounth);
  109. daile = daile !== '' ? fillzero(daile) : ''
  110. return ''+year + mounth + daile;
  111. };
  112. // 微信时间格式化
  113. const formatwechtDate = function(year,mounth,daile = ''){
  114. year = fillzero(year);
  115. mounth = fillzero(mounth);
  116. daile = daile !== '' ? fillzero(daile) : ''
  117. return year +'-'+ mounth + '-' + daile;
  118. };
  119. // 底部导航栏是否显示
  120. const bottomtabisshow = true;
  121. // 顶部标题栏是否显示
  122. const toptitleisshow = true;
  123. /*判断访问终端*/
  124. const browsertype = {
  125. versions:function(){
  126. var u = navigator.userAgent, app = navigator.appVersion;
  127. return {
  128. trident: u.indexOf('Trident') > -1, /*IE内核*/
  129. presto: u.indexOf('Presto') > -1, /*opera内核*/
  130. webKit: u.indexOf('AppleWebKit') > -1, /*苹果、谷歌内核*/
  131. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,/*火狐内核*/
  132. mobile: !!u.match(/AppleWebKit.*Mobile.*/), /*是否为移动终端*/
  133. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), /*ios终端*/
  134. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, /*android终端或者uc浏览器*/
  135. iPhone: u.indexOf('iPhone') > -1 , /*是否为iPhone或者QQHD浏览器*/
  136. iPad: u.indexOf('iPad') > -1, /*是否iPad*/
  137. webApp: u.indexOf('Safari') == -1, /*是否web应该程序,没有头部与底部*/
  138. weixin: u.toLowerCase().indexOf('micromessenger') > -1 /*是否是微信*/
  139. };
  140. }(),
  141. language:(navigator.browserLanguage || navigator.language).toLowerCase()
  142. };
  143. // 扫描二维码函数
  144. const scan = function (value,fn) {
  145. value = PublicLib.getCookieInfo("ScanContent") && JSON.parse(PublicLib.getCookieInfo("ScanContent")).scan
  146. if(value !== '') {
  147. fn();
  148. }
  149. PublicLib.putCookieInfo('ScanContent', '');
  150. };
  151. // 加密函数
  152. const encryption = function(val){
  153. return PublicLib.encryptByDES(val);
  154. };
  155. function deviceDetection() {
  156. const ua = navigator.userAgent
  157. let osVersion = ''
  158. let device = ''
  159. try {
  160. if (/android/i.test(ua)) {
  161. device = 'android'
  162. osVersion = ua.match(/Android\s+([\d.]+)/i)[0].replace('Android ', '')
  163. } else if (/ipad|iphone|ipod/i.test(ua)) {
  164. device = 'ios'
  165. osVersion = ua.match(/OS\s+([\d_]+)/i)[0].replace(/_/g, '.').replace('OS ', '')
  166. }
  167. } catch (err) {
  168. /* istanbul ignore next line */
  169. console.error(err)
  170. }
  171. return { osVersion, device }
  172. };
  173. // 判断是否为刘海屏
  174. function isFringe() {
  175. const { device } = deviceDetection()
  176. // const { screen } = global
  177. return device === 'ios' &&
  178. ((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))
  179. };
  180. if(isFringe()){
  181. document.querySelector('body').className += ' bangs';
  182. if(document.querySelector('.iphonetitle')){
  183. document.querySelector('.iphonetitle').className += ' topBangs';
  184. };
  185. }else{
  186. document.querySelector('body').className += ' unbangs';
  187. if(document.querySelector('.iphonetitle')){
  188. document.querySelector('.iphonetitle').className += ' untopBangs';
  189. };
  190. };
  191. Host = 'http://bs.kexiaoshuang.com/';
  192. const showHost = 'http://bs.kexiaoshuang.com';
  193. isWeb = true;
  194. // 超级管理员姓名 *(*)
  195. // 超级管理员身份证件号码 *(*)
  196. // 联系手机 **
  197. // 联系邮箱 **
  198. // 营业执照照片 **
  199. // 统一社会信用代码 **
  200. // 商户名称 *CertMerchantName
  201. // 个体户经营者/法人姓名 *CertLegalPerson(*)
  202. // 身份证人像面照片 *IdCardCopy
  203. // 身份证国徽面照片 *IdCardNational
  204. // 身份证姓名 *IdCardName(*)
  205. // 身份证号码 *IdCardNumber(*)
  206. // 身份证有效期开始时间 *yyyy-mm-dd CardPeriodBegin
  207. // 身份证有效期结束时间 *yyyy-mm-dd CardPeriodEnd
  208. // 商户简称 *MerchantShortname
  209. // 客服电话 *ServicePhone
  210. // 门店名称 *BizStoreName
  211. // 门店省市编码 *BizAddressCode
  212. // 门店地址 *BizStoreAddress
  213. // 门店门头照片 *StoreEntrancePic
  214. // 店内环境照片 *IndoorPic
  215. // 所属行业 *QualificationType
  216. // 主体类型 *SubjectType
  217. // 账户类型 *BankAccountType
  218. // 开户名称 * AccountName
  219. // 开户银行 *AccountBank
  220. // 开户银行省市编码 *BankAddressCode
  221. // 开户银行联行号 *
  222. // 开户银行全称(含支行) BankName
  223. // 银行账号 *AccountNumber