|
@@ -80,6 +80,7 @@ export class tools {
|
|
|
if(data.code==config.url_confg.StatesCode.SUCCESS){
|
|
|
// console.log('登录成功=',data)
|
|
|
UserData().updateUserData(data.content)
|
|
|
+ uni.$emit(config.EVENT_TYPE.USER_LOGIN_SUCCESS)
|
|
|
cb && cb()
|
|
|
}
|
|
|
} else {
|
|
@@ -126,7 +127,6 @@ export class tools {
|
|
|
public static exitRead() {
|
|
|
// let book_data = UserStatus().getUserSelectBook()
|
|
|
// 更新:书架、阅读历史,读到当前章节数据
|
|
|
- // UserStatus().getUserSelectBook().start_read_chapter_id =
|
|
|
}
|
|
|
|
|
|
// 获取用户信息
|
|
@@ -139,11 +139,50 @@ export class tools {
|
|
|
return tools.getUserData().is_vip
|
|
|
}
|
|
|
|
|
|
+ // 获取请求书架参数
|
|
|
+ public static getRequestBookshelfParameter(book_data:book_item_data) {
|
|
|
+ let book_opt = {
|
|
|
+ 'book_id':book_data.book_id,
|
|
|
+ 'start_read_chapter_id':book_data.start_read_chapter_id}
|
|
|
+ return book_opt
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 请求书架
|
|
|
+ * books_shelf: json
|
|
|
+ * stype: int 类型 1:获取 2:同步书架
|
|
|
+ */
|
|
|
+ public static requestBookShelf(book_list:book_item_data[], stype:number, successs_cb:Function, falil_cb:Function) {
|
|
|
+ let books_shelf_string = ''
|
|
|
+ if(book_list.length>0) {
|
|
|
+ books_shelf_string = JSON.stringify(book_list)
|
|
|
+ }
|
|
|
+ let opt = {'books_shelf':books_shelf_string, 'stype':stype}
|
|
|
+ http.DynamicRequest(config.url_confg.Dynamic.books_shelf, opt, (err,data)=>{
|
|
|
+ // console.log('err=',err,'data=',data)
|
|
|
+ if(!err) {
|
|
|
+ if(data.code==config.url_confg.StatesCode.SUCCESS){
|
|
|
+ successs_cb && successs_cb(data.content)
|
|
|
+ } else {
|
|
|
+ falil_cb && falil_cb()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Error(err)
|
|
|
+ falil_cb && falil_cb()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
// 获取本地书架列表
|
|
|
public static getLocalBookshelfList():book_item_data[] {
|
|
|
return BookshelfManager.getBookList()
|
|
|
}
|
|
|
|
|
|
+ // 保存本地书架列表
|
|
|
+ public static saveLocalBookshelfList() {
|
|
|
+ BookshelfManager.saveLocalBookList()
|
|
|
+ }
|
|
|
+
|
|
|
// 检查在书架
|
|
|
public static checkBookOnBookshelf(book_id:number, cb:Function) {
|
|
|
BookshelfManager.checkBookOnBookshelf(book_id, (is_on:boolean)=>{
|
|
@@ -153,25 +192,43 @@ export class tools {
|
|
|
|
|
|
// 添加书架
|
|
|
public static addBookshelf(book_data:book_item_data, cb:Function=null) {
|
|
|
- util.showLoading('加入书架...', true)
|
|
|
+ util.showLoading('加载中...', true)
|
|
|
util.hideLoading(500, ()=>{
|
|
|
- // 请求
|
|
|
- BookshelfManager.addBook(book_data)
|
|
|
uni.$emit(config.EVENT_TYPE.UPDATE_BOOKSHELF)
|
|
|
cb && cb()
|
|
|
})
|
|
|
+ // 本地添加书
|
|
|
+ BookshelfManager.addBook(book_data)
|
|
|
+ // 请求
|
|
|
+ let data_list = []
|
|
|
+ for (let i = 0; i < BookshelfManager.getBookList().length; i++) {
|
|
|
+ let element = BookshelfManager.getBookList()[i]
|
|
|
+ data_list.push(tools.getRequestBookshelfParameter(element))
|
|
|
+ }
|
|
|
+ tools.requestBookShelf(data_list,2,()=>{
|
|
|
+ console.log('同步书架(加入)-成功')
|
|
|
+ },null)
|
|
|
}
|
|
|
|
|
|
// 删除书架
|
|
|
public static deleteBookshelf(book_id_list:number[], cb:Function=null) {
|
|
|
util.showModal('删除?', `从书架删除这${book_id_list.length}本书?`, ()=>{
|
|
|
util.showLoading('移除书架...', true)
|
|
|
- util.hideLoading(500, ()=>{
|
|
|
- // 请求
|
|
|
- BookshelfManager.deleteBook(book_id_list)
|
|
|
+ util.hideLoading(500, ()=>{
|
|
|
uni.$emit(config.EVENT_TYPE.UPDATE_BOOKSHELF)
|
|
|
cb && cb()
|
|
|
})
|
|
|
+ // 本地删除书
|
|
|
+ BookshelfManager.deleteBook(book_id_list)
|
|
|
+ // 请求
|
|
|
+ let data_list = []
|
|
|
+ for (let i = 0; i < BookshelfManager.getBookList().length; i++) {
|
|
|
+ let element = BookshelfManager.getBookList()[i]
|
|
|
+ data_list.push(tools.getRequestBookshelfParameter(element))
|
|
|
+ }
|
|
|
+ tools.requestBookShelf(data_list,2,()=>{
|
|
|
+ console.log('同步书架(删除)-成功')
|
|
|
+ },null)
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -192,6 +249,11 @@ export class tools {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ // 重置排序阅读历史
|
|
|
+ public static resetSortReadHistory(book_list:book_item_data[]) {
|
|
|
+ ReadHistoryManager.resetData(book_list)
|
|
|
+ }
|
|
|
+
|
|
|
public static getChapterList(chapter_path:string,cb:Function){
|
|
|
let url = `${config.url_addr.Static}${chapter_path}`
|
|
|
http.StaticRequest(url,(err,data)=>{
|