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