refactor(custom): 完善活动页细节
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-07-20 18:31:34 +08:00
parent b20930f516
commit e55cc6c9e0
2 changed files with 61 additions and 36 deletions

View File

@@ -95,11 +95,10 @@ Taro.useReachBottom(() => {
}); });
const toPay = async item => { const toPay = async item => {
console.log(item);
const tk = Taro.getStorageSync('token'); const tk = Taro.getStorageSync('token');
if (!tk) { if (!tk) {
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/users/login/index', url: '/pages/users/login/index?isBack=1',
}); });
return; return;
} }

View File

@@ -1,9 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import Taro from "@tarojs/taro"; import Taro from '@tarojs/taro';
import UserModal from "@/components/UserModal.vue"; import UserModal from '@/components/UserModal.vue';
import { ref } from "vue"; import {ref} from 'vue';
import { getPhone, login } from "@/api/user"; import {getPhone, login, getPersonalInfo} from '@/api/user';
import logoImg from "../../../static/logo.jpg"; import logoImg from '../../../static/logo.jpg';
const isShow = ref(false); const isShow = ref(false);
@@ -12,17 +12,17 @@ const val = ref(false);
const getCode = () => { const getCode = () => {
if (!val.value) if (!val.value)
return Taro.showToast({ return Taro.showToast({
title: "请先阅读并同意用户协议&隐私政策&积分使用规则", title: '请先阅读并同意用户协议&隐私政策&积分使用规则',
icon: "none", icon: 'none',
}); });
Taro.showLoading({ Taro.showLoading({
title: "授权中...", title: '授权中...',
mask: true, mask: true,
}); });
Taro.login({ Taro.login({
success: (res) => { success: res => {
console.log(res); console.log(res);
Taro.setStorageSync("wx_code", res.code); Taro.setStorageSync('wx_code', res.code);
isShow.value = true; isShow.value = true;
}, },
complete: () => { complete: () => {
@@ -32,51 +32,64 @@ const getCode = () => {
}; };
const userInfo = ref({ const userInfo = ref({
phone: "", phone: '',
});
const optData = ref({});
Taro.useLoad(opt => {
optData.value = opt;
}); });
const getPhoneNumber = async (e: any) => { const getPhoneNumber = async (e: any) => {
if (!val.value) { if (!val.value) {
Taro.showToast({ Taro.showToast({
title: "请先阅读并同意用户协议&隐私政策&积分使用规则", title: '请先阅读并同意用户协议&隐私政策&积分使用规则',
icon: "none", icon: 'none',
}); });
} else { } else {
Taro.showLoading({ Taro.showLoading({
title: "授权手机号中", title: '授权手机号中',
mask: true, mask: true,
}); });
const { code } = e.detail; const {code} = e.detail;
const res = await getPhone({ const res = await getPhone({
code: code, code: code,
}); });
userInfo.value.phone = res.data.phone; userInfo.value.phone = res.data.phone;
if (!res.data.phone) if (!res.data.phone)
return Taro.showToast({ return Taro.showToast({
title: "手机号获取失败", title: '手机号获取失败',
icon: "none", icon: 'none',
}); });
Taro.login({ Taro.login({
success: async (res) => { success: async res => {
Taro.setStorageSync("wx_code", res.code); Taro.setStorageSync('wx_code', res.code);
const ress = await login({ const ress = await login({
Code: Taro.getStorageSync("wx_code"), Code: Taro.getStorageSync('wx_code'),
Phone: userInfo.value.phone, Phone: userInfo.value.phone,
Referee: Taro.getStorageSync("bind_id") || "", Referee: Taro.getStorageSync('bind_id') || '',
}); });
Taro.showToast({ Taro.showToast({
title: ress.msg, title: ress.msg,
icon: "success", icon: 'success',
duration: 2000, duration: 2000,
}); });
Taro.setStorageSync("token", ress.data.token); Taro.setStorageSync('token', ress.data.token);
setTimeout(() => { if (optData.value.isBack) {
Taro.removeStorageSync("wx_code"); await getUserInfo();
Taro.removeStorageSync("bind_id"); Taro.navigateBack({
Taro.switchTab({ delta: 1,
url: "/pages/user/index",
}); });
}, 2000); } else {
setTimeout(() => {
Taro.removeStorageSync('wx_code');
Taro.removeStorageSync('bind_id');
Taro.switchTab({
url: '/pages/user/index',
});
}, 2000);
}
}, },
complete: () => { complete: () => {
Taro.hideLoading(); Taro.hideLoading();
@@ -85,14 +98,28 @@ const getPhoneNumber = async (e: any) => {
} }
}; };
const getUserInfo = async () => {
const res = await getPersonalInfo();
const userInfo = {
...res.data,
data: {
...res.data.data,
permission: res.data.data.permission
? JSON.parse(res.data.data.permission)
: {},
},
};
Taro.setStorageSync('userInfo', userInfo);
};
const toPage = () => { const toPage = () => {
if (!val.value) if (!val.value)
return Taro.showToast({ return Taro.showToast({
title: "请先阅读并同意用户协议&隐私政策&积分使用规则", title: '请先阅读并同意用户协议&隐私政策&积分使用规则',
icon: "none", icon: 'none',
}); });
Taro.navigateTo({ Taro.navigateTo({
url: "/pages/users/bindPhone/index?type=1", url: '/pages/users/bindPhone/index?type=1',
}); });
}; };
@@ -132,8 +159,7 @@ const clickText = (type: number, text: string) => {
隐私政策 </view 隐私政策 </view
>&<view >&<view
style="color: #fa2c1a" style="color: #fa2c1a"
@click.stop="clickText(3, '积分使用规则')" @click.stop="clickText(3, '积分使用规则')">
>
积分使用规则 积分使用规则
</view> </view>
</view> </view>