|
@@ -1,41 +1,99 @@
|
|
|
-import modeMap from '~/configs/mode-map'
|
|
|
import axios from 'axios'
|
|
|
-const whiteList = ['/auth']
|
|
|
-
|
|
|
-export default function ({ route, error, redirect }) {
|
|
|
- if (whiteList.indexOf(route.path) > -1) return
|
|
|
+import oldRoutes from '@/utils/old-routes'
|
|
|
+import { getQueryObject } from '~/utils'
|
|
|
+import modeMap from '~/configs/mode-map'
|
|
|
+const templateList = ['app', 'ross', 'ldm']
|
|
|
+const baseURL = process.env.BASE_URL + '/wx/auth/shop/info'
|
|
|
+const dev = process.env.NODE_ENV
|
|
|
|
|
|
- const authUserId = parseInt(route.params.template)
|
|
|
- const auth = modeMap.find((item) => item.authUserId === authUserId)
|
|
|
- let routePrefix = !auth ? `/${authUserId}/app` : `/${authUserId}/${auth.mode}`
|
|
|
+// 获取供应商信息1 通过authUserId获取
|
|
|
+function fetchSupplierInfo(params) {
|
|
|
+ return axios.get(baseURL, { params })
|
|
|
+}
|
|
|
|
|
|
- const baseURL = process.env.BASE_URL + '/wx/auth/shop/info'
|
|
|
- console.log(auth && auth.mode, authUserId)
|
|
|
+// 旧链接初始化
|
|
|
+function oldLinkInit({ route, error, redirect }) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let hash = route.hash
|
|
|
+ const query = getQueryObject(hash)
|
|
|
+ const appId = query.appId
|
|
|
+ const index = hash.indexOf('?')
|
|
|
+ hash = hash.slice(1, index)
|
|
|
+ const oldRoute = oldRoutes.find((item) => hash === item.path)
|
|
|
+ if (!oldRoute) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ reject()
|
|
|
+ }
|
|
|
+ fetchSupplierInfo({ appId })
|
|
|
+ .then(({ data }) => {
|
|
|
+ const res = data
|
|
|
+ if (res.code === -1) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ }
|
|
|
+ const path = `/${data.authUserId}` + oldRoute.redirect
|
|
|
+ redirect(path)
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- return axios
|
|
|
- .get(baseURL, {
|
|
|
- params: { authUserId: authUserId },
|
|
|
- })
|
|
|
- .then(({ data }) => {
|
|
|
- if (data.code === -1) {
|
|
|
- error({
|
|
|
- statusCode: 404,
|
|
|
- message: '页面不存在',
|
|
|
- })
|
|
|
- } else if (authUserId === 12 && auth.mode === 'ross' && route.path.indexOf(`${authUserId}/app`) > -1) {
|
|
|
- // console.log(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`))
|
|
|
- redirect(route.fullPath.replace(`${authUserId}/app`, `${authUserId}/ross`))
|
|
|
- } else if (route.path.indexOf(routePrefix) !== 0) {
|
|
|
- error({
|
|
|
- statusCode: 404,
|
|
|
- message: '页面不存在',
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- error({
|
|
|
- statusCode: 404,
|
|
|
- message: '页面不存在',
|
|
|
+// 新链接初始化
|
|
|
+function newLinkInit({ route, error, redirect }) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ const authUserId = parseInt(route.params.template)
|
|
|
+ const mode = modeMap.find((mode) => mode.authUserId === authUserId)
|
|
|
+ const prefixPath_app = `/${authUserId}/app`
|
|
|
+ fetchSupplierInfo({ authUserId })
|
|
|
+ .then(({ data }) => {
|
|
|
+ if (dev === 'production') {
|
|
|
+ const res = data
|
|
|
+ const prefix = res.data.prefix
|
|
|
+ const prefixPath = `/${authUserId}/${prefix}`
|
|
|
+ // 获取供应商失败
|
|
|
+ if (res.code === -1) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ }
|
|
|
+ // 没有指定模板 && 模板不存在 && 不是app默认模板路由地址
|
|
|
+ else if (
|
|
|
+ !mode &&
|
|
|
+ !templateList.includes(prefix) &&
|
|
|
+ !route.fullPath.startsWith(prefixPath_app)
|
|
|
+ ) {
|
|
|
+ if (!route.fullPath.startsWith(prefixPath)) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ } else {
|
|
|
+ const redirectPath = route.fullPath.replace(
|
|
|
+ prefixPath,
|
|
|
+ prefixPath_app
|
|
|
+ )
|
|
|
+ redirect(redirectPath)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没有指定模板 && 是app默认模板路由地址
|
|
|
+ else if (!mode && route.fullPath.startsWith(prefixPath_app)) {
|
|
|
+ }
|
|
|
+ // 模板未定义
|
|
|
+ else if (!templateList.includes(prefix)) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ }
|
|
|
+ // 模板与供应商不匹配
|
|
|
+ else if (!route.fullPath.startsWith(prefixPath)) {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ error({ statusCode: 404, message: '页面不存在' })
|
|
|
+ console.log(err)
|
|
|
})
|
|
|
- })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export default function (context) {
|
|
|
+ return context.route.hash ? oldLinkInit(context) : newLinkInit(context)
|
|
|
}
|