|
|
@@ -78,11 +78,7 @@
|
|
|
<view class="main flex-shrink flex-column flex-align-center pt-40">
|
|
|
<view class="fs-32 color-000-6 mt-40">登录后查看更多功能</view>
|
|
|
<view class="mt-32">
|
|
|
- <button
|
|
|
- open-type="getPhoneNumber"
|
|
|
- @getphonenumber="handleLogin"
|
|
|
- class="login-btn"
|
|
|
- >登录/注册</button>
|
|
|
+ <button class="login-btn" @click="goToLogin">登录/注册</button>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -93,8 +89,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { fetchContact } from "@/api";
|
|
|
import { fetchProfile } from "@/api/user";
|
|
|
-import { login } from "@/api/auth";
|
|
|
-import { fetchToken } from "@/api/auth";
|
|
|
+import { isAuthenticated, requireAuth } from "@/utils/auth";
|
|
|
import { onLoad, onShow } from "@dcloudio/uni-app";
|
|
|
import { ref } from "vue";
|
|
|
const containerStyle = ref({});
|
|
|
@@ -144,8 +139,15 @@ const menu = ref([
|
|
|
icon: "/static/images/user/1.png",
|
|
|
},
|
|
|
]);
|
|
|
+const AUTH_REQUIRED_INDICES = [0, 1, 2, 3, 4];
|
|
|
+
|
|
|
+const goToLogin = () => {
|
|
|
+ requireAuth("/pages/user/user");
|
|
|
+};
|
|
|
+
|
|
|
const toPage = (index: number) => {
|
|
|
if (index < 0) {
|
|
|
+ if (!requireAuth("/pages-user/wallet/wallet")) return;
|
|
|
uni.navigateTo({
|
|
|
url: "/pages-user/wallet/wallet",
|
|
|
});
|
|
|
@@ -158,24 +160,14 @@ const toPage = (index: number) => {
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
+ if (AUTH_REQUIRED_INDICES.includes(index) && !requireAuth(item.path)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
uni.navigateTo({
|
|
|
url: item.path + (item.title === "常见问题" ? `?service=${service.value}` : ""),
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-const handleLogin = (e: any) => {
|
|
|
- login(e).then(() => {
|
|
|
- fetchProfile().then((res) => {
|
|
|
- res.mobilePhoneFormat =
|
|
|
- res.mobilePhone.slice(0, 3) + "****" + res.mobilePhone.slice(7);
|
|
|
- res.avatar = res.avatar
|
|
|
- ? res.avatar
|
|
|
- : "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
|
|
|
- user.value = res;
|
|
|
- });
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
onLoad(() => {
|
|
|
const bound = uni.getMenuButtonBoundingClientRect();
|
|
|
containerStyle.value = {
|
|
|
@@ -188,7 +180,7 @@ onLoad(() => {
|
|
|
});
|
|
|
});
|
|
|
onShow(() => {
|
|
|
- if (!getApp<any>().globalData.token) {
|
|
|
+ if (!isAuthenticated()) {
|
|
|
return;
|
|
|
}
|
|
|
fetchProfile().then((res) => {
|