app.vue 5.3 KB

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