index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import scrollPosition from './scroll-position'
  2. export default {
  3. // eslint-disable-next-line no-unused-vars
  4. install(Vue, options) {
  5. Vue.prototype.extend = (target, source) => {
  6. for (let obj in source) {
  7. target[obj] = source[obj]
  8. }
  9. return target
  10. }
  11. Vue.prototype.getClientWidth = () => {
  12. return document.body.clientWidth
  13. }
  14. Vue.prototype.collapse = () => {
  15. return !(Vue.prototype.getClientWidth() > 768 || Vue.prototype.getClientWidth() < 512)
  16. }
  17. Vue.prototype.bytesToSize = (bytes) => {
  18. if (bytes === 0) return '0 B'
  19. const k = 1024
  20. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  21. const i = Math.floor(Math.log(bytes) / Math.log(k))
  22. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]
  23. }
  24. Vue.prototype.transformUserType = (power) => {
  25. const type = ['学生', '企业', '教师', '学院']
  26. return type[power]
  27. }
  28. Vue.prototype.transformGrade = {
  29. 7: 'A+',
  30. 6: 'A',
  31. 5: 'B+',
  32. 4: 'B',
  33. 3: 'C+',
  34. 2: 'C',
  35. 1: 'D',
  36. 0: 'F'
  37. }
  38. Vue.prototype.scrollPosition = scrollPosition
  39. }
  40. }