app-ross.vue 13 KB

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