website.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="website-layout">
  3. <div class="layout-title">
  4. <div class="title-box">
  5. <div class="title-logo">
  6. <img src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/3156449b8a1a4874981b2a76d5947721"
  7. alt="logo.png" @click="$router.push('/website/home')">
  8. <div class="title-label" @click="$router.push('/website/home')">
  9. <div class="title-name">有极智慧园区</div>
  10. <div class="title-sub-name">SMART PARK SYSTEM</div>
  11. </div>
  12. <div class="location" @click="$router.push('/website/city')">
  13. <i class="el-icon-location"></i>
  14. <span class="location-name">{{$store.getters.city.cityName}}</span>
  15. </div>
  16. </div>
  17. <div class="login" v-if="user.userId">
  18. <div class="login-avatar">
  19. <avatar :user="user"></avatar>
  20. </div>
  21. <span class="login-name">{{user.userName}}</span>
  22. <span class="color-blue loginout" @click="loginout">退出</span>
  23. <span class="admin-system" @click="$router.push('/')">管理系统</span>
  24. </div>
  25. <div class="login" v-else>
  26. <div class="login-icon">
  27. <i class="el-icon-s-custom"></i>
  28. </div>
  29. <span class="login-name" @click="login">登录 / 注册</span>
  30. <span class="admin-system" @click="$router.push('/')">管理系统</span>
  31. </div>
  32. </div>
  33. </div>
  34. <router-view :key="key" />
  35. <div class="login-toggle" v-if="visible">
  36. <login @callback="callback"></login>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import city from '@/uitls/citys.js';
  42. import login from '@/components/website/login';
  43. import avatar from '@/components/common/avatar'
  44. import {
  45. removeToken
  46. } from '@/uitls/auth';
  47. import {
  48. getToken
  49. } from '@/uitls/auth'
  50. import {
  51. mapGetters
  52. } from 'vuex';
  53. export default {
  54. data() {
  55. return {
  56. visible: false,
  57. user: {}
  58. }
  59. },
  60. created() {
  61. this.init();
  62. },
  63. mounted() {
  64. document.getElementById('body').style.overflow = 'auto'
  65. },
  66. methods: {
  67. init() {
  68. if (this.$store.getters.user) this.user = this.$store.getters.user;
  69. this.initLocation();
  70. },
  71. initLocation() {
  72. if (this.$store.getters.city && this.$store.getters.city.cityCode) return;
  73. $.getJSON("https://restapi.amap.com/v3/ip?key=36b8970fe5bcfd92fe9e34e32d0e7461", res => {
  74. for (let i = 0; i < city.length; i++) {
  75. if (city[i].cityCode == res.adcode) {
  76. this.$store.dispatch('app/changeCity', city[i]);
  77. }
  78. }
  79. }).fail(error => {
  80. this.$store.dispatch('app/changeCity', city[0]);
  81. });
  82. },
  83. login() {
  84. this.visible = true;
  85. },
  86. callback(type) {
  87. if (type === 'init') {
  88. if (this.$route.path == '/website/homeDetail') {
  89. this.$store.dispatch('app/changeEvent', {
  90. type: 'homeDetailReload'
  91. })
  92. } else if (this.$route.path == '/website/search') {
  93. this.$store.dispatch('app/changeEvent', {
  94. type: 'searchReload'
  95. })
  96. }
  97. this.init();
  98. }
  99. this.visible = false;
  100. },
  101. loginout() {
  102. this.$confirm('是否要退出登录?', () => {
  103. removeToken();
  104. this.$store.dispatch('projectBase/changeProject', {});
  105. this.$store.dispatch('app/changeUser', {});
  106. this.$store.dispatch('app/changeOrganization', {});
  107. this.$message.success('退出成功');
  108. this.init();
  109. });
  110. },
  111. },
  112. computed: {
  113. key() {
  114. if ((this.$route.path == '/website/homeDetail' || this.$route.path == '/website/search') && !getToken())
  115. this.login();
  116. return this.$route.path;
  117. },
  118. ...mapGetters(['event'])
  119. },
  120. watch: {
  121. event() {
  122. let event = this.$store.getters.event;
  123. if (event.type == 'login') this.login();
  124. }
  125. },
  126. components: {
  127. login,
  128. avatar
  129. }
  130. }
  131. </script>
  132. <style lang="scss">
  133. .website-layout {
  134. width: 100%;
  135. position: relative;
  136. .login-toggle {
  137. position: fixed;
  138. top: 0;
  139. left: 0;
  140. right: 0;
  141. bottom: 0;
  142. z-index: 998;
  143. background: rgba(0, 0, 0, 0.5);
  144. }
  145. .layout-title {
  146. position: absolute;
  147. width: 100%;
  148. min-width: 1200px;
  149. left: 0;
  150. top: 0;
  151. height: 60px;
  152. color: #fff;
  153. z-index: 9;
  154. background: rgba(0, 0, 0, 0.5);
  155. .title-box {
  156. width: 1200px;
  157. height: 100%;
  158. margin: 0 auto;
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-between;
  162. }
  163. .title-logo {
  164. display: flex;
  165. align-items: center;
  166. img {
  167. width: 44px;
  168. height: 44px;
  169. border-radius: 4px;
  170. margin-right: 10px;
  171. cursor: pointer;
  172. }
  173. .title-label {
  174. width: 130px;
  175. cursor: pointer;
  176. }
  177. .title-name {
  178. font-size: 16px;
  179. line-height: 22px;
  180. font-weight: 500;
  181. }
  182. .title-sub-name {
  183. font-size: 12px;
  184. transform: scale(.68) translateX(-28px);
  185. opacity: .75;
  186. }
  187. .location {
  188. border: 2px solid #fff;
  189. border-radius: 26px;
  190. height: 26px;
  191. padding: 0 10px;
  192. display: flex;
  193. align-items: center;
  194. cursor: pointer;
  195. }
  196. .location-name {
  197. font-size: 12px;
  198. margin-left: 3px;
  199. }
  200. }
  201. .login {
  202. display: flex;
  203. align-items: center;
  204. .loginout {
  205. font-size: 12px;
  206. margin-left: 5px;
  207. cursor: pointer;
  208. }
  209. .login-avatar {
  210. width: 32px;
  211. height: 32px;
  212. border-radius: 32px;
  213. margin-right: 10px;
  214. overflow: hidden;
  215. }
  216. .login-icon {
  217. width: 32px;
  218. height: 32px;
  219. border: 2px solid #fff;
  220. border-radius: 32px;
  221. text-align: center;
  222. line-height: 32px;
  223. margin-right: 10px;
  224. .el-icon-s-custom {
  225. font-size: 20px;
  226. }
  227. }
  228. .login-name {
  229. cursor: pointer;
  230. font-weight: 500;
  231. }
  232. .admin-system {
  233. padding: 5px 10px;
  234. border-radius: 4px;
  235. border: 1px solid #fff;
  236. margin-left: 10px;
  237. cursor: pointer;
  238. &:hover {
  239. border-color: $--color-primary;
  240. color: $--color-primary;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. </style>