|
@@ -18,6 +18,7 @@ import { getShortBookInfo } from './server/book/short'
|
|
|
import { getUserInfo } from './server/wx/login'
|
|
import { getUserInfo } from './server/wx/login'
|
|
|
// 引入兼容性工具
|
|
// 引入兼容性工具
|
|
|
import { getAccountInfoSync } from './utils/compatibility'
|
|
import { getAccountInfoSync } from './utils/compatibility'
|
|
|
|
|
+import { bookrackShrotAddOrRemove } from './server/bookrack'
|
|
|
//引入官方小说阅读插件
|
|
//引入官方小说阅读插件
|
|
|
const novelPlugin = Taro.requirePlugin('novel-plugin')
|
|
const novelPlugin = Taro.requirePlugin('novel-plugin')
|
|
|
|
|
|
|
@@ -44,58 +45,80 @@ class App extends Component {
|
|
|
|
|
|
|
|
//每次打开小程序触发,后台切入不算
|
|
//每次打开小程序触发,后台切入不算
|
|
|
onLaunch(options) {
|
|
onLaunch(options) {
|
|
|
- // 监听进入插件页事件
|
|
|
|
|
|
|
+ // 监听进入插件页事件
|
|
|
novelPlugin.onPageLoad(this.onNovelPluginLoad)
|
|
novelPlugin.onPageLoad(this.onNovelPluginLoad)
|
|
|
}
|
|
}
|
|
|
onNovelPluginLoad(data) {
|
|
onNovelPluginLoad(data) {
|
|
|
console.log('onNovelPluginLoad', data)
|
|
console.log('onNovelPluginLoad', data)
|
|
|
- // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
|
|
|
|
|
- const novelManager = novelPlugin.getNovelManager(data.id)
|
|
|
|
|
-
|
|
|
|
|
- // getId() 返回当前阅读器实例 id
|
|
|
|
|
- console.log('id:', novelManager.getId())
|
|
|
|
|
-
|
|
|
|
|
- // 设置目录状态
|
|
|
|
|
- novelManager.setContents({
|
|
|
|
|
- contents: [
|
|
|
|
|
- {
|
|
|
|
|
- index: 0, // 第一章
|
|
|
|
|
- status: 0, // 免费
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- index: 1, // 第二章
|
|
|
|
|
- status: 2, // 未解锁
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- index: 2, // 第三章
|
|
|
|
|
- status: 1, // 已解锁
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 监听用户行为事件
|
|
|
|
|
- novelManager.onUserTriggerEvent(res => {
|
|
|
|
|
- console.log('onUserTriggerEvent', res.event_id, res)
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
|
|
|
|
|
+ const novelManager = novelPlugin.getNovelManager(data.id)
|
|
|
|
|
+ //获取自定义参数
|
|
|
|
|
+ let customParams = novelManager.getCustomServerParams();
|
|
|
|
|
+ if (customParams) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ customParams = JSON.parse(decodeURIComponent(customParams));
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('解析失败', e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //假如书籍已在书架改变插件书架状态
|
|
|
|
|
+ if(customParams && customParams.inBookshelf){
|
|
|
|
|
+ novelManager.setBookshelfStatus({
|
|
|
|
|
+ bookshelfStatus:1
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ // 默认设置目录状态
|
|
|
|
|
+ novelManager.setContents({
|
|
|
|
|
+ contents: [
|
|
|
|
|
+ {
|
|
|
|
|
+ index: 0, // 第一章
|
|
|
|
|
+ status: 0, // 免费
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ index: 1, // 第二章
|
|
|
|
|
+ status: 0, // 未解锁
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ index: 2, // 第三章
|
|
|
|
|
+ status: 0, // 已解锁
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ })
|
|
|
|
|
+ // 监听用户行为事件
|
|
|
|
|
+ novelManager.onUserTriggerEvent(res => {
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+ novelManager.onClickBookshelf((res) => {
|
|
|
|
|
+ if(res.bookshelfStatus == 0){
|
|
|
|
|
+ console.log("点击了加入书架")
|
|
|
|
|
+ bookrackShrotAddOrRemove({ bookId: customParams.bookId, add: true })
|
|
|
|
|
+ }else if(res.bookshelfStatus == 1){
|
|
|
|
|
+ console.log("点击了移出书架")
|
|
|
|
|
+ bookrackShrotAddOrRemove({ bookId: customParams.bookId, add: false })
|
|
|
|
|
+ }
|
|
|
|
|
+ novelManager.setBookshelfStatus({
|
|
|
|
|
+ bookshelfStatus:res.bookshelfStatus == 0 ? 1 : 0
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
console.log("APPcomponentDidMount")
|
|
console.log("APPcomponentDidMount")
|
|
|
/**获取状态栏高度 */
|
|
/**获取状态栏高度 */
|
|
|
Taro.getSystemInfo({}).then(res => {
|
|
Taro.getSystemInfo({}).then(res => {
|
|
|
- let { system, statusBarHeight,platform } = res
|
|
|
|
|
|
|
+ let { system, statusBarHeight, platform } = res
|
|
|
indexStore.setData({ navBarTop: statusBarHeight, system })//设置navbar高度和当前系统
|
|
indexStore.setData({ navBarTop: statusBarHeight, system })//设置navbar高度和当前系统
|
|
|
- setApp({ system:platform })
|
|
|
|
|
|
|
+ setApp({ system: platform })
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
async componentDidShow(options) {
|
|
async componentDidShow(options) {
|
|
|
- console.log("appcomponentDidShow",options)
|
|
|
|
|
- let { scene, query ,path} = options//获取当前小程序进入的场景值
|
|
|
|
|
|
|
+ console.log("appcomponentDidShow", options)
|
|
|
|
|
+ let { scene, query, path } = options//获取当前小程序进入的场景值
|
|
|
let bookConfig = Taro.getStorageSync("bookConfig")
|
|
let bookConfig = Taro.getStorageSync("bookConfig")
|
|
|
if (bookConfig) {
|
|
if (bookConfig) {
|
|
|
Book.setData({ bookConfig: JSON.parse(bookConfig) })
|
|
Book.setData({ bookConfig: JSON.parse(bookConfig) })
|
|
|
}
|
|
}
|
|
|
//阅读页面并且路径存在bookId请求数据
|
|
//阅读页面并且路径存在bookId请求数据
|
|
|
- if(query?.bookId && path === "pages/book/bookArticle/index"){
|
|
|
|
|
|
|
+ if (query?.bookId && path === "pages/book/bookArticle/index") {
|
|
|
getShortBookInfo(query?.bookId)
|
|
getShortBookInfo(query?.bookId)
|
|
|
}
|
|
}
|
|
|
indexStore.setData({ scene, query })
|
|
indexStore.setData({ scene, query })
|
|
@@ -104,11 +127,11 @@ class App extends Component {
|
|
|
initApp()//初始化全局变量
|
|
initApp()//初始化全局变量
|
|
|
let accountInfo = getAccountInfoSync().miniProgram//获取当前小程序的APPID
|
|
let accountInfo = getAccountInfoSync().miniProgram//获取当前小程序的APPID
|
|
|
let { appId, version, envVersion } = accountInfo;
|
|
let { appId, version, envVersion } = accountInfo;
|
|
|
- setApp({
|
|
|
|
|
- appId,
|
|
|
|
|
- proVersion: version,
|
|
|
|
|
|
|
+ setApp({
|
|
|
|
|
+ appId,
|
|
|
|
|
+ proVersion: version,
|
|
|
envVersion: envVersion as "develop" | "trial" | "release",
|
|
envVersion: envVersion as "develop" | "trial" | "release",
|
|
|
- pathParams:{ scene, ...query }
|
|
|
|
|
|
|
+ pathParams: { scene, ...query }
|
|
|
})
|
|
})
|
|
|
// 初始化登录,获取登录使用的token存放用于登录使用
|
|
// 初始化登录,获取登录使用的token存放用于登录使用
|
|
|
await api.loginInit(appId)
|
|
await api.loginInit(appId)
|