li.shaoyi před 2 roky
rodič
revize
53d58cbe14

+ 2 - 2
oem/zrwyt/manifest.json

@@ -5,9 +5,9 @@
     "name" : "中融文遗通",
     /*应用名称,程序桌面图标名称*/
     "version" : {
-        "name" : "1.0.7",
+        "name" : "1.0.8",
         /*应用版本名称*/
-        "code" : 100007
+        "code" : 100008
     },
     "description" : "",
     /*应用描述信息*/

+ 14 - 0
src/packages/sbyj/views/home/index.less

@@ -0,0 +1,14 @@
+.home {
+    .app-tabbar {
+        background: var(--tabbar-background) !important;
+        margin-top: auto;
+
+        .app-iconfont {
+            color: var(--tabbar-icon);
+
+            &.is-active {
+                color: var(--tabbar-icon-active);
+            }
+        }
+    }
+}

+ 147 - 3
src/packages/sbyj/views/home/index.vue

@@ -1,10 +1,36 @@
 <template>
-  <LayoutHome :tabs="tabList" />
+  <div class="home g-flex">
+    <router-view v-slot="{ Component }">
+      <RouterTransition :css="cssTransition">
+        <!-- 缓存所有组件 -->
+        <keep-alive>
+          <component class="g-flex__body" :is="Component" />
+        </keep-alive>
+      </RouterTransition>
+    </router-view>
+    <app-tabbar class="home-tabbar" :data-list="tabList" :data-index="currentTab" @click="onTabClick" />
+  </div>
 </template>
 
 <script lang="ts" setup>
+import { shallowRef, nextTick, watch, onMounted ,computed} from 'vue'
+import { fullloading, dialog } from '@/utils/vant'
 import { Tabbar } from '@mobile/components/base/tabbar/types'
-import LayoutHome from '@mobile/components/layouts/home/index.vue'
+import { getAppUpdateInfo } from '@/services/api/common'
+import { useNavigation } from '@mobile/router/navigation'
+import { useLogin } from '@/business/login'
+import { useLoginStore } from '@/stores'
+import plus from '@/utils/h5plus'
+import AppTabbar from '@mobile/components/base/tabbar/index.vue'
+import RouterTransition from '@mobile/components/base/router-transition/index.vue'
+
+const { route, routerTo, getGlobalUrlParams, setGlobalUrlParams } = useNavigation()
+const { userLogin } = useLogin()
+const loginStore = useLoginStore()
+const cssTransition = shallowRef(true) // 是否使用css动画
+const currentTab = shallowRef(0)
+
+const tabIndex = computed(() => tabList.findIndex((e) => e.name === route.name))
 
 const tabList: Tabbar[] = [
   {
@@ -32,4 +58,122 @@ const tabList: Tabbar[] = [
     activeIcon: 'g-icon-mine--fill',
   }
 ]
-</script>
+
+const onTabClick = (index: number) => {
+  const { name } = tabList[index]
+  cssTransition.value = false
+
+  if (name !== 'home-mine' || loginStore.token) {
+    currentTab.value = index
+    routerTo(name, true)
+  } else {
+    fullloading((hideLoading) => {
+      userLogin(true).then(() => {
+        currentTab.value = index
+        routerTo(name, true)
+      }).catch(() => {
+        routerTo('user-login')
+      }).finally(() => {
+        hideLoading()
+      })
+    }, '加载中...')
+  }
+}
+
+// 版本号转数值
+const versionToNumber = (value: number | string) => {
+  if (value) {
+    const num = value.toString().split(/\D/)
+    // 版本号位数
+    const place = ['', '0', '00', '000', '0000', '00000', '000000'].reverse()
+    for (let i = 0; i < num.length; i++) {
+      const len = num[i].length
+      num[i] = place[len] + num[i]
+    }
+    return +num.join('')
+  }
+  return 0
+}
+
+onMounted(() => {
+  currentTab.value = tabIndex.value
+  const os = plus.getSystemInfo('os')
+  const currentVersion = plus.getSystemInfo('version')
+  const currentVersionCode = plus.getSystemInfo('versionCode')
+
+  if (os === 'Android') {
+    // 监听下载进度
+    const ondownload = plus.onDownload((filename, progress) => {
+      if (progress === 100) {
+        dialog({
+          message: '新版本下载完成,是否安装?',
+          showCancelButton: true,
+          confirmButtonText: '安装'
+        }).then(() => {
+          plus.installApp(filename)
+        }).catch(() => {
+          plus.deleteFile(filename)
+        })
+      }
+    })
+
+    // 获取应用更新信息
+    getAppUpdateInfo().then((res) => {
+      const data = JSON.parse(res)
+      if (data) {
+        const { LastVersionCode, ApkUrl } = data[0] as Model.AppUpdateInfo
+        if (Number(LastVersionCode) > Number(currentVersionCode)) {
+          dialog({
+            message: '发现新版本,是否下载?',
+            showCancelButton: true,
+            confirmButtonText: '下载'
+          }).then(() => {
+            plus.createDownload(ApkUrl)
+          }).catch(() => {
+            ondownload.cancel()
+          })
+        }
+      }
+    })
+  }
+
+  if (os === 'iOS') {
+    // plus.httpRequest({
+    //   url: ''
+    // }).then((res) => {
+    //   const results = res.data.results
+    //   if (results?.length) {
+    //     const { version, trackViewUrl } = results[0]
+    //     if (versionToNumber(version) > versionToNumber(currentVersion)) {
+    //       dialog({
+    //         message: '发现新版本,是否更新?',
+    //         showCancelButton: true,
+    //         confirmButtonText: '更新'
+    //       }).then(() => {
+    //         plus.openURL(trackViewUrl)
+    //       })
+    //     }
+    //   }
+    // })
+  }
+})
+
+watch(() => route.name, () => {
+  const params = getGlobalUrlParams()
+  if (params.tabIndex > -1) {
+    onTabClick(params.tabIndex)
+  } else if (tabIndex.value > -1) {
+    onTabClick(tabIndex.value)
+  } else {
+    // 如果参数不是 tabIndex ,需要保留到下一个路由
+    setGlobalUrlParams(params)
+  }
+  nextTick(() => {
+    cssTransition.value = true
+  })
+})
+</script>
+
+<style lang="less">
+@import './index.less';
+</style>

+ 6 - 4
src/packages/sbyj/views/market/list/index.vue

@@ -38,7 +38,7 @@
 </template>
 
 <script lang="ts" setup>
-import { computed, onUnmounted } from 'vue'
+import { computed, onActivated, onDeactivated } from 'vue'
 import { handleNumberValue, formatDecimal } from '@/filters'
 import { useNavigation } from '@mobile/router/navigation'
 import quoteSocket from '@/services/websocket/quote'
@@ -50,6 +50,7 @@ import { useFuturesStore } from '@/stores'
 const { router } = useNavigation()
 const futuresStore = useFuturesStore()
 const subscribe = quoteSocket.createSubscribe()
+const subscribeData: string[] = [] // 订阅的商品代码
 
 // 获取游客商品列表
 useRequest(queryTouristGoods, {
@@ -65,10 +66,10 @@ const { run: getTouristQuoteDay } = useRequest(queryTouristQuoteDay, {
     manual: true,
     onSuccess: (res) => {
         res.data.forEach((item) => {
+            subscribeData.push(item.goodscode)
             futuresStore.updateGoodsQuote(item)
         })
-        const goodsCodes = res.data.map((item) => item.goodscode)
-        subscribe.start(...goodsCodes)
+        subscribe.start(...subscribeData)
     }
 })
 
@@ -93,7 +94,8 @@ const rowClick = (row: Model.GoodsQuote) => {
     })
 }
 
-onUnmounted(() => subscribe.stop())
+onActivated(() => subscribeData.length && subscribe.start(...subscribeData))
+onDeactivated(() => subscribe.stop())
 </script>
 
 <style lang="less">

+ 28 - 24
src/services/websocket/quote.ts

@@ -54,33 +54,37 @@ export default new (class {
             })
         })
 
-        if (goodsList.length) {
-            //console.log('开始行情订阅', goodsList)
-            this.connect().then(() => {
-                const content = subscribeListToByteArrary(goodsList, '2_TOKEN_NEKOT_', Long.fromNumber(2))
+        //console.log('开始行情订阅', goodsList)
+        this.connect().then(() => {
+            // 订阅列表不能为空,如果空值会导致连接断开
+            const codes = goodsList.length ? goodsList : [{
+                exchangeCode: 250,
+                goodsCode: '0',
+                subState: 0,
+            }]
+            const content = subscribeListToByteArrary(codes, '2_TOKEN_NEKOT_', Long.fromNumber(2))
 
-                this.socket.send({
-                    data: {
-                        rspCode: FunCode.QuoteSubscribeRsp,
-                        payload: new Package40(FunCode.QuoteSubscribeReq, content)
-                    },
-                    success: (raw) => {
-                        if (raw.content) {
-                            parseSubscribeRsp(raw.content).then(() => {
-                                //console.log('行情订阅成功', res)
-                            }).catch(() => {
-                                console.error('报文解析失败', raw)
-                            })
-                        } else {
-                            console.error('数据异常')
-                        }
-                    },
-                    fail: (err) => {
-                        console.error('行情订阅失败', err)
+            this.socket.send({
+                data: {
+                    rspCode: FunCode.QuoteSubscribeRsp,
+                    payload: new Package40(FunCode.QuoteSubscribeReq, content)
+                },
+                success: (raw) => {
+                    if (raw.content) {
+                        parseSubscribeRsp(raw.content).then(() => {
+                            //console.log('行情订阅成功', res)
+                        }).catch(() => {
+                            console.error('报文解析失败', raw)
+                        })
+                    } else {
+                        console.error('数据异常')
                     }
-                })
+                },
+                fail: (err) => {
+                    console.error('行情订阅失败', err)
+                }
             })
-        }
+        })
     }
 
     /**