app.vue 7.9 KB

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