完成分享
This commit is contained in:
parent
5ae2eb3541
commit
c00ab572fb
44
src/app.tsx
44
src/app.tsx
@ -2,11 +2,9 @@ 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 Taro, { useDidShow, useRouter, useShareAppMessage } from '@tarojs/taro'
|
||||
import { useSelector } from './reducers/hooks'
|
||||
import { AnalysisShortCodeApi } from './api/share'
|
||||
import { analysisShortCodeApi } from './common/shortCode'
|
||||
|
||||
const store = configStore()
|
||||
const App:FC = (params) => {
|
||||
@ -16,40 +14,36 @@ const App:FC = (params) => {
|
||||
})
|
||||
|
||||
useDidShow(() => {
|
||||
console.log('paramsparamsparamsparams:',params)
|
||||
console.log('params:',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) {
|
||||
|
||||
analysisShortCodeApi(page.options.share)
|
||||
}
|
||||
page.onShareAppMessage = (res) => {
|
||||
let path = ''
|
||||
let title = ''
|
||||
let imageUrl = ''
|
||||
let sortCode = Taro.getStorageSync('sort_code')?JSON.parse(Taro.getStorageSync('sort_code')):''
|
||||
if(res.from === 'button') {
|
||||
path = `/pages/details/index?share=${sortCode.shareShortDetail.code}`
|
||||
title = sortCode.shareShortDetail.title
|
||||
} else {
|
||||
path = `/pages/index/index?share=${sortCode.shareShortPage.code}`
|
||||
title = sortCode.shareShortPage.title
|
||||
}
|
||||
|
||||
page.onShareAppMessage = () => {
|
||||
return {
|
||||
title: '电子商城',
|
||||
path: `/pages/index/index?share=${sortCode.shareShortPage}`,
|
||||
imageUrl:'',
|
||||
title,
|
||||
path,
|
||||
imageUrl,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<ContextBlueTooth>
|
||||
<Provider store={store}>
|
||||
|
@ -1,11 +1,13 @@
|
||||
import Taro from "@tarojs/taro"
|
||||
import { BASE_URL } from "../constant"
|
||||
|
||||
//解析短码
|
||||
export const analysisShortCodeApi = () => {
|
||||
//解析短码(主要用于右上角按钮分享)
|
||||
export const analysisShortCodeApi = (val) => {
|
||||
//解析短码
|
||||
Taro.request({
|
||||
url:BASE_URL+'/v1/mall/shortCode',
|
||||
method:"GET",
|
||||
data:{md5_key: page.options?.share},
|
||||
data:{md5_key: val},
|
||||
success:(res) => {
|
||||
if(res.data.code == 0) {
|
||||
//绑定上下级
|
||||
|
@ -11,21 +11,21 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
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 { AnalysisShortCodeApi, BindShortCodeApi, GetShortCodeApi } from '@/api/share';
|
||||
import { SHARE_SCENE } from '@/common/enum';
|
||||
import useUserInfo from '@/use/useUserInfo';
|
||||
|
||||
type item = {title:string, img:string, url:string, id:number}
|
||||
|
||||
type params = {
|
||||
type Params = {
|
||||
list?: item[]
|
||||
swiperOnClick?: (val: item) => void,
|
||||
style?: Object
|
||||
}
|
||||
export default (props:params) => {
|
||||
export default (props:Params) => {
|
||||
const {checkLogin, getPhoneNumber, userInfo} = useLogin()
|
||||
|
||||
//获取参数
|
||||
//获取参数(有两种参数:1.商品id, 2.页面分享)
|
||||
const router = useRouter()
|
||||
const [params, setParams] = useState({id: '', share: null})
|
||||
|
||||
@ -38,29 +38,24 @@ export default (props:params) => {
|
||||
}
|
||||
}
|
||||
|
||||
//解析短码参数(该请求不能校验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)
|
||||
setParams({id: res.data.product_id, share: res.data})
|
||||
}
|
||||
|
||||
useDidShow(() => {
|
||||
checkLogin()
|
||||
judgeParam()
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
//先确保能拿到订单id才做其他请求
|
||||
if(params.id) {
|
||||
checkLogin()
|
||||
getShortCode()
|
||||
getProductDetail()
|
||||
}
|
||||
}, [params])
|
||||
|
||||
|
||||
|
||||
//获取数据
|
||||
const [productInfo, setProductInfo] = useState<any>({})
|
||||
const {fetchData} = GetProductDetailApi()
|
||||
@ -70,6 +65,11 @@ export default (props:params) => {
|
||||
Taro.stopPullDownRefresh()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(productInfo.code) getShortCode()
|
||||
}, [productInfo])
|
||||
|
||||
|
||||
//面料名称
|
||||
const productName = useMemo(() => {
|
||||
return formatHashTag(productInfo.code, productInfo.name)
|
||||
@ -103,38 +103,15 @@ export default (props:params) => {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const userObj = useSelector(state => state.userInfo)
|
||||
//获取分享转码
|
||||
const {setSortCode, userInfo : userObj } = useUserInfo()
|
||||
//详情页获取分享短码
|
||||
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
|
||||
const {data: resDetail} = await fetchDataShortCode({"share_user_id": userObj.adminUserInfo.user_id, type:ShareDetail.value, product_id: parseInt(params.id)})
|
||||
setSortCode({... userObj.sort_code, shareShortDetail: {title: productName as string, code: resDetail.md5_key, img:''}})
|
||||
}
|
||||
|
||||
|
||||
//转发分享
|
||||
useShareAppMessage(res => {
|
||||
let path = ''
|
||||
let title = ''
|
||||
let imageUrl = ''
|
||||
if (res.from === 'button') {
|
||||
path = `/pages/details/index?share=${sortCode.current}`
|
||||
title = productName as string
|
||||
// imageUrl =
|
||||
} else {
|
||||
path = `/pages/index/index?share=${sortCode.current}`
|
||||
title = '陆盈电子商城'
|
||||
}
|
||||
return {
|
||||
title,
|
||||
path,
|
||||
imageUrl,
|
||||
}
|
||||
})
|
||||
|
||||
//开始下单
|
||||
const placeOrder = async (e:any) => {
|
||||
try {
|
||||
|
@ -1,5 +1,6 @@
|
||||
export default {
|
||||
navigationBarTitleText: '修改地址',
|
||||
enablePullDownRefresh: true,
|
||||
backgroundTextStyle: 'dark'
|
||||
backgroundTextStyle: 'dark',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -8,10 +8,9 @@ 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, useShareAppMessage } from '@tarojs/taro'
|
||||
import Taro, { Events, useDidShow, usePullDownRefresh} from '@tarojs/taro'
|
||||
import {GetProductKindListApi, GetProductListApi} from '@/api/material'
|
||||
import useLogin from '@/use/useLogin'
|
||||
import LoadingCard from '@/components/loadingCard'
|
||||
import { dataLoadingStatus } from '@/common/util'
|
||||
|
||||
export default () => {
|
||||
|
@ -1,3 +1,4 @@
|
||||
export default {
|
||||
navigationBarTitleText: '确认订单'
|
||||
navigationBarTitleText: '确认订单',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
export default {
|
||||
navigationBarTitleText: '订单详情',
|
||||
enablePullDownRefresh: true,
|
||||
backgroundTextStyle: 'dark'
|
||||
backgroundTextStyle: 'dark',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export default {
|
||||
navigationBarTitleText: '订单列表',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export default {
|
||||
navigationBarTitleText: '搜索'
|
||||
navigationBarTitleText: '搜索',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export default {
|
||||
navigationBarTitleText: '搜索',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import {GetHotSearchApi, GetSearchHistoryApi, AddSearchHistoryApi} from "@/api/search"
|
||||
import { SCENE } from '@/common/constant';
|
||||
import useLogin from '@/use/useLogin';
|
||||
import Taro, { useDidShow } from '@tarojs/taro';
|
||||
import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro';
|
||||
|
||||
type searchDataParam = {'search_key':''}
|
||||
export default () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
export default {
|
||||
navigationBarTitleText: '我的',
|
||||
navigationStyle: 'custom'
|
||||
navigationStyle: 'custom',
|
||||
enableShareAppMessage: true,
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ export type UserAdminParam = {
|
||||
}
|
||||
|
||||
export type SortCodeParam = {
|
||||
shareShortDetail?: string, //详情分享页面短码
|
||||
shareShortPage?: string, //右上角分享页面短码
|
||||
shareShortDetail?: {title:string, code: string, img: string}, //详情分享页面短码
|
||||
shareShortPage?: {title:string, code: string, img: string}, //右上角分享页面短码
|
||||
}
|
||||
|
||||
export type DataParam = {
|
||||
|
@ -8,6 +8,8 @@ import { GetShortCodeApi } from "@/api/share"
|
||||
export default () => {
|
||||
const {setUserInfo, setAdminUserInfo, setSortCode, userInfo} = useUserInfo()
|
||||
|
||||
console.log('userInfo:::', userInfo)
|
||||
|
||||
//登录请求 (调用这个就不能再useHttp中使用,当前这个hook, 否则会死循环内存溢出)
|
||||
// const {fetchData} = LoginApi()
|
||||
|
||||
@ -109,16 +111,14 @@ export default () => {
|
||||
})
|
||||
}
|
||||
|
||||
//获取分享转码
|
||||
//获取分享码(右上角分享码)
|
||||
const {SharePage} = SHARE_SCENE
|
||||
const {fetchData: fetchDataShortCode} = GetShortCodeApi()
|
||||
const getShortCode = async (user_id) => {
|
||||
const {data: resPage} = await fetchDataShortCode({"share_user_id": user_id, type:SharePage.value})
|
||||
setSortCode({shareShortDetail: '', shareShortPage: resPage.md5_key})
|
||||
setSortCode({...userInfo.sort_code, shareShortPage: {title: '陆盈电子商城', code: resPage.md5_key, img:''}})
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
checkLogin,
|
||||
wxLogin,
|
||||
|
Loading…
x
Reference in New Issue
Block a user