utils.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function phoneValidate(phone) {
  2. var reg =
  3. /^((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}$/
  4. if (reg.test(phone)) {
  5. return true
  6. } else {
  7. return false
  8. }
  9. }
  10. function getQueryVariable(variable) {
  11. var query = window.location.search.substring(1)
  12. var vars = query.split('&')
  13. for (var i = 0; i < vars.length; i++) {
  14. var pair = vars[i].split('=')
  15. if (pair[0] == variable) {
  16. return pair[1]
  17. }
  18. }
  19. return false
  20. }
  21. function browser() {
  22. var u = navigator.userAgent
  23. // app = navigator.appVersion;
  24. return {
  25. trident: u.indexOf('Trident') > -1, //IE内核
  26. presto: u.indexOf('Presto') > -1, //opera内核
  27. webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  28. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
  29. mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  30. ios: !!u.match(/Mac OS X/), //ios终端
  31. // ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  32. android: u.indexOf('DAYAAPPA') > -1 || u.indexOf('Adr') > -1, //android终端
  33. iPhone: u.indexOf('DAYAAPPI') > -1, //是否为iPhone或者QQHD浏览器
  34. isApp: u.indexOf('DAYAAPPI') > -1 || u.indexOf('DAYAAPPA') > -1 || u.indexOf('Adr') > -1,
  35. iPad: u.indexOf('iPad') > -1, //是否iPad
  36. webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
  37. weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
  38. qq: u.match(/\sQQ/i) == ' qq' //是否QQ
  39. }
  40. }
  41. // 获取授权的code码
  42. function getUrlCode(name = 'code') {
  43. // 截取url中的code方法
  44. const url = location.search
  45. const theRequest = new Object()
  46. if (url.indexOf('?') != -1) {
  47. const str = url.substr(1)
  48. const strs = str.split('&')
  49. for (let i = 0; i < strs.length; i++) {
  50. theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
  51. }
  52. }
  53. console.log(theRequest, 'theRequest')
  54. return theRequest[name]
  55. }