diff --git a/src/main_pages/components/ListPageContent.module.scss b/src/main_pages/components/ListPageContent.module.scss index 76cd39f..e44d0d8 100644 --- a/src/main_pages/components/ListPageContent.module.scss +++ b/src/main_pages/components/ListPageContent.module.scss @@ -56,7 +56,7 @@ // border-radius: 12px; // border: 1px solid rgba(0, 0, 0, 0.06); // background: lightgray 50% / cover no-repeat; - box-shadow: 0 4px 36px 0 rgba(0, 0, 0, 0.16); + // box-shadow: 0 4px 36px 0 rgba(0, 0, 0, 0.16); } .qrcodeTip { @@ -74,12 +74,14 @@ } .listPage { - background-color: #FAFAFA; + background-color: #fafafa; font-family: "PingFang SC"; transition: padding-top 0.3s ease-in-out; // 添加过渡动画,让布局变化更平滑 display: flex; flex-direction: column; - height: calc(100vh - var(--status-bar-height, 0px) - var(--nav-bar-height, 0px) - 112px); // 减去底部导航栏高度 112px + height: calc( + 100vh - var(--status-bar-height, 0px) - var(--nav-bar-height, 0px) - 112px + ); // 减去底部导航栏高度 112px overflow: hidden; .fixedHeader { @@ -190,4 +192,4 @@ .guideBarHighZIndex { z-index: 900 !important; // 正常状态,保持较高层级 -} \ No newline at end of file +} diff --git a/src/utils/wx_helper.ts b/src/utils/wx_helper.ts index a3382f8..013f9f1 100644 --- a/src/utils/wx_helper.ts +++ b/src/utils/wx_helper.ts @@ -1,35 +1,48 @@ import Taro from "@tarojs/taro"; export function saveImage(url) { - Taro.getSetting().then(async (res) => { - if (!res.authSetting["scope.writePhotosAlbum"]) { + // 下载网络图片,返回本地 temp 文件 + const download = () => { + return Taro.downloadFile({ url }).then(res => { + if (res.statusCode === 200) { + return res.tempFilePath + } + throw new Error("图片下载失败") + }) + } + + const save = async () => { + try { + const filePath = await download() + await Taro.saveImageToPhotosAlbum({ filePath }) + Taro.showToast({ title: "保存成功" }) + } catch (e) { + console.error(e) + Taro.showToast({ title: "图片保存失败", icon: "none" }) + } + } + + Taro.getSetting().then(res => { + const authorized = res.authSetting["scope.writePhotosAlbum"] + + if (!authorized) { Taro.authorize({ scope: "scope.writePhotosAlbum", - success: async () => { - try { - Taro.saveImageToPhotosAlbum({ filePath: url }); - Taro.showToast({ title: "保存成功" }); - } catch (e) { - Taro.showToast({ title: "图片保存失败", icon: "none" }); - } + success: () => { + save() }, fail: () => { Taro.showModal({ title: "提示", content: "需要开启相册权限才能保存图片", success: (r) => { - if (r.confirm) Taro.openSetting(); - }, - }); - }, - }); + if (r.confirm) Taro.openSetting() + } + }) + } + }) } else { - try { - Taro.saveImageToPhotosAlbum({ filePath: url }); - Taro.showToast({ title: "保存成功" }); - } catch (e) { - Taro.showToast({ title: "图片保存失败", icon: "none" }); - } + save() } - }); -} \ No newline at end of file + }) +}