Logo.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <div class="sidebar-logo-container" :class="{ 'collapse': collapse }">
  3. <div class="box_weather">
  4. <el-image style="height: 45px;" :src="getImageUrl(imgUrl)" fit="cover">
  5. <template #error>
  6. <div class="image-slot">
  7. <svg-icon icon-class="failure" className="failure_icon" color="rgb(248, 152.1, 152.1)" />
  8. </div>
  9. </template>
  10. </el-image>
  11. <div class="weather_title">
  12. <span>{{ weathers || '未知' }} {{ temperatures || '未知' }}℃</span>
  13. <span>{{ currentTime }} {{ hourMinuteSecond }}</span>
  14. </div>
  15. </div>
  16. <router-link key="expand" class="sidebar-logo-link" to="/">
  17. <div class="sidebar-logo">
  18. <div class="sidebar-title">{{ title }}</div>
  19. <div class="sidebar-title1"></div>
  20. <div class="sidebar-title2"></div>
  21. </div>
  22. </router-link>
  23. <div class="avatar-container">
  24. <Dropdown :name="name" :options="['退出登录']" @changeData="logout"></Dropdown>
  25. <div class="shiny-button" @click="expandFold">
  26. {{ appStore.expandFoldType ?'收起':'展开'}}
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script setup>
  32. import axios from 'axios';
  33. import Dropdown from '@/components/Dropdown'
  34. import { ElMessageBox } from 'element-plus'
  35. import useSettingsStore from '@/store/modules/settings'
  36. import variables from '@/assets/styles/variables.module.scss'
  37. import useUserStore from '@/store/modules/user'
  38. import useAppStore from '@/store/modules/app'
  39. import { weatherList } from "./mockData";
  40. defineProps({
  41. collapse: {
  42. type: Boolean,
  43. required: true
  44. }
  45. })
  46. const imgUrl = ref('')
  47. const weathers = ref('')
  48. const temperatures = ref('')
  49. const userStore = useUserStore()
  50. const appStore = useAppStore()
  51. const name = userStore.name
  52. const title = import.meta.env.VITE_APP_TITLE;
  53. const settingsStore = useSettingsStore();
  54. const sideTheme = computed(() => settingsStore.sideTheme);
  55. const getImageUrl = (name) => {
  56. return new URL(`${name}`, import.meta.url).href
  57. }
  58. const timer = ref(null)
  59. const hourMinuteSecond = ref('')
  60. const currentTime = ref('')
  61. timer.value = setInterval(() => {
  62. hourMinuteSecond.value = formatTime(new Date(), 'hh:mm:ss')
  63. currentTime.value = formatTime(new Date(), 'yyyy-MM-dd')
  64. }, 1000);
  65. function formatTime(str, format) {
  66. let time = new Date(str)
  67. let formatTime = {
  68. 'y+': '0' + time.getFullYear(),
  69. 'M+': '0' + (time.getMonth() + 1),
  70. 'd+': '0' + time.getDate(),
  71. 'h+': '0' + time.getHours(),
  72. 'm+': '0' + time.getMinutes(),
  73. 's+': '0' + time.getSeconds()
  74. }
  75. let result = format || 'yyyy-MM-dd hh:mm:ss'
  76. for (let i in formatTime) {
  77. let regexp = new RegExp('(' + i + ')', 'g')
  78. let replaceInfoObj = regexp.exec(result)
  79. if (replaceInfoObj) {
  80. let replaceInfoArr = Array.from(replaceInfoObj)
  81. result = result.replace(
  82. regexp,
  83. formatTime[i].substring(formatTime[i].length - replaceInfoArr[0].length),
  84. formatTime[i].length
  85. )
  86. }
  87. }
  88. return result
  89. }
  90. // 获取Logo背景色
  91. const getLogoBackground = computed(() => {
  92. if (settingsStore.isDark) {
  93. return 'var(--sidebar-bg)';
  94. }
  95. return sideTheme.value === 'theme-dark' ? variables.menuBg : variables.menuLightBg;
  96. });
  97. // 获取Logo文字颜色
  98. const getLogoTextColor = computed(() => {
  99. if (settingsStore.isDark) {
  100. return 'var(--sidebar-text)';
  101. }
  102. return sideTheme.value === 'theme-dark' ? '#fff' : variables.menuLightText;
  103. });
  104. function logout() {
  105. ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {
  106. confirmButtonText: '确定',
  107. cancelButtonText: '取消',
  108. type: 'warning'
  109. }).then(() => {
  110. userStore.logOut().then(() => {
  111. location.href = '/index';
  112. })
  113. }).catch(() => { });
  114. }
  115. async function getIPCity() {
  116. try {
  117. // 使用高德API的IP定位服务获取IP省市信息
  118. const ipResponse = await axios.get(
  119. 'https://restapi.amap.com/v3/ip?key=6bd1c2303f2ca454975738f8911a27ce'
  120. );
  121. if (ipResponse.data && ipResponse.data.rectangle) {
  122. const parts = ipResponse.data.rectangle.split(";");
  123. getAddressByLatLng(parts);//回调下方的函数
  124. }
  125. } catch (error) {
  126. console.error('IP定位失败', error);
  127. }
  128. }
  129. const getAddressByLatLng = async (ip) => {
  130. try {
  131. // 使用高德API的地理编码服务将经纬度转换成地址
  132. const lat = ip;
  133. const lng = ip;
  134. const latlng = `${lat},${lng}`;//将经度纬度拼接起来传给api地址
  135. const geoResponse = await axios.get(
  136. `https://restapi.amap.com/v3/geocode/regeo?key=6bd1c2303f2ca454975738f8911a27ce&location=${latlng}`
  137. );
  138. getWeather(geoResponse.data.regeocode.addressComponent)
  139. } catch (error) {
  140. console.error('地理编码失败', error);
  141. }
  142. }
  143. const getWeather = async (params) => {
  144. let city = params.adcode
  145. let apiKey = '6bd1c2303f2ca454975738f8911a27ce'
  146. try {
  147. const response = await axios.get(
  148. `https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=${apiKey}`
  149. );
  150. if (response.status == 200) {
  151. let weatherArr = response.data.lives[0]
  152. weathers.value = weatherArr.weather
  153. temperatures.value = weatherArr.temperature
  154. weatherList.forEach(el => {
  155. if (el.name === weatherArr.weather) {
  156. imgUrl.value = el.url
  157. }
  158. });
  159. }
  160. } catch (error) {
  161. console.error('请求失败:', error);
  162. }
  163. }
  164. // 展开收起
  165. const expandFold = () =>{
  166. let foldType = true
  167. if(appStore.expandFoldType){
  168. foldType = false
  169. }else{
  170. foldType = true
  171. }
  172. appStore.getExpandFold(foldType);
  173. }
  174. onMounted(() => {
  175. getIPCity()
  176. })
  177. </script>
  178. <style lang="scss" scoped>
  179. @import '@/assets/styles/variables.module.scss';
  180. .failure_icon {
  181. width: 30px;
  182. height: 30px;
  183. }
  184. .sidebarLogoFade-enter-active {
  185. transition: opacity 1.5s;
  186. }
  187. .sidebarLogoFade-enter,
  188. .sidebarLogoFade-leave-to {
  189. opacity: 0;
  190. }
  191. .sidebar-logo-container {
  192. width: 100%;
  193. text-align: center;
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. position: relative;
  198. & .sidebar-logo-link {
  199. position: absolute;
  200. height: 100%;
  201. left: calc(50% - 280px);
  202. width: 560px;
  203. & .sidebar-logo {
  204. display: inline-block;
  205. position: relative;
  206. }
  207. & .sidebar-title {
  208. letter-spacing: 5px;
  209. font-family: fangsong;
  210. font-style: italic;
  211. z-index: 3;
  212. color: v-bind(getLogoTextColor);
  213. font-weight: 600;
  214. font-size: 22px;
  215. padding: 10px 70px;
  216. background-image: linear-gradient(to right, #1da1d3 0%, #003aa5 20%, #003aa5 80%, #1da1d3 100%, );
  217. clip-path: polygon(0 0, 50px 100%, calc(100% - 50px) 100%, 100% 0);
  218. box-shadow: inset 0px -3px 30px #62d4ff;
  219. border-bottom: 1px solid #73caff;
  220. }
  221. & .sidebar-title1 {
  222. z-index: -1;
  223. position: absolute;
  224. top: 0;
  225. bottom: 10px;
  226. left: -30px;
  227. right: -30px;
  228. background: radial-gradient(circle, #0067ff, #002d5b);
  229. clip-path: polygon(0 0, 60px 100%, calc(100% - 60px) 100%, 100% 0);
  230. box-shadow: inset 0px -3px 30px rgb(0 186 255);
  231. }
  232. & .sidebar-title2 {
  233. z-index: -2;
  234. position: absolute;
  235. top: 0;
  236. bottom: 15px;
  237. left: -65px;
  238. right: -65px;
  239. background: radial-gradient(circle, rgb(203 203 203 / 76%), #0e4dae);
  240. clip-path: polygon(0 0, 70px 100%, calc(100% - 70px) 100%, 100% 0);
  241. box-shadow: inset 0px -3px 30px rgb(208 242 255);
  242. }
  243. }
  244. }
  245. .box_weather {
  246. display: flex;
  247. align-items: center;
  248. color: #fff;
  249. margin-left: 20px;
  250. font-size: 18px;
  251. }
  252. .weather_title {
  253. display: flex;
  254. flex-direction: column;
  255. margin-left: 10px;
  256. align-items: flex-start;
  257. span {
  258. margin: 2px 0px;
  259. font-size: 14px;
  260. }
  261. }
  262. .image-slot {
  263. width: 100%;
  264. height: 100%;
  265. display: flex;
  266. align-items: center;
  267. }
  268. .avatar-container {
  269. display: flex;
  270. align-items: center;
  271. margin-right: 20px;
  272. }
  273. .shiny-button {
  274. user-select: none;
  275. margin-left: 20px;
  276. width: fit-content;
  277. position: relative;
  278. padding: 2px 20px;
  279. color: rgb(207, 248, 255);
  280. border: 3px solid transparent;
  281. border-radius: 60px;
  282. background-color: rgb(6, 69, 73);
  283. background-image: linear-gradient(to bottom right, rgb(10, 107, 115), rgb(2, 10, 14)), linear-gradient(125deg, rgba(255, 255, 255, 0) 45%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0) 53%);
  284. background-origin: border-box;
  285. background-clip: padding-box, border-box;
  286. background-size: 100%, 200%;
  287. background-position: 0px, -150px;
  288. animation: 4s border-glint linear backwards infinite;
  289. animation-delay: 1s;
  290. transition: box-shadow 0.25s, text-shaddw 0.25s;
  291. overflow: hidden;
  292. }
  293. .shiny-button:hover {
  294. cursor: pointer;
  295. background-image: linear-gradient(-60deg, rgb(40, 105, 160) 0%, rgb(186, 211, 229) 100%), linear-gradient(125deg, rgba(255, 255, 255, 0) 45%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0) 53%);
  296. color: rgb(250, 250, 255);
  297. box-shadow: rgba(0, 0, 0, 0.7) 5px 5px 5px;
  298. text-shadow: 0px 0px 3px rgba(255, 255, 255, 0.7);
  299. transition: box-shadow 0.25s, text-shaddw 0.25s;
  300. }
  301. .shiny-button::after {
  302. content: ' ';
  303. position: absolute;
  304. top: -50%;
  305. left: -120%;
  306. width: 200%;
  307. height: 200%;
  308. background-image: linear-gradient(125deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0) 52%);
  309. animation: 5s glint linear backwards infinite;
  310. animation-delay: -3s;
  311. }
  312. @keyframes glint {
  313. 0% {
  314. left: -120%;
  315. }
  316. 8% {
  317. left: 50%;
  318. }
  319. 100% {
  320. left: 50%;
  321. }
  322. }
  323. @keyframes border-glint {
  324. 0% {
  325. background-position: 0px, -250px;
  326. }
  327. 25% {
  328. background-position: 0px, -200px;
  329. }
  330. 75% {
  331. background-position: 0px, 50px;
  332. }
  333. 100% {
  334. background-position: 0px, 50px;
  335. }
  336. }
  337. </style>