app.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. localStorage.removeItem('zp-locations')
  68. },
  69. methods: {
  70. init() {
  71. this.responseWidth()
  72. this.initPageData()
  73. },
  74. // 初始化数据页面公共数据
  75. initPageData() {
  76. const id = parseInt(this.$route.params.template)
  77. // 保存页面入口
  78. this.$store.commit('user/SET_TYPE', `${id}/app`)
  79. // 保存用户AppId
  80. this.$store.commit('user/SET_AUTHUSERID', id)
  81. // 获取用户信息
  82. let userInfo = getCookies('userInfo')
  83. if (userInfo) {
  84. userInfo = JSON.parse(userInfo)
  85. if (userInfo.authUserId === id) {
  86. this.$store.commit('user/SET_USERINFO', userInfo)
  87. }
  88. }
  89. // 初始化供应商信息
  90. this.fetchSupplierInfo()
  91. },
  92. // 获取供应商信息
  93. async fetchSupplierInfo() {
  94. try {
  95. const res = await this.$http.api.fetchSupplierInfo({
  96. authUserId: this.authUserId,
  97. })
  98. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  99. this.$store.commit('user/SET_APPID', res.data.appId)
  100. if (res.data.appId) {
  101. this.checkAccountType(res.data.appId)
  102. }
  103. } catch (error) {
  104. console.log(error)
  105. } finally {
  106. this.isMounted = true
  107. }
  108. },
  109. // 校验公众号类型
  110. async checkAccountType(appId) {
  111. try {
  112. // 1订阅号,2服务号
  113. const res = await this.$http.api.checkAccountType({ appId })
  114. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  115. } catch (error) {
  116. console.log(error)
  117. }
  118. },
  119. onLogin() {
  120. // 在微信浏览器中使用微信授权登录
  121. if (isWeChat() && this.appId && this.accountType === 2) {
  122. const payload = { authUserId: this.authUserId, type: this.type }
  123. return toAuthorization(this.appId, payload)
  124. }
  125. this.$store.commit('app/SHOW_LOGIN')
  126. },
  127. // 退出登录
  128. logout() {
  129. this.$store.dispatch('user/logout')
  130. },
  131. // 回到首页
  132. backHome() {
  133. const url = '/' + this.type
  134. if (this.$route.path === url) return
  135. this.$router.replace(url)
  136. },
  137. // 响应页面宽度变化
  138. responseWidth() {
  139. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  140. window.addEventListener('resize', (e) => {
  141. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  142. })
  143. },
  144. },
  145. }
  146. </script>
  147. <style scoped lang="scss">
  148. // PC端
  149. @media screen and (min-width: 768px) {
  150. .layout {
  151. padding-top: 80px;
  152. user-select: none;
  153. .header {
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. z-index: 999;
  158. width: 100%;
  159. height: 80px;
  160. box-sizing: border-box;
  161. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  162. .navbar {
  163. width: 1200px;
  164. margin: 0 auto;
  165. height: 100%;
  166. }
  167. .logo {
  168. cursor: pointer;
  169. img {
  170. display: block;
  171. width: 44px;
  172. height: 44px;
  173. }
  174. span {
  175. font-size: 24px;
  176. color: #fff;
  177. }
  178. }
  179. .user-info {
  180. color: #fff;
  181. font-size: 16px;
  182. .login,
  183. .logout {
  184. cursor: pointer;
  185. }
  186. }
  187. }
  188. .content {
  189. min-height: calc(100vh - 80px - 80px);
  190. background-color: #f7f7f7;
  191. overflow: hidden;
  192. }
  193. .footer {
  194. height: 80px;
  195. background-color: #2c3038;
  196. color: #fff;
  197. font-size: 14px;
  198. }
  199. }
  200. }
  201. // 移动端
  202. @media screen and (max-width: 768px) {
  203. .layout {
  204. padding-top: 12.8vw;
  205. .header {
  206. position: fixed;
  207. top: 0;
  208. left: 0;
  209. z-index: 999;
  210. width: 100%;
  211. padding: 0 2.4vw;
  212. height: 12.8vw;
  213. box-sizing: border-box;
  214. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  215. .navbar {
  216. height: 100%;
  217. }
  218. .logo {
  219. img {
  220. display: block;
  221. width: 8vw;
  222. height: 8vw;
  223. }
  224. span {
  225. font-size: 4vw;
  226. color: #fff;
  227. }
  228. }
  229. .user-info {
  230. color: #fff;
  231. font-size: 3vw;
  232. }
  233. }
  234. .content {
  235. min-height: calc(100vh - 12.8vw - 12.4vw);
  236. }
  237. .footer {
  238. height: 12.4vw;
  239. background-color: #2c3038;
  240. color: #fff;
  241. font-size: 3vw;
  242. }
  243. }
  244. }
  245. </style>