|
|
@@ -61,7 +61,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { shallowRef, computed, onActivated, onDeactivated, ref, onMounted, onUnmounted } from 'vue'
|
|
|
+import { shallowRef, computed, onActivated, onDeactivated, ref } from 'vue'
|
|
|
import moment, { Moment } from 'moment'
|
|
|
import { getServerTime } from '@/services/api/common'
|
|
|
import { handleNumberValue, formatDecimal } from '@/filters'
|
|
|
@@ -134,27 +134,23 @@ if (loginStore.token) {
|
|
|
futuresStore.updateQuotation(item ?? { goodscode })
|
|
|
})
|
|
|
subscribe.start(...subscribeData.value)
|
|
|
-
|
|
|
- const [firstMarket] = touristTradeGoodsList.value
|
|
|
- if (firstMarket) {
|
|
|
- /// 获取市场运行情况
|
|
|
- marketRun({
|
|
|
- marketID: firstMarket.marketid
|
|
|
- })
|
|
|
- }
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const { data: market, run: marketRun } = useRequest(queryMarketRun, {
|
|
|
+const { dataList: marketList, run: marketRun } = useRequest(queryMarketRun, {
|
|
|
manual: true,
|
|
|
- onSuccess: (res) => {
|
|
|
- market.value = res.data[0]
|
|
|
+ onSuccess: () => {
|
|
|
// 每1分钟轮询刷新
|
|
|
timerTask.setTimeout(() => marketRun(), 60 * 1000, 'getMarketRun')
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+const market = computed(() => {
|
|
|
+ const [firstMarket] = touristTradeGoodsList.value
|
|
|
+ return marketList.value.find((e) => e.marketid === firstMarket?.marketid)
|
|
|
+})
|
|
|
+
|
|
|
// 校验服务器时间
|
|
|
const checkServerTime = () => {
|
|
|
getServerTime().then((res) => {
|
|
|
@@ -166,21 +162,25 @@ const checkServerTime = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-onMounted(() => {
|
|
|
+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()
|
|
|
})
|
|
|
|
|
|
-onActivated(() => subscribeData.value.length && subscribe.start(...subscribeData.value))
|
|
|
-onDeactivated(() => subscribe.stop())
|
|
|
-
|
|
|
-onUnmounted(() => {
|
|
|
- timerTask.clearInterval('refreshTime')
|
|
|
- timerTask.clearTimeout('getServerTime')
|
|
|
- timerTask.clearTimeout('getMarketRun')
|
|
|
+onDeactivated(() => {
|
|
|
+ subscribe.stop()
|
|
|
+ clearTimer()
|
|
|
})
|
|
|
</script>
|
|
|
|