app.vue 7.8 KB

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