index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.scrollPosition = scrollPosition
  25. Vue.prototype.getWebSocketRoot = () => {
  26. const protocol = location.protocol === "https:" ? "wss://" : "ws://"
  27. return protocol + location.host + process.env["VUE_APP_API_WSS_ROOT"]
  28. }
  29. }
  30. }