app.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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" @click="onLoginClick"></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. onLoginClick(type) {
  86. this.formType = type
  87. },
  88. init() {
  89. this.responseWidth()
  90. this.initPageData()
  91. },
  92. // 初始化数据页面公共数据
  93. initPageData() {
  94. // 获取供应商id
  95. const authUserId = parseInt(this.$route.params.template)
  96. const routePrefix = `/${authUserId}/app`
  97. // 保存页面路由前缀
  98. this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
  99. // 保存用户AppId
  100. this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
  101. // 设置页面主题
  102. if (authUserId === parseInt(12)) {
  103. this.$store.commit('app/SET_PAGE_THEME', 'ross')
  104. }
  105. // 获取用户信息
  106. let userInfo = this.$getStorage(routePrefix, 'userInfo')
  107. if (userInfo && userInfo.authUserId === authUserId) {
  108. this.$store.commit('user/SET_USER_INFO', userInfo)
  109. }
  110. // 初始化供应商信息
  111. this.fetchSupplierInfo()
  112. },
  113. // 获取供应商信息
  114. async fetchSupplierInfo() {
  115. try {
  116. const res = await this.$http.api.fetchSupplierInfo({
  117. authUserId: this.authUserId,
  118. })
  119. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  120. this.$store.commit('user/SET_APPID', res.data.appId)
  121. // 如果appId存在
  122. if (res.data.appId) {
  123. this.checkAccountType(res.data.appId)
  124. }
  125. } catch (error) {
  126. console.log(error)
  127. } finally {
  128. this.isMounted = true
  129. // 清除缓存
  130. this.refreshCacheData()
  131. }
  132. },
  133. // 校验公众号类型
  134. async checkAccountType(appId) {
  135. try {
  136. // 1订阅号,2服务号
  137. const res = await this.$http.api.checkAccountType({ appId })
  138. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  139. } catch (error) {
  140. console.log(error)
  141. }
  142. },
  143. onLogin() {
  144. // 在微信浏览器中使用微信授权登录
  145. if (isWeChat() && this.appId && this.accountType === 2) {
  146. const payload = {
  147. authUserId: this.authUserId,
  148. routePrefix: this.routePrefix,
  149. }
  150. return toAuthorization(this.appId, payload)
  151. }
  152. this.formType = 'login'
  153. this.$store.commit('app/SHOW_LOGIN')
  154. },
  155. onRegister() {
  156. this.formType = 'register'
  157. console.log(this.formType)
  158. this.$store.commit('app/SHOW_LOGIN')
  159. },
  160. // 退出登录
  161. logout() {
  162. this.$store.dispatch('user/logout')
  163. console.log(this.routePrefix)
  164. this.$removeStorage(this.routePrefix, 'userInfo')
  165. this.backHome()
  166. },
  167. // 回到首页
  168. backHome() {
  169. if (this.$route.path === this.routePrefix) return
  170. this.$router.replace(this.routePrefix)
  171. },
  172. // 响应页面宽度变化
  173. responseWidth() {
  174. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  175. window.addEventListener('resize', (e) => {
  176. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  177. })
  178. },
  179. // 数据初始化刷新浏览器
  180. refreshCacheData() {
  181. this.$removeStorage(this.routePrefix, 'club_list_data')
  182. },
  183. },
  184. }
  185. </script>
  186. <style scoped lang="scss">
  187. // PC端
  188. @media screen and (min-width: 768px) {
  189. .layout {
  190. padding-top: 80px;
  191. user-select: none;
  192. .header {
  193. position: fixed;
  194. top: 0;
  195. left: 0;
  196. z-index: 999;
  197. width: 100%;
  198. height: 80px;
  199. box-sizing: border-box;
  200. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  201. .navbar {
  202. width: 1200px;
  203. margin: 0 auto;
  204. height: 100%;
  205. }
  206. .logo {
  207. cursor: pointer;
  208. img {
  209. display: block;
  210. width: 44px;
  211. height: 44px;
  212. }
  213. span {
  214. font-size: 24px;
  215. color: #fff;
  216. }
  217. }
  218. .user-info {
  219. color: #fff;
  220. font-size: 16px;
  221. .login,
  222. .register,
  223. .logout {
  224. cursor: pointer;
  225. &:hover {
  226. @include themify($themes) {
  227. color: themed('color');
  228. }
  229. }
  230. }
  231. }
  232. }
  233. .content {
  234. min-height: calc(100vh - 80px - 80px);
  235. background-color: #f7f7f7;
  236. overflow: hidden;
  237. }
  238. .footer {
  239. height: 80px;
  240. background-color: #2c3038;
  241. color: #fff;
  242. font-size: 14px;
  243. }
  244. }
  245. }
  246. // 移动端
  247. @media screen and (max-width: 768px) {
  248. .layout {
  249. padding-top: 12.8vw;
  250. .header {
  251. position: fixed;
  252. top: 0;
  253. left: 0;
  254. z-index: 999;
  255. width: 100%;
  256. padding: 0 2.4vw;
  257. height: 12.8vw;
  258. box-sizing: border-box;
  259. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  260. .navbar {
  261. height: 100%;
  262. }
  263. .logo {
  264. img {
  265. display: block;
  266. width: 8vw;
  267. height: 8vw;
  268. }
  269. span {
  270. font-size: 4vw;
  271. color: #fff;
  272. }
  273. }
  274. .user-info {
  275. color: #fff;
  276. font-size: 3vw;
  277. }
  278. }
  279. .content {
  280. min-height: calc(100vh - 12.8vw - 12.4vw);
  281. }
  282. .footer {
  283. height: 12.4vw;
  284. background-color: #2c3038;
  285. color: #fff;
  286. font-size: 3vw;
  287. }
  288. }
  289. }
  290. </style>