├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

list.vue 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. <template>
  2. <view class="novel-list-page">
  3. <!-- 加载状态 -->
  4. <view v-if="loading" class="loading-container">
  5. <uni-icons type="spinner-cycle" size="36" color="var(--primary-color)" class="loading-icon" />
  6. <text>加载中...</text>
  7. </view>
  8. <!-- 内容区域 -->
  9. <template v-else>
  10. <!-- 顶部广告 -->
  11. <ad-banner v-if="topAds.length" :ads="topAds" />
  12. <!-- 顶部分类导航 -->
  13. <scroll-view scroll-x class="category-nav">
  14. <view
  15. v-for="category in categories"
  16. :key="category.id"
  17. class="category-item"
  18. :class="{ active: activeCategory === category.id }"
  19. @click="changeCategory(category.id)"
  20. >
  21. {{ category.name }}
  22. </view>
  23. </scroll-view>
  24. <!-- 空状态 -->
  25. <view v-if="showEmptyState" class="empty-container">
  26. <image src="/static/empty-book.png" class="empty-img" />
  27. <text class="empty-text">暂无小说数据</text>
  28. <button class="btn-refresh" @click="reloadData">重新加载</button>
  29. </view>
  30. <!-- 错误状态 -->
  31. <view v-if="error && !showNovels" class="error-container">
  32. <uni-icons type="info" size="48" color="var(--error-color)" />
  33. <text class="error-text">{{ error }}</text>
  34. <button class="btn-refresh" @click="loadNovels">重新加载</button>
  35. </view>
  36. <!-- 热门推荐 -->
  37. <view v-if="showHotNovels" class="section">
  38. <view class="section-header">
  39. <text class="section-title">热门推荐</text>
  40. <text class="section-more" @click="goMore">更多 ></text>
  41. </view>
  42. <scroll-view scroll-x class="hot-list">
  43. <view
  44. v-for="novel in displayedHotNovels"
  45. :key="novel.id"
  46. class="hot-item"
  47. @click="openNovel(novel)"
  48. >
  49. <image
  50. :src="getCoverUrl(novel.coverImg)"
  51. class="hot-cover"
  52. @error="handleImageError"
  53. />
  54. <text class="hot-title">{{ novel.title }}</text>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. <!-- 小说列表 -->
  59. <view v-if="showNovels" class="section">
  60. <view class="section-header">
  61. <text class="section-title">小说列表</text>
  62. </view>
  63. <view class="novel-grid">
  64. <view
  65. v-for="novel in displayedNovels"
  66. :key="novel.id"
  67. class="novel-item"
  68. @click="openNovel(novel)"
  69. >
  70. <image
  71. :src="getCoverUrl(novel.coverImg)"
  72. class="novel-cover"
  73. @error="handleImageError"
  74. />
  75. <text class="novel-title">{{ novel.title }}</text>
  76. <text class="novel-author">{{ novel.author || '未知作者' }}</text>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 成为签约作家按钮 -->
  81. <view class="become-author" @click="applyAuthor">
  82. <text>成为签约作家,发布你的作品</text>
  83. </view>
  84. <!-- 底部广告 -->
  85. <ad-banner v-if="bottomAds.length" :ads="bottomAds" />
  86. </template>
  87. </view>
  88. </template>
  89. <script>
  90. import AdBanner from '@/components/AdBanner';
  91. export default {
  92. components: { AdBanner },
  93. data() {
  94. return {
  95. topAds: [],
  96. bottomAds: [],
  97. categories: [],
  98. activeCategory: 0,
  99. hotNovels: [],
  100. novels: [],
  101. loading: true,
  102. error: null,
  103. currentCategoryName: '全部',
  104. // 临时解决方案 - 模拟数据
  105. mockHotNovels: [
  106. { id: 1, title: '总裁的替身前妻', coverImg: '/static/demo-cover1.jpg', author: '言情作家' },
  107. { id: 2, title: '神医毒妃', coverImg: '/static/demo-cover2.jpg', author: '古风大神' },
  108. { id: 3, title: '穿越之王妃逆袭', coverImg: '/static/demo-cover3.jpg', author: '穿越达人' }
  109. ],
  110. mockNovels: [
  111. { id: 4, title: '都市最强赘婿', author: '网络作家', coverImg: '/static/demo-cover4.jpg' },
  112. { id: 5, title: '修仙归来', author: '仙侠迷', coverImg: '/static/demo-cover5.jpg' },
  113. { id: 6, title: '校园纯爱物语', author: '青春校园', coverImg: '/static/demo-cover6.jpg' }
  114. ],
  115. // 添加分页参数
  116. page: 1,
  117. pageSize: 10,
  118. total: 0,
  119. hasMore: true
  120. }
  121. },
  122. computed: {
  123. // 添加计算属性控制显示逻辑
  124. showEmptyState() {
  125. return this.novels.length === 0 && !this.error && !this.loading;
  126. },
  127. showHotNovels() {
  128. return this.hotNovels.length > 0 && !this.error;
  129. },
  130. showNovels() {
  131. return this.novels.length > 0 && !this.error;
  132. },
  133. displayedHotNovels() {
  134. return this.hotNovels.length > 0 ? this.hotNovels : this.mockHotNovels;
  135. },
  136. displayedNovels() {
  137. return this.novels.length > 0 ? this.novels : this.mockNovels;
  138. }
  139. },
  140. mounted() {
  141. this.initData();
  142. },
  143. methods: {
  144. async initData() {
  145. try {
  146. // 改为顺序加载,便于调试
  147. await this.loadCategories();
  148. await this.loadHotNovels();
  149. await this.loadNovels();
  150. } catch (e) {
  151. console.error('初始化失败', e);
  152. this.error = '初始化失败,请检查网络连接';
  153. } finally {
  154. this.loading = false;
  155. }
  156. },
  157. // 在 list.vue 的 methods 中修改 openNovel 方法
  158. // 在 list.vue 的 methods 中添加
  159. simpleNavigate(url) {
  160. try {
  161. // 方法1: 直接使用最基础的导航方式
  162. if (typeof uni !== 'undefined' && uni.navigateTo) {
  163. // 创建一个新的URL对象,确保格式正确
  164. const cleanUrl = url.split('?')[0];
  165. const params = new URLSearchParams(url.split('?')[1] || '');
  166. uni.navigateTo({
  167. url: `${cleanUrl}?${params.toString()}`,
  168. fail: (err) => {
  169. console.error('基础navigateTo失败:', err);
  170. // 方法2: 使用页面重定向
  171. this.simpleRedirect(url);
  172. }
  173. });
  174. } else {
  175. this.simpleRedirect(url);
  176. }
  177. } catch (error) {
  178. console.error('simpleNavigate异常:', error);
  179. this.simpleRedirect(url);
  180. }
  181. },
  182. simpleRedirect(url) {
  183. try {
  184. if (typeof uni !== 'undefined' && uni.redirectTo) {
  185. uni.redirectTo({
  186. url: url,
  187. fail: (err) => {
  188. console.error('redirectTo失败:', err);
  189. // 方法3: 使用Vue Router
  190. this.useVueRouterFallback(url);
  191. }
  192. });
  193. } else {
  194. this.useVueRouterFallback(url);
  195. }
  196. } catch (error) {
  197. console.error('simpleRedirect异常:', error);
  198. this.useVueRouterFallback(url);
  199. }
  200. },
  201. useVueRouterFallback(url) {
  202. try {
  203. // 解析URL路径和参数
  204. const [path, queryString] = url.split('?');
  205. const params = new URLSearchParams(queryString || '');
  206. const query = {};
  207. for (const [key, value] of params.entries()) {
  208. query[key] = value;
  209. }
  210. // 使用Vue Router
  211. if (this.$router && typeof this.$router.push === 'function') {
  212. this.$router.push({ path, query });
  213. } else {
  214. // 最终方案: 使用原生跳转
  215. window.location.href = url;
  216. }
  217. } catch (error) {
  218. console.error('useVueRouterFallback异常:', error);
  219. // 最终降级方案
  220. window.location.href = url;
  221. }
  222. },
  223. // 在 list.vue 中修改 openNovel 方法
  224. openNovel(novel) {
  225. try {
  226. console.log('准备打开小说:', novel);
  227. const novelId = novel.id || novel.novelId || novel.bookId;
  228. if (!novelId) {
  229. console.error('无法获取小说ID:', novel);
  230. uni.showToast({
  231. title: '小说ID不存在',
  232. icon: 'none'
  233. });
  234. return;
  235. }
  236. console.log('跳转到阅读页面,小说ID:', novelId);
  237. // 使用uni-app的标准导航方式
  238. uni.navigateTo({
  239. url: `/pages/novel/reader?novelId=${novelId}&chapterId=1`,
  240. success: (res) => {
  241. console.log('导航成功', res);
  242. },
  243. fail: (err) => {
  244. console.error('导航失败', err);
  245. // 备用导航方案
  246. this.$router.push({
  247. path: '/pages/novel/reader',
  248. query: { novelId: novelId, chapterId: 1 }
  249. });
  250. }
  251. });
  252. } catch (error) {
  253. console.error('openNovel方法执行异常:', error);
  254. uni.showToast({
  255. title: '发生未知错误',
  256. icon: 'none'
  257. });
  258. }
  259. },
  260. // 添加安全导航方法
  261. safeNavigateTo(url) {
  262. try {
  263. // 方法1: 直接使用 uni.navigateTo
  264. if (typeof uni.navigateTo === 'function') {
  265. uni.navigateTo({
  266. url: url,
  267. success: (res) => {
  268. console.log('navigateTo跳转成功', res);
  269. },
  270. fail: (err) => {
  271. console.error('navigateTo跳转失败', err);
  272. // 方法2: 使用重定向作为备选
  273. this.fallbackRedirect(url);
  274. }
  275. });
  276. } else {
  277. // 方法3: 使用备用导航
  278. this.fallbackRedirect(url);
  279. }
  280. } catch (error) {
  281. console.error('safeNavigateTo方法异常:', error);
  282. this.fallbackRedirect(url);
  283. }
  284. },
  285. // 备用重定向方法
  286. fallbackRedirect(url) {
  287. try {
  288. if (typeof uni.redirectTo === 'function') {
  289. uni.redirectTo({
  290. url: url,
  291. success: (res) => {
  292. console.log('redirectTo跳转成功', res);
  293. },
  294. fail: (err) => {
  295. console.error('redirectTo也失败', err);
  296. // 方法4: 使用Vue Router
  297. this.useVueRouter(url);
  298. }
  299. });
  300. } else {
  301. this.useVueRouter(url);
  302. }
  303. } catch (error) {
  304. console.error('fallbackRedirect方法异常:', error);
  305. this.useVueRouter(url);
  306. }
  307. },
  308. // 使用Vue Router进行导航
  309. useVueRouter(url) {
  310. try {
  311. // 解析URL
  312. const path = url.split('?')[0];
  313. const queryString = url.split('?')[1] || '';
  314. const params = new URLSearchParams(queryString);
  315. const query = {};
  316. for (const [key, value] of params.entries()) {
  317. query[key] = value;
  318. }
  319. if (this.$router && typeof this.$router.push === 'function') {
  320. this.$router.push({
  321. path: path,
  322. query: query
  323. });
  324. } else {
  325. // 最终降级方案
  326. window.location.href = url;
  327. }
  328. } catch (error) {
  329. console.error('useVueRouter方法异常:', error);
  330. // 最终降级方案
  331. window.location.href = url;
  332. }
  333. },
  334. // 备用导航方法
  335. fallbackNavigate(novelId) {
  336. try {
  337. console.log('尝试备用导航方法,小说ID:', novelId);
  338. // 方法1: 使用window.location (仅H5环境)
  339. if (typeof window !== 'undefined' && window.location) {
  340. window.location.href = `/pages/novel/reader?novelId=${novelId}`;
  341. return;
  342. }
  343. // 方法2: 使用Vue Router (如果可用)
  344. if (this.$router && typeof this.$router.push === 'function') {
  345. this.$router.push({
  346. path: '/pages/novel/reader',
  347. query: { novelId }
  348. });
  349. return;
  350. }
  351. // 方法3: 显示错误提示
  352. uni.showToast({
  353. title: '无法跳转,请检查页面配置',
  354. icon: 'none'
  355. });
  356. } catch (error) {
  357. console.error('备用导航方法也失败:', error);
  358. }
  359. },
  360. // 修复响应解析方法
  361. parseResponse(res) {
  362. console.log('原始响应对象:', res);
  363. // 处理不同的响应格式
  364. let responseData = {};
  365. // 如果res有arg属性,使用arg作为响应数据
  366. if (res && res.arg) {
  367. responseData = res.arg;
  368. console.log('使用res.arg作为响应数据:', responseData);
  369. }
  370. // 如果res有data属性,使用data作为响应数据
  371. else if (res && res.data) {
  372. responseData = res.data;
  373. console.log('使用res.data作为响应数据:', responseData);
  374. }
  375. // 如果res本身就是响应数据
  376. else {
  377. responseData = res;
  378. console.log('使用res本身作为响应数据:', responseData);
  379. }
  380. return responseData;
  381. },
  382. // 修复分类加载逻辑
  383. async loadCategories() {
  384. try {
  385. const res = await this.$http.get('/category/tree', {
  386. header: { isToken: false },
  387. timeout: 10000
  388. });
  389. console.log('分类API完整响应:', res);
  390. // 使用统一的响应解析方法
  391. const responseData = this.parseResponse(res);
  392. console.log('处理后的分类响应数据:', responseData);
  393. // 修复: 检查不同的响应格式
  394. let categoriesData = [];
  395. if (responseData.code === 200 && Array.isArray(responseData.data)) {
  396. categoriesData = responseData.data;
  397. } else if (Array.isArray(responseData)) {
  398. categoriesData = responseData;
  399. } else if (responseData.code === 200 && Array.isArray(responseData.rows)) {
  400. categoriesData = responseData.rows;
  401. }
  402. if (categoriesData.length > 0) {
  403. let subCategories = [];
  404. categoriesData.forEach(parent => {
  405. if (parent && parent.children && Array.isArray(parent.children)) {
  406. // 确保每个子分类都有必要的字段
  407. const validChildren = parent.children.filter(child =>
  408. child && child.id && (child.title || child.name)
  409. ).map(child => ({
  410. id: child.id,
  411. name: child.title || child.name // 使用title或name作为分类名称
  412. }));
  413. subCategories = [...subCategories, ...validChildren];
  414. }
  415. });
  416. // 添加"全部"分类
  417. this.categories = [
  418. { id: 0, name: '全部' },
  419. ...subCategories
  420. ];
  421. console.log('处理后的分类:', this.categories);
  422. } else {
  423. console.warn('分类数据结构异常,使用默认分类', responseData);
  424. this.categories = [{ id: 0, name: '全部' }];
  425. }
  426. } catch (e) {
  427. console.error('加载分类失败', e);
  428. this.categories = [{ id: 0, name: '全部' }];
  429. }
  430. },
  431. // 修复热门小说加载逻辑
  432. async loadHotNovels() {
  433. try {
  434. const res = await this.$http.get('/novel/hot', {
  435. header: { isToken: false },
  436. timeout: 10000
  437. });
  438. console.log('热门小说API完整响应:', res);
  439. // 使用统一的响应解析方法
  440. const responseData = this.parseResponse(res);
  441. console.log('处理后的热门小说响应:', responseData);
  442. // 处理API返回的数据格式
  443. if (responseData.code === 200) {
  444. if (Array.isArray(responseData.rows)) {
  445. this.hotNovels = responseData.rows;
  446. } else if (Array.isArray(responseData.data)) {
  447. this.hotNovels = responseData.data;
  448. } else {
  449. console.warn('热门小说数据格式异常', responseData);
  450. this.hotNovels = this.mockHotNovels;
  451. }
  452. } else {
  453. console.warn('热门小说API返回异常状态码', responseData);
  454. this.hotNovels = this.mockHotNovels;
  455. }
  456. // 只在真实数据不可用时使用模拟数据
  457. if (!this.hotNovels || this.hotNovels.length === 0) {
  458. console.warn('使用模拟热门小说数据');
  459. this.hotNovels = this.mockHotNovels;
  460. }
  461. } catch (e) {
  462. console.error('加载热门小说失败', e);
  463. this.hotNovels = this.mockHotNovels;
  464. }
  465. },
  466. // 修复小说列表加载逻辑
  467. async loadNovels(reset = false) {
  468. if (reset) {
  469. this.page = 1;
  470. this.hasMore = true;
  471. this.novels = [];
  472. }
  473. if (!this.hasMore) return;
  474. this.loading = true;
  475. this.error = null;
  476. // 提前声明变量,使其在整个函数中可用
  477. let newNovels = [];
  478. let total = 0;
  479. try {
  480. const res = await this.$http.get('/novel/list', {
  481. params: {
  482. page: this.page,
  483. pageSize: this.pageSize,
  484. categoryId: this.activeCategory
  485. },
  486. header: { isToken: false },
  487. timeout: 15000
  488. });
  489. console.log('小说列表API完整响应:', res);
  490. // 使用统一的响应解析方法
  491. const responseData = this.parseResponse(res);
  492. console.log('处理后的小说列表响应:', responseData);
  493. // 处理API返回的数据格式
  494. if (responseData.code === 200) {
  495. if (Array.isArray(responseData.rows)) {
  496. newNovels = responseData.rows;
  497. total = responseData.total || 0;
  498. } else if (Array.isArray(responseData.data)) {
  499. newNovels = responseData.data;
  500. total = responseData.total || newNovels.length;
  501. }
  502. } else if (responseData.code === 500) {
  503. // 处理服务器错误
  504. console.error('服务器内部错误:', responseData.msg);
  505. throw new Error('服务器内部错误,请稍后重试');
  506. }
  507. if (newNovels.length > 0) {
  508. this.novels = [...this.novels, ...newNovels];
  509. this.hasMore = this.novels.length < total;
  510. this.page++;
  511. // 修复: 确保图片URL正确
  512. this.novels.forEach(novel => {
  513. if (novel.coverImg) {
  514. novel.coverImg = this.getCoverUrl(novel.coverImg);
  515. }
  516. });
  517. // 确保每个novel对象都有有效的id
  518. this.novels.forEach((novel, index) => {
  519. if (!novel.id) {
  520. console.warn(`小说 ${index} 缺少ID,使用索引作为临时ID`);
  521. novel.id = index + 1; // 使用索引作为临时ID
  522. }
  523. });
  524. } else if (this.page === 1) {
  525. console.warn('小说列表为空,使用模拟数据');
  526. this.novels = this.mockNovels; // 使用模拟数据
  527. }
  528. } catch (e) {
  529. console.error('加载小说失败', e);
  530. if (e.errMsg && e.errMsg.includes('timeout')) {
  531. this.error = '网络请求超时,请检查网络连接';
  532. } else if (e.message && e.message.includes('服务器内部错误')) {
  533. this.error = '服务器暂时不可用,请稍后重试';
  534. } else {
  535. this.error = '加载失败,请重试';
  536. }
  537. this.novels = this.mockNovels; // 回退到模拟数据
  538. } finally {
  539. this.loading = false;
  540. }
  541. },
  542. // 暂时禁用广告加载,避免404错误
  543. async loadAds() {
  544. try {
  545. console.log('广告功能暂未开放');
  546. this.topAds = [];
  547. this.bottomAds = [];
  548. // 以下是原有的广告加载代码,暂时注释掉
  549. /*
  550. // 使用Promise.all并行请求
  551. const [topRes, bottomRes] = await Promise.all([
  552. this.$http.get('/ad/position?code=TOP_BANNER', {
  553. header: { isToken: false }
  554. }),
  555. this.$http.get('/ad/position?code=BOTTOM_BANNER', {
  556. header: { isToken: false }
  557. })
  558. ]);
  559. // 处理广告响应
  560. this.topAds = this.parseAdResponse(topRes);
  561. this.bottomAds = this.parseAdResponse(bottomRes);
  562. */
  563. } catch (e) {
  564. console.error('加载广告失败', e);
  565. this.topAds = [];
  566. this.bottomAds = [];
  567. }
  568. },
  569. // 广告响应解析方法 - 简化逻辑
  570. parseAdResponse(response) {
  571. if (!response || !response.data) return [];
  572. const responseData = response.data;
  573. // 统一处理可能的响应格式
  574. if (responseData.code === 200 && Array.isArray(responseData.data)) {
  575. return responseData.data;
  576. } else if (Array.isArray(responseData)) {
  577. return responseData;
  578. } else if (responseData.code === 200 && Array.isArray(responseData.rows)) {
  579. return responseData.rows;
  580. }
  581. return [];
  582. },
  583. // 修复封面URL处理
  584. getCoverUrl(cover) {
  585. if (!cover) return '/static/default-cover.jpg';
  586. // 如果已经是完整URL,直接返回
  587. if (cover.startsWith('http')) return cover;
  588. // 如果是相对路径,添加基础URL
  589. if (cover.startsWith('/')) {
  590. return `${process.env.VUE_APP_BASE_URL || ''}${cover}`;
  591. }
  592. // 其他情况,直接返回
  593. return cover;
  594. },
  595. // 添加图片错误处理
  596. handleImageError(event) {
  597. console.log('图片加载失败:', event);
  598. event.target.src = '/static/default-cover.jpg';
  599. },
  600. // 其他方法...
  601. changeCategory(categoryId) {
  602. this.activeCategory = categoryId;
  603. const category = this.categories.find(c => c.id === categoryId);
  604. this.currentCategoryName = category ? category.name : '全部';
  605. this.loadNovels(true); // 重置并加载新分类
  606. },
  607. applyAuthor() {
  608. if (!this.$store.getters.token) {
  609. uni.showToast({ title: '请先登录', icon: 'none' });
  610. uni.navigateTo({ url: '/pages/login' });
  611. return;
  612. }
  613. uni.navigateTo({ url: '/pages/author/apply' });
  614. },
  615. goMore() {
  616. uni.navigateTo({
  617. url: '/pages/novel/more'
  618. });
  619. },
  620. // 确保重新加载按钮绑定到正确的方法
  621. reloadData() {
  622. this.initData();
  623. },
  624. // 添加上拉加载事件
  625. onReachBottom() {
  626. this.loadNovels();
  627. }
  628. }
  629. }
  630. </script>
  631. <style scoped>
  632. /* 添加加载状态样式 */
  633. .loading-container {
  634. display: flex;
  635. flex-direction: column;
  636. align-items: center;
  637. justify-content: center;
  638. padding: 100rpx 0;
  639. }
  640. .loading-icon {
  641. animation: rotate 1s linear infinite;
  642. margin-bottom: 20rpx;
  643. }
  644. @keyframes rotate {
  645. from { transform: rotate(0deg); }
  646. to { transform: rotate(360deg); }
  647. }
  648. /* 添加空状态样式 */
  649. .empty-container, .error-container {
  650. display: flex;
  651. flex-direction: column;
  652. align-items: center;
  653. justify-content: center;
  654. padding: 100rpx 0;
  655. text-align: center;
  656. }
  657. .empty-img {
  658. width: 200rpx;
  659. height: 200rpx;
  660. opacity: 0.6;
  661. margin-bottom: 40rpx;
  662. }
  663. .empty-text, .error-text {
  664. font-size: 32rpx;
  665. color: var(--text-color);
  666. margin-bottom: 40rpx;
  667. }
  668. .error-text {
  669. color: var(--error-color);
  670. }
  671. .btn-refresh {
  672. background-color: var(--primary-color);
  673. color: white;
  674. width: 60%;
  675. border-radius: 50rpx;
  676. }
  677. /* 确保网格布局正确 */
  678. .novel-grid {
  679. display: grid;
  680. grid-template-columns: repeat(3, 1fr);
  681. gap: 20rpx;
  682. padding: 20rpx;
  683. }
  684. .novel-item {
  685. background-color: white;
  686. border-radius: 12rpx;
  687. overflow: hidden;
  688. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  689. }
  690. /* 确保封面有默认背景和固定比例 */
  691. .novel-cover, .hot-cover {
  692. width: 100%;
  693. height: 300rpx;
  694. background-color: #f5f5f5;
  695. object-fit: cover;
  696. }
  697. .novel-title {
  698. display: block;
  699. font-size: 28rpx;
  700. padding: 10rpx 15rpx;
  701. white-space: nowrap;
  702. overflow: hidden;
  703. text-overflow: ellipsis;
  704. }
  705. .novel-author {
  706. display: block;
  707. font-size: 24rpx;
  708. color: #888;
  709. padding: 0 15rpx 15rpx;
  710. }
  711. /* 热门列表样式 */
  712. .hot-list {
  713. display: flex;
  714. padding: 20rpx;
  715. overflow-x: auto;
  716. white-space: nowrap;
  717. }
  718. .hot-item {
  719. display: inline-block;
  720. width: 200rpx;
  721. margin-right: 30rpx;
  722. }
  723. .hot-cover {
  724. width: 200rpx;
  725. height: 280rpx;
  726. border-radius: 8rpx;
  727. }
  728. .hot-title {
  729. display: block;
  730. margin-top: 10rpx;
  731. font-size: 26rpx;
  732. white-space: nowrap;
  733. overflow: hidden;
  734. text-overflow: ellipsis;
  735. }
  736. /* 分类导航样式 */
  737. .category-nav {
  738. white-space: nowrap;
  739. padding: 20rpx 0;
  740. background-color: #fff;
  741. border-bottom: 1rpx solid #eee;
  742. }
  743. .category-item {
  744. display: inline-block;
  745. padding: 10rpx 30rpx;
  746. margin: 0 10rpx;
  747. border-radius: 30rpx;
  748. font-size: 28rpx;
  749. }
  750. .category-item.active {
  751. background-color: var(--primary-color);
  752. color: white;
  753. }
  754. /* 章节标题样式 */
  755. .section {
  756. margin-top: 30rpx;
  757. }
  758. .section-header {
  759. display: flex;
  760. justify-content: space-between;
  761. align-items: center;
  762. padding: 0 20rpx 20rpx;
  763. }
  764. .section-title {
  765. font-size: 32rpx;
  766. font-weight: bold;
  767. }
  768. .section-more {
  769. font-size: 26rpx;
  770. color: var(--text-secondary-color);
  771. }
  772. /* 成为作家按钮样式 */
  773. .become-author {
  774. margin: 40rpx 20rpx;
  775. padding: 20rpx;
  776. text-align: center;
  777. background-color: var(--primary-color);
  778. color: white;
  779. border-radius: 10rpx;
  780. font-size: 30rpx;
  781. }
  782. </style>