|
|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<app-view class="market">
|
|
|
<template #header>
|
|
|
- <app-navbar class="market-header" :show-back-button="false" :style="topBG" />
|
|
|
+ <app-navbar class="market-header" :show-back-button="false" :style="firstBanner" />
|
|
|
<div style="padding: 12px;font-size: 14px;display: flex;justify-content: space-between;">
|
|
|
<span>
|
|
|
{{ serverTime?.format('YYYY/MM/DD HH:mm:ss') }}
|
|
|
@@ -73,180 +73,23 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { shallowRef, computed, onActivated, onDeactivated, ref } from 'vue'
|
|
|
-import moment, { Moment } from 'moment'
|
|
|
-import { getServerTime } from '@/services/api/common'
|
|
|
+import { computed } from 'vue'
|
|
|
import { handleNumberValue, formatDecimal, getFileUrl } from '@/filters'
|
|
|
-import { useNavigation } from '@mobile/router/navigation'
|
|
|
-import { queryTouristGoods, queryTouristQuoteDay } from '@/services/api/goods'
|
|
|
-import { useFuturesStore, useLoginStore, useUserStore } from '@/stores'
|
|
|
-import { timerTask } from '@/utils/timer'
|
|
|
-import { useRequest } from '@/hooks/request'
|
|
|
-import { queryImageConfigs } from "@/services/api/common"
|
|
|
-import { getRunStatusName } from '@/constants/market'
|
|
|
-import { queryMarketRun } from '@/services/api/market'
|
|
|
-import quoteSocket from '@/services/websocket/quote'
|
|
|
-
|
|
|
-const { router } = useNavigation()
|
|
|
-const futuresStore = useFuturesStore()
|
|
|
-const loginStore = useLoginStore()
|
|
|
-const subscribe = quoteSocket.createSubscribe()
|
|
|
-// 订阅的商品代码
|
|
|
-const subscribeData = shallowRef<string[]>([])
|
|
|
-// 系统时间
|
|
|
-const serverTime = ref<Moment>()
|
|
|
-const topBG = ref('')
|
|
|
-
|
|
|
-const { getSystemParamValue } = useUserStore()
|
|
|
-const system_1012 = getSystemParamValue('1012') ?? '1'
|
|
|
-
|
|
|
-// 请求背景图
|
|
|
-useRequest(queryImageConfigs, {
|
|
|
- params: {
|
|
|
- imageType: 2
|
|
|
- },
|
|
|
- onSuccess: (res) => {
|
|
|
- const [firstItem] = res.data
|
|
|
- if (firstItem) {
|
|
|
- topBG.value = `--header-bg:url(${getFileUrl(firstItem.imagepath)})`
|
|
|
- }
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-// 构建游客交易商品 任务 #6614
|
|
|
-const touristTradeGoodsList = computed(() => {
|
|
|
- const list = futuresStore.getGoodsListByTradeMode(52)
|
|
|
- const result = list.sort((a, b) => a.goodsorder.localeCompare(b.goodsorder))
|
|
|
-
|
|
|
- // 分组
|
|
|
- return result.reduce<{
|
|
|
- groupId: number;
|
|
|
- groupName: string;
|
|
|
- marketId: number;
|
|
|
- goodsList: Model.GoodsQuote[];
|
|
|
- }[]>((pre, cur) => {
|
|
|
- const existingGroup = pre.find((e) => e.groupId === cur.goodsgroupid)
|
|
|
-
|
|
|
- if (existingGroup) {
|
|
|
- existingGroup.goodsList.push(cur)
|
|
|
- } else {
|
|
|
- pre.push({
|
|
|
- groupId: cur.goodsgroupid,
|
|
|
- groupName: cur.goodsgroupname,
|
|
|
- marketId: cur.marketid,
|
|
|
- goodsList: [cur]
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return pre
|
|
|
- }, [])
|
|
|
-})
|
|
|
-
|
|
|
-// 构建游客参考行情商品
|
|
|
-const touristRefGoodsList = computed(() => {
|
|
|
- const list = futuresStore.getGoodsListByTradeMode(99, 97)
|
|
|
- return list.sort((a, b) => a.goodsorder.localeCompare(b.goodsorder))
|
|
|
-})
|
|
|
-
|
|
|
-const rowClick = (row: Model.GoodsQuote) => {
|
|
|
- router.push({
|
|
|
- name: 'market-detail',
|
|
|
- query: {
|
|
|
- goodscode: row.goodscode
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-// 游客商品点击
|
|
|
-const touristRowClick = (row: Model.GoodsQuote) => {
|
|
|
- /// 不显示图标
|
|
|
- if (system_1012 != '1') {
|
|
|
- return
|
|
|
- }
|
|
|
- router.push({
|
|
|
- name: 'market-chart',
|
|
|
- query: {
|
|
|
- goodscode: row.goodscode
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-if (loginStore.token) {
|
|
|
- futuresStore.onDataCompleted(() => {
|
|
|
- subscribeData.value = futuresStore.goodsList.map((e) => e.goodscode)
|
|
|
- subscribe.start(...subscribeData.value)
|
|
|
- })
|
|
|
-} else {
|
|
|
- // 获取游客商品列表
|
|
|
- queryTouristGoods({
|
|
|
- data: {
|
|
|
- trademodes: '52,99,97'
|
|
|
- }
|
|
|
- }).then((res) => {
|
|
|
- if (res.data.length) {
|
|
|
- futuresStore.goodsList = res.data
|
|
|
- subscribeData.value = res.data.map((e) => e.goodscode)
|
|
|
-
|
|
|
- // 获取游客商品盘面
|
|
|
- queryTouristQuoteDay({
|
|
|
- data: {
|
|
|
- goodsCodes: subscribeData.value.join(',')
|
|
|
- }
|
|
|
- }).then((res) => {
|
|
|
- subscribeData.value.forEach((goodscode) => {
|
|
|
- const item = res.data.find((e) => e.goodscode === goodscode)
|
|
|
- futuresStore.updateQuotation(item ?? { goodscode })
|
|
|
- })
|
|
|
- subscribe.start(...subscribeData.value)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-const { dataList: marketList, run: marketRun } = useRequest(queryMarketRun, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- // 每1分钟轮询刷新
|
|
|
- timerTask.setTimeout(() => marketRun(), 60 * 1000, 'getMarketRun')
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-// 获取市场状态
|
|
|
-const getMarketStatus = (marketId: number) => {
|
|
|
- const marketInfo = marketList.value.find((e) => e.marketid === marketId)
|
|
|
- return marketInfo && [2, 6].includes(marketInfo.runstatus) ? getRunStatusName(marketInfo.runstatus) : '未开盘'
|
|
|
-}
|
|
|
-
|
|
|
-// 校验服务器时间
|
|
|
-const checkServerTime = () => {
|
|
|
- getServerTime().then((res) => {
|
|
|
- serverTime.value = moment(res.data)
|
|
|
- // 每1分钟同步一次服务器时间
|
|
|
- timerTask.setTimeout(() => {
|
|
|
- checkServerTime()
|
|
|
- }, 60 * 1000, 'getServerTime')
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-const clearTimer = () => {
|
|
|
- timerTask.clearInterval('refreshTime')
|
|
|
- timerTask.clearTimeout('getServerTime')
|
|
|
- timerTask.clearTimeout('getMarketRun')
|
|
|
-}
|
|
|
-
|
|
|
-onActivated(() => {
|
|
|
- subscribeData.value.length && subscribe.start(...subscribeData.value)
|
|
|
- serverTime.value = moment(new Date())
|
|
|
- timerTask.setInterval(() => {
|
|
|
- serverTime.value = moment(serverTime.value).add(1000, 'ms')
|
|
|
- }, 1000, 'refreshTime')
|
|
|
- checkServerTime()
|
|
|
- marketRun()
|
|
|
-})
|
|
|
-
|
|
|
-onDeactivated(() => {
|
|
|
- subscribe.stop()
|
|
|
- clearTimer()
|
|
|
+import { useSetup } from './composables'
|
|
|
+
|
|
|
+const {
|
|
|
+ banners,
|
|
|
+ serverTime,
|
|
|
+ touristTradeGoodsList,
|
|
|
+ touristRefGoodsList,
|
|
|
+ getMarketStatus,
|
|
|
+ rowClick,
|
|
|
+ touristRowClick
|
|
|
+} = useSetup()
|
|
|
+
|
|
|
+const firstBanner = computed(() => {
|
|
|
+ const [firstItem] = banners.value
|
|
|
+ return firstItem ? `--header-bg:url(${getFileUrl(firstItem.imagepath)})` : ''
|
|
|
})
|
|
|
</script>
|
|
|
|