6
0

main.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // import global styles
  2. import './assets/style/main.css'
  3. import './assets/style/colors.css'
  4. import './assets/style/fonts.css'
  5. // imports
  6. import Vue from 'vue'
  7. import App from './App.vue'
  8. import io from "socket.io-client";
  9. // establish socket connection
  10. const self = window.location.protocol + '//' + window.location.hostname + ':5000';
  11. const sio = io(self);
  12. // initialize vue.js
  13. Vue.config.productionTip = false
  14. new Vue({
  15. render: h => h(App),
  16. created: function () {
  17. this.socket.on('edit-project', project => {
  18. if (this.project && this.project.identifier === project.identifier) {
  19. this.project = project;
  20. }
  21. });
  22. this.socket.on('remove-project', project => {
  23. if (this.project && this.project.identifier === project.identifier) {
  24. this.project = null;
  25. }
  26. });
  27. this.socket.on('connect', () => this.connected = true);
  28. setInterval(() => this.connected = sio.connected, 1000);
  29. },
  30. data: function () {
  31. return {
  32. project: null,
  33. connected: false,
  34. socket: {
  35. url: function (name) {
  36. if (name.startsWith('http'))
  37. return name;
  38. else
  39. return self + name;
  40. },
  41. on: function (name, callback) {
  42. console.log('on', name);
  43. sio.on(name, callback);
  44. },
  45. off: function (name, callback) {
  46. console.log('off', name);
  47. sio.off(name, callback);
  48. },
  49. get: function (name) {
  50. name = this.url(name);
  51. console.log('get', name);
  52. return fetch(name, {
  53. method: 'GET'
  54. });
  55. },
  56. post: function (name, value) {
  57. name = this.url(name);
  58. console.log('post', name, value);
  59. return fetch(name, {
  60. method: 'POST',
  61. body: JSON.stringify(value)
  62. });
  63. },
  64. upload: function (name, file) {
  65. name = this.url(name);
  66. const form = new FormData();
  67. form.append('file', file);
  68. console.log('upload', name, file);
  69. return fetch(name, {
  70. method: 'POST',
  71. body: form
  72. });
  73. },
  74. media: function (file, maxWidth, maxHeight) {
  75. if (maxHeight)
  76. return `${self}/data/${file.identifier}/${maxWidth}x${maxHeight}?uuid=${file.uuid}`
  77. else if (maxWidth)
  78. return `${self}/data/${file.identifier}/${maxWidth}?uuid=${file.uuid}`
  79. else
  80. return `${self}/data/${file.identifier}?uuid=${file.uuid}`
  81. }
  82. }
  83. }
  84. }
  85. }).$mount('#app')