* 根据 key 查找课本 * @param {string} bookKey - 课本标识 key * @returns {Object|null} 匹配的课本对象
(bookKey)
| 109 | * @returns {Object|null} 匹配的课本对象 |
| 110 | */ |
| 111 | resolveBookByKey(bookKey) { |
| 112 | if (!this.state.books.length) return null; |
| 113 | |
| 114 | const exact = this.state.books.find((book) => book?.key === bookKey); |
| 115 | if (exact?.bookPath) return exact; |
| 116 | |
| 117 | const fallback = this.state.books.find((book) => book?.key === this.config.DEFAULT_BOOK_KEY); |
| 118 | if (fallback?.bookPath) return fallback; |
| 119 | |
| 120 | return this.state.books.find((book) => book?.bookPath) || null; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * 从 URL hash 应用课本 |