future vor 1 Jahr
Ursprung
Commit
ba78fa0bf9

+ 23 - 30
xs-app/framework/tools.ts

@@ -1,7 +1,7 @@
 import { config } from "../config/config";
 import { book_item_data, chapter_item_data, user_data } from "../data/data";
-import { BookshelfData } from "../stores/bookshelfManager";
-import { ReadHistory } from "../stores/readHistoryManager";
+import { BookshelfManager } from "../stores/bookshelfManager";
+import { ReadHistoryManager } from "../stores/readHistoryManager";
 import { UserData } from "../stores/userDataManager";
 import { UserStatus } from "../stores/userStatusManager";
 import { http } from "./http";
@@ -141,18 +141,12 @@ export class tools {
 	
 	// 获取本地书架列表
 	public static getLocalBookshelfList():book_item_data[] {
-		return BookshelfData().getBookList()
-	}
-	
-	// 重置排序书架
-	public static resetSortBookshelf(book_list:book_item_data[]) {
-		BookshelfData().book_list = book_list
-		BookshelfData().saveBookList()
+		return BookshelfManager.getBookList()
 	}
 	
 	// 检查在书架
 	public static checkBookOnBookshelf(book_id:number, cb:Function) {
-		BookshelfData().checkBookOnBookshelf(book_id, (is_on:boolean)=>{
+		BookshelfManager.checkBookOnBookshelf(book_id, (is_on:boolean)=>{
 			cb && cb(is_on)
 		})
 	}
@@ -162,42 +156,41 @@ export class tools {
 		util.showLoading('加入书架...', true)
 		util.hideLoading(500, ()=>{
 			// 请求
-			BookshelfData().addBook(book_data)
+			BookshelfManager.addBook(book_data)
 			uni.$emit(config.EVENT_TYPE.UPDATE_BOOKSHELF)
 			cb && cb()
 		})
 	}
 	
-	// 获取本地阅读历史列表
-	public static getLocalReadHistoryList():book_item_data[] {
-		return ReadHistory().getBookList()
-	}
-	
-	// 更新阅读历史
-	public static updateReadHistory(book_data:book_item_data) {
-		ReadHistory().addBook(book_data, ()=>{
-			uni.$emit(config.EVENT_TYPE.UPDATE_READHISTORY)
-		})
-	}
-	
-	// 重置排序阅读历史
-	public static resetSortReadHistory(book_list:book_item_data[]) {
-		ReadHistory().book_list = book_list
-		ReadHistory().saveBookList()
-	}
-
 	// 删除书架
 	public static deleteBookshelf(book_id_list:number[], cb:Function=null) {
 		util.showModal('删除?', `从书架删除这${book_id_list.length}本书?`, ()=>{
 			util.showLoading('移除书架...', true)
 			util.hideLoading(500, ()=>{
 				// 请求
-				BookshelfData().deleteBook(book_id_list)
+				BookshelfManager.deleteBook(book_id_list)
 				uni.$emit(config.EVENT_TYPE.UPDATE_BOOKSHELF)
 				cb && cb()
 			})
 		})
 	}
+	
+	// 重置排序书架
+	public static resetSortBookshelf(book_list:book_item_data[]) {
+		BookshelfManager.resetData(book_list)
+	}
+	
+	// 获取本地阅读历史列表
+	public static getLocalReadHistoryList():book_item_data[] {
+		return ReadHistoryManager.getBookList()
+	}
+	
+	// 更新阅读历史
+	public static updateReadHistory(book_data:book_item_data) {
+		ReadHistoryManager.addBook(book_data, ()=>{
+			uni.$emit(config.EVENT_TYPE.UPDATE_READHISTORY)
+		})
+	}
     
 	public static getChapterList(chapter_path:string,cb:Function){
 		let url = `${config.url_addr.Static}${chapter_path}`

+ 3 - 2
xs-app/pages/bookshelf/bookshelf-bookList.vue

@@ -1,5 +1,5 @@
 <template>
-	<view class="bookList_content">
+	<view class="bookList_content" :style="{width:window_width}">
 		<view :class="book_list.length>0?'top':'top-none'">
 			<view class='top__info'>
 				{{is_edit?'':'全部'}}
@@ -27,7 +27,7 @@
 			<view class="bottom-tools__all" :style="{height:bottom_tools_real_height+'rpx'}" @click="clickSelectedAll">
 				{{ is_selected_all?'取消全选':'全选' }}
 			</view>
-			<view class="bottom-tools__delete bottom-tools__all" @click="clickDelete">
+			<view class="bottom-tools__delete bottom-tools__all" :style="{height:bottom_tools_real_height+'rpx'}" @click="clickDelete">
 				删除({{edit_book_list.length}})
 			</view>
 		</view>
@@ -40,6 +40,7 @@
     import { util } from '../../framework/util';
     import { tools } from '../../framework/tools';
 		
+	let window_width = ref(uni.getSystemInfoSync().windowWidth + 'px')	
 	let is_edit = ref(false)	
 	let edit_book_list = ref<Array<number>>([])
 	let is_selected_all = ref(false)

+ 7 - 0
xs-app/pages/bookshelf/bookshelf-readHistory.vue

@@ -1,5 +1,8 @@
 <template>
 	<view class="readHistory_content" :style="{width:window_width}">
+		<view class="" @click="clickDeleteBook">
+			清空
+		</view>
 		<view class="book-list">
 			<view class="book-list__item" v-for="(item,index) in book_list" :key="index"
 			@click="clickBook(item,index)">
@@ -32,6 +35,10 @@
 	const emits = defineEmits(['clickBook','clickDeleteBook'])
 	let window_width = ref(uni.getSystemInfoSync().windowWidth + 'px')
 	
+	function clickDeleteBook() {
+		emits('clickDeleteBook')
+	}
+	
 	function clickBook(book_data:book_item_data, index:number) {
 		emits('clickBook',book_data,index)
 	}

+ 21 - 18
xs-app/pages/bookshelf/bookshelf.vue

@@ -17,7 +17,7 @@
 		</view>
 		<view :style="{marginTop: tab_height + 'rpx'}">
 			<bookList :class="tab_current==0?'style_show':'style_hide'" :book_list='data_book_list' @clickBook='gotoReadBook'></bookList>
-			<readHistory :class="tab_current==1?'style_show':'style_hide'" :book_list='data_read_history_list' @clickBook='gotoReadBook'></readHistory>
+			<readHistory :class="tab_current==1?'style_show':'style_hide'" :book_list='data_read_history_list' @clickBook='gotoReadBook' @clickDeleteBook='readHistoryClickDeleteBook'></readHistory>
 		</view>
 	</view>
 </template>
@@ -45,33 +45,32 @@
 		uni.setNavigationBarTitle({
 			title:config.app_name
 		})
-		data_book_list.value = tools.getLocalBookshelfList()
-		// for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
-		// 	let element = tools.getLocalBookshelfList()[i]
-		// 	let read_record_data = ReadRecord().getReadRecordData(element.book_id)
-		// 	if(read_record_data) {
-		// 		element.start_read_chapter_id = read_record_data.chapter_id
-		// 	} else {
-		// 		element.start_read_chapter_id = 1
-		// 	}
-		// 	data_book_list.value.push(element)
-		// }
+		
+		// data_book_list.value = tools.getLocalBookshelfList()
+		for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
+			let element = tools.getLocalBookshelfList()[i]
+			let read_record_data = ReadRecord().getReadRecordData(element.book_id)
+			if(read_record_data) {
+				element.start_read_chapter_id = read_record_data.chapter_id
+			} else {
+				element.start_read_chapter_id = 1
+			}
+			data_book_list.value.push(element)
+		}
 		
 		data_read_history_list.value = tools.getLocalReadHistoryList()
 	}
 	
 	function initEvent() {
 		uni.$on(config.EVENT_TYPE.UPDATE_BOOKSHELF,()=>{
-			data_book_list.value = []
-			setTimeout(()=>{
-				data_book_list.value = tools.getLocalBookshelfList()
-			},35)
+			data_book_list.value = tools.getLocalBookshelfList()
 		})
 		uni.$on(config.EVENT_TYPE.UPDATE_READHISTORY,()=>{
+			// console.log('tools.getLocalReadHistoryList()=',tools.getLocalReadHistoryList())
 			data_read_history_list.value = []
 			setTimeout(()=>{
 				data_read_history_list.value = tools.getLocalReadHistoryList()
-			},35)
+			},50)
 		})
 	}
 	
@@ -79,6 +78,11 @@
 		tab_current.value = index
 	}
 	
+	function readHistoryClickDeleteBook() {
+		data_read_history_list.value = []
+		tools.resetSortReadHistory(data_read_history_list.value)
+	}
+	
 	function gotoReadBook(book_data:book_item_data, index:number) {
 		// console.log('book_data=',book_data,'index=',index)
 		tools.gotoRead(book_data)
@@ -95,7 +99,6 @@
 			if(index>0) {
 				data_read_history_list.value.splice(index,1)
 				data_read_history_list.value.unshift(book_data)
-				tools.resetSortReadHistory(data_read_history_list.value)
 				uni.pageScrollTo({ scrollTop:0 })
 			}
 		}

+ 40 - 27
xs-app/stores/bookshelfManager.ts

@@ -1,29 +1,33 @@
-import {defineStore} from 'pinia';
 import { book_item_data } from '../data/data';
 import { util } from '../framework/util';
 import { config } from '../config/config';
-export const BookshelfData = defineStore('bookshelf-data',()=>{
-	let book_list:book_item_data[] = null
-	function getBookList():book_item_data[]{
-		if(book_list) {
-			return book_list
+
+export class BookshelfManager {
+    private static book_list:book_item_data[] = null
+	
+	// 获取书列表
+	public static getBookList():book_item_data[] {
+		if(BookshelfManager.book_list) {
+			return BookshelfManager.book_list
 		}
-		book_list = []
+		BookshelfManager.book_list = []
 		let string = util.getStorage(config.storage_key.BOOKSHELF_LIST)
 		if(string) {
-			// book_list = JSON.parse(string)  响应式对象无法被改变
-			Object.assign(book_list,JSON.parse(string))  // 使用此方法赋值给相应对象
+			BookshelfManager.book_list = JSON.parse(string)
 		}
-		return book_list
+		return BookshelfManager.book_list
 	}
-	function saveBookList() {
-		// console.log('saveBookList=',getBookList())
-		util.setStorage(config.storage_key.BOOKSHELF_LIST, JSON.stringify(getBookList()))		
+	
+	// 保存本地书列表
+	public static saveLocalBookList() {
+		util.setStorage(config.storage_key.BOOKSHELF_LIST, JSON.stringify(BookshelfManager.book_list))
 	}
-	async function checkBookOnBookshelf(book_id:number, cb:Function) {
+
+    // 检查在书架
+	public static async checkBookOnBookshelf(book_id:number, cb:Function) {
 		let on_bookshelf:boolean = false
-		for (let i = 0; i < getBookList().length; i++) {
-			let element = getBookList()[i]
+		for (let i = 0; i < BookshelfManager.getBookList().length; i++) {
+			let element = BookshelfManager.getBookList()[i]
 			if(element.book_id == book_id) {
 				on_bookshelf = true
 				break
@@ -31,32 +35,41 @@ export const BookshelfData = defineStore('bookshelf-data',()=>{
 		}
 		cb && cb(on_bookshelf)
 	}
-    function addBook(book_data:book_item_data){
+	
+	// 添加书
+	public static addBook(book_data:book_item_data) {
 		if(!book_data.start_read_chapter_id) {
 			book_data.start_read_chapter_id = 1
 		}
-		getBookList().unshift(book_data)
-		saveBookList()
+		BookshelfManager.getBookList().unshift(book_data)
+		BookshelfManager.saveLocalBookList()
 	}
 	
-	function deleteBook(book_id_list:number[]) {
-		for (let i = 0; i < getBookList().length; i++) {
-			let i_element = getBookList()[i]
+	// 删除书
+	public static deleteBook(book_id_list:number[]) {
+		for (let i = 0; i < BookshelfManager.getBookList().length; i++) {
+			let i_element = BookshelfManager.getBookList()[i]
 			if(book_id_list.length==1) {
 				if(book_id_list.indexOf(i_element.book_id)>-1) {
-					getBookList().splice(i,1)
+					BookshelfManager.getBookList().splice(i,1)
 					break
 				}
 			} else {
 				for (let j = 0; j < book_id_list.length; j++) {
 					let j_element = book_id_list[i]
 					if(i_element.book_id = j_element) {
-						getBookList().splice(i,1)
+						BookshelfManager.getBookList().splice(i,1)
 					}
 				}
 			}
 		}
-		saveBookList()
+		BookshelfManager.saveLocalBookList()
+	}
+	
+	// 重置数据
+	public static resetData(book_list:book_item_data[]) {
+		BookshelfManager.book_list = book_list
+		BookshelfManager.saveLocalBookList()
 	}
-	return {book_list,getBookList,saveBookList,addBook,deleteBook,checkBookOnBookshelf}
-})
+
+}

+ 35 - 32
xs-app/stores/readHistoryManager.ts

@@ -1,26 +1,33 @@
-import {defineStore} from 'pinia';
 import { book_item_data } from '../data/data';
 import { config } from '../config/config';
 import { util } from '../framework/util';
-export const ReadHistory = defineStore('read-history',()=>{
-	let book_list:book_item_data[] = null
-	function getBookList():book_item_data[]{
-		if(book_list) {
-			return book_list
+
+export class ReadHistoryManager {
+    private static book_list:book_item_data[] = null
+
+   // 获取书列表
+	public static getBookList():book_item_data[] {
+		if(ReadHistoryManager.book_list) {
+			return ReadHistoryManager.book_list
 		}
-		book_list = []
+		ReadHistoryManager.book_list = []
 		let string = util.getStorage(config.storage_key.READ_HISTORY)
 		if(string) {
-			// book_list = JSON.parse(string)  响应式对象无法被改变
-			Object.assign(book_list,JSON.parse(string))  // 使用此方法赋值给相应对象
+			ReadHistoryManager.book_list = JSON.parse(string)
 		}
-		return book_list
+		return ReadHistoryManager.book_list
 	}
 	
-	async function checkBookOnReadHistory(book_id:number, cb:Function) {
+	// 保存本地书列表
+	private static saveLocalBookList() {
+		util.setStorage(config.storage_key.READ_HISTORY, JSON.stringify(ReadHistoryManager.book_list))
+	}
+
+    // 检查在书架
+	public static async checkBookOnReadHistory(book_id:number, cb:Function) {
 		let index = -1
-		for (let i = 0; i < getBookList().length; i++) {
-			let element = getBookList()[i]
+		for (let i = 0; i < ReadHistoryManager.getBookList().length; i++) {
+			let element = ReadHistoryManager.getBookList()[i]
 			if(element.book_id == book_id) {
 				index = i
 				break
@@ -29,44 +36,40 @@ export const ReadHistory = defineStore('read-history',()=>{
 		cb && cb(index)
 	}
 	
-	async function addBook(book_data:book_item_data, cb:Function) {
+	// 添加书
+	public static async addBook(book_data:book_item_data, cb:Function) {
 		let read_hisroty_time = util.formatDate(new Date())
 		book_data.read_hisroty_time = read_hisroty_time
 		
-		checkBookOnReadHistory(book_data.book_id, (index:number)=>{
+		ReadHistoryManager.checkBookOnReadHistory(book_data.book_id, (index:number)=>{
 			if(index>-1) {
-				getBookList().splice(index,1)
+				ReadHistoryManager.getBookList().splice(index,1)
 			} 
-			getBookList().unshift(book_data)
-			// console.log('Readhistory-getBookList()=',getBookList())
-			saveBookList()
+			ReadHistoryManager.getBookList().unshift(book_data)
+			// console.log('Readhistory-getBookList()=',ReadHistoryManager.getBookList())
+			ReadHistoryManager.saveLocalBookList()
 			cb && cb()
 		})
 	}
 	
-	async function deleteBook(book_id_list:number[]) {
-		for (let i = 0; i < getBookList().length; i++) {
-			let i_element = getBookList()[i]
+	// 删除书
+	public static deleteBook(book_id_list:number[]) {
+		for (let i = 0; i < ReadHistoryManager.getBookList().length; i++) {
+			let i_element = ReadHistoryManager.getBookList()[i]
 			if(book_id_list.length==1) {
 				if(book_id_list.indexOf(i_element.book_id)>-1) {
-					getBookList().splice(i,1)
+					ReadHistoryManager.getBookList().splice(i,1)
 					break
 				}
 			} else {
 				for (let j = 0; j < book_id_list.length; j++) {
 					let j_element = book_id_list[i]
 					if(i_element.book_id = j_element) {
-						getBookList().splice(i,1)
+						ReadHistoryManager.getBookList().splice(i,1)
 					}
 				}
 			}
 		}
-		saveBookList()
-	}
-	
-	function saveBookList() {
-		util.setStorage(config.storage_key.READ_HISTORY, JSON.stringify(getBookList()))		
+		ReadHistoryManager.saveLocalBookList()
 	}
-	
-	return {book_list,getBookList,checkBookOnReadHistory,addBook,deleteBook,saveBookList}
-})
+}