App.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <script lang="ts">
  2. import DevelopAgreement from '@/components/developAgreement.vue';
  3. export default defineComponent({
  4. components: {
  5. DevelopAgreement
  6. },
  7. })
  8. </script>
  9. <script setup lang="ts">
  10. import { defineComponent, nextTick, onMounted, provide, ref, watch } from 'vue'
  11. import { useRouter } from 'vue-router';
  12. import emitter from '@/util/eventBus'
  13. import { message } from 'ant-design-vue';
  14. window._AMapSecurityConfig = {
  15. securityJsCode: '23cf1bca0e52bbf8cb129047cdb46f10',
  16. }
  17. const router = useRouter()
  18. let nickName = ref<string>('')
  19. let avatar = ref<string>('https://joeschmoe.io/api/v1/random')
  20. let isTop = ref<boolean>(true)
  21. let menuList = ref(['首页', '优巨引擎官网', '文档中心', '管理中心'])
  22. const container = ref()
  23. let currentRouteName = ref()
  24. let visible = ref<boolean>(false)
  25. let isRouterAlive = ref<boolean>(true);
  26. let showAgreement = ref<boolean>(false)
  27. let activeIndex = ref<number>(0)
  28. let index = localStorage.getItem('activeIndex')
  29. if (index) {
  30. activeIndex.value = Number(index)
  31. }
  32. const reload = () => {
  33. isRouterAlive.value = false;
  34. nextTick(() => {
  35. isRouterAlive.value = true
  36. })
  37. }
  38. provide("reload", reload);
  39. watch(() => router.currentRoute.value.name, (newValue, oldValue) => {
  40. currentRouteName.value = newValue
  41. if (newValue !== 'home') {
  42. if (newValue === 'login') {
  43. isTop.value = false
  44. } else {
  45. isTop.value = false
  46. }
  47. window.removeEventListener('scroll', handleScrollY, true)
  48. } else {
  49. isTop.value = true
  50. window.addEventListener('scroll', handleScrollY, true)
  51. }
  52. })
  53. onMounted(() => {
  54. let userInfo = localStorage.getItem('userInfo')
  55. if (userInfo) {
  56. let info = JSON.parse(userInfo)
  57. nickName.value = info.nickname
  58. avatar.value = info.avatar || 'https://joeschmoe.io/api/v1/random'
  59. }
  60. emitter.on('userInfo', (e: any) => {
  61. let userInfo = JSON.parse(e)
  62. console.log('userInfo:', userInfo);
  63. nickName.value = userInfo.nickname
  64. avatar.value = userInfo.avatar || 'https://joeschmoe.io/api/v1/random'
  65. })
  66. })
  67. function handleScrollY() {
  68. isTop.value = !container.value.getBoundingClientRect().top
  69. }
  70. const loginOut = () => {
  71. localStorage.clear()
  72. visible.value = false
  73. nickName.value = ''
  74. avatar.value = ''
  75. router.push('/')
  76. }
  77. const menu = (i: number) => {
  78. let token = localStorage.getItem('token')
  79. if (i !== 1) {
  80. activeIndex.value = i
  81. localStorage.setItem('activeIndex', String(i))
  82. }
  83. switch (i) {
  84. case 0:
  85. router.push('/')
  86. break;
  87. case 1:
  88. window.open("http://www.liebaoai.cn/", "_blank");
  89. break;
  90. case 2:
  91. router.push('/docsCenter')
  92. break;
  93. case 3:
  94. if (token) {
  95. router.push('/management/appInfo')
  96. } else {
  97. router.push('/login')
  98. message.warning('请登录后再点击管理中心!')
  99. }
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. </script>
  106. <template>
  107. <a-layout>
  108. <!-- 头部 -->
  109. <a-layout-header
  110. :class="['header', isTop ? '' : 'header-color', currentRouteName === 'login' ? 'login-header' : '']">
  111. <div class="container">
  112. <div class="left" @click="router.push('/')">
  113. <img v-if="isTop" class="img" src="@/assets/images/1.png" alt="">
  114. <img v-else class="img" src="@/assets/images/1-2.png" alt="">
  115. <div class="name">优巨引擎·开放平台</div>
  116. </div>
  117. <div class="right">
  118. <div @click="menu(i)" class="btn hover:text-blue-400" v-for="(v, i) in menuList" :key="i"
  119. :class="activeIndex === i && !isTop ? 'active-btn' : ''">
  120. {{ v }}</div>
  121. <template v-if="nickName">
  122. <a-tooltip placement="bottom" color="white">
  123. <template #title>
  124. <!-- <div class="flex items-center px-10px py-20px cursor-pointer hover:bg-gray-300">
  125. <img class="w-18px h-18px mr-10px" src="@/assets/images/18-1.png" alt="">
  126. <div class="text-14px font-500 text-dark-400">通知</div>
  127. </div>
  128. <div style="height: 2px; background-color: #F0F0F0"></div> -->
  129. <div @click="loginOut" class="flex items-center px-10px py-20px cursor-pointer hover:bg-gray-300">
  130. <img class="w-18px h-18px mr-10px" src="@/assets/images/18-2.png" alt="">
  131. <div class="text-14px font-500 text-dark-400">账号退出</div>
  132. </div>
  133. </template>
  134. <div class="flex items-center cursor-pointer">
  135. <a-avatar size="30" :src="avatar" class="bg-[#f7f7f7]"></a-avatar>
  136. <div class="text-18 ml-10px">{{ nickName }}</div>
  137. </div>
  138. </a-tooltip>
  139. </template>
  140. <template v-else>
  141. <div v-if="currentRouteName === 'login'" class="login" @click="router.push('/register')">注册</div>
  142. <div v-else class="login" @click="router.push('/login')">登录</div>
  143. </template>
  144. </div>
  145. </div>
  146. </a-layout-header>
  147. <!-- 内容 -->
  148. <a-layout-content>
  149. <div ref="container" class="lb-container">
  150. <router-view v-if="isRouterAlive"></router-view>
  151. </div>
  152. </a-layout-content>
  153. <!-- 底部 -->
  154. <a-layout-footer class="footer">
  155. <!-- <div class="name">优巨引擎</div> -->
  156. <div class="agreement">
  157. <div @click="showAgreement = true" class="cursor-pointer">开发者服务协议</div>
  158. <div>&ensp;|&ensp;苏州优巨引擎智能数字科技有限公司</div>
  159. </div>
  160. <div class="record-number">
  161. 备案号:苏ICP备2021010118号
  162. </div>
  163. </a-layout-footer>
  164. </a-layout>
  165. <!-- 客服、公众号 -->
  166. <div v-if="activeIndex !== 3" class="fixed top-40vh right-20px">
  167. <a-tooltip placement="left" color="white">
  168. <template #title>
  169. <div class="flex flex-col items-center px-20px py-20px">
  170. <div class="text-16px mb-10px text-dark-500">在线客服,扫码联系</div>
  171. <img class="w-160px h-160px" src="@/assets/images/16-1.png" alt="">
  172. </div>
  173. </template>
  174. <div
  175. class="flex flex-col justify-center items-center w-60px h-60px bg-white rounded-10px cursor-pointer customer">
  176. <img class="w-30px h-30px" src="@/assets/images/3-1.png" alt="">
  177. <div class="text-14px font-500 text-dark-400">客服</div>
  178. </div>
  179. </a-tooltip>
  180. <a-tooltip placement="left" color="white">
  181. <template #title>
  182. <div class="flex flex-col items-center px-20px py-20px">
  183. <div class="text-16px mb-10px text-dark-500">关注公众号,了解更多</div>
  184. <img class="w-160px h-160px" src="@/assets/images/16-2.png" alt="">
  185. </div>
  186. </template>
  187. <div
  188. class="mt-20px flex flex-col justify-center items-center w-60px h-60px bg-white rounded-10px cursor-pointer customer">
  189. <img class="w-30px h-30px" src="@/assets/images/3-2.png" alt="">
  190. <div class="text-14px font-500 text-dark-400">公众号</div>
  191. </div>
  192. </a-tooltip>
  193. </div>
  194. <!-- 开发者协议 -->
  195. <a-modal centered v-model:visible="showAgreement" :footer="null" :width="900">
  196. <DevelopAgreement></DevelopAgreement>
  197. </a-modal>
  198. </template>
  199. <style lang="scss">
  200. #app {
  201. font-family: Avenir, Helvetica, Arial, sans-serif;
  202. -webkit-font-smoothing: antialiased;
  203. -moz-osx-font-smoothing: grayscale;
  204. }
  205. .header {
  206. position: fixed;
  207. top: 0;
  208. left: 0;
  209. right: 0;
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. height: $header-height !important;
  214. color: #FFFFFF !important;
  215. background: none !important;
  216. padding: 0 !important;
  217. z-index: 99;
  218. .left {
  219. display: flex;
  220. align-items: center;
  221. .img {
  222. width: 40px;
  223. height: 40px;
  224. cursor: pointer;
  225. }
  226. .name {
  227. font-size: 16px;
  228. font-weight: bold;
  229. cursor: pointer;
  230. margin-left: 20px;
  231. }
  232. }
  233. .right {
  234. display: flex;
  235. align-items: center;
  236. .btn {
  237. font-size: 15px;
  238. margin-right: 40px;
  239. cursor: pointer;
  240. }
  241. .active-btn {
  242. color: #0077EE;
  243. font-weight: bold;
  244. }
  245. .login {
  246. width: 80px;
  247. height: 32px;
  248. line-height: 32px;
  249. text-align: center;
  250. background: linear-gradient(141deg, #50A7FF 0%, #1B8DFF 100%);
  251. border-radius: 16px 16px 16px 16px;
  252. font-size: 14px;
  253. color: #FFFFFF;
  254. cursor: pointer;
  255. }
  256. }
  257. }
  258. .header-color {
  259. background-color: #ffffff !important;
  260. box-shadow: 0px 4px 4px rgb(198 198 198 / 25%);
  261. color: #222222 !important;
  262. .name {
  263. color: #0077EE;
  264. }
  265. }
  266. .login-header {
  267. background: rgba(255, 255, 255, 0.85);
  268. box-shadow: 0px 4px 4px 1px rgba(0, 0, 0, 0.06);
  269. opacity: 0.9;
  270. .name {
  271. color: #0077EE;
  272. }
  273. }
  274. .lb-container {
  275. min-height: calc(100vh - $footer-height);
  276. background: white;
  277. }
  278. .footer {
  279. height: $footer-height;
  280. padding: 10px 0 !important;
  281. display: flex;
  282. flex-direction: column;
  283. align-items: center;
  284. justify-content: space-evenly;
  285. background: #252525 !important;
  286. color: #FFFFFF !important;
  287. .name {
  288. font-size: 18px;
  289. font-weight: bold;
  290. cursor: pointer;
  291. }
  292. .agreement,
  293. .record-number {
  294. display: flex;
  295. font-size: 12px;
  296. font-weight: 400;
  297. }
  298. }
  299. .customer {
  300. box-shadow: 0px 0px 8px 1px rgba(0, 0, 0, 0.1);
  301. }
  302. </style>