|
@@ -1,8 +1,10 @@
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+import useScroll from '@/mixins/useScroll';
|
|
|
import {getBookCategories, getBookList, getBookListOfMy} from '@/api/knowledge';
|
|
import {getBookCategories, getBookList, getBookListOfMy} from '@/api/knowledge';
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'KnowledgeBook',
|
|
name: 'KnowledgeBook',
|
|
|
|
|
+ mixins: [useScroll],
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
categories: [],
|
|
categories: [],
|
|
@@ -27,8 +29,16 @@ export default {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
try { this.containerHeight = `${this.$el.parentElement.getBoundingClientRect().height - 10}px`; } catch (e) { }
|
|
try { this.containerHeight = `${this.$el.parentElement.getBoundingClientRect().height - 10}px`; } catch (e) { }
|
|
|
}, 500);
|
|
}, 500);
|
|
|
|
|
+ this.onActivated();
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ onActivated() {
|
|
|
|
|
+ this.__activated__ = true;
|
|
|
|
|
+ const menus = this.$refs.menus.$el;
|
|
|
|
|
+ if (menus) {
|
|
|
|
|
+ menus.querySelector('.el-menu-item.is-active').scrollIntoView({behavior: 'smooth', block: 'center'});
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
async getCategories() {
|
|
async getCategories() {
|
|
|
const categories = await getBookCategories().catch(() => []);
|
|
const categories = await getBookCategories().catch(() => []);
|
|
|
this.categories = [{label: '我的书架', value: -1}, ...categories];
|
|
this.categories = [{label: '我的书架', value: -1}, ...categories];
|
|
@@ -58,7 +68,7 @@ export default {
|
|
|
} catch (error) {}
|
|
} catch (error) {}
|
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
if (loading) loading.close();
|
|
if (loading) loading.close();
|
|
|
- if (this.query.page === 1) { setTimeout(() => { this.$refs.scroller.$el.scrollTo({top: 0, behavior: 'smooth'}); }, 200); }
|
|
|
|
|
|
|
+ if (this.query.page === 1) { setTimeout(() => { this.scroll(0); }, 200); }
|
|
|
},
|
|
},
|
|
|
load() {
|
|
load() {
|
|
|
if (this.books.length >= this.query.total) return;
|
|
if (this.books.length >= this.query.total) return;
|
|
@@ -89,7 +99,7 @@ export default {
|
|
|
<div class="knowledge-book-list" :style="{height: containerHeight}">
|
|
<div class="knowledge-book-list" :style="{height: containerHeight}">
|
|
|
<el-row style="height: 100%;overflow: hidden;">
|
|
<el-row style="height: 100%;overflow: hidden;">
|
|
|
<el-col style="height: 100%;overflow: hidden;" :sm="4" :xl="3">
|
|
<el-col style="height: 100%;overflow: hidden;" :sm="4" :xl="3">
|
|
|
- <el-menu style="height: 100%;overflow-y: auto" :default-active="query.index">
|
|
|
|
|
|
|
+ <el-menu ref="menus" style="height: 100%;overflow-y: auto" :default-active="query.index">
|
|
|
<el-menu-item v-for="(item, index) in categories" :key="item.value" :index="index + ''"
|
|
<el-menu-item v-for="(item, index) in categories" :key="item.value" :index="index + ''"
|
|
|
style="font-size: 18px;"
|
|
style="font-size: 18px;"
|
|
|
@click="onselect(index)">
|
|
@click="onselect(index)">
|
|
@@ -104,7 +114,7 @@ export default {
|
|
|
@keyup.enter.native="onSearch()"></el-input>
|
|
@keyup.enter.native="onSearch()"></el-input>
|
|
|
<el-button type="primary" @click="onSearch()">查询</el-button>
|
|
<el-button type="primary" @click="onSearch()">查询</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
- <el-row ref="scroller" class="books-wrapper" style="flex: auto;" v-infinite-scroll="load">
|
|
|
|
|
|
|
+ <el-row ref="scrollableElement" class="books-wrapper" style="flex: auto;" v-infinite-scroll="load">
|
|
|
<el-empty v-if="!books.length" description="暂无数据"></el-empty>
|
|
<el-empty v-if="!books.length" description="暂无数据"></el-empty>
|
|
|
<el-col v-for="(book, index) in books" :key="book.id" :sm="8" :xl="6">
|
|
<el-col v-for="(book, index) in books" :key="book.id" :sm="8" :xl="6">
|
|
|
<div class="book-wrapper" @click="onPreview(book)">
|
|
<div class="book-wrapper" @click="onPreview(book)">
|