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 { isWeChat } from '~/utils/validator'
  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. },
  161. watch: {
  162. $route: {
  163. handler: function () {
  164. setTimeout(() => {
  165. this.$nextTick(this.initAppMessageShareData)
  166. }, 1000)
  167. },
  168. deep: true,
  169. },
  170. },
  171. beforeDestroy() {
  172. window.removeEventListener('resize', () => {})
  173. this.refreshCacheData()
  174. },
  175. methods: {
  176. // 全局分享事件
  177. initAppMessageShareData() {
  178. // 判断是否为微信浏览器环境
  179. // if (!isWeChat()) return
  180. // 网站主机地址
  181. const HOST = process.env.LOCALHOSE
  182. this.$wxReady((wx) => {
  183. //需在用户可能点击分享按钮前就先调用
  184. wx.updateAppMessageShareData({
  185. title: '认证通', // 分享标题
  186. desc: '一款专业的正品认证软件系统', // 分享描述
  187. link: HOST + this.routePrefix, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  188. imgUrl: HOST + '/share-icon.png', // 分享图标
  189. success: function () {
  190. // 设置成功
  191. },
  192. })
  193. })
  194. },
  195. // 跳转
  196. onJumpTo(item) {
  197. this.drawer = false
  198. const hasLogin = this.$store.getters.accessToken
  199. // 保存登录重定向路由
  200. this.$setStorage(
  201. this.routePrefix,
  202. 'login_redicret',
  203. this.routePrefix + item.path
  204. )
  205. if (item.auth && !hasLogin) {
  206. this.$toast({ message: '请先登录', duration: 1000 })
  207. this.formType = 'login'
  208. this.$store.commit('app/SHOW_LOGIN')
  209. return
  210. }
  211. const url = this.routePrefix + item.path
  212. this.$router.push(url)
  213. },
  214. // 点击登录
  215. onLoginClick(type) {
  216. this.formType = type
  217. },
  218. // 初始化数据页面公共数据
  219. async initPageData() {
  220. this.$store.commit('app/SET_PAGE_THEME', 'ross')
  221. // 获取用户信息
  222. let userInfo = this.$getStorage(this.routePrefix, 'userInfo')
  223. if (userInfo && userInfo.authUserId === this.authUserId) {
  224. this.$store.commit('user/SET_USER_INFO', userInfo)
  225. const res = await this.$http.api.checkTokenResult()
  226. this.$store.commit('user/SET_USER_INFO', res.data)
  227. }
  228. this.isMounted = true
  229. },
  230. // 校验公众号类型
  231. async checkAccountType() {
  232. try {
  233. // 1订阅号,2服务号
  234. if (!this.appId) return
  235. const res = await this.$http.api.checkAccountType({ appId: this.appId })
  236. this.$store.commit('supplier/SET_ACCOUNT_TYPE', res.data)
  237. } catch (error) {
  238. console.log(error)
  239. }
  240. },
  241. // 登录
  242. onLogin() {
  243. this.formType = 'login'
  244. this.$store.commit('app/SHOW_LOGIN')
  245. },
  246. // 注册
  247. onRegister() {
  248. this.formType = 'register'
  249. this.$store.commit('app/SHOW_LOGIN')
  250. },
  251. // 退出登录
  252. logout() {
  253. this.$store.dispatch('user/logout')
  254. this.$removeStorage(this.routePrefix, 'userInfo')
  255. this.backHome()
  256. },
  257. // 回到首页
  258. backHome() {
  259. // if (this.$route.path === this.routePrefix) return
  260. // this.$router.replace(this.routePrefix)
  261. window.location.href = window.location.origin + this.routePrefix
  262. },
  263. // 个人中心
  264. onUserCenter() {
  265. // const path = `${this.routePrefix}/center`
  266. window.location.href =
  267. window.location.origin + `${this.routePrefix}/center`
  268. },
  269. // 响应页面宽度变化
  270. responseWidth() {
  271. this.$store.commit('app/SET_SCREEN', window.innerWidth)
  272. window.addEventListener('resize', (e) => {
  273. this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
  274. })
  275. },
  276. // 数据初始化刷新浏览器
  277. refreshCacheData() {
  278. this.$removeStorage(this.routePrefix, 'club_list_data')
  279. },
  280. },
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. @keyframes slide-down {
  285. 0% {
  286. top: 48px;
  287. z-index: 9;
  288. opacity: 0;
  289. }
  290. 100% {
  291. top: 32px;
  292. opacity: 1;
  293. }
  294. }
  295. // PC端
  296. @media screen and (min-width: 768px) {
  297. .layout {
  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. @include themify($themes) {
  340. color: themed('color');
  341. }
  342. }
  343. .icon {
  344. &.icon-register {
  345. background-image: url(~assets/theme-images/ross/pc-link-entry-register-active.png);
  346. }
  347. &.icon-doc {
  348. background-image: url(~assets/theme-images/ross/pc-link-entry-doc-active.png);
  349. }
  350. &.icon-feedback {
  351. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback-active.png);
  352. }
  353. &.icon-challenge {
  354. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge-active.png);
  355. }
  356. }
  357. }
  358. }
  359. .icon {
  360. width: 20px;
  361. height: 20px;
  362. display: inline-block;
  363. vertical-align: -4px;
  364. margin-right: 4px;
  365. background-size: 20px;
  366. background-repeat: no-repeat;
  367. background-position: center;
  368. &.icon-register {
  369. background-image: url(~assets/theme-images/ross/pc-link-entry-register.png);
  370. }
  371. &.icon-doc {
  372. background-image: url(~assets/theme-images/ross/pc-link-entry-doc.png);
  373. }
  374. &.icon-feedback {
  375. background-image: url(~assets/theme-images/ross/pc-link-entry-feedback.png);
  376. }
  377. &.icon-challenge {
  378. background-image: url(~assets/theme-images/ross/pc-link-entry-challenge.png);
  379. }
  380. }
  381. .text {
  382. font-size: 16px;
  383. color: #fff;
  384. }
  385. }
  386. .user-info {
  387. color: #fff;
  388. font-size: 16px;
  389. margin-left: 48px;
  390. .login-btn {
  391. width: 80px;
  392. height: 34px;
  393. color: #fff;
  394. background: rgba(255, 255, 255, 0.39);
  395. font-size: 14px;
  396. text-align: center;
  397. line-height: 34px;
  398. cursor: pointer;
  399. }
  400. .user-center {
  401. position: relative;
  402. .icon {
  403. width: 32px;
  404. height: 32px;
  405. text-align: center;
  406. line-height: 32px;
  407. &.el-icon-user-solid {
  408. font-size: 24px;
  409. cursor: pointer;
  410. }
  411. &.el-icon-arrow-down {
  412. font-size: 22px;
  413. transition: all 0.2s;
  414. }
  415. }
  416. &:hover {
  417. .drop-down {
  418. display: block;
  419. animation: slide-down 0.4s linear forwards;
  420. }
  421. .el-icon-arrow-down {
  422. transform: rotateZ(180deg);
  423. }
  424. }
  425. .drop-down {
  426. display: none;
  427. opacity: 0;
  428. // z-index: -1;
  429. right: 0;
  430. position: absolute;
  431. background: transparent;
  432. box-sizing: border-box;
  433. padding-top: 24px;
  434. .nav {
  435. width: 118px;
  436. padding: 8px 0;
  437. background: #fff;
  438. box-shadow: 0px 6px 16px rgba(40, 40, 40, 0.1);
  439. border-radius: 4px;
  440. li {
  441. font-size: 14px;
  442. color: #282828;
  443. text-align: center;
  444. line-height: 40px;
  445. transition: all 0.4s;
  446. cursor: pointer;
  447. &:hover {
  448. color: #f3920d;
  449. }
  450. }
  451. }
  452. }
  453. }
  454. .login,
  455. .register,
  456. .logout {
  457. cursor: pointer;
  458. &:hover {
  459. @include themify($themes) {
  460. color: themed('color');
  461. }
  462. }
  463. }
  464. }
  465. }
  466. .content {
  467. min-height: calc(100vh - 80px - 80px);
  468. background-color: #f7f7f7;
  469. overflow: hidden;
  470. }
  471. .footer {
  472. height: 80px;
  473. background-color: #2c3038;
  474. color: #fff;
  475. font-size: 14px;
  476. }
  477. }
  478. }
  479. // 移动端
  480. @media screen and (max-width: 768px) {
  481. .layout {
  482. padding-top: 12.8vw;
  483. .header {
  484. position: fixed;
  485. top: 0;
  486. left: 0;
  487. z-index: 999;
  488. width: 100%;
  489. padding: 0 4vw;
  490. height: 12.8vw;
  491. box-sizing: border-box;
  492. background: linear-gradient(90deg, #101010 0%, #404040 100%);
  493. .navbar {
  494. height: 100%;
  495. }
  496. .logo {
  497. img {
  498. display: block;
  499. width: 8vw;
  500. height: 8vw;
  501. &.ross {
  502. width: 12.2vw;
  503. height: 3.9vw;
  504. margin-right: 1.9vw;
  505. transform: translateY(-0.6vw);
  506. }
  507. }
  508. span {
  509. font-size: 4vw;
  510. color: #fff;
  511. }
  512. }
  513. .user-info {
  514. color: #fff;
  515. font-size: 3vw;
  516. .logout {
  517. margin: 0 1.6vw;
  518. }
  519. .login-btn {
  520. width: 13.4vw;
  521. height: 6.4vw;
  522. color: #fff;
  523. background: rgba(255, 255, 255, 0.39);
  524. font-size: 3.4vw;
  525. text-align: center;
  526. line-height: 6.4vw;
  527. margin-right: 2.4vw;
  528. }
  529. .user-center {
  530. position: relative;
  531. .icon {
  532. width: 5.6vw;
  533. height: 5.6vw;
  534. text-align: center;
  535. line-height: 5.6vw;
  536. margin-right: 4vw;
  537. &.el-icon-user-solid {
  538. font-size: 24px;
  539. cursor: pointer;
  540. }
  541. &.el-icon-arrow-down {
  542. display: none;
  543. }
  544. }
  545. &:hover {
  546. .drop-down {
  547. display: block;
  548. animation: slide-down 0.4s linear forwards;
  549. }
  550. .el-icon-arrow-down {
  551. transform: rotateZ(180deg);
  552. }
  553. }
  554. .drop-down {
  555. display: none;
  556. opacity: 0;
  557. // z-index: -1;
  558. right: 0;
  559. position: absolute;
  560. background: transparent;
  561. box-sizing: border-box;
  562. padding-top: 1.2vw;
  563. .nav {
  564. width: 26vw;
  565. padding: 1vw 0;
  566. background: #fff;
  567. box-shadow: 0px 0.6vw 20vw rgba(40, 40, 40, 0.1);
  568. border-radius: 0.4vw;
  569. li {
  570. font-size: 3.4vw;
  571. color: #282828;
  572. text-align: center;
  573. line-height: 8.6vw;
  574. transition: all 0.4s;
  575. }
  576. }
  577. }
  578. }
  579. }
  580. .collapse-icon {
  581. display: block;
  582. width: 5.6vw;
  583. height: 5.6vw;
  584. background: url(~assets/theme-images/common/h5-icon-collapse.png)
  585. no-repeat center;
  586. background-size: 5.6vw;
  587. }
  588. }
  589. .content {
  590. min-height: calc(100vh - 12.8vw - 12.4vw);
  591. }
  592. .footer {
  593. height: 12.4vw;
  594. background-color: #2c3038;
  595. color: #fff;
  596. font-size: 3vw;
  597. }
  598. }
  599. .nav {
  600. width: 63vw;
  601. box-sizing: border-box;
  602. padding: 0 6.4vw;
  603. .link {
  604. display: flex;
  605. justify-content: flex-start;
  606. align-items: center;
  607. border-bottom: 0.1vw solid #c2c2c2;
  608. padding-bottom: 3vw;
  609. padding-top: 6vw;
  610. .icon {
  611. width: 5.6vw;
  612. height: 5.6vw;
  613. vertical-align: -1.2vw;
  614. margin-right: 2.4vw;
  615. background-size: 5.6vw;
  616. background-repeat: no-repeat;
  617. background-position: center;
  618. &.icon-register {
  619. background-image: url(~assets/theme-images/ross/h5-link-entry-register-active.png);
  620. }
  621. &.icon-doc {
  622. background-image: url(~assets/theme-images/ross/h5-link-entry-doc-active.png);
  623. }
  624. &.icon-feedback {
  625. background-image: url(~assets/theme-images/ross/h5-link-entry-feedback-active.png);
  626. }
  627. &.icon-challenge {
  628. background-image: url(~assets/theme-images/ross/h5-link-entry-challenge.png);
  629. }
  630. }
  631. .text {
  632. font-size: 3.4vw;
  633. color: #282828;
  634. }
  635. }
  636. }
  637. }
  638. </style>