diff --git a/api/request.js b/api/request.js index bbcdfe5..0797174 100644 --- a/api/request.js +++ b/api/request.js @@ -4,7 +4,9 @@ */ // API 基础配置 -const BASE_URL = 'http://xcsq.wxinh5.host' +const BASE_URL = process.env.NODE_ENV === 'production' + ? 'https://xcsq.wxinh5.com' + : 'http://xcsq.wxinh5.host' // 请求拦截器 const requestInterceptor = (config) => { diff --git a/components/CoupletDisplay.vue b/components/CoupletDisplay.vue index f834caa..99a0d07 100644 --- a/components/CoupletDisplay.vue +++ b/components/CoupletDisplay.vue @@ -6,7 +6,18 @@
- 春联海报 + +
+
+
海报加载中...
+
+ 春联海报
@@ -25,6 +36,8 @@ + \ No newline at end of file diff --git a/components/EndPage.vue b/components/EndPage.vue index bc909dc..3a4620f 100644 --- a/components/EndPage.vue +++ b/components/EndPage.vue @@ -92,6 +92,9 @@ \ No newline at end of file diff --git a/static/lfs/img1.jpg b/static/lfs/img1.jpg new file mode 100644 index 0000000..6c6a238 Binary files /dev/null and b/static/lfs/img1.jpg differ diff --git a/static/lfs/img1.png b/static/lfs/img1.png deleted file mode 100644 index c0f734c..0000000 Binary files a/static/lfs/img1.png and /dev/null differ diff --git a/static/lfs/img2.jpg b/static/lfs/img2.jpg new file mode 100644 index 0000000..d8c5e42 Binary files /dev/null and b/static/lfs/img2.jpg differ diff --git a/static/lfs/img2.png b/static/lfs/img2.png deleted file mode 100644 index a2f3d09..0000000 Binary files a/static/lfs/img2.png and /dev/null differ diff --git a/static/lfs/img3.jpg b/static/lfs/img3.jpg new file mode 100644 index 0000000..b66b728 Binary files /dev/null and b/static/lfs/img3.jpg differ diff --git a/static/lfs/img3.png b/static/lfs/img3.png deleted file mode 100644 index ee5823c..0000000 Binary files a/static/lfs/img3.png and /dev/null differ diff --git a/static/logo.png b/static/logo.png deleted file mode 100644 index b5771e2..0000000 Binary files a/static/logo.png and /dev/null differ diff --git a/static/qianmen-bg.jpg b/static/qianmen-bg.jpg deleted file mode 100644 index c4fd4ce..0000000 Binary files a/static/qianmen-bg.jpg and /dev/null differ diff --git a/static/wfj/img1.jpg b/static/wfj/img1.jpg new file mode 100644 index 0000000..2111183 Binary files /dev/null and b/static/wfj/img1.jpg differ diff --git a/static/wfj/img1.png b/static/wfj/img1.png deleted file mode 100644 index e6e86bd..0000000 Binary files a/static/wfj/img1.png and /dev/null differ diff --git a/static/wfj/img2.jpg b/static/wfj/img2.jpg new file mode 100644 index 0000000..07517b1 Binary files /dev/null and b/static/wfj/img2.jpg differ diff --git a/static/wfj/img2.png b/static/wfj/img2.png deleted file mode 100644 index 227805f..0000000 Binary files a/static/wfj/img2.png and /dev/null differ diff --git a/static/wfj/img3.jpg b/static/wfj/img3.jpg new file mode 100644 index 0000000..a47f09f Binary files /dev/null and b/static/wfj/img3.jpg differ diff --git a/static/wfj/img3.png b/static/wfj/img3.png deleted file mode 100644 index 1940290..0000000 Binary files a/static/wfj/img3.png and /dev/null differ diff --git a/static/wfj/img4.jpg b/static/wfj/img4.jpg new file mode 100644 index 0000000..f9b98d1 Binary files /dev/null and b/static/wfj/img4.jpg differ diff --git a/static/wfj/img4.png b/static/wfj/img4.png deleted file mode 100644 index d961418..0000000 Binary files a/static/wfj/img4.png and /dev/null differ diff --git a/utils/preload.js b/utils/preload.js new file mode 100644 index 0000000..f686281 --- /dev/null +++ b/utils/preload.js @@ -0,0 +1,128 @@ +// utils/preload.js +export class ImagePreloader { + constructor() { + this.cache = new Map(); + } + + /** + * 预加载单张图片 + * @param {string} src - 图片地址 + * @returns {Promise} + */ + async preload(src) { + if (!src) return false; + + // 检查缓存 + if (this.cache.has(src)) { + return true; + } + + // data URL 直接返回 + if (src.startsWith('data:')) { + this.cache.set(src, true); + return true; + } + + try { + // 本地图片和网络图片都需要真正加载 + if (src.startsWith('/')) { + // 对于本地图片,使用Image对象加载 + await new Promise((resolve, reject) => { + const img = new Image(); + img.onload = () => resolve(); + img.onerror = reject; + img.src = src; + }); + this.cache.set(src, true); + console.log('本地图片预加载成功:', src); + return true; + } else { + // 对于网络图片,使用uni.getImageInfo + await uni.getImageInfo({ src }); + this.cache.set(src, true); + console.log('网络图片预加载成功:', src); + return true; + } + } catch (error) { + console.warn('图片预加载失败:', src, error); + this.cache.set(src, false); + return false; + } + } + + /** + * 批量预加载图片 + * @param {string[]} srcList - 图片地址数组 + * @param {number} concurrency - 并发数 + * @returns {Promise>} + */ + async preloadAll(srcList, concurrency = 3) { + const results = []; + const queue = [...srcList]; + + // 执行并发下载 + const workers = []; + for (let i = 0; i < concurrency; i++) { + workers.push(this.worker(queue, results)); + } + + await Promise.all(workers); + return results; + } + + async worker(queue, results) { + while (queue.length > 0) { + const src = queue.shift(); + if (src) { + const success = await this.preload(src); + results.push({ src, success }); + } + } + } + + /** + * 清理缓存 + */ + clearCache() { + this.cache.clear(); + } + + /** + * 预加载图片并设置到 img 标签 + * @param {string} src - 图片地址 + * @param {number} timeout - 超时时间 + * @returns {Promise} 返回图片临时路径 + */ + async preloadToTemp(src, timeout = 10000) { + if (src.startsWith('/') || src.startsWith('data:')) { + return src; + } + + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + reject(new Error('图片下载超时')); + }, timeout); + + uni.downloadFile({ + url: src, + success: (res) => { + clearTimeout(timer); + if (res.statusCode === 200) { + const tempPath = res.tempFilePath; + this.cache.set(src, tempPath); + resolve(tempPath); + } else { + reject(new Error(`下载失败: ${res.statusCode}`)); + } + }, + fail: (error) => { + clearTimeout(timer); + reject(error); + } + }); + }); + } +} + +// 创建单例 +export default new ImagePreloader(); \ No newline at end of file