From 6b7a64845eea047f8455596db7d0c36d20870fa5 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 16 Apr 2021 13:07:57 +0800 Subject: [PATCH] =?UTF-8?q?ck=E7=AE=A1=E7=90=86=E6=B7=BB=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E7=8A=B6=E6=80=81=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cookie.ts | 3 ++- src/pages/cookie/index.tsx | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/back/services/cookie.ts b/back/services/cookie.ts index 689e6abc..3c1b73a9 100644 --- a/back/services/cookie.ts +++ b/back/services/cookie.ts @@ -81,10 +81,11 @@ export default class CookieService { public async refreshCookie(_id: string) { const current = await this.get(_id); - const { status } = await this.getJdInfo(current.value); + const { status, nickname } = await this.getJdInfo(current.value); return { ...current, status, + nickname, }; } diff --git a/src/pages/cookie/index.tsx b/src/pages/cookie/index.tsx index 8ace424c..6185472b 100644 --- a/src/pages/cookie/index.tsx +++ b/src/pages/cookie/index.tsx @@ -118,6 +118,12 @@ const Config = () => { ); }, }, + { + title: '昵称', + dataIndex: 'nickname', + key: 'nickname', + align: 'center' as const, + }, { title: '值', dataIndex: 'value', @@ -208,10 +214,23 @@ const Config = () => { .get(`${config.apiPrefix}cookies`) .then((data: any) => { setValue(data.data); + asyncUpdateStatus(data.data); }) .finally(() => setLoading(false)); }; + const asyncUpdateStatus = async (data: any[]) => { + for (let i = 0; i < data.length; i++) { + const cookie = data[i]; + await sleep(1000); + refreshStatus(cookie, i); + } + }; + + const sleep = (time: number) => { + return new Promise((resolve) => setTimeout(resolve, time)); + }; + const refreshStatus = (record: any, index: number) => { request .get(`${config.apiPrefix}cookies/${record._id}/refresh`) @@ -339,6 +358,7 @@ const Config = () => { ...cookie, }); } + refreshStatus(cookie, index); setValue(result); };