feat: 添加store
This commit is contained in:
parent
cbbb48af97
commit
ef50106e5c
@ -9,12 +9,12 @@
|
||||
"dev:kv": "cross-env VITE_USE_KV=true vite",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"prepub": "envision switch root",
|
||||
"pub": "envision deploy ./dist -k center -v 0.0.9 -u -o root",
|
||||
"turbo:dev": "turbo dev:lib",
|
||||
"dev:lib": "turbo dev:lib",
|
||||
"dev:query": "turbo dev:lib --filter=@kevisual/query",
|
||||
"turbo:build": "turbo build --filter=submodules/**"
|
||||
"turbo:build": "turbo build --filter=submodules/**",
|
||||
"build:lib": "turbo build --filter=@kevisual/query**"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^6.0.0",
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { render } from './pages/Bootstrap';
|
||||
import './styles.css';
|
||||
|
||||
render('#ai-root');
|
||||
|
@ -71,5 +71,13 @@
|
||||
"content-type": "Content Type",
|
||||
"app-source": "App Source",
|
||||
"app-version": "App Version",
|
||||
"Detect": "Detect"
|
||||
"Detect": "Detect",
|
||||
"Detect Config Tips": "From the json configuration data of the uploaded [config/1.0.0] path.",
|
||||
"Upload Config": "Upload Config",
|
||||
"Upload Config Tips": "Upload the configuration to the default configuration of the [upload/1.0.0] path, and open the configuration item.",
|
||||
"Workspace Config": "Workspace Config",
|
||||
"Workspace Config Tips": "Set the default workspace, when there is no specific space to open, the default workspace will be opened. The collection information module, the position of the added resource, will be placed here by default. For example, the WeChat public account's essay.",
|
||||
"Add Config Tips": "Add configuration, when the key exists, the data update of the key will be queried first, if the key does not exist, the new configuration will be added.",
|
||||
"VIP Config": "VIP Config",
|
||||
"VIP Config Tips": "VIP Config, only the admin can configure."
|
||||
}
|
@ -71,5 +71,13 @@
|
||||
"content-type": "内容类型",
|
||||
"app-source": "应用来源",
|
||||
"app-version": "应用版本",
|
||||
"Detect": "检测"
|
||||
"Detect": "检测",
|
||||
"Detect Config Tips": "从上传的 [config/1.0.0] 路径的的json的配置的数据同步过来。",
|
||||
"Upload Config": "上传配置",
|
||||
"Upload Config Tips": "上传配置到 [upload/1.0.0] 路径的默认配置,打开配置项。",
|
||||
"Workspace Config": "工作空间配置",
|
||||
"Workspace Config Tips": "设置默认的工作空间,当没有打开具体的空间的时候,默认打开的工作空间。收集信息的模块,添加的资源的位置,默认放到这里。比如,微信公众号的随笔。",
|
||||
"Add Config Tips": "添加配置,当key存在的时候,会优先查询key数据的更新,如果key不存在,则新增配置。",
|
||||
"VIP Config": "VIP配置",
|
||||
"VIP Config Tips": "VIP配置,只有管理员才能配置。"
|
||||
}
|
@ -19,16 +19,16 @@ h3 {
|
||||
@apply text-lg font-bold;
|
||||
}
|
||||
@utility card-subtitle {
|
||||
@apply text-sm text-gray-500;
|
||||
@apply text-sm ;
|
||||
}
|
||||
@utility card-description {
|
||||
@apply text-gray-700 break-words;
|
||||
@apply break-words;
|
||||
}
|
||||
@utility card-code {
|
||||
@apply bg-gray-100 p-2;
|
||||
}
|
||||
@utility card-body {
|
||||
@apply text-gray-700;
|
||||
@apply p-2;
|
||||
}
|
||||
@utility card-key {
|
||||
@apply text-xs;
|
||||
|
@ -18,6 +18,7 @@ import { toast } from 'react-toastify';
|
||||
import { isEmpty, pick } from 'lodash-es';
|
||||
import { usePermissionModal } from '@kevisual/resources/index.ts';
|
||||
import React from 'react';
|
||||
import { queryLogin } from '@/modules';
|
||||
type DataYamlEditProps = {
|
||||
onSave: (data: any) => Promise<void>;
|
||||
type?: 'yaml' | 'json';
|
||||
@ -188,10 +189,15 @@ export const MyController = React.forwardRef(
|
||||
},
|
||||
);
|
||||
export const List = () => {
|
||||
const { list, getConfig, setShowEdit, setFormData, deleteConfig, updateData, formData, detectConfig } = useConfigStore();
|
||||
const { list, getConfigList, setShowEdit, setFormData, deleteConfig, updateData, formData, detectConfig, onOpenKey } = useConfigStore();
|
||||
const [modal, contextHolder] = useModal();
|
||||
const [isAdmin, setIsAdmin] = useState<boolean>(false);
|
||||
useEffect(() => {
|
||||
getConfig();
|
||||
getConfigList();
|
||||
queryLogin.cacheStore.getCurrentUser().then((res) => {
|
||||
const org = res?.orgs || [];
|
||||
setIsAdmin(org.includes('admin'));
|
||||
});
|
||||
}, []);
|
||||
const { setOpen, contextHolder: contextHolderPermission } = usePermissionModal({
|
||||
onSave: async (values) => {
|
||||
@ -206,12 +212,13 @@ export const List = () => {
|
||||
return true;
|
||||
},
|
||||
});
|
||||
console.log(list);
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className='w-full h-full flex bg-gray-100'>
|
||||
<div className='h-full bg-white'>
|
||||
<div className='p-2'>
|
||||
<Tooltip title={t('Add Config Tips')}>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setShowEdit(true);
|
||||
@ -219,12 +226,13 @@ export const List = () => {
|
||||
}}>
|
||||
<Plus size={16} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className=' grow p-4 '>
|
||||
<div className='flex pb-4 gap-4'>
|
||||
<Tooltip title={t('从config的json的配置的数据同步过来。')}>
|
||||
<Tooltip title={t('从上传的[config/1.0.0]路径的的json的配置的数据同步过来。')}>
|
||||
<Button
|
||||
variant='contained'
|
||||
color='primary'
|
||||
@ -235,16 +243,51 @@ export const List = () => {
|
||||
{t('Detect')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('Upload Config Tips')}>
|
||||
<Button
|
||||
variant='contained'
|
||||
color='primary'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
onOpenKey('upload.json');
|
||||
}}>
|
||||
{t('Upload Config')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('Workspace Config Tips')}>
|
||||
<Button
|
||||
variant='contained'
|
||||
color='primary'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
onOpenKey('workspace.json');
|
||||
}}>
|
||||
{t('Workspace Config')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{isAdmin && (
|
||||
<Tooltip title={t('VIP Config Tips')}>
|
||||
<Button
|
||||
variant='contained'
|
||||
color='primary'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
onOpenKey('vip.json');
|
||||
}}>
|
||||
{t('VIP Config')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<div className='w-full bg-white rounded-lg p-2 scrollbar ' style={{ height: 'calc(100% - 80px)' }}>
|
||||
<div className='flex flex-wrap gap-2 '>
|
||||
{list.map((item) => (
|
||||
<div className='card w-[300px] ' key={item.id}>
|
||||
<div className='card-title flex font-bold justify-between'>{item.title}</div>
|
||||
<div className='card-content'>
|
||||
<div className='flex gap-2'>
|
||||
<div>{t('Description')}:</div>
|
||||
<div>{item.description}</div>
|
||||
<div className='t'>
|
||||
<div className='flex gap-2 '>
|
||||
<div className='shrink-0'>{t('Description')}:</div>
|
||||
<div className='break-all grow'>{item.description}</div>
|
||||
</div>
|
||||
<div className='flex gap-2'>
|
||||
<div>{t('Key')}:</div>
|
||||
|
@ -7,7 +7,7 @@ export const queryConfig = new QueryConfig({ query: query as any });
|
||||
|
||||
interface ConfigStore {
|
||||
list: any[];
|
||||
getConfig: () => Promise<void>;
|
||||
getConfigList: () => Promise<void>;
|
||||
updateData: (data: any, opts?: { refresh?: boolean }) => Promise<any>;
|
||||
showEdit: boolean;
|
||||
setShowEdit: (showEdit: boolean) => void;
|
||||
@ -15,11 +15,12 @@ interface ConfigStore {
|
||||
setFormData: (formData: any) => void;
|
||||
deleteConfig: (id: string) => Promise<void>;
|
||||
detectConfig: () => Promise<void>;
|
||||
onOpenKey: (key: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export const useConfigStore = create<ConfigStore>((set, get) => ({
|
||||
list: [],
|
||||
getConfig: async () => {
|
||||
getConfigList: async () => {
|
||||
const res = await queryConfig.listConfig();
|
||||
if (res.code === 200) {
|
||||
set({ list: res.data?.list || [] });
|
||||
@ -30,7 +31,7 @@ export const useConfigStore = create<ConfigStore>((set, get) => ({
|
||||
if (res.code === 200) {
|
||||
get().setFormData(res.data);
|
||||
if (opts?.refresh ?? true) {
|
||||
get().getConfig();
|
||||
get().getConfigList();
|
||||
}
|
||||
toast.success('保存成功');
|
||||
} else {
|
||||
@ -45,7 +46,7 @@ export const useConfigStore = create<ConfigStore>((set, get) => ({
|
||||
deleteConfig: async (id: string) => {
|
||||
const res = await queryConfig.deleteConfig(id);
|
||||
if (res.code === 200) {
|
||||
get().getConfig();
|
||||
get().getConfigList();
|
||||
toast.success('删除成功');
|
||||
} else {
|
||||
toast.error('删除失败');
|
||||
@ -61,4 +62,17 @@ export const useConfigStore = create<ConfigStore>((set, get) => ({
|
||||
toast.error('检测失败');
|
||||
}
|
||||
},
|
||||
onOpenKey: async (key: string) => {
|
||||
const { setFormData, setShowEdit, getConfigList } = get();
|
||||
const res = await queryConfig.getConfigByKey(key);
|
||||
if (res.code === 200) {
|
||||
const data = res.data;
|
||||
setFormData(data);
|
||||
setShowEdit(true);
|
||||
getConfigList();
|
||||
} else {
|
||||
console.log(res);
|
||||
toast.error('获取配置失败');
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9ba45c37c2d642e7ae0a0856a29ba3f3cd61d2c9
|
||||
Subproject commit e0bf83f06293c3bea51f62558ffdf1eb07192249
|
@ -12,6 +12,11 @@
|
||||
"dev:lib": {
|
||||
"persistent": true,
|
||||
"cache": false
|
||||
},
|
||||
"build:lib": {
|
||||
"dependsOn": [
|
||||
"^build:lib"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user