* 加载课本配置(book.json) * @returns {Promise }
()
| 163 | * @returns {Promise<void>} |
| 164 | */ |
| 165 | async loadBookConfig() { |
| 166 | if (!this.state.bookPath) { |
| 167 | this.renderEmptyState(this.config.ERROR_MESSAGES.NO_DATA); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | try { |
| 172 | const response = await fetch(`${this.state.bookPath}/book.json`); |
| 173 | const data = await response.json(); |
| 174 | |
| 175 | this.state.units = data.units.map((unit, index) => ({ |
| 176 | ...unit, |
| 177 | id: index + 1, |
| 178 | title: unit.title, |
| 179 | audio: `${this.state.bookPath}/${unit.filename}.mp3`, |
| 180 | lrc: `${this.state.bookPath}/${unit.filename}.lrc`, |
| 181 | })); |
| 182 | |
| 183 | if (this.dom.bookCover && data.bookCover) { |
| 184 | this.dom.bookCover.src = `${this.state.bookPath}/${data.bookCover}`; |
| 185 | } |
| 186 | |
| 187 | // 清除缓存 |
| 188 | this.lrcCache.clear(); |
| 189 | this.audioPreload.clear(); |
| 190 | } catch (error) { |
| 191 | console.error(this.config.ERROR_MESSAGES.LOAD_CONFIG, error); |
| 192 | this.renderEmptyState( |
| 193 | `${this.config.ERROR_MESSAGES.LOAD_CONFIG}: ${this.state.bookPath}/book.json` |
| 194 | ); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * 更新所有课本选择器 |
no test coverage detected