navigate('/build/skills')}>
+
navigate('/build/skills',{state:state})}>
返 回
{/*
{t('skills.skillTemplateManagement')}
*/}
diff --git a/src/pages/SystemPage/components/EditRole copy.tsx b/src/pages/SystemPage/components/EditRole copy.tsx
new file mode 100644
index 0000000..43bae3d
--- /dev/null
+++ b/src/pages/SystemPage/components/EditRole copy.tsx
@@ -0,0 +1,225 @@
+import { Search } from "lucide-react";
+import { useContext, useEffect, useRef, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Button } from "../../../components/ui/button";
+import { Input } from "../../../components/ui/input";
+import { Switch } from "../../../components/ui/switch";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow
+} from "../../../components/ui/table";
+import { alertContext } from "../../../contexts/alertContext";
+import { createRole, getRoleAssistApi, getRoleLibsApi, getRolePermissionsApi, getRoleSkillsApi, updateRoleNameApi, updateRolePermissionsApi } from "../../../controllers/API/user";
+import { useDebounce } from "../../../util/hook";
+import { captureAndAlertRequestErrorHoc } from "../../../controllers/request";
+
+const pageSize = 10
+const SearchPanne = ({ title, total, onChange, children }) => {
+ const [page, setPage] = useState(1)
+ const pageCount = Math.ceil(total / pageSize)
+ const searchKeyRef = useRef('')
+ const { t } = useTranslation()
+
+ const handleSearch = useDebounce((e) => {
+ searchKeyRef.current = e.target.value
+ setPage(1)
+ onChange(1, searchKeyRef.current)
+ }, 500, false)
+
+ const loadPage = (page) => {
+ setPage(page)
+ onChange(page, searchKeyRef.current)
+ }
+
+ return <>
+
+
+ {children}
+
+
+
+
+
+ >
+
+}
+
+
+// -1 id表示新增
+export default function EditRole({ id, name, onChange, onBeforeChange }) {
+ const { setErrorData, setSuccessData } = useContext(alertContext);
+ const { t } = useTranslation()
+
+ const [form, setForm] = useState({
+ name,
+ useSkills: [],
+ useLibs: [],
+ manageLibs: []
+ })
+ useEffect(() => {
+ if (id !== -1) {
+ // 获取详情
+ getRolePermissionsApi(id).then(res => {
+ const useSkills = [], useLibs = [], manageLibs = []
+ res.data.forEach(item => {
+ switch (item.type) {
+ case 1: useLibs.push(Number(item.third_id)); break;
+ case 2: useSkills.push(item.third_id); break;
+ case 3: manageLibs.push(Number(item.third_id)); break;
+ }
+ })
+ setForm({ name, useSkills, useLibs, manageLibs })
+ })
+ }
+ }, [id])
+
+ const switchDataChange = (id, key, checked) => {
+ const index = form[key].findIndex(el => el === id)
+ checked && index === -1 && form[key].push(id)
+ !checked && index !== -1 && form[key].splice(index, 1)
+ setForm({ ...form, [key]: form[key] })
+ }
+
+ // 知识库管理权限switch
+ const switchLibManage = (id, checked) => {
+ switchDataChange(id, 'manageLibs', checked)
+ if (checked) switchDataChange(id, 'useLibs', checked)
+ }
+ // 知识库使用权限switch
+ const switchUseLib = (id, checked) => {
+ if (!checked && form.manageLibs.includes(id)) return
+ switchDataChange(id, 'useLibs', checked)
+ }
+
+ const { data: skillData, change: handleSkillChange } = usePageData
(id, 'skill')
+ const { data: libData, change: handleLibChange } = usePageData(id, 'lib')
+
+ const handleSave = async () => {
+ if (!form.name.length || form.name.length > 50) {
+ return setErrorData({
+ title: t('prompt'),
+ list: [t('system.roleNameRequired'), t('system.roleNamePrompt')],
+ });
+ }
+ if (onBeforeChange(form.name)) {
+ return setErrorData({
+ title: t('prompt'),
+ list: [t('system.roleNameExists')]
+ })
+ }
+ // 新增先创建角色
+ let roleId = id
+ if (id === -1) {
+ const res = await captureAndAlertRequestErrorHoc(createRole(form.name))
+ roleId = res.id
+ } else {
+ // 更新基本信息
+ captureAndAlertRequestErrorHoc(updateRoleNameApi(roleId, form.name))
+ }
+ // 更新角色权限
+ const res = await Promise.all([
+ updateRolePermissionsApi({ role_id: roleId, access_id: form.useSkills, type: 2 }),
+ updateRolePermissionsApi({ role_id: roleId, access_id: form.useLibs, type: 1 }),
+ updateRolePermissionsApi({ role_id: roleId, access_id: form.manageLibs, type: 3 })
+ ])
+
+ console.log('form :>> ', form, res);
+ setSuccessData({ title: t('success') })
+ onChange(true)
+ }
+
+ return
+
+
{t('system.roleName')}
+
setForm({ ...form, name: e.target.value })} maxLength={60}>
+
+
+
+
+
+
+ {t('system.skillName')}
+ {t('system.creator')}
+ {t('system.usePermission')}
+
+
+
+ {skillData.data.map((el) => (
+
+ {el.name}
+ {el.user_name}
+
+ switchDataChange(el.id, 'useSkills', bln)} />
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+ {t('system.skillName')}
+ {t('system.creator')}
+ {t('system.usePermission')}
+ {t('system.managePermission')}
+
+
+
+ {libData.data.map((el) => (
+
+ {el.name}
+ {el.user_name}
+
+ switchUseLib(el.id, bln)} />
+
+
+ switchLibManage(el.id, bln)} />
+
+
+ ))}
+
+
+
+
+
+
+
+
+
+}
+
+const usePageData = (id: number, key: 'skill' | 'lib') => {
+ const [data, setData] = useState<{ data: T[], total: number }>({ data: [], total: 0 })
+
+ useEffect(() => {
+ loadData()
+ }, [])
+
+ const loadData = async (page = 1, keyword = '') => {
+ const param = {
+ name: keyword,
+ role_id: id === -1 ? 0 : id,
+ page_num: page,
+ page_size: pageSize
+ }
+ const data = key === 'skill' ? await getRoleSkillsApi(param) : await getRoleLibsApi(param)
+ setData(data)
+ }
+
+ return {
+ data,
+ change: loadData
+ }
+}
\ No newline at end of file
diff --git a/src/pages/SystemPage/components/EditRole.tsx b/src/pages/SystemPage/components/EditRole.tsx
index f9ef7b7..eb527e2 100644
--- a/src/pages/SystemPage/components/EditRole.tsx
+++ b/src/pages/SystemPage/components/EditRole.tsx
@@ -1,8 +1,8 @@
-import { Search } from "lucide-react";
-import { useContext, useEffect, useRef, useState } from "react";
+import { useContext, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
-import { Button } from "../../../components/ui/button";
-import { Input } from "../../../components/ui/input";
+import { Button } from "../../../components/bs-ui/button";
+import { Input, SearchInput } from "../../../components/bs-ui/input";
+import AutoPagination from "../../../components/bs-ui/pagination/autoPagination";
import { Switch } from "../../../components/ui/switch";
import {
Table,
@@ -11,45 +11,40 @@ import {
TableHead,
TableHeader,
TableRow
-} from "../../../components/ui/table";
+} from "../../../components/bs-ui/table";
import { alertContext } from "../../../contexts/alertContext";
-import { createRole, getRoleLibsApi, getRolePermissionsApi, getRoleSkillsApi, updateRoleNameApi, updateRolePermissionsApi } from "../../../controllers/API/user";
-import { useDebounce } from "../../../util/hook";
+import { createRole, getRoleAssistApi, getRoleLibsApi, getRolePermissionsApi, getRoleSkillsApi, updateRoleNameApi, updateRolePermissionsApi } from "../../../controllers/API/user";
import { captureAndAlertRequestErrorHoc } from "../../../controllers/request";
+import { useTable } from "../../../util/hook";
-const pageSize = 10
-const SearchPanne = ({ title, total, onChange, children }) => {
- const [page, setPage] = useState(1)
- const pageCount = Math.ceil(total / pageSize)
- const searchKeyRef = useRef('')
- const { t } = useTranslation()
-
- const handleSearch = useDebounce((e) => {
- searchKeyRef.current = e.target.value
- setPage(1)
- onChange(1, searchKeyRef.current)
- }, 500, false)
-
- const loadPage = (page) => {
- setPage(page)
- onChange(page, searchKeyRef.current)
- }
+const SearchPanne = ({ role_id, title, type, children }) => {
+ const { page, pageSize, data, total, loading, setPage, search } = useTable({ pageSize: 10 }, (params) => {
+ const { page, pageSize, keyword } = params
+ const param = {
+ name: keyword,
+ role_id,
+ page_num: page,
+ page_size: pageSize
+ }
+ return type === 'skill' ? getRoleSkillsApi(param)
+ : (type === 'assistant' ? getRoleAssistApi({ ...param, type: 'assistant' })
+ : getRoleLibsApi(param))
+ })
return <>
-
{title}
-
-
+
{title}
+
search(e.target.value)}>
- {children}
-
-
-
-
+ {loading ?
+
+
+
+ : children(data)}
+
>
-
}
@@ -62,21 +57,23 @@ export default function EditRole({ id, name, onChange, onBeforeChange }) {
name,
useSkills: [],
useLibs: [],
+ useAssistant: [],
manageLibs: []
})
useEffect(() => {
if (id !== -1) {
- // 获取详情
+ // 获取详情,初始化选中数据
getRolePermissionsApi(id).then(res => {
- const useSkills = [], useLibs = [], manageLibs = []
+ const useSkills = [], useLibs = [], manageLibs = [], useAssistant = []
res.data.forEach(item => {
switch (item.type) {
case 1: useLibs.push(Number(item.third_id)); break;
case 2: useSkills.push(item.third_id); break;
case 3: manageLibs.push(Number(item.third_id)); break;
+ case 5: useAssistant.push(item.third_id); break;
}
})
- setForm({ name, useSkills, useLibs, manageLibs })
+ setForm({ name, useSkills, useLibs, useAssistant, manageLibs })
})
}
}, [id])
@@ -98,10 +95,14 @@ export default function EditRole({ id, name, onChange, onBeforeChange }) {
if (!checked && form.manageLibs.includes(id)) return
switchDataChange(id, 'useLibs', checked)
}
-
- const { data: skillData, change: handleSkillChange } = usePageData(id, 'skill')
- const { data: libData, change: handleLibChange } = usePageData(id, 'lib')
-
+ /**
+ * 保存权限信息
+ * 1.验证重名
+ * 2.新增时先保存基本信息 创建 ID
+ * 3.修改时先更新基本信息
+ * 4.批量 保存各个种类权限信息(助手、技能、知识库等)
+ * @returns
+ */
const handleSave = async () => {
if (!form.name.length || form.name.length > 50) {
return setErrorData({
@@ -115,7 +116,7 @@ export default function EditRole({ id, name, onChange, onBeforeChange }) {
list: [t('system.roleNameExists')]
})
}
- // 新增先创建角色
+ // 没有id时需要走创建流程,否则修改
let roleId = id
if (id === -1) {
const res = await captureAndAlertRequestErrorHoc(createRole(form.name))
@@ -128,7 +129,8 @@ export default function EditRole({ id, name, onChange, onBeforeChange }) {
const res = await Promise.all([
updateRolePermissionsApi({ role_id: roleId, access_id: form.useSkills, type: 2 }),
updateRolePermissionsApi({ role_id: roleId, access_id: form.useLibs, type: 1 }),
- updateRolePermissionsApi({ role_id: roleId, access_id: form.manageLibs, type: 3 })
+ updateRolePermissionsApi({ role_id: roleId, access_id: form.manageLibs, type: 3 }),
+ updateRolePermissionsApi({ role_id: roleId, access_id: form.useAssistant, type: 5 })
])
console.log('form :>> ', form, res);
@@ -136,90 +138,101 @@ export default function EditRole({ id, name, onChange, onBeforeChange }) {
onChange(true)
}
- return
+ const roleId = id === -1 ? 0 : id
+
+ return
+ {/* 助手 */}
-
-
-
-
- {t('system.skillName')}
- {t('system.creator')}
- {t('system.usePermission')}
-
-
-
- {skillData.data.map((el) => (
-
- {el.name}
- {el.user_name}
-
- switchDataChange(el.id, 'useSkills', bln)} />
-
+
+ {(data) => (
+
+
+
+ NPC名称
+ {t('system.creator')}
+ {t('system.usePermission')}
- ))}
-
-
+
+
+ {data.map((el) => (
+
+ {el.name}
+ {el.user_name}
+
+ switchDataChange(el.id, 'useAssistant', bln)} />
+
+
+ ))}
+
+
+ )}
+ {/* 技能 */}
-
-
-
-
- {t('system.skillName')}
- {t('system.creator')}
- {t('system.usePermission')}
- {t('system.managePermission')}
-
-
-
- {libData.data.map((el) => (
-
- {el.name}
- {el.user_name}
-
- switchUseLib(el.id, bln)} />
-
-
- switchLibManage(el.id, bln)} />
-
+
+ {(data) => (
+
+
+
+ {t('system.skillName')}
+ {t('system.creator')}
+ {t('system.usePermission')}
- ))}
-
-
+
+
+ {data.map((el) => (
+
+ {el.name}
+ {el.user_name}
+
+ switchDataChange(el.id, 'useSkills', bln)} />
+
+
+ ))}
+
+
+ )}
+
+
+ {/* 知识库 */}
+
+
+ {(data) => (
+
+
+
+ {t('lib.libraryName')}
+ {t('system.creator')}
+ {t('system.usePermission')}
+ {t('system.managePermission')}
+
+
+
+ {data.map((el) => (
+
+ {el.name}
+ {el.user_name}
+
+ switchUseLib(el.id, bln)} />
+
+
+ switchLibManage(el.id, bln)} />
+
+
+ ))}
+
+
+ )}
-
+
-}
-
-const usePageData =
(id: number, key: 'skill' | 'lib') => {
- const [data, setData] = useState<{ data: T[], total: number }>({ data: [], total: 0 })
-
- useEffect(() => {
- loadData()
- }, [])
-
- const loadData = async (page = 1, keyword = '') => {
- const param = {
- name: keyword,
- role_id: id === -1 ? 0 : id,
- page_num: page,
- page_size: pageSize
- }
- const data = key === 'skill' ? await getRoleSkillsApi(param) : await getRoleLibsApi(param)
- setData(data)
- }
-
- return {
- data,
- change: loadData
- }
}
\ No newline at end of file
diff --git a/src/pages/SystemPage/components/Roles.tsx b/src/pages/SystemPage/components/Roles.tsx
index 7a2567a..42db983 100644
--- a/src/pages/SystemPage/components/Roles.tsx
+++ b/src/pages/SystemPage/components/Roles.tsx
@@ -90,7 +90,7 @@ export default function Roles() {
{el.role_name}
{el.create_time.replace('T', ' ')}
-
+
diff --git a/src/style/applies.css b/src/style/applies.css
index 15adee9..0f08565 100644
--- a/src/style/applies.css
+++ b/src/style/applies.css
@@ -207,7 +207,7 @@
@apply focus:placeholder-transparent focus:ring-ring focus:border-ring
}
.input-primary {
- @apply bg-background block border-border form-input px-3 placeholder:text-muted-foreground rounded-md shadow-sm sm:text-sm truncate w-full;
+ @apply bg-background block border-border form-input px-3 placeholder:text-[#999] rounded-md shadow-sm sm:text-sm truncate w-full;
}
.input-edit-node{
diff --git a/src/style/zk.scss b/src/style/zk.scss
index 0d98392..2ba65db 100644
--- a/src/style/zk.scss
+++ b/src/style/zk.scss
@@ -204,6 +204,9 @@
width: 100%!important;
height: 100%;
}
+ .chata{
+ height: 96vh!important;
+ }
}
.chatShareM{
.duihua-chat{
@@ -3180,7 +3183,7 @@
justify-content: center;
background: #0D0D0D!important;
cursor: pointer;
- z-index: 1;
+ z-index: 10;
>span{
font-family: PingFang SC;
font-weight: 400;
@@ -3216,12 +3219,16 @@
background: #1A1A1A;
border-radius: 7px;
margin: 7px;
+ position: relative;
cursor: pointer;
.npcInfoItemBg{
- position: relative;
+ position: absolute;
overflow: hidden;
+ width: 100%;
height: 64px;
- margin-bottom: -56px;
+ top: 0;
+ left: 0;
+ // margin-bottom: -56px;
background: rgba(0, 0, 0, 0.06);
-webkit-mask-image: linear-gradient(to bottom, #fff, transparent);
mask-image: linear-gradient(to bottom, #fff, transparent);
@@ -3240,6 +3247,7 @@
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
+ z-index: -1;
>span{
width: 180px;
height: 180px;
@@ -3312,6 +3320,7 @@
}
>div:nth-of-type(2){
margin-right: 14px;
+ z-index: 1000;
}
}
>p{
@@ -4176,4 +4185,33 @@
}
.input-dialog{
color: #999999;
+ }
+ .daimaStyle{
+ background: rgba(255, 255, 255, 0.05);
+ border-radius: 14px!important;
+ border: none;
+ overflow: hidden;
+ margin: 6px 0;
+ &:focus{
+ // border: 1px solid #997e1f!important;
+ border: none!important;
+ outline: none!important;
+ }
+ .code-block-modal{
+ background: rgba(255, 213, 76, 0.04);
+ }
+ .overflow-auto{
+ background: rgba(255, 255, 255, 0.05)!important;
+ background-color: rgba(255, 255, 255, 0.05)!important;
+
+ .language-sql{
+ background-color: rgba(255, 255, 255, 0.00)!important;
+ // background: rgba(255, 255, 255, 0.05)!important;
+ // background: none;
+ span{
+ background: none;
+ // background: rgba(255, 255, 255, 0.05)!important;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/util/hook.ts b/src/util/hook.ts
index f431cd1..d7ca84c 100644
--- a/src/util/hook.ts
+++ b/src/util/hook.ts
@@ -71,7 +71,7 @@ export function useTable(param, apiFun) {
const requestIdRef = useRef(0); // 控制请求响应顺序
const loadData = () => {
- setLoading(true);
+ // setLoading(true);
const requestId = ++requestIdRef.current
apiFun({ ...page, ...paramRef.current }).then(res => {
if (requestId !== requestIdRef.current) return
@@ -79,9 +79,9 @@ export function useTable(param, apiFun) {
// res.data.unshift({type:0})
setData(res.data);
setTotal(res.total);
- setLoading(false);
+ // setLoading(false);
}).catch(() => {
- setLoading(false);
+ // setLoading(false);
})
}
const debounceLoad = useDebounce(loadData, 600, false)