123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <template>
- <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="https://static.caimei365.com/www/authentic/h5/icon-logo.png"
- />
- <span>认证通</span>
- </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="login pr-3 pl-3 border rounded-sm border-white leading-6"
- @click="onLogin"
- >
- 登录
- </div>
- </template>
- </div>
- </div>
- </div>
- <div class="content">
- <nuxt />
- </div>
- <div class="footer flex justify-center items-center">
- - 由采美网提供技术支持 -
- </div>
- <SimpleLogin></SimpleLogin>
- </div>
- </template>
- <script>
- import { getCookies } from '@/utils/auth'
- import { mapGetters } from 'vuex'
- import { isWeChat } from '~/utils/validator'
- import { toAuthorization } from '~/utils'
- export default {
- computed: {
- ...mapGetters([
- 'userInfo',
- 'type',
- 'accessToken',
- 'authUserId',
- 'appId',
- 'accountType',
- ]),
- },
- head() {
- return {
- link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
- }
- },
- data() {
- return {
- isMounted: false,
- }
- },
- mounted() {
- this.init()
- },
- beforeDestroy() {
- window.removeEventListener('resize', () => {})
- },
- methods: {
- init() {
- this.responseWidth()
- this.initPageData()
- },
- // 初始化数据页面公共数据
- initPageData() {
- const id = this.$route.params.template
- // 保存页面入口
- this.$store.commit('user/SET_TYPE', `${id}/app`)
- // 保存用户AppId
- this.$store.commit('user/SET_AUTHUSERID', id)
- // 获取用户信息
- const userInfo = getCookies('userInfo')
- if (userInfo && userInfo.authUserId === id) {
- this.$store.commit('user/SET_USERINFO', JSON.parse(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)
- if (res.data.appId) {
- this.checkAccountType(res.data.appId)
- }
- } catch (error) {
- console.log(error)
- } finally {
- this.isMounted = true
- }
- },
- // 校验公众号类型
- 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, type: this.type }
- return toAuthorization(this.appId, payload)
- }
- this.$store.commit('app/SHOW_LOGIN')
- },
- // 退出登录
- logout() {
- this.$store.dispatch('user/logout')
- },
- // 回到首页
- backHome() {
- const url = '/' + this.type
- if (this.$route.path === url) return
- this.$router.replace(url)
- },
- // 响应页面宽度变化
- responseWidth() {
- this.$store.commit('app/SET_SCREEN', window.innerWidth)
- window.addEventListener('resize', (e) => {
- this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
- })
- },
- },
- }
- </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;
- }
- span {
- font-size: 24px;
- color: #fff;
- }
- }
- .user-info {
- color: #fff;
- font-size: 16px;
- .login,
- .logout {
- cursor: pointer;
- }
- }
- }
- .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 2.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;
- }
- span {
- font-size: 4vw;
- color: #fff;
- }
- }
- .user-info {
- color: #fff;
- font-size: 3vw;
- }
- }
- .content {
- min-height: calc(100vh - 12.8vw - 12.4vw);
- }
- .footer {
- height: 12.4vw;
- background-color: #2c3038;
- color: #fff;
- font-size: 3vw;
- }
- }
- }
- </style>
|