| | |
| | | </div> |
| | | </section> |
| | | </template> |
| | | |
| | | |
| | | <script setup> |
| | | import { ref, onMounted, onBeforeUnmount } from 'vue'; |
| | | import { useRoute, useRouter } from 'vue-router'; |
| | |
| | | const loading = ref(false); |
| | | const finished = ref(false); |
| | | const category = ref('') |
| | | const sockets = ref(null) |
| | | const pageNo = ref(1); // 初始页码 |
| | | |
| | | onMounted(async () => { |
| | | typName.value = route.query.typName |
| | | tabIndex.value = route.query.tabIndex |
| | | category.value = route.query.category |
| | | |
| | | |
| | | }) |
| | | |
| | | onBeforeUnmount(() => { |
| | | sockets.value && sockets.value.close() |
| | | }) |
| | | |
| | | // 去除字符串中的 % 符号 |
| | | const removePercentSign = (str) => { |
| | | if (typeof str === 'string' && str.includes('%')) { |
| | | return str.replace(/%/g, '') |
| | | } |
| | | return str |
| | | } |
| | | |
| | | const startStocksSocket = () => { |
| | | sockets.value = new WebSocket(`wss://ws.sceazy.com/websocket-server`) |
| | | sockets.value.onmessage = (evt) => { |
| | | const { data } = evt |
| | | const _data = JSON.parse(data) |
| | | |
| | | // 处理 pcp 值,去除 % 符号 |
| | | const pcpValue = removePercentSign(_data.pcp) |
| | | |
| | | let upData = list.value.find(item => item.pid == _data.pid); |
| | | if (upData) { |
| | | upData.changeRatio = pcpValue; |
| | | upData.close = _data.last; |
| | | } |
| | | } |
| | | } |
| | | |
| | | const getRealtimeByType = () => { |
| | | _getRealtimeByType({ |
| | |
| | | if (data.length < 20) { |
| | | finished.value = true |
| | | } |
| | | startStocksSocket() |
| | | |
| | | pageNo.value++ |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | const itemClick = (item) => { |
| | | if (category.value) { |
| | | if(category.value){ |
| | | router.push(`/quotes/usStockDetail?symbol=${item.symbol}&symbolType=${symbolType}&enName=${item.enName}&isMore=1&tabIndex=${tabIndex.value}&typName=${typName.value}&category=${category.value}`) |
| | | } else { |
| | | }else{ |
| | | router.push(`/quotes/usStockDetail?symbol=${item.symbol}&symbolType=${symbolType}&enName=${item.enName}&isMore=1&tabIndex=${tabIndex.value}&typName=${typName.value}`) |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | const onRoute = (path) => { |
| | |
| | | } |
| | | |
| | | const handleBack = () => { |
| | | if (route.query?.tabIndex) { |
| | | if(route.query?.tabIndex){ |
| | | router.push(`/quotes/index?tabActive=${route.query.tabIndex}`) |
| | | } else { |
| | | }else { |
| | | onRoute('/quotes/index?tabActive=4') |
| | | } |
| | | } |