Переглянути джерело

feat(mp-weixin): 添加微信小程序特定功能支持

- 在 PrivacyPopup 组件中添加微信小程序隐私协议打开和授权监听代码
- 在 PrivacyPopup 中针对微信小程序调整同意按钮显示逻辑
- 在 Zcontact 组件中分别为微信小程序和非微信环境添加不同的按钮实现
- 在首页 index 页面针对微信小程序实现公众号和文章页面的跳转功能
- 非微信小程序环境下显示提示信息,提醒用户仅微信小程序支持相关功能
zhangtao 1 день тому
батько
коміт
ba0621c0f7

+ 15 - 0
src/components/PrivacyPopup.vue

@@ -26,6 +26,7 @@ function privacyHandler(resolve: any) {
 }
 
 onBeforeMount(() => {
+  // #ifdef MP-WEIXIN
   // 注册监听
   if (wx.onNeedPrivacyAuthorization) {
     wx.onNeedPrivacyAuthorization((resolve: any) => {
@@ -34,6 +35,7 @@ onBeforeMount(() => {
       }
     })
   }
+  // #endif
 })
 
 /**
@@ -68,7 +70,9 @@ function handleDisagree() {
  * 打开隐私协议
  */
 function openPrivacyContract() {
+  // #ifdef MP-WEIXIN
   wx.openPrivacyContract({})
+  // #endif
 }
 
 /**
@@ -109,6 +113,7 @@ export default {
         <button id="disagree-btn" class="is-block is-round is-medium is-plain wd-privacy-popup__footer-disagree wd-button" @click="handleDisagree">
           拒绝
         </button>
+        <!-- #ifdef MP-WEIXIN -->
         <button
           id="agree-btn"
           class="wd-button is-block is-round is-medium is-primary wd-privacy-popup__footer-agree"
@@ -117,6 +122,16 @@ export default {
         >
           同意
         </button>
+        <!-- #endif -->
+        <!-- #ifndef MP-WEIXIN -->
+        <button
+          id="agree-btn"
+          class="wd-button is-block is-round is-medium is-primary wd-privacy-popup__footer-agree"
+          @click="handleAgree"
+        >
+          同意
+        </button>
+        <!-- #endif -->
       </view>
     </wd-popup>
   </view>

+ 7 - 0
src/components/Zcontact.vue

@@ -3,9 +3,16 @@
 </script>
 
 <template>
+  <!-- #ifdef MP-WEIXIN -->
   <button open-type="contact" class="zbutton">
     <slot />
   </button>
+  <!-- #endif -->
+  <!-- #ifndef MP-WEIXIN -->
+  <button class="zbutton">
+    <slot />
+  </button>
+  <!-- #endif -->
 </template>
 
 <style scoped lang="scss">

+ 10 - 1
src/pages/index/index.vue

@@ -87,10 +87,14 @@ function handleClick(name: string) {
     return
   }
   if (name === 'refueling-tabbar') { // 跳转至公众号
+    // #ifdef MP-WEIXIN
     ;(wx as any).openOfficialAccountProfile({
       username: 'gh_6a682fa2ed1d',
     })
-
+    // #endif
+    // #ifndef MP-WEIXIN
+    show({ msg: '请在微信小程序中使用此功能' })
+    // #endif
     return
   }
 
@@ -126,9 +130,14 @@ function handleChangeSwiper(e: UniHelper.SwiperOnChangeEvent) {
   currentIndex.value = e.detail.current
 }
 function handleJyBanner() {
+  // #ifdef MP-WEIXIN
   wx.openOfficialAccountArticle({
     url: 'https://mp.weixin.qq.com/s/lxpdZ6DUhgqg00AT9klu5Q',
   })
+  // #endif
+  // #ifndef MP-WEIXIN
+  show({ msg: '请在微信小程序中使用此功能' })
+  // #endif
 }
 </script>