app.vue 7.2 KB

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