123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- <template>
- <div :class="themeClass">
- <div class="layout" v-if="isMounted">
- <div class="header">
- <div class="navbar flex justify-between items-center">
- <div class="logo flex items-center" @click="backHome">
- <img
- src="~/assets/theme-images/ross/ross-logo-f.png"
- v-if="themeName === 'ross'"
- class="ross"
- />
- <img src="~/assets/theme-images/common/icon-logo.png" v-else />
- <span>认证通</span>
- </div>
- <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)">
- <span class="icon" :class="item.icon"></span>
- <span class="text">{{ item.name }}</span>
- </div>
- </template>
- </div>
- <div class="user-info">
- <template v-if="accessToken">
- <span v-text="userInfo.mobile"></span>
- <span class="underline logout" @click="logout">退出登录</span>
- </template>
- <template v-else>
- <div class="flex justify-center">
- <div
- class="login mx-3 rounded-sm border-white md:leading-6"
- @click="onLogin"
- >
- 登录
- </div>
- |
- <div
- class="register mx-3 rounded-sm border-white md:leading-6"
- @click="onRegister"
- >
- 注册
- </div>
- </div>
- </template>
- </div>
- <span class="collapse-icon" @click="drawer = true"></span>
- </div>
- </div>
- </div>
- <div class="content">
- <nuxt />
- </div>
- <div class="footer flex justify-center items-center">
- - 由采美网提供技术支持 -
- </div>
- <SimpleLogin :type="formType" @click="onLoginClick"></SimpleLogin>
- </div>
- <template v-if="!isPc">
- <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)">
- <span class="icon" :class="item.icon"></span>
- <span class="text">{{ item.name }}</span>
- </div>
- </template>
- </div>
- </el-drawer>
- </template>
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- import { isWeChat } from '~/utils/validator'
- import { toAuthorization } from '~/utils'
- export default {
- computed: {
- ...mapGetters([
- 'userInfo',
- 'accessToken',
- 'authUserId',
- 'appId',
- 'accountType',
- 'routePrefix',
- 'themeName',
- 'routePrefix',
- 'isPc',
- ]),
- themeClass() {
- return `theme-${this.themeName}`
- },
- },
- 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,
- list: [
- {
- id: 1,
- name: '授权申请',
- path: '/form/club-register',
- icon: 'icon-register',
- },
- {
- id: 2,
- name: '产品资料',
- path: '/database/article',
- icon: 'icon-doc',
- },
- {
- id: 3,
- name: '意见反馈',
- path: '/feedback',
- icon: 'icon-feedback',
- },
- ],
- }
- },
- mounted() {
- this.init()
- console.log(1)
- },
- beforeDestroy() {
- window.removeEventListener('resize', () => {})
- },
- methods: {
- toDetail(item) {
- this.drawer = false
- const hasLogin = this.$store.getters.accessToken
- // 保存登录重定向路由
- this.$setStorage(
- this.routePrefix,
- 'login_redicret',
- 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')
- return
- }
- if (item.id === 0) {
- const url = this.routePrefix + item.path
- this.$router.push(url)
- } else {
- const url = this.routePrefix + item.path
- this.$router.push(url)
- }
- },
- 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) {
- 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)
- }
- },
- 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()
- },
- // 回到首页
- backHome() {
- if (this.$route.path === this.routePrefix) return
- this.$router.replace(this.routePrefix)
- },
- // 响应页面宽度变化
- responseWidth() {
- this.$store.commit('app/SET_SCREEN', window.innerWidth)
- window.addEventListener('resize', (e) => {
- this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
- })
- },
- // 数据初始化刷新浏览器
- refreshCacheData() {
- this.$removeStorage(this.routePrefix, 'club_list_data')
- },
- },
- }
- </script>
- <style scoped lang="scss">
- // PC端
- @media screen and (min-width: 768px) {
- .layout {
- padding-top: 80px;
- user-select: none;
- .header {
- position: fixed;
- top: 0;
- left: 0;
- z-index: 999;
- width: 100%;
- height: 80px;
- box-sizing: border-box;
- background: linear-gradient(90deg, #101010 0%, #404040 100%);
- .navbar {
- width: 1200px;
- margin: 0 auto;
- height: 100%;
- }
- .logo {
- cursor: pointer;
- img {
- display: block;
- width: 44px;
- height: 44px;
- &.ross {
- width: 85px;
- height: 27px;
- margin-right: 15px;
- transform: translateY(-2px);
- }
- }
- span {
- font-size: 24px;
- color: #fff;
- }
- }
- .nav {
- .link {
- display: inline;
- margin-left: 32px;
- cursor: pointer;
- &:hover {
- .text {
- @include themify($themes) {
- color: themed('color');
- }
- }
- .icon {
- &.icon-register {
- background-image: url(~assets/theme-images/ross/pc-link-entry-register-active.png);
- }
- &.icon-doc {
- background-image: url(~assets/theme-images/ross/pc-link-entry-doc-active.png);
- }
- &.icon-feedback {
- background-image: url(~assets/theme-images/ross/pc-link-entry-feedback-active.png);
- }
- }
- }
- }
- .icon {
- width: 20px;
- height: 20px;
- display: inline-block;
- vertical-align: -4px;
- margin-right: 4px;
- background-size: 20px;
- background-repeat: no-repeat;
- background-position: center;
- &.icon-register {
- background-image: url(~assets/theme-images/ross/pc-link-entry-register.png);
- }
- &.icon-doc {
- background-image: url(~assets/theme-images/ross/pc-link-entry-doc.png);
- }
- &.icon-feedback {
- background-image: url(~assets/theme-images/ross/pc-link-entry-feedback.png);
- }
- }
- .text {
- font-size: 16px;
- color: #fff;
- }
- }
- .user-info {
- color: #fff;
- font-size: 16px;
- margin-left: 48px;
- .login,
- .register,
- .logout {
- cursor: pointer;
- &:hover {
- @include themify($themes) {
- color: themed('color');
- }
- }
- }
- }
- }
- .content {
- min-height: calc(100vh - 80px - 80px);
- background-color: #f7f7f7;
- overflow: hidden;
- }
- .footer {
- height: 80px;
- background-color: #2c3038;
- color: #fff;
- font-size: 14px;
- }
- }
- }
- // 移动端
- @media screen and (max-width: 768px) {
- .layout {
- padding-top: 12.8vw;
- .header {
- position: fixed;
- top: 0;
- left: 0;
- z-index: 999;
- width: 100%;
- padding: 0 4vw;
- height: 12.8vw;
- box-sizing: border-box;
- background: linear-gradient(90deg, #101010 0%, #404040 100%);
- .navbar {
- height: 100%;
- }
- .logo {
- img {
- display: block;
- width: 8vw;
- height: 8vw;
- &.ross {
- width: 12.2vw;
- height: 3.9vw;
- margin-right: 1.9vw;
- transform: translateY(-0.6vw);
- }
- }
- span {
- font-size: 4vw;
- color: #fff;
- }
- }
- .user-info {
- color: #fff;
- font-size: 3vw;
- .logout {
- margin: 0 1.6vw;
- }
- }
- .collapse-icon {
- display: block;
- width: 5.6vw;
- height: 5.6vw;
- background: url(~assets/theme-images/common/h5-icon-collapse.png)
- no-repeat center;
- background-size: 5.6vw;
- }
- }
- .content {
- min-height: calc(100vh - 12.8vw - 12.4vw);
- }
- .footer {
- height: 12.4vw;
- background-color: #2c3038;
- color: #fff;
- font-size: 3vw;
- }
- }
- .nav {
- width: 63vw;
- box-sizing: border-box;
- padding: 0 6.4vw;
- .link {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- border-bottom: 0.1vw solid #c2c2c2;
- padding-bottom: 3vw;
- padding-top: 6vw;
- .icon {
- width: 5.6vw;
- height: 5.6vw;
- vertical-align: -1.2vw;
- margin-right: 2.4vw;
- background-size: 5.6vw;
- background-repeat: no-repeat;
- background-position: center;
- &.icon-register {
- background-image: url(~assets/theme-images/ross/h5-link-entry-register-active.png);
- }
- &.icon-doc {
- background-image: url(~assets/theme-images/ross/h5-link-entry-doc-active.png);
- }
- &.icon-feedback {
- background-image: url(~assets/theme-images/ross/h5-link-entry-feedback-active.png);
- }
- }
- .text {
- font-size: 3.4vw;
- color: #282828;
- }
- }
- }
- }
- </style>
|