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/api/system/file/index.ts b/src/api/system/file/index.ts index 18a06dd..1717c70 100644 --- a/src/api/system/file/index.ts +++ b/src/api/system/file/index.ts @@ -1,6 +1,7 @@ import request from '@/utils/request'; import Taro from '@tarojs/taro' import dayjs from 'dayjs'; +// @ts-ignore import crypto from 'crypto-js'; import {Base64} from 'js-base64'; import {FileRecord} from "@/api/system/file/model"; @@ -49,7 +50,7 @@ export async function uploadOssByPath(filePath: string) { }) } -const computeSignature = (accessKeySecret, canonicalString) => { +const computeSignature = (accessKeySecret: string, canonicalString: string) => { return crypto.enc.Base64.stringify(crypto.HmacSHA1(canonicalString, accessKeySecret)); } diff --git a/src/app.ts b/src/app.ts index 418ba66..e7a7095 100644 --- a/src/app.ts +++ b/src/app.ts @@ -70,14 +70,14 @@ function App(props: { children: any; }) { // 统计邀请来源 trackInviteSource(inviteParams.source || 'unknown', parseInt(inviteParams.inviter || '0')) - // 显示邀请提示 - setTimeout(() => { - Taro.showToast({ - title: '检测到邀请信息', - icon: 'success', - duration: 2000 - }) - }, 1000) + // 检测到邀请信息 + // setTimeout(() => { + // Taro.showToast({ + // title: '检测到邀请信息', + // icon: 'success', + // duration: 2000 + // }) + // }, 1000) } } catch (error) { console.error('处理启动参数失败:', error) diff --git a/src/components/UserProfile.tsx b/src/components/UserProfile.tsx index 96c664f..b95e448 100644 --- a/src/components/UserProfile.tsx +++ b/src/components/UserProfile.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { View, Text, Image } from '@tarojs/components'; +import { View, Text } from '@tarojs/components'; import { Button, Avatar } from '@nutui/nutui-react-taro'; import { useUser } from '@/hooks/useUser'; import navTo from '@/utils/common'; diff --git a/src/pages/index/Header.tsx b/src/pages/index/Header.tsx index be5a673..4c23733 100644 --- a/src/pages/index/Header.tsx +++ b/src/pages/index/Header.tsx @@ -7,11 +7,13 @@ import {getUserInfo, getWxOpenId} from "@/api/layout"; import {TenantId} from "@/config/app"; import {getOrganization} from "@/api/system/organization"; import {myUserVerify} from "@/api/system/userVerify"; -import { useShopInfo } from '@/hooks/useShopInfo'; +import {useShopInfo} from '@/hooks/useShopInfo'; import {handleInviteRelation} from "@/utils/invite"; -import {View,Text} from '@tarojs/components' +import {View, Text} from '@tarojs/components' import MySearch from "./MySearch"; import './Header.scss'; +import navTo from "@/utils/common"; +import {User} from "@/api/system/user/model"; const Header = (props: any) => { // 使用新的useShopInfo Hook @@ -22,6 +24,10 @@ const Header = (props: any) => { const [IsLogin, setIsLogin] = useState(true) const [statusBarHeight, setStatusBarHeight] = useState() + const [userInfo, setUserInfo] = useState({ + avatar: '', + mobile: '未登录' + }) const reload = async () => { Taro.getSystemInfo({ @@ -31,62 +37,59 @@ const Header = (props: any) => { }) // 注意:商店信息现在通过useShopInfo自动管理,不需要手动获取 // 获取用户信息 - getUserInfo().then((data) => { - if (data) { - setIsLogin(true); - console.log('用户信息>>>', data.phone) - // 保存userId - Taro.setStorageSync('UserId', data.userId) - // 获取openId - if (!data.openid) { - Taro.login({ - success: (res) => { - getWxOpenId({code: res.code}).then(() => { - }) - } - }) - } - // 是否已认证 - if (data.certification) { - Taro.setStorageSync('Certification', '1') - } - // 机构ID - Taro.setStorageSync('OrganizationId', data.organizationId) - // 父级机构ID - if (Number(data.organizationId) > 0) { - getOrganization(Number(data.organizationId)).then(res => { - Taro.setStorageSync('OrganizationParentId', res.parentId) - }) - } - // 管理员 - const isKdy = data.roles?.findIndex(item => item.roleCode == 'admin') - if (isKdy != -1) { - Taro.setStorageSync('RoleName', '管理') - Taro.setStorageSync('RoleCode', 'admin') - return false; - } - // 注册用户 - const isUser = data.roles?.findIndex(item => item.roleCode == 'user') - if (isUser != -1) { - Taro.setStorageSync('RoleName', '注册用户') - Taro.setStorageSync('RoleCode', 'user') - return false; - } + const data = await getUserInfo(); + if (data) { + setIsLogin(true); + console.log('用户信息>>>', data.phone) + // 保存userId + Taro.setStorageSync('UserId', data.userId) + // 获取openId + if (!data.openid) { + Taro.login({ + success: (res) => { + getWxOpenId({code: res.code}).then(() => { + }) + } + }) } - }).catch(() => { - setIsLogin(false); - console.log('未登录') - }); - // 认证信息 - myUserVerify({status: 1}).then(data => { - if (data?.realName) { - Taro.setStorageSync('RealName', data.realName) + // 是否已认证 + if (data.certification) { + Taro.setStorageSync('Certification', '1') } - }) + // 机构ID + Taro.setStorageSync('OrganizationId', data.organizationId) + // 父级机构ID + if (Number(data.organizationId) > 0) { + getOrganization(Number(data.organizationId)).then(res => { + Taro.setStorageSync('OrganizationParentId', res.parentId) + }) + } + // 管理员 + const isKdy = data.roles?.findIndex(item => item.roleCode == 'admin') + if (isKdy != -1) { + Taro.setStorageSync('RoleName', '管理') + Taro.setStorageSync('RoleCode', 'admin') + return false; + } + // 注册用户 + const isUser = data.roles?.findIndex(item => item.roleCode == 'user') + if (isUser != -1) { + Taro.setStorageSync('RoleName', '注册用户') + Taro.setStorageSync('RoleCode', 'user') + return false; + } + // 认证信息 + myUserVerify({status: 1}).then(data => { + if (data?.realName) { + Taro.setStorageSync('RealName', data.realName) + } + }) + setUserInfo(data) + } } /* 获取用户手机号 */ - const handleGetPhoneNumber = ({detail}: {detail: {code?: string, encryptedData?: string, iv?: string}}) => { + const handleGetPhoneNumber = ({detail}: { detail: { code?: string, encryptedData?: string, iv?: string } }) => { const {code, encryptedData, iv} = detail Taro.login({ success: function () { @@ -167,7 +170,16 @@ const Header = (props: any) => { onBackClick={() => { }} left={ - !IsLogin ? ( + IsLogin ? ( + navTo(`/user/profile/profile`,true)}> + + {userInfo?.mobile} + + + ) : ( - ) : ( - - - {getWebsiteName()} - - )}> diff --git a/src/pages/index/HeaderWithHook.tsx b/src/pages/index/HeaderWithHook.tsx index da16113..0c24694 100644 --- a/src/pages/index/HeaderWithHook.tsx +++ b/src/pages/index/HeaderWithHook.tsx @@ -3,11 +3,10 @@ import Taro from '@tarojs/taro'; import {Button, Space} from '@nutui/nutui-react-taro' import {TriangleDown} from '@nutui/icons-react-taro' import {Popup, Avatar, NavBar} from '@nutui/nutui-react-taro' -import {getUserInfo, getWxOpenId} from "@/api/layout"; +import {getWxOpenId} from "@/api/layout"; import {TenantId} from "@/config/app"; import {getOrganization} from "@/api/system/organization"; import {myUserVerify} from "@/api/system/userVerify"; -import {User} from "@/api/system/user/model"; import { useShopInfo } from '@/hooks/useShopInfo'; import { useUser } from '@/hooks/useUser'; import {handleInviteRelation} from "@/utils/invite"; @@ -17,7 +16,6 @@ import './Header.scss'; const Header = (props: any) => { // 使用新的hooks const { - shopInfo, loading: shopLoading, getWebsiteName, getWebsiteLogo @@ -56,14 +54,14 @@ const Header = (props: any) => { // 检查用户认证状态 if (user?.userId) { // 获取组织信息 - getOrganization({userId: user.userId}).then((data) => { + getOrganization(user.userId).then((data) => { console.log('组织信息>>>', data) }).catch(() => { console.log('获取组织信息失败') }); // 检查用户认证 - myUserVerify({userId: user.userId}).then((data) => { + myUserVerify({id: user.userId}).then((data) => { console.log('认证信息>>>', data) }).catch(() => { console.log('获取认证信息失败') diff --git a/src/utils/invite.ts b/src/utils/invite.ts index d4cf820..09adbd9 100644 --- a/src/utils/invite.ts +++ b/src/utils/invite.ts @@ -1,5 +1,5 @@ import Taro from '@tarojs/taro' -import { createInviteRelation } from '@/api/invite' +import {bindRefereeRelation} from "@/api/invite"; /** * 邀请参数接口 @@ -15,32 +15,98 @@ export interface InviteParams { */ export function parseInviteParams(options: any): InviteParams | null { try { - // 从 scene 参数中解析邀请信息 - if (options.scene) { - // 确保 scene 是字符串类型 - const sceneStr = typeof options.scene === 'string' ? options.scene : String(options.scene) + console.log('解析邀请参数:', options) - const params: InviteParams = {} - const pairs = sceneStr.split('&') + // 优先从 query.scene 中解析邀请信息 + if (options.query && options.query.scene) { + const sceneStr = typeof options.query.scene === 'string' ? options.query.scene : String(options.query.scene) + console.log('从 query.scene 解析:', sceneStr) - pairs.forEach((pair: string) => { - const [key, value] = pair.split('=') - if (key && value) { - switch (key) { - case 'inviter': - params.inviter = decodeURIComponent(value) - break - case 'source': - params.source = decodeURIComponent(value) - break - case 't': - params.t = decodeURIComponent(value) - break + // 处理 uid_xxxxx 格式的参数 + if (sceneStr.startsWith('uid_')) { + const uid = sceneStr.replace('uid_', '') + if (uid) { + return { + inviter: uid, + source: 'qrcode', + t: String(Date.now()) } } - }) + } - return params.inviter ? params : null + // 处理 key=value&key=value 格式的参数 + if (sceneStr.includes('=')) { + const params: InviteParams = {} + const pairs = sceneStr.split('&') + + pairs.forEach((pair: string) => { + const [key, value] = pair.split('=') + if (key && value) { + switch (key) { + case 'inviter': + case 'uid': + params.inviter = decodeURIComponent(value) + break + case 'source': + params.source = decodeURIComponent(value) + break + case 't': + params.t = decodeURIComponent(value) + break + } + } + }) + + if (params.inviter) { + return params + } + } + } + + // 从 scene 参数中解析邀请信息(兼容旧版本) + if (options.scene) { + const sceneStr = typeof options.scene === 'string' ? options.scene : String(options.scene) + console.log('从 scene 解析:', sceneStr) + + // 处理 uid_xxxxx 格式的参数 + if (sceneStr.startsWith('uid_')) { + const uid = sceneStr.replace('uid_', '') + if (uid) { + return { + inviter: uid, + source: 'qrcode', + t: String(Date.now()) + } + } + } + + // 处理 key=value&key=value 格式的参数 + if (sceneStr.includes('=')) { + const params: InviteParams = {} + const pairs = sceneStr.split('&') + + pairs.forEach((pair: string) => { + const [key, value] = pair.split('=') + if (key && value) { + switch (key) { + case 'inviter': + case 'uid': + params.inviter = decodeURIComponent(value) + break + case 'source': + params.source = decodeURIComponent(value) + break + case 't': + params.t = decodeURIComponent(value) + break + } + } + }) + + if (params.inviter) { + return params + } + } } // 从 query 参数中解析邀请信息(兼容旧版本) @@ -132,12 +198,11 @@ export async function handleInviteRelation(userId: number): Promise { } // 建立邀请关系 - await createInviteRelation({ - inviterId: inviterId, - inviteeId: userId, + await bindRefereeRelation({ + dealerId: inviterId, + userId: userId, source: inviteParams.source || 'unknown', - scene: `inviter=${inviterId}&source=${inviteParams.source}&t=${inviteParams.t}`, - inviteTime: new Date().toISOString() + scene: `inviter=${inviterId}&source=${inviteParams.source}&t=${inviteParams.t}` }) // 清除本地存储的邀请参数 diff --git a/src/utils/request.ts b/src/utils/request.ts index fc85dd4..bc4777f 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -172,9 +172,9 @@ const handleAuthError = () => { duration: 2000 }); - setTimeout(() => { - Taro.reLaunch({ url: '/passport/login' }); - }, 2000); + // setTimeout(() => { + // Taro.reLaunch({ url: '/passport/login' }); + // }, 2000); }; // 错误处理