ソースを参照

商管APP url参数改为 cordova插件方法传参, 逻辑修改

yunxing 4 年 前
コミット
bf302be5b4
9 ファイル変更96 行追加54 行削除
  1. 2 1
      .env.aly
  2. 2 1
      .env.development
  3. 2 1
      .env.production
  4. 2 1
      .env.test
  5. 56 41
      src/App.vue
  6. 0 4
      src/components/Navbar.vue
  7. 12 2
      src/main.ts
  8. 6 0
      src/store/index.ts
  9. 14 3
      src/views/overview/index.vue

+ 2 - 1
.env.aly

@@ -1,4 +1,5 @@
 NODE_ENV=production
 VUE_APP_RealEnv=aly
 VUE_APP_BaseURL=
-VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_URL=

+ 2 - 1
.env.development

@@ -1,4 +1,5 @@
 VUE_APP_RealEnv=development
 VUE_APP_PublicPath=/wandaBmGuideH5
 VUE_APP_BaseURL=/glsms
-VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_URL=VTJGc2RHVmtYMS9hcUpQU3ZCT2ZLenNKaTc2WHZwc01TVXptd3ZiQmNmcEg1Z3VvZXQ4eDh3d0lma1EwNG9obnVTQy9Ib0ZOVXBhaE45WC9iVUhWQXg3YU9NWWlpYWo1YWJONmpFYnFVUUN6OUxxaUhJNUlKN29iT0ZpUEo4cU0=

+ 2 - 1
.env.production

@@ -1,4 +1,5 @@
 NODE_ENV=production
 VUE_APP_RealEnv=production
 VUE_APP_BaseURL=/glsms
-VUE_APP_PublicPath=/glsms/wandaBmGuideH5
+VUE_APP_PublicPath=/glsms/wandaBmGuideH5
+VUE_APP_URL=

+ 2 - 1
.env.test

@@ -1,4 +1,5 @@
 NODE_ENV=production
 VUE_APP_RealEnv=test
 VUE_APP_BaseURL=
-VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_PublicPath=/wandaBmGuideH5
+VUE_APP_URL=

+ 56 - 41
src/App.vue

@@ -92,56 +92,59 @@ export default {
         }
     },
     beforeMount() {},
-    created() {
-        // window.vm = this
-        this.handleUrl()
-        // 路径无参数,不执行后续逻辑
-        if(!this.urlFlag){
-            // this.loadComplete = true
-            return
-        }
-        // store.commit('SETSSOTOKEN', 'admin:liujiandong')
-        // console.log(window.location.href)
-        this.SETHAVEFENGMAP(false)
-        // 判断 安卓,ios
-        const { os } = osInfo()
-        if (os === 'iOS') {
-            this.isIOS = true
-        } else {
-            this.isIOS = false
-        }
-        // 获取楼层列表
-        this.getFloorList()
-    },
-    mounted() {
-        // 路径无参数,不执行后续逻辑
-        if(!this.urlFlag){
-            // this.loadComplete = true
-            return
-        }
-        // console.log('环境变量', process.env.VUE_APP_RealEnv)
-        if (this.plazaId) {
-            this.getFengMap()
-            store.dispatch('getBrand')
-        } else {
-            window.fengmapData = null
-            this.loadComplete = true
-        }
+    created(){
+        window.vmh5 = this
     },
     computed: {
-        ...mapGetters(['plazaId', 'fmapID']),
+        ...mapGetters(['plazaId', 'fmapID', 'url']),
     },
     methods: {
         ...mapActions(['getfmapID', 'getFloors']),
-        ...mapMutations(['SETHAVEFENGMAP', 'SETCATEGORYID', 'SETSMSXT', 'SETSSOTOKEN', 'SETPLAZAID']),
+        ...mapMutations(['SETHAVEFENGMAP', 'SETCATEGORYID', 'SETSMSXT', 'SETSSOTOKEN', 'SETPLAZAID', 'SETURL']),
+         createdFn() {
+            // window.vm = this
+            this.handleUrl()
+            // 路径无参数,不执行后续逻辑
+            if(!this.urlFlag){
+                // this.loadComplete = true
+                return
+            }
+            // store.commit('SETSSOTOKEN', 'admin:liujiandong')
+            // console.log(window.location.href)
+            this.SETHAVEFENGMAP(false)
+            // 判断 安卓,ios
+            const { os } = osInfo()
+            if (os === 'iOS') {
+                this.isIOS = true
+            } else {
+                this.isIOS = false
+            }
+            // 获取楼层列表
+            this.getFloorList()
+        },
+        mountedFn() {
+            // 路径无参数,不执行后续逻辑
+            if(!this.urlFlag){
+                // this.loadComplete = true
+                return
+            }
+            // console.log('环境变量', process.env.VUE_APP_RealEnv)
+            if (this.plazaId) {
+                this.getFengMap()
+                store.dispatch('getBrand')
+            } else {
+                window.fengmapData = null
+                this.loadComplete = true
+            }
+        },
         getFengMap() {
             this.getfmapID().then(() => {
                 this.getMap()
             })
         },
         getMap() {
-            console.log('%c时间:', 'color:blue;background:#fff')
-            console.time('蜂鸟下载,解析')
+            // console.log('%c时间:', 'color:blue;background:#fff')
+            // console.time('蜂鸟下载,解析')
             window.fengmapData = new SFengParser(
                 'fengMap',
                 `${this.mapServerURL}/fmap/${this.fmapID}`,
@@ -162,7 +165,7 @@ export default {
                 window.fengmapData.loadTheme(`${this.mapServerURL}/webtheme/${this.fmapID}/${this.fmapID}.theme`).then((res) => {
                     this.SETHAVEFENGMAP(1)
                 })
-                console.timeEnd('蜂鸟下载,解析')
+                // console.timeEnd('蜂鸟下载,解析')
                 this.loadComplete = true
                 // 缓存楼层数据
                 if (dataArr.length) {
@@ -196,7 +199,8 @@ export default {
          * 处理url参数
          */
         handleUrl() {
-            let href = window.location.href.split('?')[1]
+            // let href = window.location.href.split('?')[1]
+            let href =  this.url
             if(!href){
                 this.urlFlag =  false 
                 return
@@ -234,6 +238,7 @@ export default {
     },
     watch: {
         plazaId(plazaId) {
+            // console.log('watch plazaId',plazaId)
             // console.log('项目id', plazaId)
             window.fengmapData = null
             // 当获取到到项目id,请求底图
@@ -248,6 +253,16 @@ export default {
         $route(to, from) {
             // console.log(to, from)
         },
+        url: {
+            // 监听url,有url时再进行接口查询
+            handler(newV){
+                if(newV){
+                    this.createdFn()
+                    this.mountedFn()
+                }
+            },
+            immediate:true
+        }
     },
 }
 </script>

+ 0 - 4
src/components/Navbar.vue

@@ -20,8 +20,6 @@ import store from '@/store'
 import { debounce } from 'lodash'
 // 扫一扫回到函数
 window.__scanCallback = function (data) {
-    console.log('__scanCallback')
-    console.log(data)
     switch (data.code) {
         // 扫描的⾮设备⼆维码
         case 0:
@@ -72,7 +70,6 @@ export default {
         ...mapMutations(['SCANASSETID']),
         // 返回工程信息化主菜单
         backApp() {
-            console.log('backApp')
             window.webkit &&
                 webkit.messageHandlers.cordova_iab.postMessage(
                     JSON.stringify({
@@ -82,7 +79,6 @@ export default {
         },
         // 扫码,300ms触发一次
         scan: debounce(function () {
-            console.log('扫码')
             window.webkit &&
                 webkit.messageHandlers.cordova_iab.postMessage(
                     JSON.stringify({

+ 12 - 2
src/main.ts

@@ -14,6 +14,16 @@ if (process.env.NODE_ENV === 'production' && process.env.VUE_APP_RealEnv !== 'pr
     // TODO: vConsole
     // new VConsole()
 }
+
+// url传参(在工程信息化 商管APP中 才能调用到的方法),存放store
+window.__keyCallback = function (data) {
+    if(data.text){
+        store.commit('SETURL', data.text)
+    }else{
+        store.commit('SETURL', null)
+    }
+}
+
 const ua = navigator.userAgent
 let flag = false
 // 打包后,使用cordova插件,需要监听deviceready事件
@@ -32,7 +42,7 @@ if (process.env.NODE_ENV === 'production' && ua.match(/(iPhone | Android)/)) {
         router,
         store,
         render: (h) => h(App),
-    }).$mount('#app')
+    }).$mount('#app')        
 }
 // 如果直接在电脑上预览,2s后,dispatch deviceready
 setTimeout(() => {
@@ -45,7 +55,7 @@ setTimeout(() => {
         },
     })
     window.addEventListener('deviceready', function(event) {
-        console.log('deviceready success')
+        // console.log('deviceready success')
     })
     // 随后在对应的元素上触发该事件
     if (window.dispatchEvent) {

+ 6 - 0
src/store/index.ts

@@ -33,6 +33,7 @@ export default new Vuex.Store({
             5: '其他事项',
         },
         scanAssetid: null, //扫码返回的assetid
+        url: process.env.VUE_APP_URL,
     },
     getters: {
         ssoToken: (state) => state.ssoToken,
@@ -50,6 +51,7 @@ export default new Vuex.Store({
         oldSmsxt: (state) => state.oldSmsxt,
         isGlobal: (state) => state.isGlobal,
         scanAssetid: (state) => state.scanAssetid,
+        url: (state) => state.url,
     },
     mutations: {
         SETSSOTOKEN(state, data) {
@@ -100,6 +102,10 @@ export default new Vuex.Store({
         SCANASSETID(state, data) {
             state.scanAssetid = data
         },
+        // 设置返回的url
+        SETURL(state, data) {
+            state.url = data
+        },
     },
     actions: {
         async getfmapID(context) {

+ 14 - 3
src/views/overview/index.vue

@@ -243,7 +243,7 @@ export default {
         }
     },
     computed: {
-        ...mapGetters(['plazaId']),
+        ...mapGetters(['plazaId', 'url']),
     },
     watch: {
         /**
@@ -261,10 +261,21 @@ export default {
                 }, 1000)
             })
         },
+        plazaId: {
+            // 监听广场ID,有id时再进行接口查询
+            handler(newV){
+                if(newV){
+                    this.queryBaseInfo()
+                    this.queryRecordCountFunc()
+                }
+            },
+            immediate:true
+        }
     },
     created() {
-        this.queryBaseInfo()
-        this.queryRecordCountFunc()
+        // console.log('overview created')
+        // this.queryBaseInfo()
+        // this.queryRecordCountFunc()
     },
 
     beforeMount() {},