app.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="layout" v-if="isMounted">
  3. <div class="header">
  4. <div class="navbar flex justify-between items-center">
  5. <div class="logo flex items-center" @click="backHome">
  6. <img
  7. src="https://static.caimei365.com/www/authentic/h5/icon-logo.png"
  8. />
  9. <span>认证通</span>
  10. </div>
  11. <div class="user-info">
  12. <template v-if="accessToken">
  13. <span v-text="userInfo.mobile"></span>
  14. <span class="underline logout" @click="logout">退出登录</span>
  15. </template>
  16. <template v-else>
  17. <div
  18. class="login pr-3 pl-3 border rounded-sm border-white leading-6"
  19. @click="onLogin"
  20. >
  21. 登录
  22. </div>
  23. </template>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="content">
  28. <nuxt />
  29. </div>
  30. <div class="footer flex justify-center items-center">
  31. - 由采美网提供技术支持 -
  32. </div>
  33. <SimpleLogin></SimpleLogin>
  34. </div>
  35. </template>
  36. <script>
  37. import { getCookies } from '@/utils/auth'
  38. import { mapGetters } from 'vuex'
  39. import { isWeChat } from '~/utils/validator'
  40. import { toAuthorization } from '~/utils'
  41. export default {
  42. computed: {
  43. ...mapGetters([
  44. 'userInfo',
  45. 'type',
  46. 'accessToken',
  47. 'authUserId',
  48. 'appId',
  49. 'accountType',
  50. ]),
  51. },
  52. head() {
  53. return {
  54. link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  55. }
  56. },
  57. data() {
  58. return {
  59. isMounted: false,
  60. }
  61. },
  62. mounted() {
  63. this.init()
  64. },
  65. beforeDestroy() {
  66. window.removeEventListener('resize', () => {})
  67. },
  68. methods: {
  69. init() {
  70. this.responseWidth()
  71. this.initPageData()
  72. },
  73. // 初始化数据页面公共数据
  74. initPageData() {
  75. const id = this.$route.params.template
  76. // 保存页面入口
  77. this.$store.commit('user/SET_TYPE', `${id}/app`)
  78. // 保存用户AppId
  79. this.$store.commit('user/SET_AUTHUSERID', id)
  80. // 获取用户信息
  81. const userInfo = getCookies('userInfo')
  82. if (userInfo && userInfo.authUserId === id) {
  83. this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
  84. }
  85. // 初始化供应商信息
  86. this.fetchSupplierInfo()
  87. },
  88. // 获取供应商信息
  89. async fetchSupplierInfo() {
  90. try {
  91. const res = await this.$http.api.fetchSupplierInfo({
  92. authUserId: this.authUserId,
  93. })
  94. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  95. this.$store.commit('user/SET_APPID', res.data.appId)
  96. if (res.data.appId) {
  97. this.checkAccountType(res.data.appId)
  98. }
  99. } catch (error) {
  100. console.log(error)
  101. } finally {
  102. this.isMounted = true
  103. }
  104. },
  105. // 校验公众号类型
  106. async checkAccountType(appId) {
  107. try {
  108. // 1订阅号,2服务号
  109. const res = await this.$http.api.checkAccountType({ appId })
  110. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  111. } catch (error) {
  112. console.log(error)
  113. }
  114. },
  115. onLogin() {
  116. // 在微信浏览器中使用微信授权登录
  117. if (isWeChat() && this.appId && this.accountType === 2) {
  118. const payload = { authUserId: this.authUserId, type: this.type }
  119. return toAuthorization(this.appId, payload)
  120. }
  121. this.$store.commit('app/SHOW_LOGIN')
  122. },
  123. // 退出登录
  124. logout() {
  125. this.$store.dispatch('user/logout')
  126. },
  127. // 回到首页
  128. backHome() {
  129. const url = '/' + this.type
  130. if (this.$route.path === url) return
  131. this.$router.replace(url)
  132. },
  133. // 响应页面宽度变化
  134. responseWidth() {
  135. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  136. window.addEventListener('resize', (e) => {
  137. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  138. })
  139. },
  140. },
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. // PC端
  145. @media screen and (min-width: 768px) {
  146. .layout {
  147. padding-top: 80px;
  148. user-select: none;
  149. .header {
  150. position: fixed;
  151. top: 0;
  152. left: 0;
  153. z-index: 999;
  154. width: 100%;
  155. height: 80px;
  156. box-sizing: border-box;
  157. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  158. .navbar {
  159. width: 1200px;
  160. margin: 0 auto;
  161. height: 100%;
  162. }
  163. .logo {
  164. cursor: pointer;
  165. img {
  166. display: block;
  167. width: 44px;
  168. height: 44px;
  169. }
  170. span {
  171. font-size: 24px;
  172. color: #fff;
  173. }
  174. }
  175. .user-info {
  176. color: #fff;
  177. font-size: 16px;
  178. .login,
  179. .logout {
  180. cursor: pointer;
  181. }
  182. }
  183. }
  184. .content {
  185. min-height: calc(100vh - 80px - 80px);
  186. background-color: #f7f7f7;
  187. overflow: hidden;
  188. }
  189. .footer {
  190. height: 80px;
  191. background-color: #2c3038;
  192. color: #fff;
  193. font-size: 14px;
  194. }
  195. }
  196. }
  197. // 移动端
  198. @media screen and (max-width: 768px) {
  199. .layout {
  200. padding-top: 12.8vw;
  201. .header {
  202. position: fixed;
  203. top: 0;
  204. left: 0;
  205. z-index: 999;
  206. width: 100%;
  207. padding: 0 2.4vw;
  208. height: 12.8vw;
  209. box-sizing: border-box;
  210. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  211. .navbar {
  212. height: 100%;
  213. }
  214. .logo {
  215. img {
  216. display: block;
  217. width: 8vw;
  218. height: 8vw;
  219. }
  220. span {
  221. font-size: 4vw;
  222. color: #fff;
  223. }
  224. }
  225. .user-info {
  226. color: #fff;
  227. font-size: 3vw;
  228. }
  229. }
  230. .content {
  231. min-height: calc(100vh - 12.8vw - 12.4vw);
  232. }
  233. .footer {
  234. height: 12.4vw;
  235. background-color: #2c3038;
  236. color: #fff;
  237. font-size: 3vw;
  238. }
  239. }
  240. }
  241. </style>