Browse Source

location href处理

yunxing 4 years ago
parent
commit
8380c292e1
2 changed files with 32 additions and 4 deletions
  1. 31 3
      src/App.vue
  2. 1 1
      src/store/index.ts

+ 31 - 3
src/App.vue

@@ -86,7 +86,8 @@ export default {
     },
     beforeMount() {},
     created() {
-        store.commit('SETSSOTOKEN', 'admin:liujiandong')
+        this.handleUrl()
+        // store.commit('SETSSOTOKEN', 'admin:liujiandong')
         // console.log(window.location.href)
         this.SETHAVEFENGMAP(false)
         // 判断 安卓,ios
@@ -113,7 +114,7 @@ export default {
     },
     methods: {
         ...mapActions(['getfmapID', 'getFloors']),
-        ...mapMutations(['SETHAVEFENGMAP', 'SETCATEGORYID', 'SETSMSXT']),
+        ...mapMutations(['SETHAVEFENGMAP', 'SETCATEGORYID', 'SETSMSXT', 'SETSSOTOKEN', 'SETPLAZAID']),
         getFengMap() {
             this.getfmapID().then(() => {
                 this.getMap()
@@ -156,7 +157,7 @@ export default {
             // console.log(active)
             if (active == 1) {
                 this.SETCATEGORYID('LCGN')
-                this.SETSMSXT("")
+                this.SETSMSXT('')
             }
             this.$router.push({ name: this.routeDict[active] })
             store.commit('SETAPPTITLE', this.titleDict[active])
@@ -167,6 +168,33 @@ export default {
         getFloorList() {
             this.getFloors()
         },
+        /**
+         * 处理url参数
+         */
+        handleUrl() {
+            let url = window.location.href
+            let params = this.queryURLParams(url)
+            console.log('%c 路径参数:', 'color:blue')
+            console.log(params)
+            const { username, plazaId } = params
+            if (username) {
+                this.SETSSOTOKEN(`admin:${username}`)
+            }
+            if (plazaId) {
+                // TODO:
+                plazaId = '1000772'
+                this.SETPLAZAID(plazaId)
+            }
+        },
+        /**
+         * 查询url参数
+         */
+        queryURLParams(url) {
+            let obj = {}
+            url.replace(/([^?=&#]+)=([^?=&#]+)/g, (_, key, value) => (obj[key] = value))
+            url.replace(/#([^?=&#]+)/g, (_, hash) => (obj['HASH'] = hash))
+            return obj
+        },
     },
     watch: {
         plazaId(plazaId) {

+ 1 - 1
src/store/index.ts

@@ -9,7 +9,7 @@ Vue.use(Vuex)
 
 export default new Vuex.Store({
     state: {
-        ssoToken: 'admin:liujiandong',
+        ssoToken: 'admin:maohongru',
         appTitle: '管理说明书', //顶部标题
         // ssoToken: null,
         plazaId: '1000772', //项目Id 北京通州