import Taro, { useRouter } from '@tarojs/taro'
import { parseQueryString } from '@/utils'

export default () => {
  const router = useRouter()

  // 扫码进入的
  if (router?.params?.scene) {
    const qrCodeStr = Taro.getStorageSync('qrcode')
    if (qrCodeStr && qrCodeStr !== 'undefined') {
      const qrParams = parseQueryString(qrCodeStr) || {}
      router.params = {
        ...router.params || {},
        ...qrParams,
      }
    }
  }

  return router
}
