app.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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="$store.commit('app/SHOW_LOGIN')"
  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. <simple-login></simple-login>
  34. </div>
  35. </template>
  36. <script>
  37. import { getCookies } from '@/utils/auth'
  38. import keys from '@/keys.config'
  39. import { mapGetters } from 'vuex'
  40. export default {
  41. computed: {
  42. ...mapGetters(['userInfo', 'type', 'accessToken']),
  43. },
  44. data() {
  45. return {
  46. isMounted: false,
  47. }
  48. },
  49. mounted() {
  50. this.init()
  51. },
  52. beforeDestroy() {
  53. window.removeEventListener('resize', () => {})
  54. },
  55. methods: {
  56. init() {
  57. this.responseWidth()
  58. this.initPageData()
  59. },
  60. // 初始化数据页面公共数据
  61. initPageData() {
  62. const key = this.$route.path.split('/')[1]
  63. // 保存页面入口
  64. this.$store.commit('user/SET_TYPE', key)
  65. // 保存用户AppId
  66. this.$store.commit('user/SET_APPID', keys[key].appId)
  67. // 获取用户信息
  68. const userInfo = getCookies('userInfo')
  69. if (userInfo) {
  70. this.$store.commit('user/SET_USERINFO', JSON.parse(userInfo))
  71. }
  72. // 初始化供应商信息
  73. this.fetchSupplierInfo()
  74. },
  75. // 获取供应商信息
  76. async fetchSupplierInfo() {
  77. const appId = this.$store.getters.appId
  78. try {
  79. const res = await this.$http.api.fetchSupplierInfo({ appId })
  80. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  81. } catch (error) {
  82. console.log(error)
  83. } finally {
  84. this.isMounted = true
  85. }
  86. },
  87. // 退出登录
  88. logout() {
  89. this.$store.dispatch('user/logout')
  90. },
  91. // 回到首页
  92. backHome() {
  93. const url = '/' + this.type
  94. if (this.$route.path === url) return
  95. this.$router.replace(url)
  96. },
  97. // 响应页面宽度变化
  98. responseWidth() {
  99. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  100. window.addEventListener('resize', (e) => {
  101. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  102. })
  103. },
  104. },
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. // PC端
  109. @media screen and (min-width: 768px) {
  110. .layout {
  111. padding-top: 80px;
  112. user-select: none;
  113. .header {
  114. position: fixed;
  115. top: 0;
  116. left: 0;
  117. z-index: 999;
  118. width: 100%;
  119. height: 80px;
  120. box-sizing: border-box;
  121. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  122. .navbar {
  123. width: 1200px;
  124. margin: 0 auto;
  125. height: 100%;
  126. }
  127. .logo {
  128. cursor: pointer;
  129. img {
  130. display: block;
  131. width: 44px;
  132. height: 44px;
  133. }
  134. span {
  135. font-size: 24px;
  136. color: #fff;
  137. }
  138. }
  139. .user-info {
  140. color: #fff;
  141. font-size: 16px;
  142. .login,
  143. .logout {
  144. cursor: pointer;
  145. }
  146. }
  147. }
  148. .content {
  149. min-height: calc(100vh - 80px - 80px);
  150. background-color: #f7f7f7;
  151. overflow: hidden;
  152. }
  153. .footer {
  154. height: 80px;
  155. background-color: #2c3038;
  156. color: #fff;
  157. font-size: 14px;
  158. }
  159. }
  160. }
  161. // 移动端
  162. @media screen and (max-width: 768px) {
  163. .layout {
  164. padding-top: 12.8vw;
  165. .header {
  166. position: fixed;
  167. top: 0;
  168. left: 0;
  169. z-index: 999;
  170. width: 100%;
  171. padding: 0 2.4vw;
  172. height: 12.8vw;
  173. box-sizing: border-box;
  174. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  175. .navbar {
  176. height: 100%;
  177. }
  178. .logo {
  179. img {
  180. display: block;
  181. width: 8vw;
  182. height: 8vw;
  183. }
  184. span {
  185. font-size: 4vw;
  186. color: #fff;
  187. }
  188. }
  189. .user-info {
  190. color: #fff;
  191. font-size: 3vw;
  192. }
  193. }
  194. .content {
  195. min-height: calc(100vh - 12.8vw - 12.4vw);
  196. }
  197. .footer {
  198. height: 12.4vw;
  199. background-color: #2c3038;
  200. color: #fff;
  201. font-size: 3vw;
  202. }
  203. }
  204. }
  205. </style>