Explorar el Código

页面逻辑整理优化

yuwenjun1997 hace 2 años
padre
commit
88b4607151

+ 7 - 49
layouts/app-ldm.vue

@@ -34,65 +34,23 @@ export default {
     }
   },
   mounted() {
-    this.init()
+    this.responseWidth()
+    this.initPageData()
   },
   beforeDestroy() {
     window.removeEventListener('resize', () => {})
+    this.refreshCacheData()
   },
   methods: {
-    init() {
-      this.responseWidth()
-      this.initPageData()
-    },
     // 初始化数据页面公共数据
     initPageData() {
-      // 获取供应商id
-      const authUserId = parseInt(this.$route.params.template)
-      const routePrefix = `/${authUserId}/ldm`
-      // 保存页面路由前缀
-      this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
-      // 保存用户AppId
-      this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
-
+      // this.$store.commit('app/SET_PAGE_THEME', 'app')
       // 获取用户信息
-      let userInfo = this.$getStorage(routePrefix, 'userInfo')
-      if (userInfo && userInfo.authUserId === authUserId) {
+      let userInfo = this.$getStorage(this.routePrefix, 'userInfo')
+      if (userInfo && userInfo.authUserId === this.authUserId) {
         this.$store.commit('user/SET_USER_INFO', userInfo)
       }
-      // 初始化供应商信息
-      this.fetchSupplierInfo()
-    },
-
-    // 获取供应商信息
-    async fetchSupplierInfo() {
-      try {
-        const res = await this.$http.api.fetchSupplierInfo({
-          authUserId: this.authUserId,
-        })
-        this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
-        this.$store.commit('user/SET_APPID', res.data.appId)
-        // 如果appId存在
-        if (res.data.appId) {
-          this.checkAccountType(res.data.appId)
-        }
-      } catch (error) {
-        console.log(error)
-      } finally {
-        this.isMounted = true
-        // 清除缓存
-        this.refreshCacheData()
-      }
-    },
-
-    // 校验公众号类型
-    async checkAccountType(appId) {
-      try {
-        // 1订阅号,2服务号
-        const res = await this.$http.api.checkAccountType({ appId })
-        this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
-      } catch (error) {
-        console.log(error)
-      }
+      this.isMounted = true
     },
 
     // 退出登录

+ 21 - 78
layouts/app-ross.vue

@@ -1,10 +1,6 @@
 <template>
-  <div :class="themeClass">
-    <div
-      class="layout"
-      v-if="isMounted"
-      :style="{ paddingTop: showHeader ? '' : 0 }"
-    >
+  <div :class="themeClass" v-if="isMounted">
+    <div class="layout" :style="{ paddingTop: showHeader ? '' : 0 }">
       <div class="header" v-show="showHeader">
         <div class="navbar flex justify-between items-center">
           <div class="logo flex items-center" @click="backHome">
@@ -19,7 +15,7 @@
           <div class="flex justify-center items-center">
             <div class="nav" v-if="isPc">
               <template v-for="item in list">
-                <div class="link" :key="item.id" @click="toDetail(item)">
+                <div class="link" :key="item.id" @click="onJumpTo(item)">
                   <span class="icon" :class="item.icon"></span>
                   <span class="text">{{ item.name }}</span>
                 </div>
@@ -65,7 +61,7 @@
       <el-drawer :visible.sync="drawer" size="63%">
         <div class="nav">
           <template v-for="item in list">
-            <div class="link" :key="item.id" @click="toDetail(item)">
+            <div class="link" :key="item.id" @click="onJumpTo(item)">
               <span class="icon" :class="item.icon"></span>
               <span class="text">{{ item.name }}</span>
             </div>
@@ -78,8 +74,6 @@
 
 <script>
 import { mapGetters } from 'vuex'
-import { isWeChat } from '~/utils/validator'
-import { toAuthorization } from '~/utils'
 export default {
   computed: {
     ...mapGetters([
@@ -87,7 +81,6 @@ export default {
       'accessToken',
       'authUserId',
       'appId',
-      'accountType',
       'routePrefix',
       'themeName',
       'isPc',
@@ -112,9 +105,9 @@ export default {
   },
   data() {
     return {
-      isMounted: false,
       formType: 'login',
       drawer: false,
+      isMounted: false,
       list: [
         {
           id: 1,
@@ -138,14 +131,17 @@ export default {
     }
   },
   mounted() {
-    this.init()
-    console.log(1)
+    this.responseWidth()
+    this.initPageData()
+    // this.checkAccountType()
   },
   beforeDestroy() {
     window.removeEventListener('resize', () => {})
+    this.refreshCacheData()
   },
   methods: {
-    toDetail(item) {
+    // 跳转
+    onJumpTo(item) {
       this.drawer = false
       const hasLogin = this.$store.getters.accessToken
       // 保存登录重定向路由
@@ -155,14 +151,6 @@ export default {
         this.routePrefix + item.path
       )
       if (item.id > 2 && !hasLogin) {
-        // 在微信浏览器中使用微信授权登录
-        if (isWeChat() && this.appId && this.accountType === 2) {
-          const payload = {
-            authUserId: this.authUserId,
-            routePrefix: this.routePrefix,
-          }
-          return toAuthorization(this.appId, payload)
-        }
         this.$toast({ message: '请先登录', duration: 1000 })
         this.formType = 'login'
         this.$store.commit('app/SHOW_LOGIN')
@@ -178,94 +166,49 @@ export default {
       }
     },
 
+    // 点击登录
     onLoginClick(type) {
       this.formType = type
     },
 
-    init() {
-      this.responseWidth()
-      this.initPageData()
-    },
     // 初始化数据页面公共数据
     initPageData() {
-      // 获取供应商id
-      const authUserId = parseInt(this.$route.params.template)
-      const routePrefix = `/${authUserId}/ross`
-      // 保存页面路由前缀
-      this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
-      // 保存用户AppId
-      this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
-
-      // 设置页面主题12
-      // if (authUserId === parseInt(12)) {
-      //   this.$store.commit('app/SET_PAGE_THEME', 'ross')
-      // }
       this.$store.commit('app/SET_PAGE_THEME', 'ross')
-
       // 获取用户信息
-      let userInfo = this.$getStorage(routePrefix, 'userInfo')
-      if (userInfo && userInfo.authUserId === authUserId) {
+      let userInfo = this.$getStorage(this.routePrefix, 'userInfo')
+      if (userInfo && userInfo.authUserId === this.authUserId) {
         this.$store.commit('user/SET_USER_INFO', userInfo)
       }
-      // 初始化供应商信息
-      this.fetchSupplierInfo()
-    },
-
-    // 获取供应商信息
-    async fetchSupplierInfo() {
-      try {
-        const res = await this.$http.api.fetchSupplierInfo({
-          authUserId: this.authUserId,
-        })
-        this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
-        this.$store.commit('user/SET_APPID', res.data.appId)
-        // 如果appId存在
-        if (res.data.appId) {
-          this.checkAccountType(res.data.appId)
-        }
-      } catch (error) {
-        console.log(error)
-      } finally {
-        this.isMounted = true
-        // 清除缓存
-        this.refreshCacheData()
-      }
+      this.isMounted = true
     },
 
     // 校验公众号类型
-    async checkAccountType(appId) {
+    async checkAccountType() {
       try {
         // 1订阅号,2服务号
-        const res = await this.$http.api.checkAccountType({ appId })
-        this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
+        if (!this.appId) return
+        const res = await this.$http.api.checkAccountType({ appId: this.appId })
+        this.$store.commit('supplier/SET_ACCOUNT_TYPE', res.data)
       } catch (error) {
         console.log(error)
       }
     },
 
+    // 登录
     onLogin() {
-      // 在微信浏览器中使用微信授权登录
-      if (isWeChat() && this.appId && this.accountType === 2) {
-        const payload = {
-          authUserId: this.authUserId,
-          routePrefix: this.routePrefix,
-        }
-        return toAuthorization(this.appId, payload)
-      }
       this.formType = 'login'
       this.$store.commit('app/SHOW_LOGIN')
     },
 
+    // 注册
     onRegister() {
       this.formType = 'register'
-      console.log(this.formType)
       this.$store.commit('app/SHOW_LOGIN')
     },
 
     // 退出登录
     logout() {
       this.$store.dispatch('user/logout')
-      console.log(this.routePrefix)
       this.$removeStorage(this.routePrefix, 'userInfo')
       this.backHome()
     },

+ 51 - 72
layouts/app.vue

@@ -1,10 +1,6 @@
 <template>
-  <div :class="themeClass">
-    <div
-      class="layout"
-      v-if="isMounted"
-      :style="{ paddingTop: showHeader ? '' : 0 }"
-    >
+  <div :class="themeClass" v-if="isMounted">
+    <div class="layout" :style="{ paddingTop: showHeader ? '' : 0 }">
       <div class="header" v-show="showHeader">
         <div class="navbar flex justify-between items-center">
           <div class="logo flex items-center" @click="backHome">
@@ -54,8 +50,6 @@
 
 <script>
 import { mapGetters } from 'vuex'
-import { isWeChat } from '~/utils/validator'
-import { toAuthorization } from '~/utils'
 export default {
   computed: {
     ...mapGetters([
@@ -63,9 +57,9 @@ export default {
       'accessToken',
       'authUserId',
       'appId',
-      'accountType',
       'routePrefix',
       'themeName',
+      'isPc',
       'showHeader',
       'showFooter',
       'supplierInfo',
@@ -74,112 +68,97 @@ export default {
       return `theme-${this.themeName}`
     },
   },
-  // head(context) {
-  //   return {
-  //     link: [{ rel: 'icon', type: 'image/x-icon', href: context.themeName === 'ross' ? '' : '/favicon.ico' }],
-  //   }
-  // },
+  head() {
+    return {
+      meta: [
+        {
+          name: 'viewport',
+          content:
+            'width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
+        },
+      ],
+    }
+  },
   data() {
     return {
-      isMounted: false,
       formType: 'login',
+      drawer: false,
+      isMounted: false,
+      list: [
+        {
+          id: 1,
+          name: '授权申请',
+          path: '/form/club-register',
+          icon: 'icon-register',
+        },
+        {
+          id: 2,
+          name: '产品资料',
+          path: '/docs/0',
+          icon: 'icon-doc',
+        },
+        {
+          id: 3,
+          name: '意见反馈',
+          path: '/feedback',
+          icon: 'icon-feedback',
+        },
+      ],
     }
   },
   mounted() {
-    this.init()
-    console.log(1)
+    this.responseWidth()
+    this.initPageData()
+    // this.checkAccountType()
   },
   beforeDestroy() {
     window.removeEventListener('resize', () => {})
+    this.refreshCacheData()
   },
   methods: {
+    // 点击登录
     onLoginClick(type) {
       this.formType = type
     },
 
-    init() {
-      this.responseWidth()
-      this.initPageData()
-    },
     // 初始化数据页面公共数据
     initPageData() {
-      // 获取供应商id
-      const authUserId = parseInt(this.$route.params.template)
-      const routePrefix = `/${authUserId}/app`
-      // 保存页面路由前缀
-      this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
-      // 保存用户AppId
-      this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
-
-      // 设置页面主题
-      // if (authUserId === parseInt(12)) {
-      //   this.$store.commit('app/SET_PAGE_THEME', 'ross')
-      // }
-
+      // this.$store.commit('app/SET_PAGE_THEME', 'app')
       // 获取用户信息
-      let userInfo = this.$getStorage(routePrefix, 'userInfo')
-      if (userInfo && userInfo.authUserId === authUserId) {
+      let userInfo = this.$getStorage(this.routePrefix, 'userInfo')
+      if (userInfo && userInfo.authUserId === this.authUserId) {
         this.$store.commit('user/SET_USER_INFO', userInfo)
       }
-      // 初始化供应商信息
-      this.fetchSupplierInfo()
-    },
-
-    // 获取供应商信息
-    async fetchSupplierInfo() {
-      try {
-        const res = await this.$http.api.fetchSupplierInfo({
-          authUserId: this.authUserId,
-        })
-        this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
-        this.$store.commit('user/SET_APPID', res.data.appId)
-        // 如果appId存在
-        if (res.data.appId) {
-          this.checkAccountType(res.data.appId)
-        }
-      } catch (error) {
-        console.log(error)
-      } finally {
-        this.isMounted = true
-        // 清除缓存
-        this.refreshCacheData()
-      }
+      this.isMounted = true
     },
 
     // 校验公众号类型
-    async checkAccountType(appId) {
+    async checkAccountType() {
       try {
         // 1订阅号,2服务号
-        const res = await this.$http.api.checkAccountType({ appId })
-        this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
+        if (!this.appId) return
+        const res = await this.$http.api.checkAccountType({ appId: this.appId })
+        this.$store.commit('supplier/SET_ACCOUNT_TYPE', res.data)
       } catch (error) {
         console.log(error)
       }
     },
 
+    // 登录
     onLogin() {
-      // 在微信浏览器中使用微信授权登录
-      if (isWeChat() && this.appId && this.accountType === 2) {
-        const payload = {
-          authUserId: this.authUserId,
-          routePrefix: this.routePrefix,
-        }
-        return toAuthorization(this.appId, payload)
-      }
       this.formType = 'login'
       this.$store.commit('app/SHOW_LOGIN')
     },
 
+    // 注册
     onRegister() {
       this.formType = 'register'
-      console.log(this.formType)
       this.$store.commit('app/SHOW_LOGIN')
     },
 
     // 退出登录
     logout() {
       this.$store.dispatch('user/logout')
-      console.log(this.routePrefix)
       this.$removeStorage(this.routePrefix, 'userInfo')
       this.backHome()
     },

+ 0 - 116
middleware/auth.js

@@ -1,116 +0,0 @@
-import axios from 'axios'
-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
-
-// 获取供应商信息1 通过authUserId获取
-function fetchSupplierInfo(params) {
-  return axios.get(baseURL, { params })
-}
-
-// 旧链接初始化
-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()
-      })
-  })
-}
-
-// 新链接初始化
-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: '页面不存在' })
-        resolve(err)
-      })
-  })
-}
-
-// 公共页页面入口
-function publickLinkInit({ route, error, redirect }) {
-  const whiteList = ['/download']
-  return new Promise((resovle) => {
-    if (whiteList.indexOf(route.path) === -1) {
-      error({ statusCode: 404, message: '页面不存在' })
-    }
-    resovle()
-  })
-}
-
-export default function (context) {
-  let hash = context.route.hash
-  const query = getQueryObject(hash)
-  const appId = query.appId
-  if (appId) return oldLinkInit(context) // 老连接适配
-  const authUserId = parseInt(context.route.params.template)
-  if (authUserId) return newLinkInit(context) // 模板入口页面
-  return publickLinkInit(context) // 公共页页面入口
-}

+ 111 - 0
middleware/intercept.js

@@ -0,0 +1,111 @@
+import modeMap from '~/configs/mode-map'
+const dev = process.env.EVN
+
+// 是否是公共页面入口
+function isPublicEntry(name) {
+  return /^public-.+$/gi.test(name)
+}
+
+// 是否是模板页面入口
+function isTemplateEntry(name) {
+  return /^template-.+$/gi.test(name)
+}
+
+// 错误信息
+function showError(error, options) {
+  return error({
+    statusCode: options.statusCode || 500,
+    message:
+      (dev === 'production' ? '服务器出错' : options.message) || '服务器出错',
+  })
+}
+
+// 供应商与模板匹配
+function isMatchTemplate(authUserId, prefix) {
+  const mode = modeMap.find((item) => item.authUserId == authUserId)
+  return mode && mode.prefix === prefix
+}
+
+// 供应商是否存在指定模板
+function isFixedTemplate(authUserId) {
+  const mode = modeMap.find((item) => item.authUserId == authUserId)
+  return mode && true
+}
+
+// 修改路由
+function replaceFullPath(fullPath) {
+  return fullPath.replace(/^(\/\d+\/)([a-z]+)(.*)/gi, (match, $1, $2, $3) => {
+    return $1 + 'app' + $3
+  })
+}
+
+// 初始化页面信息
+function initPageData(store, data) {
+  // 保存页面路由前缀
+  store.commit('app/SET_ROUTE_PREFIX', `/${data.authUserId}/${data.prefix}`)
+  // 保存供应商信息
+  store.commit('supplier/SET_SUPPLIER_INFO', data)
+}
+
+// 从模板入口进入
+async function initTemplateEntry(context) {
+  const { route, $http, error, store, redirect } = context
+  try {
+    // 模板不存在
+    let authUserId = route.params.template
+    if (!authUserId) {
+      showError(error, { statusCode: 500, message: '页面不存在' })
+      return
+    }
+    const res = await $http.api.fetchSupplierInfo({ authUserId })
+    const prefix = route.name.split('-')[1]
+
+    // 未匹配模板
+    if (prefix === 'mode') {
+      const redirectPath = replaceFullPath(route.fullPath)
+      redirect(redirectPath)
+      return
+    }
+
+    // 默认模板
+    if (prefix === 'app') {
+      if (isFixedTemplate(authUserId)) {
+        showError(error, { statusCode: 500, message: '模板与供应商不匹配' })
+        return
+      }
+    }
+
+    // 非默认模板
+    if (['ross', 'ldm'].includes(prefix)) {
+      // 供应商为指定模板
+      if (!isMatchTemplate(authUserId, prefix)) {
+        showError(error, { statusCode: 500, message: '模板与供应商不匹配' })
+        return
+      }
+    }
+
+    res.data.prefix = prefix
+
+    // console.log(res.data)
+    initPageData(store, res.data)
+  } catch (err) {
+    console.log(err)
+    showError(error, { statusCode: 500, message: err.message || err.msg })
+  }
+}
+
+// 公共入口进入
+function initPublicEntry() {
+  console.log('公共入口进入')
+  return new Promise((resolve) => {
+    resolve()
+  })
+}
+
+export default function (context) {
+  const name = context.route.name
+  // console.log(name)
+  if (isPublicEntry(name)) return initPublicEntry(context)
+  if (isTemplateEntry(name)) return initTemplateEntry(context)
+  context.error({ statusCode: 404, message: '页面不存在' })
+}

+ 2 - 2
nuxt.config.js

@@ -5,7 +5,7 @@ console.log(process.env.BASE_URL)
 
 export default {
   router: {
-    middleware: 'auth',
+    middleware: ['intercept'],
   },
 
   // Global page headers: https://go.nuxtjs.dev/config-head
@@ -46,7 +46,7 @@ export default {
     'swiper/css/swiper.css',
     'animate.css/animate.min.css',
     '~/assets/css/global.css',
-    'three-dots/dist/three-dots.min.css'
+    'three-dots/dist/three-dots.min.css',
   ],
 
   // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins

+ 0 - 3
pages/_template/_.vue

@@ -1,3 +0,0 @@
-<template>
-  <div></div>
-</template>

+ 1 - 0
pages/_template/_mode.vue

@@ -0,0 +1 @@
+<template></template>

+ 0 - 195
pages/auth/index.vue

@@ -1,195 +0,0 @@
-<template>
-  <div class="auth-page" v-if="showBind">
-    <div class="form p-4">
-      <div class="form-item mb-4">
-        <input type="text" placeholder="手机号" v-model="formData.mobile" />
-      </div>
-      <div class="form-item mb-4 code">
-        <input
-          type="text"
-          placeholder="验证码"
-          class="code"
-          v-model="formData.verifyCode"
-        />
-        <span class="send" @click="onSend">{{ sendCodeBtnText }}</span>
-      </div>
-      <div class="submit" @click="onSubmit">登录</div>
-    </div>
-  </div>
-</template>
-
-<script>
-import { isMobile } from '@/utils/validator'
-export default {
-  data() {
-    return {
-      showBind: false,
-      sendStatus: 0,
-      formData: {
-        authUserId: '',
-        appId: '',
-        openId: '',
-        accessToken: '',
-        mobile: '',
-        verifyCode: '',
-      },
-      redirectPath: '',
-      code: '',
-    }
-  },
-  computed: {
-    sendCodeBtnText() {
-      return this.sendStatus === 0
-        ? '发送验证码'
-        : `再次发送${this.sendStatus}s`
-    },
-  },
-  mounted() {
-    this.initData()
-  },
-  beforeDestroy() {
-    this.$removeStorage(this.redirectPath, 'login_redicret')
-  },
-  methods: {
-    // 初始化数据
-    initData() {
-      // 获取链接参数
-      const { code, type, authUserId, appId } = this.$route.query
-      this.code = code
-      this.formData.appId = appId
-      this.formData.authUserId = parseInt(authUserId)
-      this.redirectPath = `/${authUserId}/${type}`
-      // 保存页面路由前缀
-      this.$store.commit('app/SET_ROUTE_PREFIX', this.redirectPath)
-      // 保存用户AppId
-      this.$store.commit('user/SET_AUTH_USER_ID', this.formData.authUserId)
-      // 尝试微信授权自动登录
-      this.autoLogin()
-    },
-
-    // 绑定并登录
-    async onSubmit() {
-      try {
-        const res = await this.$http.api.wechatLoginWithCode(this.formData)
-        this.loginSuccess(res)
-      } catch (error) {
-        console.log(error)
-      }
-    },
-
-    loginSuccess(res) {
-      this.$toast('登录成功')
-      this.$store.dispatch('user/login', res.data)
-      this.$setStorage(this.redirectPath, 'userInfo', res.data)
-      // 重定向
-      const login_redicret = this.$getStorage(
-        this.redirectPath,
-        'login_redicret'
-      )
-      if (login_redicret && login_redicret !== this.$route.path) {
-        this.$router.push(login_redicret)
-      } else {
-        this.$router.push(this.redirectPath)
-      }
-    },
-
-    // 发送验证码
-    async onSend() {
-      if (this.sendStatus > 0) return
-      // 验证手机号是否合法
-      if (!isMobile(this.formData.mobile)) {
-        this.$toast('请输入正确的手机号')
-        return
-      }
-      try {
-        // 发送验证码
-        const res = await this.$http.api.sendVerifyCode({
-          mobile: this.formData.mobile,
-          authUserId: this.formData.authUserId,
-          type: 1,
-        })
-        this.$toast('验证码已发送')
-        // 开启倒计时
-        this.countdown()
-      } catch (error) {
-        console.log(error)
-      }
-    },
-
-    // 短信倒计时
-    countdown() {
-      this.sendStatus = 30
-      this.timer = setInterval(() => {
-        if (this.sendStatus === 0) {
-          clearInterval(this.timer)
-          return
-        }
-        this.sendStatus--
-      }, 1000)
-    },
-
-    // 微信授权登录
-    async autoLogin() {
-      try {
-        const res = await this.$http.api.wechatLogin({
-          code: this.code,
-          appId: this.formData.appId,
-        })
-        this.loginSuccess(res)
-      } catch (error) {
-        // 未绑定微信号
-        if (error.code === -2) {
-          this.$toast('未绑定手机号')
-          this.showBind = true
-          this.formData.openId = error.data.openId
-          this.formData.accessToken = error.data.accessToken
-        } else {
-          this.$toast('登陆失败请重试')
-          // 其他错误跳转首页
-          setTimeout(() => {
-            this.$router.push(this.redirectPath)
-          }, 1000)
-        }
-      }
-    },
-  },
-}
-</script>
-
-<style scoped lang="scss">
-.auth-page {
-  .form {
-    .form-item {
-      position: relative;
-      border-bottom: 0.1vw solid #d8d8d8;
-      input {
-        display: block;
-        width: 100%;
-        font-size: 4.2vw;
-        line-height: 10vw;
-      }
-
-      .send {
-        position: absolute;
-        right: 2.4vw;
-        top: 50%;
-        transform: translateY(-50%);
-        font-size: 3.4vw;
-        @include themify($themes) {
-          color: themed('color');
-        }
-      }
-    }
-
-    .submit {
-      @include themify($themes) {
-        background: themed('color');
-      }
-      font-size: 3.2vw;
-      color: #fff;
-      text-align: center;
-      line-height: 10vw;
-    }
-  }
-}
-</style>

+ 3 - 1
pages/download/index.vue → pages/public/download/index.vue

@@ -23,7 +23,7 @@ export default {
       timer: null,
       time: 0,
       isRequest: false,
-      success: false
+      success: false,
     }
   },
   computed: {
@@ -39,6 +39,8 @@ export default {
   methods: {
     async init() {
       try {
+        const state = this.$route.query.state
+        if (!state) return
         // 获取参数
         const query = JSON.parse(decrypt(this.$route.query.state))
         this.query = query

+ 5 - 5
store/getters.js

@@ -11,12 +11,12 @@ export default {
   showFooter: (state) => state.app.showFooter,
   // 用户相关
   userInfo: (state) => state.user.userInfo,
-  authUserId: (state) => state.user.authUserId,
-  authId: (state) => state.user.authId,
-  accessToken: (state) => state.user.accessToken,
-  appId: (state) => state.user.appId,
+  authId: (state) => state.user.userInfo.authId,
+  accessToken: (state) => state.user.userInfo.accessToken,
+  clubUserId: (state) => state.user.userInfo.clubUserId,
   accountType: (state) => state.user.accountType,
-  clubUserId: (state) => state.user.clubUserId,
   // 供应商相关
   supplierInfo: (state) => state.supplier.supplierInfo,
+  authUserId: (state) => state.supplier.supplierInfo.authUserId,
+  appId: (state) => state.supplier.supplierInfo.appId,
 }

+ 5 - 0
store/supplier.js

@@ -1,11 +1,16 @@
 const state = () => ({
   supplierInfo: {},
+  accountType: '',
 })
 
 const mutations = {
   SET_SUPPLIER_INFO(state, supplierInfo) {
     state.supplierInfo = supplierInfo
   },
+  // 微信公众号状态
+  SET_ACCOUNT_TYPE(state, accountType) {
+    state.accountType = accountType
+  },
 }
 
 const actions = {}

+ 0 - 21
store/user.js

@@ -1,32 +1,11 @@
 const state = () => ({
-  authUserId: '',
   userInfo: {},
-  accessToken: '',
-  appId: '',
-  accountType: '',
-  clubUserId: '',
-  authId: '',
 })
 
 const mutations = {
   // 设置用户信息
   SET_USER_INFO(state, data) {
     state.userInfo = data
-    state.clubUserId = data.clubUserId
-    state.authId = data.authId
-    state.accessToken = data.accessToken
-  },
-  // 设置appId
-  SET_APPID(state, appId) {
-    state.appId = appId
-  },
-  // 设置供应商id
-  SET_AUTH_USER_ID(state, authUserId) {
-    state.authUserId = authUserId
-  },
-  // 微信公众号状态
-  SET_ACCOUNT_TYPE(state, accountType) {
-    state.accountType = accountType
   },
 }