index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. export default {
  2. install(Vue) {
  3. Vue.mixin({
  4. data() {
  5. return {
  6. //用户信息
  7. usrLogin: false,
  8. usrName: '',
  9. usrInfo: {},
  10. //浏览器宽度≤768返回true
  11. windowMax768: window.innerWidth <= 768,
  12. }
  13. },
  14. mounted() {
  15. this.usrInfo = $A.getUserInfo((data, isLogin) => {
  16. this.usrLogin = isLogin;
  17. this.usrInfo = data;
  18. this.usrName = this.usrInfo.username || '';
  19. }, false);
  20. this.usrLogin = $A.getToken() !== false;
  21. this.usrName = this.usrInfo.username || '';
  22. //
  23. window.addEventListener('resize', this.windowMax768Listener);
  24. },
  25. beforeDestroy() {
  26. window.removeEventListener('resize', this.windowMax768Listener);
  27. },
  28. methods: {
  29. isArray(obj) {
  30. return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == '[object array]' && typeof obj.length == "number";
  31. },
  32. isJson(obj) {
  33. return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
  34. },
  35. windowMax768Listener() {
  36. this.windowMax768 = window.innerWidth <= 768
  37. }
  38. }
  39. });
  40. }
  41. }