From a93cc66dcf2aa4d4ec30153432a7cf33f0f97612 Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 7 Feb 2024 15:04:57 +0800 Subject: [PATCH] refactor: remove stupid code Signed-off-by: Innei --- src/components/kv-editor/index.tsx | 55 +++++++++---------- .../extra-features/snippets/tabs/for-edit.tsx | 1 + src/views/setting/tabs/user.tsx | 29 +++++----- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/components/kv-editor/index.tsx b/src/components/kv-editor/index.tsx index 68034eda9..d6f21caaf 100644 --- a/src/components/kv-editor/index.tsx +++ b/src/components/kv-editor/index.tsx @@ -27,36 +27,32 @@ export const KVEditor = defineComponent({ const KVArray = ref<{ key: string; value: string }[]>([]) const keySet = ref(new Set()) - - const cleaner = watch( - () => props.value, - (newValue) => { - if (!isEmpty(newValue)) { - const arr = Object.entries(newValue).map(([k, v]) => { - keySet.value.add(k) - return { - key: k, - value: v.toString(), - } - }) - KVArray.value = arr - cleaner() - } - }, - { deep: true }, - ) - + onMounted(() => { + if (!isEmpty(props.value)) { + const arr = Object.entries(props.value).map(([k, v]) => { + keySet.value.add(k) + return { + key: k, + value: v.toString(), + } + }) + KVArray.value = arr + } + }) watch( () => KVArray.value, (newValue) => { - const record = newValue.reduce((acc, cur) => { - // filter empty key value - if (cur.key === '' && cur.value === '') { + const record = newValue.reduce( + (acc, cur) => { + // filter empty key value + if (cur.key === '' && cur.value === '') { + return acc + } + acc[cur.key] = cur.value.toString() return acc - } - acc[cur.key] = cur.value.toString() - return acc - }, {} as { [key: string]: string }) + }, + {} as { [key: string]: string }, + ) props.onChange(record) }, { deep: true }, @@ -89,9 +85,12 @@ export const KVEditor = defineComponent({ }} > {{ - default(rowProps: { index: number; value: typeof KVArray.value[0] }) { + default(rowProps: { + index: number + value: (typeof KVArray.value)[0] + }) { return ( -
+
{props.plainKeyInput ? ( { data.value.secret = kv diff --git a/src/views/setting/tabs/user.tsx b/src/views/setting/tabs/user.tsx index ca1171d5a..343f19ccf 100644 --- a/src/views/setting/tabs/user.tsx +++ b/src/views/setting/tabs/user.tsx @@ -5,7 +5,6 @@ import { RelativeTime } from 'components/time/relative-time' import { UploadWrapper } from 'components/upload' import { socialKeyMap } from 'constants/social' import { cloneDeep, isEmpty } from 'lodash-es' -import type { UserModel } from 'models/user' import { NButton, NForm, @@ -17,8 +16,9 @@ import { NUploadDragger, useMessage, } from 'naive-ui' -import { RESTManager, deepDiff } from 'utils' +import { deepDiff, RESTManager } from 'utils' import { computed, defineComponent, onMounted, ref } from 'vue' +import type { UserModel } from 'models/user' import styles from './user.module.css' @@ -62,7 +62,7 @@ export const TabUser = defineComponent(() => { yGap={20} > - +
{ -
+
{data.value.lastLoginTime ? ( { -
+
{data.value.lastLoginIp ? ( { - { - return { label: key, value: socialKeyMap[key] } - })} - onChange={(newValue) => { - data.value.socialIds = newValue - }} - value={data.value.socialIds || {}} - > + { + return { label: key, value: socialKeyMap[key] } + })} + onChange={(newValue) => { + data.value.socialIds = newValue + }} + value={data.value.socialIds || {}} + >