LibsPage.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. //-----------------------------------------------------------------------------
  6. import Vue from 'vue';
  7. import Component from 'vue-class-component';
  8. import Window from '../../share/Window.vue';
  9. import * as utils from '../../../share/utils';
  10. //import rstore from '../../../store/modules/reader';
  11. export default @Component({
  12. components: {
  13. Window
  14. },
  15. watch: {
  16. libs: function() {
  17. this.loadLibs();
  18. },
  19. }
  20. })
  21. class LibsPage extends Vue {
  22. created() {
  23. this.popupWindow = null;
  24. this.commit = this.$store.commit;
  25. //this.commit('reader/setLibs', rstore.libsDefaults);
  26. }
  27. init() {
  28. const subdomain = (window.location.protocol != 'http:' ? 'b.' : '');
  29. const origin = `http://${subdomain}${window.location.host}`;
  30. this.popupWindow = window.open(`${origin}/#/external-libs`);
  31. if (this.popupWindow) {
  32. //Проверка закрытия окна
  33. (async() => {
  34. while(this.popupWindow) {
  35. if (this.popupWindow && this.popupWindow.closed)
  36. this.close();
  37. await utils.sleep(1000);
  38. }
  39. })();
  40. window.addEventListener('message', (event) => {
  41. if (event.origin !== origin)
  42. return;
  43. console.log(event.data);
  44. }, false);
  45. (async() => {
  46. while(this.popupWindow) {
  47. this.popupWindow.postMessage({from: 'LibsPage', type: 'mes', data: 'hello'}, origin);
  48. await utils.sleep(1000);
  49. }
  50. })();
  51. this.loadLibs();
  52. }
  53. }
  54. done() {
  55. if (this.popupWindow) {
  56. this.popupWindow.close();
  57. this.popupWindow = null;
  58. }
  59. }
  60. get libs() {
  61. return this.$store.state.reader.libs;
  62. }
  63. loadLibs() {
  64. }
  65. /* submitUrl() {
  66. if (this.bookUrl) {
  67. this.$emit('load-book', {url: this.addProtocol(this.bookUrl), force: true});
  68. this.bookUrl = '';
  69. }
  70. }*/
  71. close() {
  72. this.$emit('libs-close');
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. </script>
  77. <style scoped>
  78. .separator {
  79. height: 1px;
  80. background-color: #A0A0A0;
  81. }
  82. </style>