app.vue 7.7 KB

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