deviceType.js 721 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. export default class DeviceType {
  2. static install(Vue) {
  3. Vue.prototype.$deviceType = new this()
  4. }
  5. constructor() {
  6. this.ios = false
  7. this.android = false
  8. this.pc = false
  9. this.ios = false
  10. this.ua = ''
  11. if (window) {
  12. this.ua = window && window.navigator && window.navigator.userAgent || ''
  13. }
  14. if (/(iPhone|iPad|iPod|iOS)/i.test(this.ua)) {
  15. this.ios = true
  16. } else if (/(Android)/i.test(this.ua)) {
  17. this.android = true
  18. } else {
  19. this.pc = true
  20. }
  21. }
  22. isIos(){
  23. return this.ios
  24. }
  25. isAndroid() {
  26. return this.android
  27. }
  28. isMobile() {
  29. return this.ios || this.android
  30. }
  31. isPC() {
  32. return this.pc
  33. }
  34. isWx() {
  35. }
  36. }