app-ross.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. <template>
  2. <div :class="themeClass" v-if="isMounted">
  3. <div class="layout" :style="{ paddingTop: showHeader ? '' : 0 }">
  4. <div class="header" v-show="showHeader">
  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. class="ross"
  10. />
  11. <span>认证通</span>
  12. </div>
  13. <div class="flex justify-center items-center">
  14. <div class="nav" v-if="isPc">
  15. <template v-for="item in list">
  16. <div class="link" :key="item.id" @click="onJumpTo(item)">
  17. <span class="icon" :class="item.icon"></span>
  18. <span class="text">{{ item.name }}</span>
  19. </div>
  20. </template>
  21. </div>
  22. <div class="user-info">
  23. <!-- <template v-if="accessToken">
  24. <span v-text="userInfo.mobile"></span>
  25. <span class="underline logout" @click="logout">退出登录</span>
  26. </template>
  27. <template v-else>
  28. <div class="flex justify-center">
  29. <div
  30. class="login mx-3 rounded-sm border-white md:leading-6"
  31. @click="onLogin"
  32. >
  33. 登录
  34. </div>
  35. |
  36. <div
  37. class="register mx-3 rounded-sm border-white md:leading-6"
  38. @click="onRegister"
  39. >
  40. 注册
  41. </div>
  42. </div>
  43. </template> -->
  44. <template v-if="accessToken">
  45. <div class="user-center">
  46. <span class="icon el-icon-user-solid"></span>
  47. <span class="icon el-icon-arrow-down"></span>
  48. <div class="drop-down">
  49. <ul class="nav">
  50. <li @click.stop="onUserCenter">个人中心</li>
  51. <li @click.stop="logout">退出登录</li>
  52. </ul>
  53. </div>
  54. </div>
  55. </template>
  56. <template v-else>
  57. <div class="login-btn" @click="onLogin">登录</div>
  58. </template>
  59. </div>
  60. <span class="collapse-icon" @click="drawer = true"></span>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="content">
  65. <nuxt />
  66. </div>
  67. <div class="footer flex justify-center items-center" v-show="showFooter">
  68. - {{ supplierInfo.shopName }} | 由采美网提供技术支持 -
  69. </div>
  70. <SimpleLogin :type="formType" @click="onLoginClick"></SimpleLogin>
  71. </div>
  72. <template v-if="!isPc">
  73. <el-drawer :visible.sync="drawer" size="63%">
  74. <div class="nav">
  75. <template v-for="item in list">
  76. <div class="link" :key="item.id" @click="onJumpTo(item)">
  77. <span class="icon" :class="item.icon"></span>
  78. <span class="text">{{ item.name }}</span>
  79. </div>
  80. </template>
  81. </div>
  82. </el-drawer>
  83. </template>
  84. </div>
  85. </template>
  86. <script>
  87. import { mapGetters } from 'vuex'
  88. import { EventBus } from '@/plugins/router'
  89. export default {
  90. computed: {
  91. ...mapGetters([
  92. 'userInfo',
  93. 'accessToken',
  94. 'authUserId',
  95. 'appId',
  96. 'routePrefix',
  97. 'themeName',
  98. 'isPc',
  99. 'showHeader',
  100. 'showFooter',
  101. 'supplierInfo',
  102. 'wxConfig',
  103. ]),
  104. themeClass() {
  105. return `theme-${this.themeName}`
  106. },
  107. },
  108. head() {
  109. return {
  110. meta: [
  111. {
  112. name: 'viewport',
  113. content:
  114. 'width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
  115. },
  116. ],
  117. }
  118. },
  119. data() {
  120. return {
  121. formType: 'login',
  122. drawer: false,
  123. isMounted: false,
  124. list: [
  125. // {
  126. // id: 4,
  127. // name: '挑战赛',
  128. // path: '/activity/challenge',
  129. // icon: 'icon-challenge',
  130. // auth: false,
  131. // },
  132. {
  133. id: 1,
  134. name: '授权申请',
  135. path: '/form/club-register',
  136. icon: 'icon-register',
  137. auth: false,
  138. },
  139. {
  140. id: 2,
  141. name: '云资料库',
  142. path: '/docs/0',
  143. icon: 'icon-doc',
  144. auth: false,
  145. },
  146. {
  147. id: 3,
  148. name: '意见反馈',
  149. path: '/feedback',
  150. icon: 'icon-feedback',
  151. auth: true,
  152. },
  153. ],
  154. }
  155. },
  156. mounted() {
  157. this.responseWidth()
  158. this.initPageData()
  159. this.initAppMessageShareData()
  160. EventBus.$on('afterEach', () => {
  161. this.initAppMessageShareData()
  162. })
  163. },
  164. beforeDestroy() {
  165. window.removeEventListener('resize', () => {})
  166. this.refreshCacheData()
  167. EventBus.$off('afterEach')
  168. },
  169. methods: {
  170. // 全局分享事件
  171. initAppMessageShareData() {
  172. let retryCount = 1
  173. // 判断是否为微信浏览器环境
  174. // if (!isWeChat()) return
  175. const whiteList = ['template-ross-activity-challenge']
  176. if (whiteList.indexOf(this.$route.name) > -1) return
  177. // 网站主机地址
  178. const HOST = process.env.LOCALHOSE
  179. this.$wxReady((wx) => {
  180. //需在用户可能点击分享按钮前就先调用
  181. wx.updateAppMessageShareData({
  182. title: '认证通', // 分享标题
  183. desc: '一款专业的正品认证软件系统', // 分享描述
  184. link: HOST + this.routePrefix, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  185. imgUrl: HOST + '/share-icon.png', // 分享图标
  186. fail: () => {
  187. if (retryCount === 0) return
  188. this.initAppMessageShareData()
  189. retryCount--
  190. },
  191. })
  192. })
  193. },
  194. // 跳转
  195. onJumpTo(item) {
  196. this.drawer = false
  197. const hasLogin = this.$store.getters.accessToken
  198. // 保存登录重定向路由
  199. this.$setStorage(
  200. this.routePrefix,
  201. 'login_redicret',
  202. this.routePrefix + item.path
  203. )
  204. if (item.auth && !hasLogin) {
  205. this.$toast({ message: '请先登录', duration: 1000 })
  206. this.formType = 'login'
  207. this.$store.commit('app/SHOW_LOGIN')
  208. return
  209. }
  210. const url = this.routePrefix + item.path
  211. this.$router.push(url)
  212. },
  213. // 点击登录
  214. onLoginClick(type) {
  215. this.formType = type
  216. },
  217. // 初始化数据页面公共数据
  218. async initPageData() {
  219. this.$store.commit('app/SET_PAGE_THEME', 'ross')
  220. // 获取用户信息
  221. let userInfo = this.$getStorage(this.routePrefix, 'userInfo')
  222. if (userInfo && userInfo.authUserId === this.authUserId) {
  223. this.$store.commit('user/SET_USER_INFO', userInfo)
  224. const res = await this.$http.api.checkTokenResult()
  225. this.$store.commit('user/SET_USER_INFO', res.data)
  226. }
  227. this.isMounted = true
  228. },
  229. // 校验公众号类型
  230. async checkAccountType() {
  231. try {
  232. // 1订阅号,2服务号
  233. if (!this.appId) return
  234. const res = await this.$http.api.checkAccountType({ appId: this.appId })
  235. this.$store.commit('supplier/SET_ACCOUNT_TYPE', res.data)
  236. } catch (error) {
  237. console.log(error)
  238. }
  239. },
  240. // 登录
  241. onLogin() {
  242. this.formType = 'login'
  243. this.$store.commit('app/SHOW_LOGIN')
  244. },
  245. // 注册
  246. onRegister() {
  247. this.formType = 'register'
  248. this.$store.commit('app/SHOW_LOGIN')
  249. },
  250. // 退出登录
  251. logout() {
  252. this.$store.dispatch('user/logout')
  253. this.$removeStorage(this.routePrefix, 'userInfo')
  254. this.backHome()
  255. },
  256. // 回到首页
  257. backHome() {
  258. // if (this.$route.path === this.routePrefix) return
  259. // this.$router.replace(this.routePrefix)
  260. window.location.href = window.location.origin + this.routePrefix
  261. },
  262. // 个人中心
  263. onUserCenter() {
  264. // const path = `${this.routePrefix}/center`
  265. window.location.href =
  266. window.location.origin + `${this.routePrefix}/center`
  267. },
  268. // 响应页面宽度变化
  269. responseWidth() {
  270. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  271. window.addEventListener('resize', (e) => {
  272. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  273. })
  274. },
  275. // 数据初始化刷新浏览器
  276. refreshCacheData() {
  277. this.$removeStorage(this.routePrefix, 'club_list_data')
  278. },
  279. },
  280. }
  281. </script>
  282. <style scoped lang="scss">
  283. @keyframes slide-down {
  284. 0% {
  285. top: 48px;
  286. z-index: 9;
  287. opacity: 0;
  288. }
  289. 100% {
  290. top: 32px;
  291. opacity: 1;
  292. }
  293. }
  294. // PC端
  295. @media screen and (min-width: 768px) {
  296. .layout {
  297. @include useTheme() {
  298. padding-top: 80px;
  299. user-select: none;
  300. .header {
  301. position: fixed;
  302. top: 0;
  303. left: 0;
  304. z-index: 999;
  305. width: 100%;
  306. height: 80px;
  307. box-sizing: border-box;
  308. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  309. .navbar {
  310. width: 1200px;
  311. margin: 0 auto;
  312. height: 100%;
  313. }
  314. .logo {
  315. cursor: pointer;
  316. img {
  317. display: block;
  318. width: 44px;
  319. height: 44px;
  320. &.ross {
  321. width: 85px;
  322. height: 27px;
  323. margin-right: 15px;
  324. transform: translateY(-2px);
  325. }
  326. }
  327. span {
  328. font-size: 24px;
  329. color: #fff;
  330. }
  331. }
  332. .nav {
  333. .link {
  334. display: inline;
  335. margin-left: 32px;
  336. cursor: pointer;
  337. &:hover {
  338. .text {
  339. color: fetch('color');
  340. }
  341. .icon {
  342. &.icon-register {
  343. background-image: url(~assets/theme-images/ross/pc-link-entry-register-active.png);
  344. }
  345. &.icon-doc {
  346. background-image: url(~assets/theme-images/ross/pc-link-entry-doc-active.png);
  347. }
  348. &.icon-feedback {
  349. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback-active.png);
  350. }
  351. &.icon-challenge {
  352. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge-active.png);
  353. }
  354. }
  355. }
  356. }
  357. .icon {
  358. width: 20px;
  359. height: 20px;
  360. display: inline-block;
  361. vertical-align: -4px;
  362. margin-right: 4px;
  363. background-size: 20px;
  364. background-repeat: no-repeat;
  365. background-position: center;
  366. &.icon-register {
  367. background-image: url(~assets/theme-images/ross/pc-link-entry-register.png);
  368. }
  369. &.icon-doc {
  370. background-image: url(~assets/theme-images/ross/pc-link-entry-doc.png);
  371. }
  372. &.icon-feedback {
  373. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback.png);
  374. }
  375. &.icon-challenge {
  376. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge.png);
  377. }
  378. }
  379. .text {
  380. font-size: 16px;
  381. color: #fff;
  382. }
  383. }
  384. .user-info {
  385. color: #fff;
  386. font-size: 16px;
  387. margin-left: 48px;
  388. .login-btn {
  389. width: 80px;
  390. height: 34px;
  391. color: #fff;
  392. background: rgba(255, 255, 255, 0.39);
  393. font-size: 14px;
  394. text-align: center;
  395. line-height: 34px;
  396. cursor: pointer;
  397. }
  398. .user-center {
  399. position: relative;
  400. .icon {
  401. width: 32px;
  402. height: 32px;
  403. text-align: center;
  404. line-height: 32px;
  405. &.el-icon-user-solid {
  406. font-size: 24px;
  407. cursor: pointer;
  408. }
  409. &.el-icon-arrow-down {
  410. font-size: 22px;
  411. transition: all 0.2s;
  412. }
  413. }
  414. &:hover {
  415. .drop-down {
  416. display: block;
  417. animation: slide-down 0.4s linear forwards;
  418. }
  419. .el-icon-arrow-down {
  420. transform: rotateZ(180deg);
  421. }
  422. }
  423. .drop-down {
  424. display: none;
  425. opacity: 0;
  426. // z-index: -1;
  427. right: 0;
  428. position: absolute;
  429. background: transparent;
  430. box-sizing: border-box;
  431. padding-top: 24px;
  432. .nav {
  433. width: 118px;
  434. padding: 8px 0;
  435. background: #fff;
  436. box-shadow: 0px 6px 16px rgba(40, 40, 40, 0.1);
  437. border-radius: 4px;
  438. li {
  439. font-size: 14px;
  440. color: #282828;
  441. text-align: center;
  442. line-height: 40px;
  443. transition: all 0.4s;
  444. cursor: pointer;
  445. &:hover {
  446. color: #f3920d;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .login,
  453. .register,
  454. .logout {
  455. cursor: pointer;
  456. &:hover {
  457. color: fetch('color');
  458. }
  459. }
  460. }
  461. }
  462. .content {
  463. min-height: calc(100vh - 80px - 80px);
  464. background-color: #f7f7f7;
  465. overflow: hidden;
  466. }
  467. .footer {
  468. height: 80px;
  469. background-color: #2c3038;
  470. color: #fff;
  471. font-size: 14px;
  472. }
  473. }
  474. }
  475. }
  476. // 移动端
  477. @media screen and (max-width: 768px) {
  478. .layout {
  479. @include useTheme() {
  480. padding-top: 12.8vw;
  481. .header {
  482. position: fixed;
  483. top: 0;
  484. left: 0;
  485. z-index: 999;
  486. width: 100%;
  487. padding: 0 4vw;
  488. height: 12.8vw;
  489. box-sizing: border-box;
  490. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  491. .navbar {
  492. height: 100%;
  493. }
  494. .logo {
  495. img {
  496. display: block;
  497. width: 8vw;
  498. height: 8vw;
  499. &.ross {
  500. width: 12.2vw;
  501. height: 3.9vw;
  502. margin-right: 1.9vw;
  503. transform: translateY(-0.6vw);
  504. }
  505. }
  506. span {
  507. font-size: 4vw;
  508. color: #fff;
  509. }
  510. }
  511. .user-info {
  512. color: #fff;
  513. font-size: 3vw;
  514. .logout {
  515. margin: 0 1.6vw;
  516. }
  517. .login-btn {
  518. width: 13.4vw;
  519. height: 6.4vw;
  520. color: #fff;
  521. background: rgba(255, 255, 255, 0.39);
  522. font-size: 3.4vw;
  523. text-align: center;
  524. line-height: 6.4vw;
  525. margin-right: 2.4vw;
  526. }
  527. .user-center {
  528. position: relative;
  529. .icon {
  530. width: 5.6vw;
  531. height: 5.6vw;
  532. text-align: center;
  533. line-height: 5.6vw;
  534. margin-right: 4vw;
  535. &.el-icon-user-solid {
  536. font-size: 24px;
  537. cursor: pointer;
  538. }
  539. &.el-icon-arrow-down {
  540. display: none;
  541. }
  542. }
  543. &:hover {
  544. .drop-down {
  545. display: block;
  546. animation: slide-down 0.4s linear forwards;
  547. }
  548. .el-icon-arrow-down {
  549. transform: rotateZ(180deg);
  550. }
  551. }
  552. .drop-down {
  553. display: none;
  554. opacity: 0;
  555. // z-index: -1;
  556. right: 0;
  557. position: absolute;
  558. background: transparent;
  559. box-sizing: border-box;
  560. padding-top: 1.2vw;
  561. .nav {
  562. width: 26vw;
  563. padding: 1vw 0;
  564. background: #fff;
  565. box-shadow: 0px 0.6vw 20vw rgba(40, 40, 40, 0.1);
  566. border-radius: 0.4vw;
  567. li {
  568. font-size: 3.4vw;
  569. color: #282828;
  570. text-align: center;
  571. line-height: 8.6vw;
  572. transition: all 0.4s;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. .collapse-icon {
  579. display: block;
  580. width: 5.6vw;
  581. height: 5.6vw;
  582. background: url(~assets/theme-images/common/h5-icon-collapse.png)
  583. no-repeat center;
  584. background-size: 5.6vw;
  585. }
  586. }
  587. .content {
  588. min-height: calc(100vh - 12.8vw - 12.4vw);
  589. }
  590. .footer {
  591. height: 12.4vw;
  592. background-color: #2c3038;
  593. color: #fff;
  594. font-size: 3vw;
  595. }
  596. }
  597. }
  598. .nav {
  599. width: 63vw;
  600. box-sizing: border-box;
  601. padding: 0 6.4vw;
  602. .link {
  603. display: flex;
  604. justify-content: flex-start;
  605. align-items: center;
  606. border-bottom: 0.1vw solid #c2c2c2;
  607. padding-bottom: 3vw;
  608. padding-top: 6vw;
  609. .icon {
  610. width: 5.6vw;
  611. height: 5.6vw;
  612. vertical-align: -1.2vw;
  613. margin-right: 2.4vw;
  614. background-size: 5.6vw;
  615. background-repeat: no-repeat;
  616. background-position: center;
  617. &.icon-register {
  618. background-image: url(~assets/theme-images/ross/h5-link-entry-register-active.png);
  619. }
  620. &.icon-doc {
  621. background-image: url(~assets/theme-images/ross/h5-link-entry-doc-active.png);
  622. }
  623. &.icon-feedback {
  624. background-image: url(~assets/theme-images/ross/h5-link-entry-feedback-active.png);
  625. }
  626. &.icon-challenge {
  627. background-image: url(~assets/theme-images/ross/h5-link-entry-challenge.png);
  628. }
  629. }
  630. .text {
  631. font-size: 3.4vw;
  632. color: #282828;
  633. }
  634. }
  635. }
  636. }
  637. </style>