-
Notifications
You must be signed in to change notification settings - Fork 41
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
1 parent
ef74a54
commit 04e2df8
Showing
12 changed files
with
176 additions
and
35 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
import React from 'react'; | ||
import { Form, InputNumber } from '@arco-design/web-react'; | ||
import type { FastifyFormFieldComponent } from 'react-fastify-form'; | ||
import { getValidateStatus } from '../utils'; | ||
|
||
export const FastifyFormNumber: FastifyFormFieldComponent = React.memo( | ||
(props) => { | ||
const { name, label, value, onChange, error, maxLength, placeholder } = | ||
props; | ||
|
||
return ( | ||
<Form.Item | ||
label={label} | ||
validateStatus={getValidateStatus(error)} | ||
help={error} | ||
> | ||
<InputNumber | ||
name={name} | ||
size="large" | ||
maxLength={maxLength} | ||
placeholder={placeholder} | ||
value={value} | ||
onChange={(val) => onChange(val)} | ||
/> | ||
</Form.Item> | ||
); | ||
} | ||
); | ||
FastifyFormNumber.displayName = 'FastifyFormNumber'; |
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,13 @@ | ||
import { request } from '../utils'; | ||
|
||
/** | ||
* 新增/编辑 记录 | ||
*/ | ||
export async function addResource( | ||
resourceName: string, | ||
resourceData: Record<string, any> | ||
): Promise<void> { | ||
await request.put(`/resource/${resourceName}/add`, { | ||
...resourceData, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,29 @@ | ||
import axios from 'axios'; | ||
import { Message } from '@arco-design/web-react'; | ||
import { useRequest } from 'ahooks'; | ||
|
||
export const request = axios.create({ | ||
baseURL: '/admin', | ||
}); | ||
|
||
/** | ||
* 发送修改请求 | ||
*/ | ||
export function useAsyncRequest<T>(fn: () => Promise<T>) { | ||
const { data, error, loading, runAsync } = useRequest( | ||
async () => { | ||
try { | ||
await fn(); | ||
Message.success('操作成功'); | ||
} catch (err) { | ||
console.error(err); | ||
Message.error('操作失败'); | ||
} | ||
}, | ||
{ | ||
manual: true, | ||
} | ||
); | ||
|
||
return [{ data, error, loading }, runAsync] as const; | ||
} |
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
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,20 @@ | ||
/** | ||
* 数据库类型 | ||
* | ||
* 用于在数据库中管理 | ||
*/ | ||
export type ResourcePropertyMetaType = 'string' | 'number' | 'unknown'; | ||
|
||
/** | ||
* 视图类型 | ||
* | ||
* 用于前端展示 | ||
*/ | ||
export type ResourcePropertyMetaViewType = | ||
| 'text' | ||
| 'textarea' | ||
| 'number' | ||
| 'password' | ||
| 'select' | ||
| 'checkbox' | ||
| 'custom'; |
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,22 @@ | ||
import type { | ||
ResourcePropertyMetaType, | ||
ResourcePropertyMetaViewType, | ||
} from './types'; | ||
|
||
/** | ||
* 获取默认视图样式 | ||
* @param metaType 数据库类型 | ||
*/ | ||
export function getDefaultViewType( | ||
metaType: ResourcePropertyMetaType | ||
): ResourcePropertyMetaViewType { | ||
if (metaType === 'string') { | ||
return 'text'; | ||
} | ||
|
||
if (metaType === 'number') { | ||
return 'number'; | ||
} | ||
|
||
return 'text'; | ||
} |