罗广辉
2026-04-25 114c3d78ff8be7ceb9880ab236e81c24ca6d256f
src/pages/login/index.vue
@@ -30,6 +30,10 @@
    <button class="login-btn" :style="[inputStyle]" @tap="submit">登录</button>
    <image class="lowerRightCorner" :src="droneSvg" />
    <!-- #ifdef MP-WEIXIN -->
    <GetPrivacy ref="privacyComponent" position="center" @allowPrivacy="allowPrivacy"/>
    <!-- #endif -->
  </view>
</template>
@@ -38,7 +42,9 @@
import md5 from "js-md5";
import { loginByUsername } from "@/api/user/index.js";
import { useUserStore } from "@/store/index.js";
// #ifdef MP-WEIXIN
import GetPrivacy from '@/components/GetPrivacy.vue'
// #endif
import { HOME_PATH, LOGIN_PATH, removeQueryString } from "@/router";
import { onMounted } from "vue";
@@ -147,6 +153,29 @@
    redirect = decodeURIComponent(options.redirect);
  }
});
// #ifdef MP-WEIXIN
const allowPrivacy = () =>{
  // 同意隐私协议触发事件,有些接口需要同意授权后才能执行,比如获取手机号授权接口,可以在同意隐私协议后,再执行授权获取手机号接口,如果不需要可以不添加该方法
  console.log('同意隐私授权')
}
const privacyComponent =ref(null)
onShow(() =>{
  wx.getPrivacySetting({
    success: res => {
      console.log(res)
      if (!res.needAuthorization) {
        privacyComponent?.value?.closePrivacy()
        // 查询授权,针对有tab切换的页面,可以在onshow中查询隐私授权状态,判断在tab切换后是否需要关闭授权弹框
        console.log('已经同意隐私授权,不需要再次授权')
      }
    },
    fail: () => {},
    complete: () => {}
  })
})
// #endif
</script>
<style lang="scss" scoped>