diff --git a/src/api/share.ts b/src/api/share.ts index 0761cfa..aaecc87 100644 --- a/src/api/share.ts +++ b/src/api/share.ts @@ -9,3 +9,23 @@ import { useRequest } from "@/use/useHttp" method: "post", }) } + +/** + * 解析短码 + */ + export const AnalysisShortCodeApi = () => { + return useRequest({ + url: `/v1/mall/shortCode`, + method: "get", + }) +} + +/** + * 绑定上下级 + */ +export const BindShortCodeApi = () => { + return useRequest({ + url: `/v1/mall/shortCode/bind`, + method: "post", + }) +} \ No newline at end of file diff --git a/src/app.tsx b/src/app.tsx index 3a3c559..ebbb4e1 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -2,27 +2,58 @@ import { FC } from 'react' import ContextBlueTooth from "@/use/contextBlueTooth" import { Provider } from 'react-redux' import configStore from './store' - +import {BASE_URL, WX_APPID} from '@/common/constant' import './app.scss' -import { useShareAppMessage } from '@tarojs/taro' +import Taro, { useDidShow, useRouter, useShareAppMessage } from '@tarojs/taro' import { useSelector } from './reducers/hooks' +import { AnalysisShortCodeApi } from './api/share' const store = configStore() -const App:FC = ({children}) => { - //转发分享 - // const userObj = useSelector(state => state.userInfo) - useShareAppMessage(res => { - return { - title: '电子商城', - path: `/pages/details/index`, - imageUrl:'', - } +const App:FC = (params) => { + + Taro.showShareMenu({ + withShareTicket: true }) + useDidShow(() => { + console.log('paramsparamsparamsparams:',params) + }) + + const res = useRouter() + const page = Taro.getCurrentInstance().page + + // console.log('page::::',page) + //解析短码参数(该请求不能校验token) + // const {fetchData: fetchDataAnalysisShortCode} = AnalysisShortCodeApi() + // const analysisShortCode = async () => { + // let res = await fetchDataAnalysisShortCode({md5_key: page?.options?.share}) + // // setParams({id: res.data.id, share: res.data}) + // console.log('res::::&&', res.data) + // } + + const sortCode = JSON.parse(Taro.getStorageSync('sort_code')) + console.log('res:::', page) + if(page && page.onShareAppMessage) { + if(page.options?.share) { + + } + + page.onShareAppMessage = () => { + return { + title: '电子商城', + path: `/pages/index/index?share=${sortCode.shareShortPage}`, + imageUrl:'', + } + } + } + + + + return ( - {children} + {params.children} ) diff --git a/src/common/shortCode/index.js b/src/common/shortCode/index.js new file mode 100644 index 0000000..1f8b46b --- /dev/null +++ b/src/common/shortCode/index.js @@ -0,0 +1,31 @@ + +//解析短码 +export const analysisShortCodeApi = () => { + //解析短码 + Taro.request({ + url:BASE_URL+'/v1/mall/shortCode', + method:"GET", + data:{md5_key: page.options?.share}, + success:(res) => { + if(res.data.code == 0) { + //绑定上下级 + bindParent(res.data.data.share_user_id) + } + } + }) +} + +//绑定上下级 +const bindParent = (share_user_id) => { + //绑定上下级 + Taro.request({ + url:BASE_URL+'/v1/mall/shortCode/bind', + method:"POST", + data:{share_user_id: share_user_id}, + success:(res) => { + if(res.data.code == 0) { + //绑定上下级 + } + } + }) + } \ No newline at end of file diff --git a/src/pages/details/index.tsx b/src/pages/details/index.tsx index 9234816..d7311b5 100644 --- a/src/pages/details/index.tsx +++ b/src/pages/details/index.tsx @@ -12,6 +12,8 @@ import {formatHashTag, formatImgUrl} from '@/common/fotmat' import {GetProductDetailApi} from '@/api/material' import useLogin from '@/use/useLogin'; import { useSelector } from '@/reducers/hooks'; +import { AnalysisShortCodeApi, GetShortCodeApi } from '@/api/share'; +import { SHARE_SCENE } from '@/common/enum'; type item = {title:string, img:string, url:string, id:number} @@ -23,20 +25,47 @@ type params = { export default (props:params) => { const {checkLogin, getPhoneNumber, userInfo} = useLogin() + //获取参数 + const router = useRouter() + const [params, setParams] = useState({id: '', share: null}) + + //判断是否是分享过来的参数 + const judgeParam = async () => { + if(router.params.id) { + setParams({...params, id:router.params.id}) + }else if(router.params.share) { + analysisShortCode() + } + } + + //解析短码参数(该请求不能校验token) + const {fetchData: fetchDataAnalysisShortCode} = AnalysisShortCodeApi() + const analysisShortCode = async () => { + let res = await fetchDataAnalysisShortCode({md5_key: router.params.share}) + setParams({id: res.data.id, share: res.data}) + console.log('res::::&&', res.data) + } + useDidShow(() => { - checkLogin() + judgeParam() }) - const router = useRouter() + useEffect(() => { + //先确保能拿到订单id才做其他请求 + if(params.id) { + checkLogin() + getShortCode() + getProductDetail() + } + }, [params]) + + //获取数据 const [productInfo, setProductInfo] = useState({}) const {fetchData} = GetProductDetailApi() - useEffect(() => { - getProductDetail() - }, []) const getProductDetail = async () => { - let {data} = await fetchData({id: router.params.id}) + let {data} = await fetchData({id: params.id}) setProductInfo(data) Taro.stopPullDownRefresh() } @@ -74,18 +103,29 @@ export default (props:params) => { }) } - //转发分享 + const userObj = useSelector(state => state.userInfo) + //获取分享转码 + const {ShareDetail} = SHARE_SCENE + const {fetchData: fetchDataShortCode} = GetShortCodeApi() + const sortCode = useRef('') + const getShortCode = async () => { + const {data: resDetail} = await fetchDataShortCode({"share_user_id": userObj.adminUserInfo.user_id, type:ShareDetail.value, id: params.id}) + sortCode.current = resDetail.md5_key + } + + + //转发分享 useShareAppMessage(res => { let path = '' let title = '' let imageUrl = '' if (res.from === 'button') { - path = `/pages/details/index?id=${userObj.sort_code.shareShortDetail}` + path = `/pages/details/index?share=${sortCode.current}` title = productName as string // imageUrl = } else { - path = `/pages/details/index?id=${userObj.sort_code.shareShortPage}` + path = `/pages/index/index?share=${sortCode.current}` title = '陆盈电子商城' } return { diff --git a/src/pages/index/index.config.ts b/src/pages/index/index.config.ts index 86e3b2e..c0922b9 100644 --- a/src/pages/index/index.config.ts +++ b/src/pages/index/index.config.ts @@ -1,3 +1,4 @@ export default { navigationBarTitleText: '首页', + enableShareAppMessage: true, } diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 43fd1b5..37cb494 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -8,7 +8,7 @@ import ShopCart from '@/components/shopCart' import { goLink } from '@/common/common' import styles from './index.module.scss' import React, { useEffect, useMemo, useRef, useState } from 'react' -import Taro, { Events, useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro' +import Taro, { Events, useDidShow, usePullDownRefresh, useRouter, useShareAppMessage } from '@tarojs/taro' import {GetProductKindListApi, GetProductListApi} from '@/api/material' import useLogin from '@/use/useLogin' import LoadingCard from '@/components/loadingCard' diff --git a/src/pages/orderList/index.module.scss b/src/pages/orderList/index.module.scss index f7222c8..e8f528a 100644 --- a/src/pages/orderList/index.module.scss +++ b/src/pages/orderList/index.module.scss @@ -1,5 +1,5 @@ .order_list_main{ - min-height: 100vh; + height: 100vh; background-color: $color_bg_one; display: flex; flex-direction: column; @@ -8,6 +8,7 @@ background-color: #fff; box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.16); border-bottom: 2px solid #e2e2e2; + height: 160px; .order_status_list{ font-size: $font_size; color: #9E9E9E; @@ -28,8 +29,7 @@ } } .order_list{ - flex:1; - height: 0; + height: calc(100vh - 160px); .order_item_con{ margin-top: 20px; padding: 0 20px; diff --git a/src/reducers/userInfo.ts b/src/reducers/userInfo.ts index a23c93f..3d29040 100644 --- a/src/reducers/userInfo.ts +++ b/src/reducers/userInfo.ts @@ -68,8 +68,6 @@ const INIT_USER = { sort_code: Taro.getStorageSync('sort_code')?JSON.parse(Taro.getStorageSync('sort_code')):null, } - - export default function counter (state = INIT_USER, action: Action) { const {type, data} = action switch (type) { diff --git a/src/use/useLogin.ts b/src/use/useLogin.ts index 8c3217d..2888151 100644 --- a/src/use/useLogin.ts +++ b/src/use/useLogin.ts @@ -110,14 +110,15 @@ export default () => { } //获取分享转码 - const {ShareDetail, SharePage} = SHARE_SCENE + const {SharePage} = SHARE_SCENE const {fetchData: fetchDataShortCode} = GetShortCodeApi() const getShortCode = async (user_id) => { - const {data: resDetail} = await fetchDataShortCode({"share_user_id": user_id, type:ShareDetail.value}) const {data: resPage} = await fetchDataShortCode({"share_user_id": user_id, type:SharePage.value}) - setSortCode({shareShortDetail: resDetail.md5_key, shareShortPage: resPage.md5_key}) + setSortCode({shareShortDetail: '', shareShortPage: resPage.md5_key}) } + // + return { checkLogin, wxLogin,