app-ross.vue 17 KB

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