app-ross.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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="flex justify-center items-center">
  20. <div class="nav" v-if="isPc">
  21. <template v-for="item in list">
  22. <div class="link" :key="item.id" @click="toDetail(item)">
  23. <span class="icon" :class="item.icon"></span>
  24. <span class="text">{{ item.name }}</span>
  25. </div>
  26. </template>
  27. </div>
  28. <div class="user-info">
  29. <template v-if="accessToken">
  30. <span v-text="userInfo.mobile"></span>
  31. <span class="underline logout" @click="logout">退出登录</span>
  32. </template>
  33. <template v-else>
  34. <div class="flex justify-center">
  35. <div
  36. class="login mx-3 rounded-sm border-white md:leading-6"
  37. @click="onLogin"
  38. >
  39. 登录
  40. </div>
  41. |
  42. <div
  43. class="register mx-3 rounded-sm border-white md:leading-6"
  44. @click="onRegister"
  45. >
  46. 注册
  47. </div>
  48. </div>
  49. </template>
  50. </div>
  51. <span class="collapse-icon" @click="drawer = true"></span>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="content">
  56. <nuxt />
  57. </div>
  58. <div class="footer flex justify-center items-center" v-show="showFooter">
  59. - {{ supplierInfo.shopName }} | 由采美网提供技术支持 -
  60. </div>
  61. <SimpleLogin :type="formType" @click="onLoginClick"></SimpleLogin>
  62. </div>
  63. <template v-if="!isPc">
  64. <el-drawer :visible.sync="drawer" size="63%">
  65. <div class="nav">
  66. <template v-for="item in list">
  67. <div class="link" :key="item.id" @click="toDetail(item)">
  68. <span class="icon" :class="item.icon"></span>
  69. <span class="text">{{ item.name }}</span>
  70. </div>
  71. </template>
  72. </div>
  73. </el-drawer>
  74. </template>
  75. </div>
  76. </template>
  77. <script>
  78. import { mapGetters } from 'vuex'
  79. import { isWeChat } from '~/utils/validator'
  80. import { toAuthorization } from '~/utils'
  81. export default {
  82. computed: {
  83. ...mapGetters([
  84. 'userInfo',
  85. 'accessToken',
  86. 'authUserId',
  87. 'appId',
  88. 'accountType',
  89. 'routePrefix',
  90. 'themeName',
  91. 'isPc',
  92. 'showHeader',
  93. 'showFooter',
  94. 'supplierInfo',
  95. ]),
  96. themeClass() {
  97. return `theme-${this.themeName}`
  98. },
  99. },
  100. head() {
  101. return {
  102. meta: [
  103. {
  104. name: 'viewport',
  105. content:
  106. 'width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
  107. },
  108. ],
  109. }
  110. },
  111. data() {
  112. return {
  113. isMounted: false,
  114. formType: 'login',
  115. drawer: false,
  116. list: [
  117. {
  118. id: 1,
  119. name: '授权申请',
  120. path: '/form/club-register',
  121. icon: 'icon-register',
  122. },
  123. {
  124. id: 2,
  125. name: '产品资料',
  126. path: '/docs/0',
  127. icon: 'icon-doc',
  128. },
  129. {
  130. id: 3,
  131. name: '意见反馈',
  132. path: '/feedback',
  133. icon: 'icon-feedback',
  134. },
  135. ],
  136. }
  137. },
  138. mounted() {
  139. this.init()
  140. console.log(1)
  141. },
  142. beforeDestroy() {
  143. window.removeEventListener('resize', () => {})
  144. },
  145. methods: {
  146. toDetail(item) {
  147. this.drawer = false
  148. const hasLogin = this.$store.getters.accessToken
  149. // 保存登录重定向路由
  150. this.$setStorage(
  151. this.routePrefix,
  152. 'login_redicret',
  153. this.routePrefix + item.path
  154. )
  155. if (item.id > 2 && !hasLogin) {
  156. // 在微信浏览器中使用微信授权登录
  157. if (isWeChat() && this.appId && this.accountType === 2) {
  158. const payload = {
  159. authUserId: this.authUserId,
  160. routePrefix: this.routePrefix,
  161. }
  162. return toAuthorization(this.appId, payload)
  163. }
  164. this.$toast({ message: '请先登录', duration: 1000 })
  165. this.formType = 'login'
  166. this.$store.commit('app/SHOW_LOGIN')
  167. return
  168. }
  169. if (item.id === 0) {
  170. const url = this.routePrefix + item.path
  171. this.$router.push(url)
  172. } else {
  173. const url = this.routePrefix + item.path
  174. this.$router.push(url)
  175. }
  176. },
  177. onLoginClick(type) {
  178. this.formType = type
  179. },
  180. init() {
  181. this.responseWidth()
  182. this.initPageData()
  183. },
  184. // 初始化数据页面公共数据
  185. initPageData() {
  186. // 获取供应商id
  187. const authUserId = parseInt(this.$route.params.template)
  188. const routePrefix = `/${authUserId}/ross`
  189. // 保存页面路由前缀
  190. this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
  191. // 保存用户AppId
  192. this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
  193. // 设置页面主题12
  194. // if (authUserId === parseInt(12)) {
  195. // this.$store.commit('app/SET_PAGE_THEME', 'ross')
  196. // }
  197. this.$store.commit('app/SET_PAGE_THEME', 'ross')
  198. // 获取用户信息
  199. let userInfo = this.$getStorage(routePrefix, 'userInfo')
  200. if (userInfo && userInfo.authUserId === authUserId) {
  201. this.$store.commit('user/SET_USER_INFO', userInfo)
  202. }
  203. // 初始化供应商信息
  204. this.fetchSupplierInfo()
  205. },
  206. // 获取供应商信息
  207. async fetchSupplierInfo() {
  208. try {
  209. const res = await this.$http.api.fetchSupplierInfo({
  210. authUserId: this.authUserId,
  211. })
  212. this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
  213. this.$store.commit('user/SET_APPID', res.data.appId)
  214. // 如果appId存在
  215. if (res.data.appId) {
  216. this.checkAccountType(res.data.appId)
  217. }
  218. } catch (error) {
  219. console.log(error)
  220. } finally {
  221. this.isMounted = true
  222. // 清除缓存
  223. this.refreshCacheData()
  224. }
  225. },
  226. // 校验公众号类型
  227. async checkAccountType(appId) {
  228. try {
  229. // 1订阅号,2服务号
  230. const res = await this.$http.api.checkAccountType({ appId })
  231. this.$store.commit('user/SET_ACCOUNT_TYPE', res.data)
  232. } catch (error) {
  233. console.log(error)
  234. }
  235. },
  236. onLogin() {
  237. // 在微信浏览器中使用微信授权登录
  238. if (isWeChat() && this.appId && this.accountType === 2) {
  239. const payload = {
  240. authUserId: this.authUserId,
  241. routePrefix: this.routePrefix,
  242. }
  243. return toAuthorization(this.appId, payload)
  244. }
  245. this.formType = 'login'
  246. this.$store.commit('app/SHOW_LOGIN')
  247. },
  248. onRegister() {
  249. this.formType = 'register'
  250. console.log(this.formType)
  251. this.$store.commit('app/SHOW_LOGIN')
  252. },
  253. // 退出登录
  254. logout() {
  255. this.$store.dispatch('user/logout')
  256. console.log(this.routePrefix)
  257. this.$removeStorage(this.routePrefix, 'userInfo')
  258. this.backHome()
  259. },
  260. // 回到首页
  261. backHome() {
  262. if (this.$route.path === this.routePrefix) return
  263. this.$router.replace(this.routePrefix)
  264. },
  265. // 响应页面宽度变化
  266. responseWidth() {
  267. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  268. window.addEventListener('resize', (e) => {
  269. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  270. })
  271. },
  272. // 数据初始化刷新浏览器
  273. refreshCacheData() {
  274. this.$removeStorage(this.routePrefix, 'club_list_data')
  275. },
  276. },
  277. }
  278. </script>
  279. <style scoped lang="scss">
  280. // PC端
  281. @media screen and (min-width: 768px) {
  282. .layout {
  283. padding-top: 80px;
  284. user-select: none;
  285. .header {
  286. position: fixed;
  287. top: 0;
  288. left: 0;
  289. z-index: 999;
  290. width: 100%;
  291. height: 80px;
  292. box-sizing: border-box;
  293. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  294. .navbar {
  295. width: 1200px;
  296. margin: 0 auto;
  297. height: 100%;
  298. }
  299. .logo {
  300. cursor: pointer;
  301. img {
  302. display: block;
  303. width: 44px;
  304. height: 44px;
  305. &.ross {
  306. width: 85px;
  307. height: 27px;
  308. margin-right: 15px;
  309. transform: translateY(-2px);
  310. }
  311. }
  312. span {
  313. font-size: 24px;
  314. color: #fff;
  315. }
  316. }
  317. .nav {
  318. .link {
  319. display: inline;
  320. margin-left: 32px;
  321. cursor: pointer;
  322. &:hover {
  323. .text {
  324. @include themify($themes) {
  325. color: themed('color');
  326. }
  327. }
  328. .icon {
  329. &.icon-register {
  330. background-image: url(~assets/theme-images/ross/pc-link-entry-register-active.png);
  331. }
  332. &.icon-doc {
  333. background-image: url(~assets/theme-images/ross/pc-link-entry-doc-active.png);
  334. }
  335. &.icon-feedback {
  336. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback-active.png);
  337. }
  338. }
  339. }
  340. }
  341. .icon {
  342. width: 20px;
  343. height: 20px;
  344. display: inline-block;
  345. vertical-align: -4px;
  346. margin-right: 4px;
  347. background-size: 20px;
  348. background-repeat: no-repeat;
  349. background-position: center;
  350. &.icon-register {
  351. background-image: url(~assets/theme-images/ross/pc-link-entry-register.png);
  352. }
  353. &.icon-doc {
  354. background-image: url(~assets/theme-images/ross/pc-link-entry-doc.png);
  355. }
  356. &.icon-feedback {
  357. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback.png);
  358. }
  359. }
  360. .text {
  361. font-size: 16px;
  362. color: #fff;
  363. }
  364. }
  365. .user-info {
  366. color: #fff;
  367. font-size: 16px;
  368. margin-left: 48px;
  369. .login,
  370. .register,
  371. .logout {
  372. cursor: pointer;
  373. &:hover {
  374. @include themify($themes) {
  375. color: themed('color');
  376. }
  377. }
  378. }
  379. }
  380. }
  381. .content {
  382. min-height: calc(100vh - 80px - 80px);
  383. background-color: #f7f7f7;
  384. overflow: hidden;
  385. }
  386. .footer {
  387. height: 80px;
  388. background-color: #2c3038;
  389. color: #fff;
  390. font-size: 14px;
  391. }
  392. }
  393. }
  394. // 移动端
  395. @media screen and (max-width: 768px) {
  396. .layout {
  397. padding-top: 12.8vw;
  398. .header {
  399. position: fixed;
  400. top: 0;
  401. left: 0;
  402. z-index: 999;
  403. width: 100%;
  404. padding: 0 4vw;
  405. height: 12.8vw;
  406. box-sizing: border-box;
  407. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  408. .navbar {
  409. height: 100%;
  410. }
  411. .logo {
  412. img {
  413. display: block;
  414. width: 8vw;
  415. height: 8vw;
  416. &.ross {
  417. width: 12.2vw;
  418. height: 3.9vw;
  419. margin-right: 1.9vw;
  420. transform: translateY(-0.6vw);
  421. }
  422. }
  423. span {
  424. font-size: 4vw;
  425. color: #fff;
  426. }
  427. }
  428. .user-info {
  429. color: #fff;
  430. font-size: 3vw;
  431. .logout {
  432. margin: 0 1.6vw;
  433. }
  434. }
  435. .collapse-icon {
  436. display: block;
  437. width: 5.6vw;
  438. height: 5.6vw;
  439. background: url(~assets/theme-images/common/h5-icon-collapse.png)
  440. no-repeat center;
  441. background-size: 5.6vw;
  442. }
  443. }
  444. .content {
  445. min-height: calc(100vh - 12.8vw - 12.4vw);
  446. }
  447. .footer {
  448. height: 12.4vw;
  449. background-color: #2c3038;
  450. color: #fff;
  451. font-size: 3vw;
  452. }
  453. }
  454. .nav {
  455. width: 63vw;
  456. box-sizing: border-box;
  457. padding: 0 6.4vw;
  458. .link {
  459. display: flex;
  460. justify-content: flex-start;
  461. align-items: center;
  462. border-bottom: 0.1vw solid #c2c2c2;
  463. padding-bottom: 3vw;
  464. padding-top: 6vw;
  465. .icon {
  466. width: 5.6vw;
  467. height: 5.6vw;
  468. vertical-align: -1.2vw;
  469. margin-right: 2.4vw;
  470. background-size: 5.6vw;
  471. background-repeat: no-repeat;
  472. background-position: center;
  473. &.icon-register {
  474. background-image: url(~assets/theme-images/ross/h5-link-entry-register-active.png);
  475. }
  476. &.icon-doc {
  477. background-image: url(~assets/theme-images/ross/h5-link-entry-doc-active.png);
  478. }
  479. &.icon-feedback {
  480. background-image: url(~assets/theme-images/ross/h5-link-entry-feedback-active.png);
  481. }
  482. }
  483. .text {
  484. font-size: 3.4vw;
  485. color: #282828;
  486. }
  487. }
  488. }
  489. }
  490. </style>