app-ross.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. padding-top: 80px;
  298. user-select: none;
  299. .header {
  300. position: fixed;
  301. top: 0;
  302. left: 0;
  303. z-index: 999;
  304. width: 100%;
  305. height: 80px;
  306. box-sizing: border-box;
  307. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  308. .navbar {
  309. width: 1200px;
  310. margin: 0 auto;
  311. height: 100%;
  312. }
  313. .logo {
  314. cursor: pointer;
  315. img {
  316. display: block;
  317. width: 44px;
  318. height: 44px;
  319. &.ross {
  320. width: 85px;
  321. height: 27px;
  322. margin-right: 15px;
  323. transform: translateY(-2px);
  324. }
  325. }
  326. span {
  327. font-size: 24px;
  328. color: #fff;
  329. }
  330. }
  331. .nav {
  332. .link {
  333. display: inline;
  334. margin-left: 32px;
  335. cursor: pointer;
  336. &:hover {
  337. .text {
  338. @include themify($themes) {
  339. color: themed('color');
  340. }
  341. }
  342. .icon {
  343. &.icon-register {
  344. background-image: url(~assets/theme-images/ross/pc-link-entry-register-active.png);
  345. }
  346. &.icon-doc {
  347. background-image: url(~assets/theme-images/ross/pc-link-entry-doc-active.png);
  348. }
  349. &.icon-feedback {
  350. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback-active.png);
  351. }
  352. &.icon-challenge {
  353. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge-active.png);
  354. }
  355. }
  356. }
  357. }
  358. .icon {
  359. width: 20px;
  360. height: 20px;
  361. display: inline-block;
  362. vertical-align: -4px;
  363. margin-right: 4px;
  364. background-size: 20px;
  365. background-repeat: no-repeat;
  366. background-position: center;
  367. &.icon-register {
  368. background-image: url(~assets/theme-images/ross/pc-link-entry-register.png);
  369. }
  370. &.icon-doc {
  371. background-image: url(~assets/theme-images/ross/pc-link-entry-doc.png);
  372. }
  373. &.icon-feedback {
  374. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback.png);
  375. }
  376. &.icon-challenge {
  377. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge.png);
  378. }
  379. }
  380. .text {
  381. font-size: 16px;
  382. color: #fff;
  383. }
  384. }
  385. .user-info {
  386. color: #fff;
  387. font-size: 16px;
  388. margin-left: 48px;
  389. .login-btn {
  390. width: 80px;
  391. height: 34px;
  392. color: #fff;
  393. background: rgba(255, 255, 255, 0.39);
  394. font-size: 14px;
  395. text-align: center;
  396. line-height: 34px;
  397. cursor: pointer;
  398. }
  399. .user-center {
  400. position: relative;
  401. .icon {
  402. width: 32px;
  403. height: 32px;
  404. text-align: center;
  405. line-height: 32px;
  406. &.el-icon-user-solid {
  407. font-size: 24px;
  408. cursor: pointer;
  409. }
  410. &.el-icon-arrow-down {
  411. font-size: 22px;
  412. transition: all 0.2s;
  413. }
  414. }
  415. &:hover {
  416. .drop-down {
  417. display: block;
  418. animation: slide-down 0.4s linear forwards;
  419. }
  420. .el-icon-arrow-down {
  421. transform: rotateZ(180deg);
  422. }
  423. }
  424. .drop-down {
  425. display: none;
  426. opacity: 0;
  427. // z-index: -1;
  428. right: 0;
  429. position: absolute;
  430. background: transparent;
  431. box-sizing: border-box;
  432. padding-top: 24px;
  433. .nav {
  434. width: 118px;
  435. padding: 8px 0;
  436. background: #fff;
  437. box-shadow: 0px 6px 16px rgba(40, 40, 40, 0.1);
  438. border-radius: 4px;
  439. li {
  440. font-size: 14px;
  441. color: #282828;
  442. text-align: center;
  443. line-height: 40px;
  444. transition: all 0.4s;
  445. cursor: pointer;
  446. &:hover {
  447. color: #f3920d;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. .login,
  454. .register,
  455. .logout {
  456. cursor: pointer;
  457. &:hover {
  458. @include themify($themes) {
  459. color: themed('color');
  460. }
  461. }
  462. }
  463. }
  464. }
  465. .content {
  466. min-height: calc(100vh - 80px - 80px);
  467. background-color: #f7f7f7;
  468. overflow: hidden;
  469. }
  470. .footer {
  471. height: 80px;
  472. background-color: #2c3038;
  473. color: #fff;
  474. font-size: 14px;
  475. }
  476. }
  477. }
  478. // 移动端
  479. @media screen and (max-width: 768px) {
  480. .layout {
  481. padding-top: 12.8vw;
  482. .header {
  483. position: fixed;
  484. top: 0;
  485. left: 0;
  486. z-index: 999;
  487. width: 100%;
  488. padding: 0 4vw;
  489. height: 12.8vw;
  490. box-sizing: border-box;
  491. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  492. .navbar {
  493. height: 100%;
  494. }
  495. .logo {
  496. img {
  497. display: block;
  498. width: 8vw;
  499. height: 8vw;
  500. &.ross {
  501. width: 12.2vw;
  502. height: 3.9vw;
  503. margin-right: 1.9vw;
  504. transform: translateY(-0.6vw);
  505. }
  506. }
  507. span {
  508. font-size: 4vw;
  509. color: #fff;
  510. }
  511. }
  512. .user-info {
  513. color: #fff;
  514. font-size: 3vw;
  515. .logout {
  516. margin: 0 1.6vw;
  517. }
  518. .login-btn {
  519. width: 13.4vw;
  520. height: 6.4vw;
  521. color: #fff;
  522. background: rgba(255, 255, 255, 0.39);
  523. font-size: 3.4vw;
  524. text-align: center;
  525. line-height: 6.4vw;
  526. margin-right: 2.4vw;
  527. }
  528. .user-center {
  529. position: relative;
  530. .icon {
  531. width: 5.6vw;
  532. height: 5.6vw;
  533. text-align: center;
  534. line-height: 5.6vw;
  535. margin-right: 4vw;
  536. &.el-icon-user-solid {
  537. font-size: 24px;
  538. cursor: pointer;
  539. }
  540. &.el-icon-arrow-down {
  541. display: none;
  542. }
  543. }
  544. &:hover {
  545. .drop-down {
  546. display: block;
  547. animation: slide-down 0.4s linear forwards;
  548. }
  549. .el-icon-arrow-down {
  550. transform: rotateZ(180deg);
  551. }
  552. }
  553. .drop-down {
  554. display: none;
  555. opacity: 0;
  556. // z-index: -1;
  557. right: 0;
  558. position: absolute;
  559. background: transparent;
  560. box-sizing: border-box;
  561. padding-top: 1.2vw;
  562. .nav {
  563. width: 26vw;
  564. padding: 1vw 0;
  565. background: #fff;
  566. box-shadow: 0px 0.6vw 20vw rgba(40, 40, 40, 0.1);
  567. border-radius: 0.4vw;
  568. li {
  569. font-size: 3.4vw;
  570. color: #282828;
  571. text-align: center;
  572. line-height: 8.6vw;
  573. transition: all 0.4s;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. .collapse-icon {
  580. display: block;
  581. width: 5.6vw;
  582. height: 5.6vw;
  583. background: url(~assets/theme-images/common/h5-icon-collapse.png)
  584. no-repeat center;
  585. background-size: 5.6vw;
  586. }
  587. }
  588. .content {
  589. min-height: calc(100vh - 12.8vw - 12.4vw);
  590. }
  591. .footer {
  592. height: 12.4vw;
  593. background-color: #2c3038;
  594. color: #fff;
  595. font-size: 3vw;
  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>