From bfab2b190a512fc48024eea79308ebc945bf3711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 9 Sep 2025 20:05:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer):=20=E9=87=8D=E6=9E=84=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=91=98=E7=94=B3=E8=AF=B7=E9=A1=B5=E9=9D=A2=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改页面标题为"邀请注册"- 增加头像上传和昵称输入功能 - 添加获取微信昵称和手机号的功能- 优化表单布局和样式 - 移除审核状态相关代码 --- config/env.ts | 2 +- src/admin/components/UserCard.tsx | 223 -------------------- src/admin/components/UserCell.tsx | 186 ----------------- src/admin/components/UserFooter.tsx | 102 ---------- src/admin/components/UserOrder.tsx | 69 ------- src/admin/index.tsx | 302 ++++++++++++++++++++++++++-- src/api/system/user/model/index.ts | 2 + src/app.config.ts | 54 ++--- src/cms/detail/index.tsx | 2 +- src/dealer/apply/add.config.ts | 2 +- src/dealer/apply/add.tsx | 235 ++++++++++++++++++---- src/hooks/useUser.ts | 14 +- src/pages/index/Header.tsx | 176 ++++++++-------- 13 files changed, 616 insertions(+), 753 deletions(-) delete mode 100644 src/admin/components/UserCard.tsx delete mode 100644 src/admin/components/UserCell.tsx delete mode 100644 src/admin/components/UserFooter.tsx delete mode 100644 src/admin/components/UserOrder.tsx diff --git a/config/env.ts b/config/env.ts index c3f95e2..de8e281 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'http://127.0.0.1:9200/api', + API_BASE_URL: 'https://cms-api.websoft.top/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/admin/components/UserCard.tsx b/src/admin/components/UserCard.tsx deleted file mode 100644 index afe3a05..0000000 --- a/src/admin/components/UserCard.tsx +++ /dev/null @@ -1,223 +0,0 @@ -import {Button} from '@nutui/nutui-react-taro' -import {Avatar, Tag} from '@nutui/nutui-react-taro' -import {getWxOpenId} from '@/api/layout'; -import Taro from '@tarojs/taro'; -import {useEffect} from "react"; -import navTo from "@/utils/common"; -import {TenantId} from "@/config/app"; -import {useUser} from "@/hooks/useUser"; -import {useUserData} from "@/hooks/useUserData"; - -function UserCard() { - const { - user, - isLoggedIn, - loginUser, - fetchUserInfo, - getDisplayName, - getRoleName - } = useUser(); - const {data} = useUserData() - - useEffect(() => { - // Taro.getSetting:获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 - Taro.getSetting({ - success: (res) => { - if (res.authSetting['scope.userInfo']) { - // 用户已经授权过,可以直接获取用户信息 - console.log('用户已经授权过,可以直接获取用户信息') - reload(); - } else { - // 用户未授权,需要弹出授权窗口 - console.log('用户未授权,需要弹出授权窗口') - showAuthModal(); - } - } - }); - }, []); - - - const reload = async () => { - // 如果已登录,获取最新用户信息 - if (isLoggedIn) { - try { - const data = await fetchUserInfo(); - if (data) { - // 获取openId - if (!data.openid) { - Taro.login({ - success: (res) => { - getWxOpenId({code: res.code}).then(() => { - }) - } - }) - } - } - } catch (error) { - console.error('获取用户信息失败:', error) - } - } - }; - - const showAuthModal = () => { - Taro.showModal({ - title: '授权提示', - content: '需要获取您的用户信息', - confirmText: '去授权', - cancelText: '取消', - success: (res) => { - if (res.confirm) { - // 用户点击确认,打开授权设置页面 - openSetting(); - } - } - }); - }; - - - const openSetting = () => { - // Taro.openSetting:调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 - Taro.openSetting({ - success: (res) => { - if (res.authSetting['scope.userInfo']) { - // 用户授权成功,可以获取用户信息 - reload(); - } else { - // 用户拒绝授权,提示授权失败 - Taro.showToast({ - title: '授权失败', - icon: 'none' - }); - } - } - }); - }; - - /* 获取用户手机号 */ - const handleGetPhoneNumber = ({detail}: { detail: { code?: string, encryptedData?: string, iv?: string } }) => { - const {code, encryptedData, iv} = detail - Taro.login({ - success: function (loginRes) { - if (code) { - Taro.request({ - url: 'https://server.websoft.top/api/wx-login/loginByMpWxPhone', - method: 'POST', - data: { - authCode: loginRes.code, - code, - encryptedData, - iv, - notVerifyPhone: true, - refereeId: 0, - sceneType: 'save_referee', - tenantId: TenantId - }, - header: { - 'content-type': 'application/json', - TenantId - }, - success: function (res) { - if (res.data.code == 1) { - Taro.showToast({ - title: res.data.message, - icon: 'error', - duration: 2000 - }) - return false; - } - // 登录成功 - const token = res.data.data.access_token; - const userData = res.data.data.user; - - // 使用useUser Hook的loginUser方法更新状态 - loginUser(token, userData); - - // 显示登录成功提示 - Taro.showToast({ - title: '登录成功', - icon: 'success', - duration: 1500 - }) - - // 刷新页面数据 - reload(); - } - }) - } else { - console.log('登录失败!') - } - } - }) - } - - return ( -
-
-
-
-
- { - isLoggedIn ? ( - - ) : ( - - ) - } -
-
{getDisplayName()}
- {isLoggedIn ? ( -
- -
- {getRoleName()} -
-
-
- ) : ''} -
-
-
navTo('/user/profile/profile', true)}> - {'个人资料'} -
-
-
-
navTo('/user/wallet/wallet', true)}> - 余额 - ¥ {data?.balance || '0.00'} -
-
navTo('/user/coupon/index', true)}> - 优惠券 - {data?.coupons || 0} -
-
navTo('/user/gift/index', true)}> - 礼品卡 - {data?.giftCards || 0} -
- {/*
*/} - {/* 积分*/} - {/* {pointsCount}*/} - {/*
*/} -
-
-
-
- - ) -} - -export default UserCard; diff --git a/src/admin/components/UserCell.tsx b/src/admin/components/UserCell.tsx deleted file mode 100644 index 0928980..0000000 --- a/src/admin/components/UserCell.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import {Cell} from '@nutui/nutui-react-taro' -import navTo from "@/utils/common"; -import Taro from '@tarojs/taro' -import {View, Text} from '@tarojs/components' -import {ArrowRight, ShieldCheck, LogisticsError, Location, Reward, Tips, Ask, Setting, Scan} from '@nutui/icons-react-taro' -import {useUser} from '@/hooks/useUser' - -const UserCell = () => { - const {logoutUser, isCertified, hasRole, isAdmin} = useUser(); - - const onLogout = () => { - Taro.showModal({ - title: '提示', - content: '确定要退出登录吗?', - success: function (res) { - if (res.confirm) { - // 使用 useUser hook 的 logoutUser 方法 - logoutUser(); - Taro.reLaunch({ - url: '/pages/index/index' - }) - } - } - }) - } - - return ( - <> - - - {/*是否分销商*/} - {!hasRole('dealer') && !isAdmin() && ( - navTo('/dealer/index', true)}> - - 开通会员 - 享优惠 - - } - extra={} - /> - )} - - {/*是否管理员*/} - {isAdmin() && ( - navTo('/admin/article/index', true)}> - - 管理中心 - - } - extra={} - /> - )} - - - 我的服务 - - }> - - - 门店核销 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/wallet/index', true) - }} - /> - - - 我的钱包 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/wallet/index', true) - }} - /> - - - 收货地址 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/address/index', true) - }} - /> - - - 实名认证 - {isCertified() && ( - 已认证 - )} - - } - align="center" - extra={} - onClick={() => { - navTo('/user/userVerify/index', true) - }} - /> - - - 常见问题 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/help/index') - }} - /> - - - 关于我们 - - } - align="center" - extra={} - onClick={() => { - navTo('/user/about/index') - }} - /> - - - 账号管理 - - }> - } - onClick={() => navTo('/user/profile/profile', true)} - /> - } - onClick={onLogout} - /> - - - - ) -} -export default UserCell diff --git a/src/admin/components/UserFooter.tsx b/src/admin/components/UserFooter.tsx deleted file mode 100644 index fb74b71..0000000 --- a/src/admin/components/UserFooter.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import {loginBySms} from "@/api/passport/login"; -import {useState} from "react"; -import Taro from '@tarojs/taro' -import {Popup} from '@nutui/nutui-react-taro' -import {UserParam} from "@/api/system/user/model"; -import {Button} from '@nutui/nutui-react-taro' -import {Form, Input} from '@nutui/nutui-react-taro' -import {Copyright, Version} from "@/config/app"; -const UserFooter = () => { - const [openLoginByPhone, setOpenLoginByPhone] = useState(false) - const [clickNum, setClickNum] = useState(0) - const [FormData, setFormData] = useState( - { - phone: undefined, - password: undefined - } - ) - - const onLoginByPhone = () => { - setFormData({}) - setClickNum(clickNum + 1); - if (clickNum > 10) { - setOpenLoginByPhone(true); - } - } - - const closeLoginByPhone = () => { - setClickNum(0) - setOpenLoginByPhone(false) - } - - // 提交表单 - const submitByPhone = (values: any) => { - loginBySms({ - phone: values.phone, - code: values.code - }).then(() => { - setOpenLoginByPhone(false); - setTimeout(() => { - Taro.reLaunch({ - url: '/pages/index/index' - }) - },1000) - }) - } - - return ( - <> -
-
当前版本:{Version}
-
Copyright © { new Date().getFullYear() } {Copyright}
-
- - -
submitByPhone(values)} - footer={ -
- -
- } - > - - - - - - -
-
- - ) -} -export default UserFooter diff --git a/src/admin/components/UserOrder.tsx b/src/admin/components/UserOrder.tsx deleted file mode 100644 index 92e94a4..0000000 --- a/src/admin/components/UserOrder.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import {useEffect} from "react"; -import navTo from "@/utils/common"; -import {View, Text} from '@tarojs/components'; -import {ArrowRight, Wallet, Comment, Transit, Refund, Package} from '@nutui/icons-react-taro'; - -function UserOrder() { - - const reload = () => { - - }; - - useEffect(() => { - reload() - }, []); - - return ( - <> - - - - 我的订单 - navTo('/user/order/order', true)}> - 全部订单 - - - - - navTo('/user/order/order?statusFilter=0', true)}> - - 待付款 - - navTo('/user/order/order?statusFilter=1', true)}> - - 待发货 - - navTo('/user/order/order?statusFilter=3', true)}> - - 待收货 - - navTo('/user/order/order?statusFilter=5', true)}> - - 已完成 - - navTo('/user/order/order?statusFilter=6', true)}> - - 退货/售后 - - - - - - - ) -} - -export default UserOrder; diff --git a/src/admin/index.tsx b/src/admin/index.tsx index 8fd127e..2c9d6a0 100644 --- a/src/admin/index.tsx +++ b/src/admin/index.tsx @@ -1,25 +1,295 @@ -import {useEffect} from 'react' -import {useUser} from "@/hooks/useUser"; -import {Text} from '@tarojs/components'; +import React from 'react' +import {View, Text} from '@tarojs/components' +import {ConfigProvider, Button, Grid, Avatar} from '@nutui/nutui-react-taro' +import { + User, + Shopping, + Dongdong, + ArrowRight, + Purse, + People +} from '@nutui/icons-react-taro' +import {useDealerUser} from '@/hooks/useDealerUser' +import { useThemeStyles } from '@/hooks/useTheme' +import {businessGradients, cardGradients, gradientUtils} from '@/styles/gradients' +import Taro from '@tarojs/taro' -function Admin() { +const DealerIndex: React.FC = () => { const { - isAdmin - } = useUser(); + dealerUser, + error, + refresh, + } = useDealerUser() - useEffect(() => { - }, []); + // 使用主题样式 + const themeStyles = useThemeStyles() - if (!isAdmin()) { - return ( - 您不是管理员 - ); + // 导航到各个功能页面 + const navigateToPage = (url: string) => { + Taro.navigateTo({url}) } + + // 格式化金额 + const formatMoney = (money?: string) => { + if (!money) return '0.00' + return parseFloat(money).toFixed(2) + } + + // 格式化时间 + const formatTime = (time?: string) => { + if (!time) return '-' + return new Date(time).toLocaleDateString() + } + + // 获取用户主题 + const userTheme = gradientUtils.getThemeByUserId(dealerUser?.userId) + + // 获取渐变背景 + const getGradientBackground = (themeColor?: string) => { + if (themeColor) { + const darkerColor = gradientUtils.adjustColorBrightness(themeColor, -30) + return gradientUtils.createGradient(themeColor, darkerColor) + } + return userTheme.background + } + + console.log(getGradientBackground(),'getGradientBackground()') + + if (error) { + return ( + + + {error} + + + + ) + } + return ( - <> - 待开发... - + + + {/*头部信息*/} + {dealerUser && ( + + {/* 装饰性背景元素 - 小程序兼容版本 */} + + + + + } + className="mr-4" + style={{ + border: '2px solid rgba(255, 255, 255, 0.3)' + }} + /> + + + {dealerUser?.realName || '分销商'} + + + ID: {dealerUser.userId} | 推荐人: {dealerUser.refereeId || '无'} + + + + 加入时间 + + {formatTime(dealerUser.createTime)} + + + + + )} + + {/* 佣金统计卡片 */} + {dealerUser && ( + + + 佣金统计 + + + + + {formatMoney(dealerUser.money)} + + 可提现 + + + + {formatMoney(dealerUser.freezeMoney)} + + 冻结中 + + + + {formatMoney(dealerUser.totalMoney)} + + 累计收益 + + + + )} + + {/* 团队统计 */} + {dealerUser && ( + + + 我的邀请 + navigateToPage('/dealer/team/index')} + > + 查看详情 + + + + + + + {dealerUser.firstNum || 0} + + 一级成员 + + + + {dealerUser.secondNum || 0} + + 二级成员 + + + + {dealerUser.thirdNum || 0} + + 三级成员 + + + + )} + + {/* 功能导航 */} + + 分销工具 + + + navigateToPage('/dealer/orders/index')}> + + + + + + + + navigateToPage('/dealer/withdraw/index')}> + + + + + + + + navigateToPage('/dealer/team/index')}> + + + + + + + + navigateToPage('/dealer/qrcode/index')}> + + + + + + + + + {/* 第二行功能 */} + {/**/} + {/* navigateToPage('/dealer/invite-stats/index')}>*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + + {/* /!* 预留其他功能位置 *!/*/} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/* */} + {/**/} + + + + + {/* 底部安全区域 */} + + ) } -export default Admin +export default DealerIndex diff --git a/src/api/system/user/model/index.ts b/src/api/system/user/model/index.ts index 33c8feb..ab734c4 100644 --- a/src/api/system/user/model/index.ts +++ b/src/api/system/user/model/index.ts @@ -128,6 +128,8 @@ export interface User { certification?: boolean; // 实名认证类型 certificationType?: number; + // 推荐人ID + refereeId?: number; } /** diff --git a/src/app.config.ts b/src/app.config.ts index 4fa7148..bfdf8f8 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -81,13 +81,13 @@ export default defineAppConfig({ // 'orderConfirmCart/index', // 'search/index'] // }, - // { - // "root": "admin", - // "pages": [ - // "index", - // "article/index", - // ] - // } + { + "root": "admin", + "pages": [ + "index", + "article/index", + ] + } ], window: { backgroundTextStyle: 'dark', @@ -95,18 +95,18 @@ export default defineAppConfig({ navigationBarTitleText: 'WeChat', navigationBarTextStyle: 'black' }, - tabBar: { - custom: false, - color: "#8a8a8a", - selectedColor: "#0e932e", - backgroundColor: "#ffffff", - list: [ - { - pagePath: "pages/index/index", - iconPath: "assets/tabbar/index.png", - selectedIconPath: "assets/tabbar/index-active.png", - text: "首页", - }, + // tabBar: { + // custom: false, + // color: "#8a8a8a", + // selectedColor: "#0e932e", + // backgroundColor: "#ffffff", + // list: [ + // { + // pagePath: "pages/index/index", + // iconPath: "assets/tabbar/index.png", + // selectedIconPath: "assets/tabbar/index-active.png", + // text: "首页", + // }, // { // pagePath: "pages/find/find", // iconPath: "assets/tabbar/find.png", @@ -119,14 +119,14 @@ export default defineAppConfig({ // selectedIconPath: "assets/tabbar/cart-active.png", // text: "购物车", // }, - { - pagePath: "pages/user/user", - iconPath: "assets/tabbar/user.png", - selectedIconPath: "assets/tabbar/user-active.png", - text: "我的", - }, - ], - }, + // { + // pagePath: "pages/user/user", + // iconPath: "assets/tabbar/user.png", + // selectedIconPath: "assets/tabbar/user-active.png", + // text: "我的", + // }, + // ], + // }, requiredPrivateInfos: [ "getLocation", "chooseLocation", diff --git a/src/cms/detail/index.tsx b/src/cms/detail/index.tsx index f92c890..2d70c73 100644 --- a/src/cms/detail/index.tsx +++ b/src/cms/detail/index.tsx @@ -18,7 +18,7 @@ function Detail() { const item = await getCmsArticle(Number(params.id)) if (item) { - item.content = wxParse(item.content) + item.content = wxParse(`${item.content}`) setItem(item) Taro.setNavigationBarTitle({ title: `${item?.categoryName}` diff --git a/src/dealer/apply/add.config.ts b/src/dealer/apply/add.config.ts index 02d2f80..ac37521 100644 --- a/src/dealer/apply/add.config.ts +++ b/src/dealer/apply/add.config.ts @@ -1,4 +1,4 @@ export default definePageConfig({ - navigationBarTitleText: '申请成为业务员', + navigationBarTitleText: '邀请注册', navigationBarTextStyle: 'black' }) diff --git a/src/dealer/apply/add.tsx b/src/dealer/apply/add.tsx index 08c2f15..804bfaa 100644 --- a/src/dealer/apply/add.tsx +++ b/src/dealer/apply/add.tsx @@ -1,8 +1,8 @@ import {useEffect, useState, useRef} from "react"; -import {Loading, CellGroup, Cell, Input, Form} from '@nutui/nutui-react-taro' +import {Loading, CellGroup, Cell, Input, Form, Avatar, Button, Space} from '@nutui/nutui-react-taro' import {Edit} from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' -import {View} from '@tarojs/components' +import {View, Text} from '@tarojs/components' import FixedButton from "@/components/FixedButton"; import {useUser} from "@/hooks/useUser"; import {ShopDealerApply} from "@/api/shop/shopDealerApply/model"; @@ -12,11 +12,28 @@ import { updateShopDealerApply } from "@/api/shop/shopDealerApply"; import {getShopDealerUser} from "@/api/shop/shopDealerUser"; +import {TenantId} from "@/config/app"; +import {updateUser} from "@/api/system/user"; +import {User} from "@/api/system/user/model"; +import {getStoredInviteParams, handleInviteRelation} from "@/utils/invite"; + +// 类型定义 +interface ChooseAvatarEvent { + detail: { + avatarUrl: string; + }; +} + +interface InputEvent { + detail: { + value: string; + }; +} const AddUserAddress = () => { - const {user} = useUser() + const {user, loginUser} = useUser() const [loading, setLoading] = useState(true) - const [FormData, setFormData] = useState() + const [FormData, setFormData] = useState() const formRef = useRef(null) const [isEditMode, setIsEditMode] = useState(false) const [existingApply, setExistingApply] = useState(null) @@ -36,6 +53,13 @@ const AddUserAddress = () => { } const reload = async () => { + const inviteParams = getStoredInviteParams() + if (inviteParams?.inviter) { + setFormData({ + ...user, + refereeId: Number(inviteParams.inviter), + }) + } // 判断用户是否登录 if (!user?.userId) { return false; @@ -62,6 +86,56 @@ const AddUserAddress = () => { } } + + const uploadAvatar = ({detail}: ChooseAvatarEvent) => { + // 先更新本地显示的头像 + setFormData({ + ...FormData, + avatar: `${detail.avatarUrl}`, + }) + + Taro.uploadFile({ + url: 'https://server.websoft.top/api/oss/upload', + filePath: detail.avatarUrl, + name: 'file', + header: { + 'content-type': 'application/json', + TenantId + }, + success: async (res) => { + const data = JSON.parse(res.data); + if (data.code === 0) { + try { + // 使用 useUser hook 的 updateUser 方法更新头像 + await updateUser({ + avatar: `${data.data.thumbnail}` + }) + // 由于 useEffect 监听了 user 变化,FormData 会自动同步更新 + } catch (error) { + console.error('更新头像失败:', error) + // 如果更新失败,恢复原来的头像 + setFormData({ + ...FormData, + avatar: user?.avatar || '' + }) + } + } + }, + fail: (error) => { + console.error('上传头像失败:', error) + Taro.showToast({ + title: '上传失败', + icon: 'error' + }) + // 恢复原来的头像 + setFormData({ + ...FormData, + avatar: user?.avatar || '' + }) + } + }) + } + // 提交表单 const submitSucceed = async (values: any) => { try { @@ -107,6 +181,99 @@ const AddUserAddress = () => { } } + // 获取微信昵称 + const getWxNickname = (nickname: string) => { + // 更新表单数据 + setFormData({ + ...FormData, + nickname: nickname + }); + } + + /* 获取用户手机号 */ + const handleGetPhoneNumber = ({detail}: { detail: { code?: string, encryptedData?: string, iv?: string } }) => { + const {code, encryptedData, iv} = detail + Taro.login({ + success: (loginRes) => { + if (code) { + Taro.request({ + url: 'https://server.websoft.top/api/wx-login/loginByMpWxPhone', + method: 'POST', + data: { + authCode: loginRes.code, + code, + encryptedData, + iv, + notVerifyPhone: true, + refereeId: 0, + sceneType: 'save_referee', + tenantId: TenantId + }, + header: { + 'content-type': 'application/json', + TenantId + }, + success: async function (res) { + if (res.data.code == 1) { + Taro.showToast({ + title: res.data.message, + icon: 'error', + duration: 2000 + }) + return false; + } + // 登录成功 + const token = res.data.data.access_token; + const userData = res.data.data.user; + console.log(userData,'userData...') + // 使用useUser Hook的loginUser方法更新状态 + loginUser(token, userData); + + if(userData.phone){ + console.log('手机号已获取',userData.phone) + setFormData({ + ...userData, + phone: userData.phone + }) + } + + + + // 处理邀请关系 + if (userData?.userId) { + try { + const inviteSuccess = await handleInviteRelation(userData.userId) + if (inviteSuccess) { + Taro.showToast({ + title: '邀请关系建立成功', + icon: 'success', + duration: 2000 + }) + } + } catch (error) { + console.error('处理邀请关系失败:', error) + } + } + + // 显示登录成功提示 + // Taro.showToast({ + // title: '注册成功', + // icon: 'success', + // duration: 1500 + // }) + + // 不需要重新启动小程序,状态已经通过useUser更新 + // 可以选择性地刷新当前页面数据 + // await reload(); + } + }) + } else { + console.log('登录失败!') + } + } + }) + } + // 处理固定按钮点击事件 const handleFixedButtonClick = () => { // 触发表单提交 @@ -139,47 +306,43 @@ const AddUserAddress = () => { > - - - - - - - + + + + + + + + + + + { + FormData?.phone && + + + } + + getWxNickname(e.detail.value)} + /> - {/* 审核状态显示(仅在编辑模式下显示) */} - {isEditMode && ( - - - {getApplyStatusText(FormData?.applyStatus)} - - } - /> - {FormData?.applyStatus === 20 && ( - - )} - {FormData?.applyStatus === 30 && ( - - )} - - )} - {/* 底部浮动按钮 */} - {(!isEditMode || FormData?.applyStatus === 10 || FormData?.applyStatus === 30) && ( + {(!isEditMode) && ( } text={isEditMode ? '保存修改' : '提交申请'} - disabled={FormData?.applyStatus === 10} onClick={handleFixedButtonClick} /> )} diff --git a/src/hooks/useUser.ts b/src/hooks/useUser.ts index c8bf04c..479a0f3 100644 --- a/src/hooks/useUser.ts +++ b/src/hooks/useUser.ts @@ -3,7 +3,7 @@ import Taro from '@tarojs/taro'; import { User } from '@/api/system/user/model'; import { getUserInfo, updateUserInfo, loginByOpenId } from '@/api/layout'; import { TenantId } from '@/config/app'; -import { handleInviteRelation } from '@/utils/invite'; +import {getStoredInviteParams, handleInviteRelation} from '@/utils/invite'; // 用户Hook export const useUser = () => { @@ -43,7 +43,17 @@ export const useUser = () => { } else { reject(new Error('自动登录失败')); } - }).catch(reject); + }).catch(_ => { + // 首次注册,跳转到邀请注册页面 + const pages = Taro.getCurrentPages(); + const currentPage = pages[pages.length - 1]; + const inviteParams = getStoredInviteParams() + if (currentPage?.route !== 'dealer/apply/add' && inviteParams?.inviter) { + return Taro.navigateTo({ + url: '/dealer/apply/add' + }); + } + }); }, fail: reject }); diff --git a/src/pages/index/Header.tsx b/src/pages/index/Header.tsx index 194ed58..a5afb84 100644 --- a/src/pages/index/Header.tsx +++ b/src/pages/index/Header.tsx @@ -1,15 +1,15 @@ import {useEffect, useState} from "react"; import Taro from '@tarojs/taro'; -import {Button, Space} from '@nutui/nutui-react-taro' +import {Space} from '@nutui/nutui-react-taro' import {TriangleDown} from '@nutui/icons-react-taro' import {Avatar, NavBar} from '@nutui/nutui-react-taro' import {getWxOpenId} from "@/api/layout"; -import {TenantId} from "@/config/app"; +// import {TenantId} from "@/config/app"; import {getOrganization} from "@/api/system/organization"; import {myUserVerify} from "@/api/system/userVerify"; import {useShopInfo} from '@/hooks/useShopInfo'; import {useUser} from '@/hooks/useUser'; -import {handleInviteRelation} from "@/utils/invite"; +// import {handleInviteRelation} from "@/utils/invite"; import {View, Text} from '@tarojs/components' import MySearch from "./MySearch"; import './Header.scss'; @@ -18,14 +18,14 @@ import navTo from "@/utils/common"; const Header = (props: any) => { // 使用新的useShopInfo Hook const { - getWebsiteLogo + getWebsiteLogo, + getWebsiteName } = useShopInfo(); // 使用useUser Hook管理用户状态 const { user, isLoggedIn, - loginUser, fetchUserInfo } = useUser(); @@ -112,78 +112,78 @@ const Header = (props: any) => { } /* 获取用户手机号 */ - const handleGetPhoneNumber = ({detail}: { detail: { code?: string, encryptedData?: string, iv?: string } }) => { - const {code, encryptedData, iv} = detail - Taro.login({ - success: (loginRes) => { - if (code) { - Taro.request({ - url: 'https://server.websoft.top/api/wx-login/loginByMpWxPhone', - method: 'POST', - data: { - authCode: loginRes.code, - code, - encryptedData, - iv, - notVerifyPhone: true, - refereeId: 0, - sceneType: 'save_referee', - tenantId: TenantId - }, - header: { - 'content-type': 'application/json', - TenantId - }, - success: async function (res) { - if (res.data.code == 1) { - Taro.showToast({ - title: res.data.message, - icon: 'error', - duration: 2000 - }) - return false; - } - // 登录成功 - const token = res.data.data.access_token; - const userData = res.data.data.user; - - // 使用useUser Hook的loginUser方法更新状态 - loginUser(token, userData); - - // 处理邀请关系 - if (userData?.userId) { - try { - const inviteSuccess = await handleInviteRelation(userData.userId) - if (inviteSuccess) { - Taro.showToast({ - title: '邀请关系建立成功', - icon: 'success', - duration: 2000 - }) - } - } catch (error) { - console.error('处理邀请关系失败:', error) - } - } - - // 显示登录成功提示 - Taro.showToast({ - title: '登录成功', - icon: 'success', - duration: 1500 - }) - - // 不需要重新启动小程序,状态已经通过useUser更新 - // 可以选择性地刷新当前页面数据 - reload(); - } - }) - } else { - console.log('登录失败!') - } - } - }) - } + // const handleGetPhoneNumber = ({detail}: { detail: { code?: string, encryptedData?: string, iv?: string } }) => { + // const {code, encryptedData, iv} = detail + // Taro.login({ + // success: (loginRes) => { + // if (code) { + // Taro.request({ + // url: 'https://server.websoft.top/api/wx-login/loginByMpWxPhone', + // method: 'POST', + // data: { + // authCode: loginRes.code, + // code, + // encryptedData, + // iv, + // notVerifyPhone: true, + // refereeId: 0, + // sceneType: 'save_referee', + // tenantId: TenantId + // }, + // header: { + // 'content-type': 'application/json', + // TenantId + // }, + // success: async function (res) { + // if (res.data.code == 1) { + // Taro.showToast({ + // title: res.data.message, + // icon: 'error', + // duration: 2000 + // }) + // return false; + // } + // // 登录成功 + // const token = res.data.data.access_token; + // const userData = res.data.data.user; + // + // // 使用useUser Hook的loginUser方法更新状态 + // loginUser(token, userData); + // + // // 处理邀请关系 + // if (userData?.userId) { + // try { + // const inviteSuccess = await handleInviteRelation(userData.userId) + // if (inviteSuccess) { + // Taro.showToast({ + // title: '邀请关系建立成功', + // icon: 'success', + // duration: 2000 + // }) + // } + // } catch (error) { + // console.error('处理邀请关系失败:', error) + // } + // } + // + // // 显示登录成功提示 + // Taro.showToast({ + // title: '登录成功', + // icon: 'success', + // duration: 1500 + // }) + // + // // 不需要重新启动小程序,状态已经通过useUser更新 + // // 可以选择性地刷新当前页面数据 + // reload(); + // } + // }) + // } else { + // console.log('登录失败!') + // } + // } + // }) + // } useEffect(() => { reload().then() @@ -214,23 +214,21 @@ const Header = (props: any) => { onClick={() => navTo(`/user/profile/profile`, true)}> - {user?.nickname || Taro.getStorageSync('Nickname') || '已登录'} + {getWebsiteName()} ) : ( - + + + {getWebsiteName()} + + )}>