Przeglądaj źródła

Подключил отображение компонента загрузки (todo: переделать)

Book Pauk 6 lat temu
rodzic
commit
e79fcfa868

+ 4 - 2
client/api/reader.js

@@ -11,6 +11,8 @@ const workerApi = axios.create({
 
 
 class Reader {
 class Reader {
     async loadBook(url, callback) {
     async loadBook(url, callback) {
+        const refreshPause = 100;
+
         let response = await api.post('/load-book', {type: 'url', url});
         let response = await api.post('/load-book', {type: 'url', url});
 
 
         const workerId = response.data.workerId;
         const workerId = response.data.workerId;
@@ -29,10 +31,10 @@ class Reader {
                 throw new Error(response.data.error);
                 throw new Error(response.data.error);
             }
             }
             if (i > 0)
             if (i > 0)
-                await sleep(500);
+                await sleep(refreshPause);
 
 
             i++;
             i++;
-            if (i > 60) {
+            if (i > 30*1000/refreshPause) {
                 throw new Error('Слишком долгое время ожидания');
                 throw new Error('Слишком долгое время ожидания');
             }
             }
             response = await workerApi.post('/get-state', {workerId});
             response = await workerApi.post('/get-state', {workerId});

+ 14 - 4
client/components/Reader/LoaderPage/LoaderPage.vue

@@ -1,5 +1,5 @@
 <template>
 <template>
-    <div class="main">
+    <div ref="main" class="main">
         <div class="part">
         <div class="part">
             <span class="greeting bold-font">{{ title }}</span>
             <span class="greeting bold-font">{{ title }}</span>
             <span class="greeting">Добро пожаловать!</span>
             <span class="greeting">Добро пожаловать!</span>
@@ -59,14 +59,16 @@ class LoaderPage extends Vue {
 
 
     async submitUrl() {
     async submitUrl() {
         if (this.bookUrl) {
         if (this.bookUrl) {
+            const loading = this.$loading({ target: this.$refs.main, customClass: 'loading'});
             try {
             try {
                 const book = await readerApi.loadBook(this.bookUrl, (state) => {
                 const book = await readerApi.loadBook(this.bookUrl, (state) => {
-                    this.loadState = state;
+                    const progress = state.progress || 0;
+                    loading.text = `${state.state} ${progress}%`;
                 });
                 });
-
-                this.loadState = book;
+                loading.close();
             } catch (e) {
             } catch (e) {
                 this.loadState = e.message;
                 this.loadState = e.message;
+                loading.close();
             }
             }
         }
         }
     }
     }
@@ -89,6 +91,14 @@ class LoaderPage extends Vue {
 }
 }
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 </script>
 </script>
+<style>
+.loading {
+    background-color: rgba(0, 0, 0, 0.8);
+}
+.el-loading-text {
+    color: #ffffff !important;
+}
+</style>
 <style scoped>
 <style scoped>
 .main {
 .main {
     flex: 1;
     flex: 1;

+ 6 - 4
client/element.js

@@ -50,14 +50,16 @@ import './theme/main.css';
 import ElInput from 'element-ui/lib/input';
 import ElInput from 'element-ui/lib/input';
 import './theme/input.css';
 import './theme/input.css';
 
 
-const ElNotification = () => import('element-ui/lib/notification');
+import Notification from 'element-ui/lib/notification';
 import './theme/notification.css';
 import './theme/notification.css';
 
 
+import Loading from 'element-ui/lib/loading';
+import './theme/loading.css';
+
 const components = {
 const components = {
     ElMenu, ElMenuItem, ElButton, ElCheckbox, ElTabs, ElTabPane, ElTooltip,
     ElMenu, ElMenuItem, ElButton, ElCheckbox, ElTabs, ElTabPane, ElTooltip,
     ElContainer, ElAside, ElMain, ElHeader,
     ElContainer, ElAside, ElMain, ElHeader,
-    ElInput,
-    ElNotification
+    ElInput
 };
 };
 
 
 for (let [name, comp] of Object.entries(components)) {
 for (let [name, comp] of Object.entries(components)) {
@@ -66,7 +68,7 @@ for (let [name, comp] of Object.entries(components)) {
 
 
 //Vue.use(Loading.directive);
 //Vue.use(Loading.directive);
 
 
-//Vue.prototype.$loading = Loading.service;
+Vue.prototype.$loading = Loading.service;
 //Vue.prototype.$msgbox = MessageBox;
 //Vue.prototype.$msgbox = MessageBox;
 //Vue.prototype.$alert = MessageBox.alert;
 //Vue.prototype.$alert = MessageBox.alert;
 //Vue.prototype.$confirm = MessageBox.confirm;
 //Vue.prototype.$confirm = MessageBox.confirm;