app-ross.vue 13 KB

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