utils.js 1.9 KB

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