Browse Source

🎈 perf: 优化若干内容

Pchen. 9 months ago
parent
commit
440cadee18

+ 6 - 4
src/pages/admin/lepaoRecords/lepaoRecords.vue

@@ -87,9 +87,11 @@
           </a-table-column>
           </a-table-column>
           <a-table-column title="状态" ellipsis tooltip>
           <a-table-column title="状态" ellipsis tooltip>
             <template #cell="{ record }">
             <template #cell="{ record }">
-              <div class="circle one" v-if="record.result.record_failed_reason === '自动确认有效'"></div>
-              <div class="circle else" v-else></div>
-              {{ record.result.record_failed_reason }}
+              <div class="state">
+                <div class="circle one" v-if="record.result.record_failed_reason === '自动确认有效'"></div>
+                <div class="circle else" v-else></div>
+                {{ record.result.record_failed_reason }}
+              </div>
             </template>
             </template>
           </a-table-column>
           </a-table-column>
           <a-table-column title="跑区" :filterable="{
           <a-table-column title="跑区" :filterable="{
@@ -208,7 +210,7 @@ const handlePageSizeChange = (size) => {
 }
 }
 
 
 const stramptoTime = (time) => {
 const stramptoTime = (time) => {
-  return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
+  return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
 }
 }
 
 
 function calculatePace(seconds, kilometers) {
 function calculatePace(seconds, kilometers) {

+ 31 - 5
src/pages/lepao/accountList/index.vue

@@ -229,7 +229,7 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-import { ref, reactive, h } from 'vue'
+import { ref, reactive, onUnmounted, onMounted, h } from 'vue'
 import { accountList, deleteAccount, addAccount, changeAutoRun, singleRun } from '@/api/lepao'
 import { accountList, deleteAccount, addAccount, changeAutoRun, singleRun } from '@/api/lepao'
 import { Modal, Notification, Message } from '@arco-design/web-vue'
 import { Modal, Notification, Message } from '@arco-design/web-vue'
 import { IconSearch } from '@arco-design/web-vue/es/icon'
 import { IconSearch } from '@arco-design/web-vue/es/icon'
@@ -385,7 +385,6 @@ const handleCancel = () => {
 
 
 const getAccounts = async () => {
 const getAccounts = async () => {
   try {
   try {
-    loading.value = true
     const res = await accountList()
     const res = await accountList()
     if (!res || res.code !== 0)
     if (!res || res.code !== 0)
       return Notification.error({
       return Notification.error({
@@ -398,8 +397,6 @@ const getAccounts = async () => {
       title: '获取账号列表失败!',
       title: '获取账号列表失败!',
       content: error.message || '请稍后再试'
       content: error.message || '请稍后再试'
     })
     })
-  } finally {
-    loading.value = false
   }
   }
 }
 }
 
 
@@ -467,7 +464,36 @@ const stramptoTime = (time) => {
   return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
   return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
 }
 }
 
 
-getAccounts()
+let timer = null
+
+// 轮询
+const startPolling = () => {
+    if (!timer) {
+        timer = setInterval(async () => {
+            await getAccounts()
+        }, 5000)
+    }
+}
+
+// 停止轮询
+const stopPolling = () => {
+    if (timer) {
+        clearInterval(timer)
+        timer = null
+    }
+}
+
+onMounted(async () => {
+    loading.value = true
+    await getAccounts()
+    loading.value = false
+    startPolling()
+})
+
+// 组件销毁时停止轮询
+onUnmounted(() => {
+    stopPolling()
+})
 </script>
 </script>
 
 
 <style scoped lang="less">
 <style scoped lang="less">