refactor(frontend):优化股票排序

- 在 stock.vue 中引入 lodash 的 keys 和 pad 函数
-优化排序逻辑,使用 lodash 的 keys 函数替代 Object.keys
-移除不必要的 padZero 函数,简化 GetSortKey 的实现
- 在 package.json 中添加 lodash 依赖
This commit is contained in:
ArvinLovegood 2025-04-01 14:00:46 +08:00
parent 7af3fe72d5
commit 63e898bef8
5 changed files with 14 additions and 13 deletions

View File

@ -14,6 +14,7 @@
"@vicons/ionicons5": "^0.13.0",
"file-saver": "^2.0.5",
"html2canvas": "^1.4.1",
"lodash": "^4.17.21",
"md-editor-v3": "^5.2.3",
"vue": "^3.2.25",
"vue-router": "^4.5.0",
@ -1758,8 +1759,7 @@
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash-es": {
"version": "4.17.21",

View File

@ -15,6 +15,7 @@
"@vicons/ionicons5": "^0.13.0",
"file-saver": "^2.0.5",
"html2canvas": "^1.4.1",
"lodash": "^4.17.21",
"md-editor-v3": "^5.2.3",
"vue": "^3.2.25",
"vue-router": "^4.5.0",

View File

@ -1 +1 @@
2091cce83d29f564a50e85f1667b2f4c
cf858d682535e094e087a036e009d7f8

View File

@ -46,6 +46,7 @@ import html2canvas from "html2canvas";
import {asBlob} from 'html-docx-js-typescript';
import vueDanmaku from 'vue3-danmaku'
import {keys, pad} from "lodash";
const danmus = ref([])
const ws = ref(null)
@ -116,7 +117,8 @@ const icon = ref('https://raw.githubusercontent.com/ArvinLovegood/go-stock/maste
const sortedResults = computed(() => {
//console.log("computed",sortedResults.value)
const sortedKeys =Object.keys(results.value).sort();
const sortedKeys =keys(results.value).sort();
//console.log("sortedKeys",sortedKeys)
const sortedObject = {};
sortedKeys.forEach(key => {
sortedObject[key] = results.value[key];
@ -141,7 +143,7 @@ onBeforeMount(()=>{
followedStock.StockCode="gb_"+ followedStock.StockCode.replace("us", "").toLowerCase()
}
if (!stocks.value.includes(followedStock.StockCode)) {
console.log("followList",followedStock.StockCode)
//console.log("followList",followedStock.StockCode)
stocks.value.push(followedStock.StockCode)
}
}
@ -395,6 +397,7 @@ function removeMonitor(code,name,key) {
})
}
function SendDanmu(){
//danmus.value.push(data.name)
console.log("SendDanmu",data.name)
@ -491,7 +494,8 @@ async function updateData(result) {
}
}
result.key=GetSortKey(result.sort,result["股票代码"])
result.key=result.sort
//result.key=GetSortKey(result.sort,result[""])
results.value[GetSortKey(result.sort,result["股票代码"])]=result
}
@ -505,13 +509,11 @@ async function monitor() {
}
}
//0
function padZero(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
function GetSortKey(sort,code){
return padZero(sort,6)+"_"+code
//let sortKey= pad(sort,6,'0')+"_"+code
//console.log("GetSortKey:",sortKey)
return sort
}
function onSelect(item) {

View File

@ -3,9 +3,7 @@ import naive from 'naive-ui'
import App from './App.vue'
import router from './router/router'
const app = createApp(App)
app.use(router)
app.use(naive)
app.mount('#app')