订单列表对接

This commit is contained in:
czm 2022-06-02 20:14:05 +08:00
parent b921bcaa07
commit 5ae2eb3541
9 changed files with 152 additions and 30 deletions

View File

@ -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",
})
}

View File

@ -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 (
<ContextBlueTooth>
<Provider store={store}>
{children}
{params.children}
</Provider>
</ContextBlueTooth>
)

View File

@ -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) {
//绑定上下级
}
}
})
}

View File

@ -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<any>({})
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 {

View File

@ -1,3 +1,4 @@
export default {
navigationBarTitleText: '首页',
enableShareAppMessage: true,
}

View File

@ -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'

View File

@ -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;

View File

@ -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) {

View File

@ -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,