diff --git a/public/index.html b/public/index.html index 9713f20..caef4d3 100644 --- a/public/index.html +++ b/public/index.html @@ -1,26 +1,25 @@ - - - - - - - - - - - - - - - - - - -
- - + + + + + + + + + + + + + + + + + +
+ + diff --git a/src/assets/scss/common.scss b/src/assets/scss/common.scss index 106f70f..a1e35b4 100644 --- a/src/assets/scss/common.scss +++ b/src/assets/scss/common.scss @@ -1,4 +1,4 @@ -@import 'variable.scss'; +@use "./variable.scss" as *; .divider { height: .24rem; @@ -146,4 +146,4 @@ button:disabled { background: #e1e1e1 !important; border-color: #e1e1e1 !important; -} \ No newline at end of file +} diff --git a/src/common/wechat-web.js b/src/common/wechat-web.js index d87d873..29abd26 100644 --- a/src/common/wechat-web.js +++ b/src/common/wechat-web.js @@ -1,88 +1,126 @@ let wechatInstance; -import util from "@/util"; +let wechatReadyPromise = null; +// import util from "@/util"; + +function getShareConfig(shareConfig = {}) { + // const link = shareConfig.link || location.href; + return { + title: shareConfig.title || document.title || "自在福田", + desc: shareConfig.desc || "", + link: shareConfig.link, + imgUrl: shareConfig.imgUrl || "", + callback: shareConfig.callback, + }; +} + +function emitShareCallback(shareConfig, key, res) { + shareConfig.callback && + shareConfig.callback({ + key, + ...res, + }); +} function signToWechat(config, shareConfig) { if (!wx) { console.warn("请安装微信网页JS-SDK, url: https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"); + return; } const defaultConfig = { ...config, debug: false, jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "scanQRCode", "getLocation", "openLocation", "updateAppMessageShareData", "updateTimelineShareData"], }; - wx.config(defaultConfig); - wx.ready(function () { - console.log("wechat sdk config success"); - wechatInstance = wx; + wechatReadyPromise = new Promise((resolve, reject) => { + wx.ready(function () { + wechatInstance = wx; - wx.onMenuShareAppMessage({ - title: shareConfig.title, - desc: shareConfig.desc, - link: util.addExternalParamsToQuery(shareConfig.link, "no_login", 1), - imgUrl: shareConfig.imgUrl, - complete: (res) => { - shareConfig.callback && - shareConfig.callback({ - key: "updateAppMessageShareData", - ...res, - }); - }, + const safeShareConfig = getShareConfig(shareConfig); + if (typeof wx.updateAppMessageShareData === "function") { + wx.updateAppMessageShareData({ + title: safeShareConfig.title, + desc: safeShareConfig.desc, + link: safeShareConfig.link, + imgUrl: safeShareConfig.imgUrl, + complete: (res) => { + emitShareCallback(safeShareConfig, "updateAppMessageShareData", res); + }, + }); + } + + if (typeof wx.updateTimelineShareData === "function") { + wx.updateTimelineShareData({ + title: safeShareConfig.title, + link: safeShareConfig.link, + imgUrl: safeShareConfig.imgUrl, + complete: (res) => { + emitShareCallback(safeShareConfig, "updateTimelineShareData", res); + }, + }); + } + + if (typeof wx.onMenuShareAppMessage === "function") { + wx.onMenuShareAppMessage({ + title: safeShareConfig.title, + desc: safeShareConfig.desc, + link: safeShareConfig.link, + imgUrl: safeShareConfig.imgUrl, + complete: (res) => { + emitShareCallback(safeShareConfig, "onMenuShareAppMessage", res); + }, + }); + } + + if (typeof wx.onMenuShareTimeline === "function") { + wx.onMenuShareTimeline({ + title: safeShareConfig.title, + link: safeShareConfig.link, + imgUrl: safeShareConfig.imgUrl, + complete: (res) => { + emitShareCallback(safeShareConfig, "onMenuShareTimeline", res); + }, + }); + } + + resolve(wx); }); - // // 分享朋友圈 - wx.onMenuShareTimeline({ - title: shareConfig.title, - link: util.addExternalParamsToQuery(shareConfig.link, "no_login", 1), - imgUrl: shareConfig.imgUrl, - complete: (res) => { - shareConfig.callback && - shareConfig.callback({ - key: "updateTimelineShareData", - ...res, - }); - }, - }); - - // wx.updateAppMessageShareData({ - // title: shareConfig.title, - // desc: shareConfig.desc, - // link: shareConfig.link, - // imgUrl: shareConfig.imgUrl, - // complete: res => { - // shareConfig.callback && shareConfig.callback({ - // key: 'updateAppMessageShareData', - // ...res - // }); - // } - // }); - // // 分享朋友圈 - // wx.updateTimelineShareData({ - // title: shareConfig.title, - // link: shareConfig.link, - // imgUrl: shareConfig.imgUrl, - // complete: res => { - // shareConfig.callback && shareConfig.callback({ - // key: 'updateTimelineShareData', - // ...res - // }); - // } - // }); + if (typeof wx.error === "function") { + wx.error((error) => { + reject(error); + }); + } }); + wx.config(defaultConfig); } -function getLocation() { +async function getWechatInstance() { + if (wechatInstance) { + return wechatInstance; + } + if (wechatReadyPromise) { + return wechatReadyPromise; + } + return Promise.reject(new Error("微信 JS-SDK 尚未初始化")); +} + +async function getLocation() { + const instance = await getWechatInstance(); return new Promise((resolve, reject) => { - wechatInstance.getLocation({ + instance.getLocation({ type: "wgs84", success: (res) => { if (res.errMsg === "getLocation:ok") { resolve(res); } else { - reject(); + reject(new Error(res.errMsg || "获取定位失败")); } }, - error: () => { - reject(); + fail: (error) => { + reject(error || new Error("获取定位失败")); + }, + cancel: () => { + reject(new Error("用户取消定位")); }, }); }); diff --git a/src/components/merit-goods/index.vue b/src/components/merit-goods/index.vue index af9b388..7f058c7 100644 --- a/src/components/merit-goods/index.vue +++ b/src/components/merit-goods/index.vue @@ -40,6 +40,8 @@ export default { height: 2.93rem; margin-right: 0.4rem; border-radius: 0.11rem; + object-fit: contain; + background: #f1f1f1; } .info { flex: 1; diff --git a/src/components/user-merit/index.vue b/src/components/user-merit/index.vue index 05d78b0..5359249 100644 --- a/src/components/user-merit/index.vue +++ b/src/components/user-merit/index.vue @@ -51,12 +51,13 @@ export default { align-items: flex-end; margin-bottom: 0.2rem; font-size: 0.4rem; + line-height: 1.3; } p.goods_name { font-size: 0.34rem; max-width: 15em; line-height: 1.2; - overflow-x: hidden; + overflow: hidden; color: #666; white-space: nowrap; text-overflow: ellipsis; diff --git a/src/pages/goods-detail/index.vue b/src/pages/goods-detail/index.vue index 89f46e9..df87406 100644 --- a/src/pages/goods-detail/index.vue +++ b/src/pages/goods-detail/index.vue @@ -1,12 +1,12 @@