-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/admin/src/components/EditorProfileModal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ModalForm, ProFormSelect } from '@ant-design/pro-form'; | ||
import { Alert, message } from 'antd'; | ||
export default function (props: { setValue: any; value: any; trigger: any }) { | ||
const { setValue, value, trigger } = props; | ||
return ( | ||
<ModalForm | ||
title="编辑器偏好设置" | ||
trigger={trigger} | ||
width={450} | ||
autoFocusFirstInput | ||
submitTimeout={3000} | ||
initialValues={value || {}} | ||
onFinish={async (vals) => { | ||
setValue({ ...value, ...vals }); | ||
message.success('保存成功!'); | ||
return true; | ||
}} | ||
layout="horizontal" | ||
labelCol={{ span: 6 }} | ||
key="editForm" | ||
> | ||
<Alert | ||
type="info" | ||
message="此配置保存在浏览器存储中,切换设备需重新设置。" | ||
style={{ marginBottom: 8 }} | ||
></Alert> | ||
|
||
<ProFormSelect | ||
width="md" | ||
required | ||
id="afterSave" | ||
name="afterSave" | ||
label="保存后行为" | ||
placeholder="请选择保存后行为,默认留在此页面" | ||
request={async () => { | ||
return [ | ||
{ | ||
label: '留在此页', | ||
value: 'stay', | ||
}, | ||
{ | ||
label: '返回之前页面', | ||
value: 'goBack', | ||
}, | ||
]; | ||
}} | ||
/> | ||
</ModalForm> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useState } from 'react'; | ||
export const useCacheState = (init, key) => { | ||
const k = `vanblog-admin-${key}`; | ||
const [currValue, setCuttValue] = useState(JSON.parse(localStorage.getItem(k)) || init); | ||
return [ | ||
currValue, | ||
(newValue) => { | ||
localStorage.setItem(k, JSON.stringify(newValue)); | ||
setCuttValue(newValue); | ||
}, | ||
]; | ||
}; |