mirror of
https://gitee.com/ShopeX/ECShopX_mobile-frontend
synced 2026-05-15 02:35:40 +08:00
bug(custom): baocuo
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
/**
|
||||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
* 公众号/服务号冷启动时不在顶层 import S,否则会 ReferenceError: Can't find variable: S
|
||||
*/
|
||||
import S from '@/spx'
|
||||
import { transformPlatformUrl } from '@/utils/platform'
|
||||
import req from './req'
|
||||
|
||||
function getS() {
|
||||
return (
|
||||
(typeof global !== 'undefined' && global.__SPX__) ||
|
||||
(typeof globalThis !== 'undefined' && globalThis.__SPX__) ||
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
function createHead() {
|
||||
const s = getS()
|
||||
return {
|
||||
header: {
|
||||
'x-wxapp-session': (S && S.getAuthToken()) || '',
|
||||
'x-wxapp-session': (s && s.getAuthToken && s.getAuthToken()) || '',
|
||||
'salesperson-type': 'shopping_guide'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ class API {
|
||||
this.isRefreshingToken = false
|
||||
// S.logout()
|
||||
setTimeout(() => {
|
||||
console.log(getCurrentInstance().router)
|
||||
const { path, params } = getCurrentInstance().router
|
||||
console.log(getCurrentInstance()?.router)
|
||||
const { path, params } = getCurrentInstance()?.router
|
||||
delete params.$taroTimestamp
|
||||
const fullPath = Object.keys(params).length > 0 ? `${path}?${qs.stringify(params)}` : path
|
||||
// let url
|
||||
|
||||
@@ -155,8 +155,8 @@ class API {
|
||||
this.isRefreshingToken = false
|
||||
getS().logout()
|
||||
setTimeout(() => {
|
||||
console.log(getCurrentInstance().router)
|
||||
const { path, params } = getCurrentInstance().router
|
||||
console.log(getCurrentInstance()?.router)
|
||||
const { path, params } = getCurrentInstance()?.router
|
||||
delete params.$taroTimestamp
|
||||
const fullPath = Object.keys(params).length > 0 ? `${path}?${qs.stringify(params)}` : path
|
||||
let url
|
||||
|
||||
@@ -9,11 +9,10 @@ import { SpImg, PointLine } from '@/components'
|
||||
import api from '@/api'
|
||||
import { connect } from 'react-redux'
|
||||
import { isObject, classNames, isWeb, VERSION_PLATFORM } from '@/utils'
|
||||
import configStore from '@/store'
|
||||
|
||||
import './index.scss'
|
||||
|
||||
const { store } = configStore()
|
||||
/** 不在此处调用 configStore(),否则首页加载会触发 reducer 循环依赖报错;@connect 会从 Provider 取 store */
|
||||
|
||||
@connect(
|
||||
({ colors, user }) => ({
|
||||
|
||||
@@ -92,7 +92,7 @@ function SpDeliver(props, ref) {
|
||||
} = state
|
||||
const formRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { cart_type } = $instance.router?.params || {}
|
||||
const { cart_type } = $instance?.router?.params || {}
|
||||
// useEffect(() => {
|
||||
// fetch()
|
||||
// }, [])
|
||||
|
||||
@@ -43,9 +43,9 @@ function SpGoodsItem(props) {
|
||||
loadingRef.current = true
|
||||
let isPurchase = false
|
||||
if (isWeixin) {
|
||||
isPurchase = $instance.page.route.includes('subpages/purchase')
|
||||
isPurchase = $instance?.page.route.includes('subpages/purchase')
|
||||
} else {
|
||||
isPurchase = $instance.page.path.includes('subpages/purchase')
|
||||
isPurchase = $instance?.page.path.includes('subpages/purchase')
|
||||
}
|
||||
setIsPurchase(isPurchase)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ function SpLogin(props) {
|
||||
if (isLogin) {
|
||||
onChange && onChange(e)
|
||||
} else {
|
||||
const { path, params } = $instance.router
|
||||
const { path, params } = $instance?.router
|
||||
const _path = `${path.split('?')[0]}?${qs.stringify(params)}`
|
||||
let url = `/subpages/auth/login?redirect=${encodeURIComponent(`${_path}`)}`
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ const CustomNavigationHeader = memo((props) => {
|
||||
const navTitle =
|
||||
title ||
|
||||
value?.wgtName ||
|
||||
getCurrentInstance().page?.config?.navigationBarTitleText ||
|
||||
getCurrentInstance()?.page?.config?.navigationBarTitleText ||
|
||||
appName
|
||||
return (
|
||||
<Text className='title-text'>{navTitle}</Text>
|
||||
|
||||
@@ -105,7 +105,7 @@ function SpPoster(props) {
|
||||
Taro.showLoading({
|
||||
title: '海报生成中...'
|
||||
})
|
||||
const ctx = Taro.createCanvasContext(eleId, Taro.getCurrentInstance().page)
|
||||
const ctx = Taro.createCanvasContext(eleId, Taro.getCurrentInstance()?.page)
|
||||
let canvasObj
|
||||
switch (type) {
|
||||
case 'goodsDetial':
|
||||
@@ -216,7 +216,7 @@ function SpPoster(props) {
|
||||
height: pxHeight,
|
||||
canvasId: eleId
|
||||
},
|
||||
Taro.getCurrentInstance().page
|
||||
Taro.getCurrentInstance()?.page
|
||||
)
|
||||
resolve(tempFilePath)
|
||||
} else if (isAlipay) {
|
||||
|
||||
@@ -38,7 +38,7 @@ function SpScrollView(props, ref) {
|
||||
useEffect(() => {
|
||||
let observer = null
|
||||
if (isWeixin || isAlipay) {
|
||||
observer = Taro.createIntersectionObserver(Taro.getCurrentInstance().page, {
|
||||
observer = Taro.createIntersectionObserver(Taro.getCurrentInstance()?.page, {
|
||||
observeAll: true
|
||||
})
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -137,7 +137,7 @@ export default class TabBar extends Component {
|
||||
updateCurTab() {
|
||||
this.fetchCart()
|
||||
const { tabList, localCurrent } = this.state
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
|
||||
console.log('--updateCurTab--', localCurrent, fullPath, tabList)
|
||||
|
||||
@@ -164,7 +164,7 @@ export default class TabBar extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
const { path } = getCurrentRoute(this.$instance.router)
|
||||
const { path } = getCurrentRoute(this.$instance?.router)
|
||||
if (this.state.tabList[cartTabIdx] && path === this.state.tabList[cartTabIdx].url) {
|
||||
updateCartCount('')
|
||||
return
|
||||
@@ -181,7 +181,7 @@ export default class TabBar extends Component {
|
||||
if (cur !== current) {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, withLogin } = curTab
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
|
||||
if (withLogin && !S.getAuthToken()) {
|
||||
return Taro.navigateTo({
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function withPointitem(Component) {
|
||||
}
|
||||
|
||||
isPointitem() {
|
||||
const options = getCurrentInstance().params
|
||||
const options = getCurrentInstance()?.params
|
||||
return options && options.type === 'pointitem'
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export default (props = {}) => {
|
||||
const $instance = getCurrentInstance()
|
||||
|
||||
useEffect(() => {
|
||||
const { token } = $instance.router?.params || {}
|
||||
const { token } = $instance?.router?.params || {}
|
||||
if (token) {
|
||||
Taro.setStorageSync(SG_DIANWU_TOKEN, token)
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ export default class DistributionShopCategory extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ export default class DistributionGoods extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
|
||||
@@ -183,7 +183,7 @@ export default class DistributionShopCategory extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, urlRedirect } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
if (!urlRedirect || (url === '/subpages/member/index' && !S.getAuthToken())) {
|
||||
Taro.navigateTo({ url })
|
||||
|
||||
@@ -136,7 +136,7 @@ export default class DistributionShopGoods extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export default class DistributionShopHome extends Component {
|
||||
|
||||
async componentDidMount() {
|
||||
// if (!S.getAuthToken()) {
|
||||
// const { path } = this.$instance.router
|
||||
// const { path } = this.$instance?.router
|
||||
// const params = await entryLaunch.getRouteParams()
|
||||
// const redirect = encodeURIComponent(`${path}?${qs.stringify(params)}`)
|
||||
// Taro.navigateTo({
|
||||
@@ -299,7 +299,7 @@ export default class DistributionShopHome extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, urlRedirect } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
if (!urlRedirect || (url === '/subpages/member/index' && !S.getAuthToken())) {
|
||||
Taro.navigateTo({ url })
|
||||
|
||||
@@ -97,7 +97,7 @@ export default class GroupDetail extends Component {
|
||||
|
||||
if (!S.getAuthToken()) {
|
||||
showToast('请先登录')
|
||||
const { params, path } = this.$instance.router
|
||||
const { params, path } = this.$instance?.router
|
||||
let url = ''
|
||||
if (isWeixin || isAlipay) {
|
||||
url = `/subpages/member/index?redirect=${encodeURIComponent(
|
||||
|
||||
@@ -44,7 +44,7 @@ function AddressIndex(props) {
|
||||
}, [])
|
||||
|
||||
const initNavigationBarTitle = () => {
|
||||
return $instance.router?.params?.address_id ? '编辑地址' : '新增地址'
|
||||
return $instance?.router?.params?.address_id ? '编辑地址' : '新增地址'
|
||||
}
|
||||
|
||||
const fetchAddressList = async () => {
|
||||
@@ -62,7 +62,7 @@ function AddressIndex(props) {
|
||||
})
|
||||
|
||||
list.map((a_item) => {
|
||||
if (a_item.address_id === $instance.router?.params?.address_id) {
|
||||
if (a_item.address_id === $instance?.router?.params?.address_id) {
|
||||
setState((draft) => {
|
||||
draft.info = a_item
|
||||
draft.chooseValue = [a_item.province, a_item.city, a_item.county]
|
||||
@@ -70,7 +70,7 @@ function AddressIndex(props) {
|
||||
}
|
||||
})
|
||||
|
||||
if ($instance.router?.params?.isWechatAddress) {
|
||||
if ($instance?.router?.params?.isWechatAddress) {
|
||||
try {
|
||||
const resAddress = await Taro.chooseAddress()
|
||||
const query = {
|
||||
|
||||
@@ -286,7 +286,7 @@ export default class Reg extends Component {
|
||||
}
|
||||
|
||||
handleGetPhoneNumber = async (e) => {
|
||||
// let { code } = getCurrentInstance().params
|
||||
// let { code } = getCurrentInstance()?.params
|
||||
// try {
|
||||
// await Taro.checkSession()
|
||||
// } catch (e) {
|
||||
|
||||
@@ -39,7 +39,7 @@ export default class DetailPluspriceList extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
console.log('---componentDidMount---')
|
||||
// const { marketing_id } = getCurrentInstance().params
|
||||
// const { marketing_id } = getCurrentInstance()?.params
|
||||
// this.setState({
|
||||
// query: {
|
||||
// marketing_id: marketing_id
|
||||
|
||||
@@ -90,7 +90,7 @@ function CompDeliver(props, ref) {
|
||||
} = state
|
||||
const formRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { cart_type } = $instance.router?.params || {}
|
||||
const { cart_type } = $instance?.router?.params || {}
|
||||
// useEffect(() => {
|
||||
// fetch()
|
||||
// }, [])
|
||||
|
||||
@@ -65,7 +65,7 @@ export default class Deliver extends Component {
|
||||
|
||||
render() {
|
||||
const { curStore, receiptType, address, isOpenStore, colors, headShop = {} } = this.props
|
||||
const { goodType, type } = this.$instance.router?.params || {}
|
||||
const { goodType, type } = this.$instance?.router?.params || {}
|
||||
// 收货方式[快递,同城,自提]
|
||||
const deliveryList = [
|
||||
{
|
||||
|
||||
@@ -138,7 +138,7 @@ function CartCheckout(props) {
|
||||
launchScene = routerParams.launchScene
|
||||
} = $instance?.router?.params || {}
|
||||
const isLaunchScene = launchScene == 1 ? true : false
|
||||
console.log('$instance.router?.params:', $instance.router)
|
||||
console.log('$instance?.router?.params:', $instance?.router)
|
||||
|
||||
useEffect(() => {
|
||||
Taro.eventCenter.on('onEventCheckoutInvoiceChange', (params) => {
|
||||
|
||||
@@ -59,7 +59,7 @@ function CartIndex() {
|
||||
|
||||
const dispatch = useDispatch()
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { current, recommendList, policyModal, cartRemind } = state
|
||||
|
||||
@@ -35,7 +35,7 @@ function CompGoodsBuyToolbar(props) {
|
||||
|
||||
const RenderBtns = () => {
|
||||
// 兑换券
|
||||
const { card_id } = $instance.router?.params || {}
|
||||
const { card_id } = $instance?.router?.params || {}
|
||||
if (card_id) {
|
||||
btns.push(BUY_TOOL_BTNS().EX_CHANGE)
|
||||
return
|
||||
|
||||
@@ -176,7 +176,7 @@ function EspierDetail(props) {
|
||||
}, [packageOpen, skuPanelOpen, sharePanelOpen, posterModalOpen, promotionOpen, isParameter])
|
||||
|
||||
useEffect(() => {
|
||||
const { path } = $instance.router
|
||||
const { path } = $instance?.router
|
||||
if (id && path === '/pages/item/espier-detail') {
|
||||
fetch()
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { View, WebView } from '@tarojs/components'
|
||||
const initialState = {}
|
||||
function WebviewIndex() {
|
||||
const $instance = getCurrentInstance()
|
||||
const { url } = $instance.router?.params
|
||||
const { url } = $instance?.router?.params
|
||||
const webviewSrc = decodeURIComponent(url)
|
||||
|
||||
return (
|
||||
|
||||
@@ -12,7 +12,7 @@ export function requestIntercept() {
|
||||
let requestParams = chain.requestParams
|
||||
const { method, data, url } = requestParams
|
||||
// console.log('getCurrentInstance:', getCurrentInstance())
|
||||
if (isObject(getCurrentInstance().router)) {
|
||||
if (isObject(getCurrentInstance()?.router)) {
|
||||
const { path } = getCurrentInstance()?.router
|
||||
// console.log('getCurrentInstance params:', path)
|
||||
if (
|
||||
|
||||
@@ -79,7 +79,7 @@ export default class recommendDetail extends Component {
|
||||
// 确认本人文章是否已收藏
|
||||
confirmCollectArticle = async () => {
|
||||
const { id } = this.$instance?.router?.params
|
||||
console.log('this.$instance.router:', this.$instance.router)
|
||||
console.log('this.$instance?.router:', this.$instance?.router)
|
||||
if (S.getAuthToken()) {
|
||||
const res = await api.article.collectArticleInfo({ article_id: id })
|
||||
if (res.length === 0) {
|
||||
@@ -107,7 +107,7 @@ export default class recommendDetail extends Component {
|
||||
|
||||
async fetchContent() {
|
||||
const { id } = this.$instance?.router?.params
|
||||
console.log('this.$instance.router:', this.$instance.router)
|
||||
console.log('this.$instance?.router:', this.$instance?.router)
|
||||
// 关注数加1
|
||||
const resFocus = await api.article.focus(id)
|
||||
|
||||
@@ -144,7 +144,7 @@ export default class recommendDetail extends Component {
|
||||
if(!S.getAuthToken()){
|
||||
return false
|
||||
}
|
||||
const { id } = getCurrentInstance().params
|
||||
const { id } = getCurrentInstance()?.params
|
||||
const { status } = await api.article.praiseCheck(id)
|
||||
this.setState({
|
||||
praiseCheckStatus: status
|
||||
|
||||
@@ -398,7 +398,7 @@ export default class TradeDetail extends Component {
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -124,7 +124,7 @@ export default class TradePickList extends Component {
|
||||
const { tid } = trade
|
||||
if (type === 'confirm') {
|
||||
await api.trade.confirm(tid)
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -425,12 +425,12 @@ export default class TradeDetail extends Component {
|
||||
if (confirm) {
|
||||
await api.trade.confirm(info.tid)
|
||||
if (isWeixin || isAlipay) {
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
} else {
|
||||
const { path } = this.$instance.router
|
||||
const { path } = this.$instance?.router
|
||||
Taro.redirectTo({
|
||||
url: path
|
||||
})
|
||||
|
||||
@@ -121,7 +121,7 @@ export default class TradePickList extends Component {
|
||||
const { tid } = trade
|
||||
if (type === 'confirm') {
|
||||
await api.trade.confirm(tid)
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -257,7 +257,7 @@ export default class TradeList extends Component {
|
||||
|
||||
if (type === 'confirm') {
|
||||
await api.trade.confirm(tid)
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ const AuthLoading = () => {
|
||||
const $instance = getCurrentInstance()
|
||||
const {
|
||||
params: { code, redi_url }
|
||||
} = $instance.router
|
||||
} = $instance?.router
|
||||
|
||||
const { getUserInfo } = useLogin()
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ const PageBindPhone = () => {
|
||||
const $instance = getCurrentInstance()
|
||||
const {
|
||||
params: { unionid, redi_url }
|
||||
} = $instance.router
|
||||
} = $instance?.router
|
||||
|
||||
const { getUserInfo } = useLogin()
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ const PageEditPassword = () => {
|
||||
|
||||
const {
|
||||
params: { phone, unionid, vcode }
|
||||
} = $instance.router
|
||||
} = $instance?.router
|
||||
|
||||
const [state, setState] = useImmer(initialValue)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const PageBindPhone = () => {
|
||||
const $instance = getCurrentInstance()
|
||||
const {
|
||||
params: { phone, redi_url }
|
||||
} = $instance.router
|
||||
} = $instance?.router
|
||||
|
||||
const [state, setState] = useImmer(initialValue)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ async function setTokenAndRedirect(token = '', tokenSetSuccessCallback) {
|
||||
const hasToken = setToken(token)
|
||||
|
||||
const $instance = this ? this.$instance : getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
if (hasToken) {
|
||||
await tokenSetSuccessCallback?.()
|
||||
const { redi_url, redirect } = router?.params
|
||||
|
||||
@@ -17,7 +17,7 @@ function ViewCase() {
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { designWorks } = state
|
||||
const $instance = getCurrentInstance()
|
||||
const { design_works } = $instance.router?.params || {}
|
||||
const { design_works } = $instance?.router?.params || {}
|
||||
useEffect(() => {
|
||||
if (design_works) {
|
||||
const designWorksList = JSON.parse(design_works)
|
||||
|
||||
@@ -40,7 +40,7 @@ const BoxList = () => {
|
||||
state
|
||||
const goodsRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { activity_id } = $instance.router?.params
|
||||
const { activity_id } = $instance?.router?.params
|
||||
|
||||
// useEffect(() => {
|
||||
// if (startDate && startTime && endDate && endTime) {
|
||||
|
||||
@@ -67,7 +67,7 @@ function CheifOrderManage(props) {
|
||||
const { checkIsChief } = useSelector((state) => state.user)
|
||||
const orderRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { activity_id } = $instance.router?.params
|
||||
const { activity_id } = $instance?.router?.params
|
||||
|
||||
const {
|
||||
keywords,
|
||||
|
||||
@@ -65,7 +65,7 @@ function CommunityOrder(props) {
|
||||
const { colorPrimary } = useSelector((state) => state.sys)
|
||||
const orderRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { activity_id } = $instance.router?.params
|
||||
const { activity_id } = $instance?.router?.params
|
||||
|
||||
const { keywords, orderList, curTabIdx, isOpened, remark, payLoading } = state
|
||||
const fetch = async ({ pageIndex, pageSize }) => {
|
||||
@@ -267,7 +267,7 @@ function CommunityOrder(props) {
|
||||
title: '支付成功',
|
||||
icon: 'success'
|
||||
})
|
||||
const { fullPath } = getCurrentRoute($instance.router?.params || {})
|
||||
const { fullPath } = getCurrentRoute($instance?.router?.params || {})
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -402,7 +402,7 @@ export default class TradeDetail extends Component {
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
const { fullPath } = getCurrentRoute(this.$instance.router)
|
||||
const { fullPath } = getCurrentRoute(this.$instance?.router)
|
||||
Taro.redirectTo({
|
||||
url: fullPath
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ function ActivityCode(props) {
|
||||
useEffect(() => {}, [])
|
||||
|
||||
const handleScanGoodsBN = async () => {
|
||||
// 注意:真机scancode扫码完成后回调,taro getCurrentInstance().router = null,无法获取到路由参数
|
||||
// 注意:真机scancode扫码完成后回调,taro getCurrentInstance()?.router = null,无法获取到路由参数
|
||||
const { errMsg, result } = await Taro.scanCode()
|
||||
console.log('handleScanCode:', result)
|
||||
if (errMsg == 'scanCode:ok') {
|
||||
|
||||
@@ -140,7 +140,7 @@ function DianWuCashier() {
|
||||
}
|
||||
|
||||
const handleScanGoodsBN = async () => {
|
||||
// 注意:真机scancode扫码完成后回调,taro getCurrentInstance().router = null,无法获取到路由参数
|
||||
// 注意:真机scancode扫码完成后回调,taro getCurrentInstance()?.router = null,无法获取到路由参数
|
||||
const { errMsg, result } = await Taro.scanCode()
|
||||
console.log('handleScanCode:', result)
|
||||
if (errMsg == 'scanCode:ok') {
|
||||
|
||||
@@ -13,7 +13,7 @@ const SpRecordLayout = () => {
|
||||
const [records, setRecords] = useState([])
|
||||
const $instance = Taro.getCurrentInstance()
|
||||
|
||||
const { path, params } = $instance.router
|
||||
const { path, params } = $instance?.router
|
||||
const id = params.id
|
||||
useEffect(() => {
|
||||
initData()
|
||||
|
||||
@@ -34,7 +34,7 @@ const initialState = {
|
||||
function CartIndex() {
|
||||
const dispatch = useDispatch()
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { current, policyModal } = state
|
||||
|
||||
@@ -121,7 +121,7 @@ export default class TabBar extends Component {
|
||||
updateCurTab() {
|
||||
this.fetchCart()
|
||||
const { tabList, localCurrent } = this.state
|
||||
const fullPath = getCurrentRoute(getCurrentInstance().router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(getCurrentInstance()?.router).fullPath.split('?')[0]
|
||||
if (tabList.length == 0) {
|
||||
return
|
||||
}
|
||||
@@ -145,7 +145,7 @@ export default class TabBar extends Component {
|
||||
})
|
||||
}
|
||||
|
||||
const { path } = getCurrentRoute(getCurrentInstance().router)
|
||||
const { path } = getCurrentRoute(getCurrentInstance()?.router)
|
||||
if (this.state.tabList[cartTabIdx] && path === this.state.tabList[cartTabIdx].url) {
|
||||
updateCartCount('')
|
||||
return
|
||||
@@ -163,7 +163,7 @@ export default class TabBar extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, withLogin } = curTab
|
||||
console.log('tabbar-withLogin', url, withLogin)
|
||||
const fullPath = getCurrentRoute(getCurrentInstance().router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(getCurrentInstance()?.router).fullPath.split('?')[0]
|
||||
// if (withLogin && !S.getAuthToken()) {
|
||||
// return Taro.navigateTo({
|
||||
// url: process.env.APP_AUTH_PAGE
|
||||
|
||||
@@ -82,7 +82,7 @@ function ItemList() {
|
||||
|
||||
const goodsRef = useRef()
|
||||
const pageRef = useRef()
|
||||
// console.log('$instance?.router?.params', $instance.router?.params)
|
||||
// console.log('$instance?.router?.params', $instance?.router?.params)
|
||||
useEffect(() => {
|
||||
if (S.getAuthToken()) {
|
||||
dispatch(fetchUserFavs())
|
||||
|
||||
@@ -34,7 +34,7 @@ function CompGoodsBuyToolbar(props) {
|
||||
|
||||
const RenderBtns = () => {
|
||||
// 兑换券
|
||||
const { card_id } = $instance.router?.params || {}
|
||||
const { card_id } = $instance?.router?.params || {}
|
||||
if (card_id) {
|
||||
btns.push(BUY_TOOL_BTNS().EX_CHANGE)
|
||||
return
|
||||
|
||||
@@ -73,7 +73,7 @@ function CompDeliver(props, ref) {
|
||||
} = state
|
||||
const formRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { cart_type } = $instance.router?.params || {}
|
||||
const { cart_type } = $instance?.router?.params || {}
|
||||
// useEffect(() => {
|
||||
// fetch()
|
||||
// }, [])
|
||||
|
||||
@@ -105,8 +105,8 @@ function PointShopEspierCheckout() {
|
||||
scene, // 情景值
|
||||
goodType,
|
||||
ticket = null
|
||||
} = $instance.router?.params || {}
|
||||
console.log('$instance.router?.params:', $instance)
|
||||
} = $instance?.router?.params || {}
|
||||
console.log('$instance?.router?.params:', $instance)
|
||||
useEffect(() => {
|
||||
if (isLogin) {
|
||||
getTradeSetting()
|
||||
|
||||
@@ -111,7 +111,7 @@ function PointShopEspierDetail(props) {
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const { path } = $instance.router
|
||||
const { path } = $instance?.router
|
||||
if (id && path === '/subpages/pointshop/espier-detail') {
|
||||
fetch()
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ function PurchaseCheckout(props) {
|
||||
scene, // 情景值
|
||||
goodType,
|
||||
ticket = null
|
||||
} = $instance.router?.params || {}
|
||||
} = $instance?.router?.params || {}
|
||||
|
||||
useEffect(() => {
|
||||
if (isLogin) {
|
||||
|
||||
@@ -41,7 +41,7 @@ function CartIndex() {
|
||||
|
||||
const dispatch = useDispatch()
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { current, policyModal } = state
|
||||
|
||||
@@ -79,7 +79,7 @@ function ItemList() {
|
||||
const dispatch = useDispatch()
|
||||
|
||||
const goodsRef = useRef()
|
||||
// console.log('$instance?.router?.params', $instance.router?.params)
|
||||
// console.log('$instance?.router?.params', $instance?.router?.params)
|
||||
useEffect(() => {
|
||||
if (S.getAuthToken()) {
|
||||
dispatch(fetchUserFavs())
|
||||
|
||||
@@ -35,7 +35,7 @@ function Cart() {
|
||||
const { allChecked, current } = state
|
||||
const dispatch = useDispatch()
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
const {
|
||||
validSalesmanCart = [],
|
||||
invalidSalesmanCart = [],
|
||||
|
||||
@@ -90,7 +90,7 @@ function CompDeliver(props, ref) {
|
||||
} = state
|
||||
const formRef = useRef()
|
||||
const $instance = getCurrentInstance()
|
||||
const { cart_type } = $instance.router?.params || {}
|
||||
const { cart_type } = $instance?.router?.params || {}
|
||||
// useEffect(() => {
|
||||
// fetch()
|
||||
// }, [])
|
||||
|
||||
@@ -218,7 +218,7 @@ export default class DistributionShopCategory extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ export default class DistributionGoods extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
|
||||
@@ -184,7 +184,7 @@ export default class DistributionShopCategory extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, urlRedirect } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
if (!urlRedirect || (url === '/subpages/member/index' && !S.getAuthToken())) {
|
||||
Taro.navigateTo({ url })
|
||||
|
||||
@@ -137,7 +137,7 @@ export default class DistributionShopGoods extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
Taro.redirectTo({ url })
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export default class DistributionShopHome extends Component {
|
||||
|
||||
async componentDidMount() {
|
||||
// if (!S.getAuthToken()) {
|
||||
// const { path } = this.$instance.router
|
||||
// const { path } = this.$instance?.router
|
||||
// const params = await entryLaunch.getRouteParams()
|
||||
// const redirect = encodeURIComponent(`${path}?${qs.stringify(params)}`)
|
||||
// Taro.navigateTo({
|
||||
@@ -338,7 +338,7 @@ export default class DistributionShopHome extends Component {
|
||||
const curTab = this.state.tabList[current]
|
||||
const { url, urlRedirect } = curTab
|
||||
|
||||
const fullPath = getCurrentRoute(this.$instance.router).fullPath.split('?')[0]
|
||||
const fullPath = getCurrentRoute(this.$instance?.router).fullPath.split('?')[0]
|
||||
if (url && fullPath !== url) {
|
||||
if (!urlRedirect || (url === '/subpages/member/index' && !S.getAuthToken())) {
|
||||
Taro.navigateTo({ url })
|
||||
|
||||
@@ -131,7 +131,7 @@ function CartCheckout(props) {
|
||||
scene, // 情景值
|
||||
goodType = routerParams.goodType
|
||||
} = $instance?.router?.params || {}
|
||||
console.log('$instance.router?.params:', $instance.router)
|
||||
console.log('$instance?.router?.params:', $instance?.router)
|
||||
useEffect(() => {
|
||||
if (isLogin) {
|
||||
getTradeSetting()
|
||||
|
||||
@@ -26,7 +26,7 @@ const PageBrandInfo = () => {
|
||||
|
||||
const {
|
||||
params: { distributor_id }
|
||||
} = $instance.router
|
||||
} = $instance?.router
|
||||
|
||||
const getDetail = async () => {
|
||||
const {
|
||||
|
||||
@@ -38,7 +38,7 @@ function CompAddCart(props) {
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { hideClose } = state
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
const plus_buy_activity = shopCartCount?.storeDetails?.plus_buy_activity?.[0]
|
||||
const exchange_item = plus_buy_activity?.plus_item
|
||||
? pickBy(plus_buy_activity?.plus_item, { ...doc.cart.PLUS_BUY_ITEM })
|
||||
|
||||
@@ -26,7 +26,7 @@ function CompTab(props) {
|
||||
const [state, setState] = useImmer(initialState)
|
||||
const { fav, couponList, extend } = state
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
|
||||
if (!shopCartCount) {
|
||||
return null
|
||||
|
||||
@@ -64,7 +64,7 @@ function StoreIndex() {
|
||||
const { shopCartCount } = useSelector((state) => state.cart)
|
||||
const { setNavigationBarTitle } = useNavigation()
|
||||
const $instance = getCurrentInstance()
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
|
||||
const {
|
||||
wgts,
|
||||
|
||||
@@ -39,7 +39,7 @@ class EntryLaunch {
|
||||
* @function 获取小程序路由参数
|
||||
*/
|
||||
async getRouteParams(options) {
|
||||
const params = options?.query || options?.params || $instance.router?.params || {}
|
||||
const params = options?.query || options?.params || $instance?.router?.params || {}
|
||||
|
||||
const pageStack = Taro.getCurrentPages()
|
||||
|
||||
@@ -56,7 +56,7 @@ class EntryLaunch {
|
||||
}
|
||||
|
||||
let _options = {}
|
||||
console.log('$instance.router?.params', $instance.router?.params)
|
||||
console.log('$instance?.router?.params', $instance?.router?.params)
|
||||
if (params?.scene) {
|
||||
console.log('params scene:', params.scene, resolveUrlParamsParse(params.scene))
|
||||
_options = {
|
||||
@@ -457,7 +457,7 @@ class EntryLaunch {
|
||||
* 导购任务埋点上报
|
||||
*/
|
||||
async postGuideTask(customPath) {
|
||||
const { path, params } = $instance.router
|
||||
const { path, params } = $instance?.router
|
||||
const paths = customPath || path
|
||||
const routePath = {
|
||||
'/pages/item/espier-detail': 'activeItemDetail',
|
||||
|
||||
@@ -168,7 +168,7 @@ export const isIphoneX = () => {
|
||||
|
||||
// TODO: 验证方法在h5及边界情况稳定性
|
||||
export function getCurrentRoute() {
|
||||
const router = getCurrentInstance().router
|
||||
const router = getCurrentInstance()?.router
|
||||
// eslint-disable-next-line
|
||||
const { $taroTimestamp, ...params } = router?.params || {}
|
||||
const path = router?.path
|
||||
|
||||
@@ -37,7 +37,7 @@ export const transformPlatformUrl = (url) => {
|
||||
// 授权页面
|
||||
export const goToAuthPage = () => {
|
||||
const $instance = useMemo(getCurrentInstance, [])
|
||||
const router = $instance.router
|
||||
const router = $instance?.router
|
||||
const { path } = router
|
||||
Taro.navigateTo({
|
||||
url: `/pages/auth/login?redirect=`
|
||||
|
||||
Reference in New Issue
Block a user