app.vue 7.9 KB

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