Commit d5ea7570 by Lin

feat: 知识管理表单编辑接口联调/交互样式修改

1 parent d47fc120
import { gscPost} from '@/utils/gscRequest';
/**
* 质检规则列表查询
*/
export async function inspectionRuleList(data: any) {
try {
const response = await gscPost('/inspectionRule/findPageInspectionRule', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检规则新增
*/
export async function addInspectionRule(data: any) {
try {
const response = await gscPost('/inspectionRule/addInspectionRule', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检规则列表修改
*/
export async function updateInspectionRule(data: any) {
try {
const response = await gscPost('/inspectionRule/updateInspectionRule', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检规则列表删除
*/
export async function deleteInspectionRule(data: any) {
try {
const response = await gscPost('/inspectionRule/deleteInspectionRule', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检模版列表查询
*/
export async function inspectionTemplateList(data: any) {
try {
const response = await gscPost('/inspectionTemplate/findPageInspectionTemplate', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检模版新增
*/
export async function saveInspectionTemplate(data: any) {
try {
const response = await gscPost('/inspectionTemplate/saveInspectionTemplate', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检模版修改
*/
export async function updateInspectionTemplate(data: any) {
try {
const response = await gscPost('/inspectionTemplate/updateInspectionTemplate', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 质检模版删除
*/
export async function deleteInspectionTemplate(data: any) {
try {
const response = await gscPost('/inspectionTemplate/deleteInspectionTemplate', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 培训智能体列表查询
*/
export async function trainingPlanList(data: any) {
try {
const response = await gscPost('/trainingPlan/findPageTrainingPlan', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 培训智能体新增
*/
export async function addTrainingPlan(data: any) {
try {
const response = await gscPost('/trainingPlan/addTrainingPlan', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 培训智能体修改
*/
export async function updateTrainingPlan(data: any) {
try {
const response = await gscPost('/trainingPlan/updateTrainingPlan', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 培训智能体删除
*/
export async function deleteTrainingPlan(data: any) {
try {
const response = await gscPost('/trainingPlan/deleteTrainingPlan', data);
return response;
} catch (error) {
throw error;
}
}
/**
* 培训智能体详情
*/
export async function ftrainingPlanDetail(data: any) {
try {
const response = await gscPost(`/trainingPlan/findTrainingPlanDetail/${data.planId}`, data);
return response;
} catch (error) {
throw error;
}
}
...@@ -66,7 +66,7 @@ export async function findPageKnowledgeMaterial(data: any) { ...@@ -66,7 +66,7 @@ export async function findPageKnowledgeMaterial(data: any) {
*/ */
export async function updateKnowledgeMaterial(data: any) { export async function updateKnowledgeMaterial(data: any) {
try { try {
const response = await gscPost('/knowledgeMaterial/updateKnowledgeMaterial', data); const response = await gscPost('/knowledgeMaterial/updateKnowledgeMaterial', data, { returnAll:true });
return response; return response;
} catch (error) { } catch (error) {
throw error; throw error;
......
...@@ -48,8 +48,27 @@ ...@@ -48,8 +48,27 @@
</el-upload> </el-upload>
</div> </div>
<div class="grid grid-cols-2 gap-12" v-else> <div class="grid grid-cols-2 gap-12" v-else>
<div class="w-[376px] h-[120px] rounded-[5px] opacity-100 border border-[#e1e3e6] bg-[#f5f7fa]"></div> <div class="w-[376px] h-[120px] rounded-[5px] opacity-100 border border-[#e1e3e6] bg-[#f5f7fa] p-[16px] flex flex-col gap-3" >
<div class="w-[376px] h-[120px] rounded-[5px] opacity-100 border border-[#e1e3e6] bg-[#f5f7fa]"></div> <div>
<div class="flex items-start gap-2">
<el-icon class="text-[#00AD74] text-[16px] pt-[4px]"><CircleCheckFilled /></el-icon>
<!-- <el-icon class="text-[#EB2F2F] text-[16px] pt-[4px]"><WarningFilled /></el-icon> -->
<div class="text-[14px] text-[#565D6B] font-normal truncate leading-5">文件名称文件名称文件名称.pdf</div>
</div>
<div class="text-[12px] text-[#969AA3]">文件大小: 10M</div>
<!-- <div class="text-[12px] text-[#EB2F2F]">文件格式有误,请重新上传</div> -->
</div>
<div class="flex items-center gap-6 text-[12px] mt-2">
<div class="flex items-center gap-1 cursor-pointer text-[#1956FE] text-xs transition-colors" @click="handleReSelect">
<el-icon><Edit /></el-icon>
<span>重新选择</span>
</div>
<div class="flex items-center gap-1 cursor-pointer text-[#1956FE] text-xs transition-colors" @click="handleFileRemove(formData.files[0], formData.files)">
<el-icon><Delete /></el-icon>
<span>删除</span>
</div>
</div>
</div>
</div> </div>
</el-form-item> </el-form-item>
...@@ -61,6 +80,7 @@ ...@@ -61,6 +80,7 @@
<el-input <el-input
v-model="formData.name" v-model="formData.name"
placeholder="请输入" placeholder="请输入"
maxlength="20"
class="custom-form-input" class="custom-form-input"
/> />
</el-form-item> </el-form-item>
...@@ -89,17 +109,17 @@ ...@@ -89,17 +109,17 @@
<div class="flex h-[450px] w-full rounded-md"> <div class="flex h-[450px] w-full rounded-md">
<!-- 左侧:组织架构树 --> <!-- 左侧:组织架构树 -->
<div class="w-3/5 border border-gray-200 rounded-md flex flex-col mr-[16px]"> <div class="w-3/5 rounded-md flex flex-col mr-[16px]">
<div class="bg-gray-50 px-4 py-2 text-sm text-gray-600 flex justify-between items-center border-b border-gray-100"> <div class="bg-gray-50 px-4 py-2 text-sm text-gray-600 flex justify-between items-center">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<!-- 使用模拟的全选框外观,实际逻辑需根据业务绑定 --> <!-- 使用模拟的全选框外观,实际逻辑需根据业务绑定 -->
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange" /> <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange" />
<span>组织架构</span> <span>组织架构</span>
</div> </div>
<span class="text-gray-400 text-xs">共 50 项</span> <span class="text-gray-400 text-xs">共 {{ totalNodeCount }} 项</span>
</div> </div>
<div class="flex-1 overflow-y-auto p-2 custom-scrollbar"> <div class="flex-1 overflow-auto p-2 custom-scrollbar">
<el-tree <el-tree
ref="treeRef" ref="treeRef"
:data="treeData" :data="treeData"
...@@ -114,10 +134,11 @@ ...@@ -114,10 +134,11 @@
</div> </div>
<!-- 右侧:已选列表 --> <!-- 右侧:已选列表 -->
<div class="w-2/5 border border-gray-200 rounded-md flex flex-col bg-white"> <div class="w-2/5 rounded-md flex flex-col bg-white">
<div class="bg-gray-50 px-4 py-2 text-sm text-gray-600 flex justify-between items-center border-b border-gray-100 h-[41px]"> <div class="bg-gray-50 px-4 py-2 text-sm text-gray-600 flex justify-between items-center h-[41px]">
<span>已选 · {{ selectedNodes.length }}</span> <span>已选 · {{ selectedNodes.length }}</span>
<button <button
type="button"
@click="clearSelection" @click="clearSelection"
class="text-blue-500 hover:text-blue-600 text-sm cursor-pointer" class="text-blue-500 hover:text-blue-600 text-sm cursor-pointer"
> >
...@@ -140,13 +161,13 @@ ...@@ -140,13 +161,13 @@
<div <div
v-for="node in selectedNodes" v-for="node in selectedNodes"
:key="node.id" :key="node.id"
class="flex justify-between items-center px-3 py-2 rounded group hover:bg-[#F7F8F9] transition" class="flex justify-between items-center px-3 py-2 rounded group transition"
> >
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="text-sm text-gray-700">{{ getNodeDisplayText(node) }}</span> <span class="text-sm text-gray-700">{{ getNodeDisplayText(node) }}</span>
</div> </div>
<el-icon <el-icon
class="cursor-pointer text-gray-400 hover:text-red-500 opacity-0 group-hover:opacity-100 transition" class="cursor-pointer text-gray-400 opacity-0 group-hover:opacity-100 transition"
@click="removeNode(node)" @click="removeNode(node)"
> >
<Close /> <Close />
...@@ -182,11 +203,11 @@ ...@@ -182,11 +203,11 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, watch, onMounted } from 'vue'; import { ref, reactive, watch, onMounted, computed, nextTick, toRaw } from 'vue';
import { Close, UploadFilled, Folder } from '@element-plus/icons-vue'; import { Close, UploadFilled, Folder, CircleCheckFilled, Edit, Delete, WarningFilled } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { findCategoryList } from '@/api/knowledge'; import { findCategoryList, updateKnowledgeMaterial } from '@/api/knowledge';
import { findDeptTree } from '@/api/dept';
// 定义 props // 定义 props
const props = defineProps({ const props = defineProps({
// 是否为独立页面模式(全屏显示),false 时为组件模式(在 drawer 中使用) // 是否为独立页面模式(全屏显示),false 时为组件模式(在 drawer 中使用)
...@@ -202,7 +223,7 @@ const props = defineProps({ ...@@ -202,7 +223,7 @@ const props = defineProps({
}); });
// 定义 emits // 定义 emits
const emit = defineEmits(['close']); const emit = defineEmits(['close', 'refresh']);
// --- Form Data --- // --- Form Data ---
const formRef = ref(null); const formRef = ref(null);
...@@ -229,7 +250,6 @@ const getCategoryList = async () => { ...@@ -229,7 +250,6 @@ const getCategoryList = async () => {
})); }));
} }
} catch (error) { } catch (error) {
console.error('获取分类列表失败:', error);
ElMessage.error('获取分类列表失败'); ElMessage.error('获取分类列表失败');
} }
}; };
...@@ -244,16 +264,171 @@ const handleFileRemove = (file, fileList) => { ...@@ -244,16 +264,171 @@ const handleFileRemove = (file, fileList) => {
formData.files = fileList; formData.files = fileList;
}; };
// 重新选择文件
const handleReSelect = () => {
// 创建一个隐藏的文件输入框
const input = document.createElement('input');
input.type = 'file';
input.multiple = true;
input.style.display = 'none';
input.onchange = (e) => {
const files = Array.from(e.target.files);
if (files.length > 0) {
const fileList = files.map(file => ({
name: file.name,
raw: file,
status: 'ready',
uid: Date.now() + Math.random()
}));
formData.files = fileList;
}
// 清理临时input元素
document.body.removeChild(input);
};
// 添加到body并触发点击
document.body.appendChild(input);
input.click();
};
const rules = {
name: [{ required: true, message: '请输入素材名称', trigger: 'blur' }],
group: [{ required: true, message: '请选择分组', trigger: 'change' }],
files: [{ required: true, message: '请上传文件', trigger: 'change' }] // 实际上传校验通常需要自定义
};
// --- Tree Data & Logic ---
const treeRef = ref(null);
const checkAll = ref(false);
const isIndeterminate = ref(false);
const selectedNodes = ref([]);
// 模拟数据结构 - 模仿截图中的结构
const treeData = reactive([]);
const defaultProps = {
children: 'children',
label: 'departmentName',
class: (data, node) => {
if (data.children && data.children.length > 0) {
return 'is-parent-node';
} else {
return 'is-leaf-node';
}
},
};
// 递归统计所有节点数量
const countAllNodes = (nodes) => {
if (!nodes || !Array.isArray(nodes)) {
return 0;
}
let count = 0;
for (const node of nodes) {
count += 1; // 当前节点
if (node.children && node.children.length > 0) {
count += countAllNodes(node.children); // 递归统计子节点
}
}
return count;
};
// 计算总节点数
const totalNodeCount = computed(() => {
return countAllNodes(treeData);
});
// 递归获取所有节点的 key
const getAllNodeKeys = (nodes) => {
let keys = [];
for (const node of nodes) {
keys.push(node.id);
if (node.children && node.children.length > 0) {
keys = keys.concat(getAllNodeKeys(node.children));
}
}
return keys;
};
// 判断节点是否为叶子节点(没有子节点)
const isLeafNode = (node) => {
return !node.children || node.children.length === 0;
};
// 更新全选和半选状态
const updateCheckAllState = () => {
if (!treeRef.value) {
return;
}
const checkedKeys = treeRef.value.getCheckedKeys();
const allKeys = getAllNodeKeys(treeData);
if (checkedKeys.length === 0) {
checkAll.value = false;
isIndeterminate.value = false;
} else if (checkedKeys.length === allKeys.length) {
checkAll.value = true;
isIndeterminate.value = false;
} else {
checkAll.value = false;
isIndeterminate.value = true;
}
};
// 设置树形选择框的选中状态(用于回显)
const setTreeCheckedKeys = (deptIds) => {
if (!treeRef.value || !deptIds || !Array.isArray(deptIds) || deptIds.length === 0) {
return;
}
// 获取树中所有节点的 ID,用于判断 ID 类型
const allNodeIds = getAllNodeKeys(treeData);
if (allNodeIds.length === 0) {
return; // 树数据还未加载完成
}
// 判断树节点的 ID 类型(取第一个节点作为参考)
const firstNodeId = allNodeIds[0];
const isNumericId = typeof firstNodeId === 'number';
// 将 deptIds 转换为与树节点 id 类型一致
const checkedKeys = deptIds.map(id => {
if (isNumericId) {
// 如果树节点 ID 是数字,将字符串 ID 转换为数字
const numId = Number(id);
return isNaN(numId) ? id : numId;
} else {
// 如果树节点 ID 是字符串,保持字符串格式
return String(id);
}
});
// 设置选中状态
treeRef.value.setCheckedKeys(checkedKeys);
// 更新 selectedNodes(只保留叶子节点)
const checkedNodes = treeRef.value.getCheckedNodes();
selectedNodes.value = checkedNodes.filter(node => isLeafNode(node));
// 更新 formData(包含所有选中节点及其父节点的 id)
formData.departments = selectedNodes.value.map(n => n.id);
// 更新全选状态
updateCheckAllState();
};
// 监听 material 变化,填充表单数据 // 监听 material 变化,填充表单数据
watch(() => props.material, (newMaterial) => { watch(() => props.material, async (newMaterial) => {
if (newMaterial) { if (newMaterial) {
formData.name = newMaterial.title || newMaterial.name || ''; formData.name = newMaterial.title || newMaterial.name || '';
if (newMaterial.fileUrl) { if (newMaterial.fileUrl || newMaterial.filePath) {
const fileName = newMaterial.title || newMaterial.fileUrl.split('/').pop() || '文件'; const fileUrl = newMaterial.fileUrl || newMaterial.filePath;
const fileName = newMaterial.title || newMaterial.name || fileUrl.split('/').pop() || '文件';
formData.files = [{ formData.files = [{
name: fileName, name: fileName,
url: newMaterial.fileUrl, url: fileUrl,
status: 'success' status: 'success'
}]; }];
} else { } else {
...@@ -261,80 +436,101 @@ watch(() => props.material, (newMaterial) => { ...@@ -261,80 +436,101 @@ watch(() => props.material, (newMaterial) => {
} }
formData.group = newMaterial.categoryId || newMaterial.group || ''; formData.group = newMaterial.categoryId || newMaterial.group || '';
formData.departments = newMaterial.departments || [];
// 过滤 departments,只保留叶子节点的 id
const rawDepartments = newMaterial.departments || [];
if (treeData && treeData.length > 0) {
// 树数据已加载,直接过滤
formData.departments = filterLeafNodeIds(rawDepartments);
} else {
// 树数据未加载,先保存原始数据,等待树数据加载完成后再过滤
formData.departments = rawDepartments;
}
// 如果有 deptIds,需要回显到树形选择框
// 需要等待树数据加载完成后再设置
if (newMaterial.deptIds && Array.isArray(newMaterial.deptIds) && newMaterial.deptIds.length > 0) {
// 如果树数据已加载,直接设置;否则等待树数据加载完成
if (treeData && treeData.length > 0) {
await nextTick();
// 添加小延迟确保树组件完全渲染
setTimeout(() => {
setTreeCheckedKeys(newMaterial.deptIds);
}, 100);
}
// 如果树数据还未加载,getDeptTree 会在加载完成后自动设置
}
} else { } else {
formData.name = ''; formData.name = '';
formData.files = []; formData.files = [];
formData.group = ''; formData.group = '';
formData.departments = []; formData.departments = [];
// 清空树形选择框
if (treeRef.value) {
treeRef.value.setCheckedKeys([]);
selectedNodes.value = [];
checkAll.value = false;
isIndeterminate.value = false;
}
} }
}, { immediate: true }); }, { immediate: true });
const rules = { const getDeptTree = async () => {
name: [{ required: true, message: '请输入素材名称', trigger: 'blur' }], try {
group: [{ required: true, message: '请选择分组', trigger: 'change' }], const res = await findDeptTree({});
files: [{ required: true, message: '请上传文件', trigger: 'change' }] // 实际上传校验通常需要自定义 // treeData 是 reactive,需要直接赋值或使用 Object.assign
}; const deptData = res?.data || res || [];
if (Array.isArray(deptData) && deptData.length > 0) {
// --- Tree Data & Logic --- // 清空原有数据并赋值新数据
const treeRef = ref(null); treeData.splice(0, treeData.length, ...deptData);
const checkAll = ref(false); }
const isIndeterminate = ref(false); // 树数据加载完成后,如果有 material,需要过滤 departments 并回显选中状态
const selectedNodes = ref([]); if (props.material) {
// 过滤 departments,只保留叶子节点的 id
if (props.material.departments && Array.isArray(props.material.departments)) {
formData.departments = filterLeafNodeIds(props.material.departments);
}
// 模拟数据结构 - 模仿截图中的结构 // 如果有 deptIds,需要回显选中状态
const treeData = [ if (props.material.deptIds && props.material.deptIds.length > 0) {
{ // 使用 nextTick 确保树组件已渲染完成,并添加小延迟确保 DOM 更新
id: 1, await nextTick();
label: '总经办', setTimeout(() => {
}, setTreeCheckedKeys(props.material.deptIds);
{ }, 100);
id: 2, }
label: '经营管理中心',
children: [
{ id: 21, label: '项目申报部' },
{ id: 22, label: '商务服务部' },
{ id: 23, label: '经营管理部1' },
{ id: 24, label: '经营管理部2' },
{ id: 25, label: '权益服务部1' },
{ id: 26, label: '权益服务部2' },
{ id: 27, label: '权益服务部3' },
{ id: 28, label: '权益服务部4' },
]
},
{
id: 3,
label: '营销管理中心',
children: [
{ id: 31, label: '业务项目部' },
{ id: 32, label: '销售部' },
{ id: 33, label: '总部运营部' },
]
},
{
id: 4,
label: '智慧门店运营中心',
children: [
{ id: 41, label: '数字化运营部' },
{ id: 42, label: '场景运营部' },
{ id: 43, label: '零售运营部' },
]
} }
]; } catch (error) {
console.error('获取部门树数据失败:', error);
ElMessage.error('获取部门树数据失败');
}
};
const defaultProps = { // 查找节点的所有父节点路径(从根到当前节点)
children: 'children', const findNodePath = (nodeId, nodes = treeData, path = []) => {
label: 'label', for (const node of nodes) {
const currentPath = [...path, node];
if (node.id === nodeId) {
return currentPath;
}
if (node.children && node.children.length > 0) {
const found = findNodePath(nodeId, node.children, currentPath);
if (found !== null) {
return found;
}
}
}
return null;
}; };
// 查找节点的父节点 // 根据 id 在树形数据中查找节点
const findParentNode = (nodeId, nodes = treeData, parent = null) => { const findNodeById = (nodeId, nodes = treeData) => {
for (const node of nodes) { for (const node of nodes) {
if (node.id === nodeId) { if (node.id === nodeId) {
return parent; return node;
} }
if (node.children && node.children.length > 0) { if (node.children && node.children.length > 0) {
const found = findParentNode(nodeId, node.children, node); const found = findNodeById(nodeId, node.children);
if (found !== null) { if (found !== null) {
return found; return found;
} }
...@@ -343,35 +539,54 @@ const findParentNode = (nodeId, nodes = treeData, parent = null) => { ...@@ -343,35 +539,54 @@ const findParentNode = (nodeId, nodes = treeData, parent = null) => {
return null; return null;
}; };
// 获取节点的显示文本(父标签/子标签格式) // 过滤 departments,只保留叶子节点的 id
const filterLeafNodeIds = (deptIds) => {
if (!Array.isArray(deptIds) || deptIds.length === 0) {
return [];
}
// 等待树数据加载完成
if (!treeData || treeData.length === 0) {
return deptIds; // 如果树数据未加载,先返回原数据
}
return deptIds.filter(id => {
const node = findNodeById(id);
return node && isLeafNode(node);
});
};
// 获取节点的显示文本(完整路径格式:根/父/子)
const getNodeDisplayText = (node) => { const getNodeDisplayText = (node) => {
const parent = findParentNode(node.id); const path = findNodePath(node.id);
if (parent) { if (path && path.length > 0) {
return `${parent.label}/${node.label}`; return path.map(n => n.departmentName).join('/');
} }
return node.label; return node.departmentName;
}; };
// 处理树形选择变化 // 处理树形选择变化
const handleTreeCheck = (currentObj, treeStatus) => { const handleTreeCheck = (currentObj, treeStatus) => {
// checkedNodes 包含所有被勾选的节点(包括父节点) // 只保留叶子节点(没有子节点的节点),避免显示父级节点
// 如果只想展示叶子节点或特定逻辑,可以在这里过滤 selectedNodes.value = treeStatus.checkedNodes.filter(node => isLeafNode(node));
selectedNodes.value = treeStatus.checkedNodes;
// 更新 formData // 更新 formData
formData.departments = selectedNodes.value.map(n => n.id); formData.departments = selectedNodes.value.map(n => n.id);
// 更新全选状态
updateCheckAllState();
}; };
// 全选逻辑(简化版) // 全选逻辑(简化版)
const handleCheckAllChange = (val) => { const handleCheckAllChange = (val) => {
if (val) { if (val) {
treeRef.value.setCheckedNodes(treeData); treeRef.value.setCheckedNodes(treeData);
// 递归获取所有节点用于显示 // 只保留叶子节点用于显示
// 实际项目中可能使用 setCheckedKeys([allIds]) selectedNodes.value = treeRef.value.getCheckedNodes().filter(node => isLeafNode(node));
selectedNodes.value = treeRef.value.getCheckedNodes(); // 更新 formData
formData.departments = selectedNodes.value.map(n => n.id);
} else { } else {
treeRef.value.setCheckedKeys([]); treeRef.value.setCheckedKeys([]);
selectedNodes.value = []; selectedNodes.value = [];
formData.departments = [];
} }
isIndeterminate.value = false; isIndeterminate.value = false;
}; };
...@@ -380,6 +595,7 @@ const handleCheckAllChange = (val) => { ...@@ -380,6 +595,7 @@ const handleCheckAllChange = (val) => {
const clearSelection = () => { const clearSelection = () => {
treeRef.value.setCheckedKeys([]); treeRef.value.setCheckedKeys([]);
selectedNodes.value = []; selectedNodes.value = [];
formData.departments = [];
checkAll.value = false; checkAll.value = false;
isIndeterminate.value = false; isIndeterminate.value = false;
}; };
...@@ -387,20 +603,91 @@ const clearSelection = () => { ...@@ -387,20 +603,91 @@ const clearSelection = () => {
// 从右侧列表移除单个节点 // 从右侧列表移除单个节点
const removeNode = (node) => { const removeNode = (node) => {
treeRef.value.setChecked(node.id, false); // 取消树中对应的勾选 treeRef.value.setChecked(node.id, false); // 取消树中对应的勾选
// 重新计算 selectedNodes // 重新计算 selectedNodes,只保留叶子节点
selectedNodes.value = treeRef.value.getCheckedNodes(); selectedNodes.value = treeRef.value.getCheckedNodes().filter(n => isLeafNode(n));
// 更新 formData
formData.departments = selectedNodes.value.map(n => n.id);
// 更新全选状态
updateCheckAllState();
};
// 重置表单
const resetForm = () => {
// 重置表单数据
formData.name = '';
formData.files = [];
formData.group = '';
formData.departments = [];
// 清空树形选择框
if (treeRef.value) {
treeRef.value.setCheckedKeys([]);
selectedNodes.value = [];
checkAll.value = false;
isIndeterminate.value = false;
}
// 重置表单验证状态
if (formRef.value) {
formRef.value.resetFields();
}
}; };
// --- Actions --- // --- Actions ---
const submitForm = () => { const submitForm = () => {
formRef.value.validate((valid) => { formRef.value.validate(async (valid) => {
if (valid) { if (valid) {
if (props.material) { // if (props.material) {
// ElMessage.success('素材保存成功!');
// } else {
// ElMessage.success('素材上传成功!');
// }
// 打印formData的原始数据
const rawData = toRaw(formData);
console.log('Submission - formData原始数据:', rawData);
console.log('Submission - 详细信息:', {
name: rawData.name,
group: rawData.group,
departments: rawData.departments,
files: rawData.files.map(file => ({
name: file.name,
size: file.size || file.raw?.size,
type: file.type || file.raw?.type,
url: file.url,
status: file.status
}))
});
// 确保 departments 始终只包含 id,过滤掉对象,只保留 id
const extractDeptIds = (departments) => {
if (!Array.isArray(departments)) {
return [];
}
return departments.map(item => {
// 如果是对象,提取 id 属性;如果已经是 id,直接返回
return typeof item === 'object' && item !== null ? (item.id || item) : item;
}).filter(id => id !== undefined && id !== null);
};
let requestData = {
id: props.material?.id,
name: rawData.name,
knowledgeType:1,
deptIds: extractDeptIds(rawData.departments),
categoryId: rawData.group,
filePath: rawData.files[0].url
}
const res = await updateKnowledgeMaterial(requestData);
let { code } = res.data;
if (code == 0) {
ElMessage.success('素材保存成功!'); ElMessage.success('素材保存成功!');
} else { // 重置表单
ElMessage.success('素材上传成功!'); resetForm();
// 通知父组件刷新列表
emit('refresh');
// 关闭 drawer
emit('close');
} }
console.log('Submission:', formData);
} else { } else {
ElMessage.error('请填写完整信息'); ElMessage.error('请填写完整信息');
} }
...@@ -422,6 +709,7 @@ const handleClose = () => { ...@@ -422,6 +709,7 @@ const handleClose = () => {
// 组件挂载时获取分类列表 // 组件挂载时获取分类列表
onMounted(() => { onMounted(() => {
getCategoryList(); getCategoryList();
getDeptTree();
}); });
</script> </script>
...@@ -442,29 +730,55 @@ onMounted(() => { ...@@ -442,29 +730,55 @@ onMounted(() => {
background-color: #d1d5db; /* tailwind gray-300 */ background-color: #d1d5db; /* tailwind gray-300 */
} }
/* 将 .el-tree-node__children 下的 div 标签设置为 inline-block,并允许换行 */ /* 优化树形结构布局 */
:deep(.el-tree-node__children > div) { /* 基础节点样式调整 */
display: flex; :deep(.el-tree-node) {
width: 200px; white-space: normal;
overflow-y: auto; align-items: flex-start;
margin-top: 10px;
} }
/* 恢复第一层级的正常堆叠(防止顶层节点也变成 Grid) */ /*
:deep(.el-tree > .el-tree-node > .el-tree-node__children) { 核心布局逻辑:
display: flex; /* 或者 grid-template-columns: 1fr; */ 利用 defaultProps 中注入的 class 控制父子节点展示差异
*/
/* 父节点(含子项):独占一行 */
:deep(.is-parent-node) {
display: block;
width: 100%;
}
/* 叶子节点:行内块展示(卡片化),允许自动换行 */
:deep(.is-leaf-node) {
display: inline-block;
width: auto;
margin-right: 8px;
margin-bottom: 4px;
vertical-align: top;
}
/* 子级容器:Flex 布局,支持换行 */
:deep(.el-tree-node__children) {
display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px;
padding-top: 4px;
} }
/* 针对特定层级的微调,让子节点更像 Card */ /* 覆盖原有的 content 样式,确保对齐 */
:deep(.el-tree-node__content) { :deep(.el-tree-node__content) {
height: 32px; height: 32px;
border-radius: 4px; border-radius: 4px;
} }
:deep(.el-tree-node__content:hover) {
background-color: #f3f4f6; /* 叶子节点的内容区域样式优化,使其像一个个小模块 */
:deep(.is-leaf-node > .el-tree-node__content) {
background-color: #ffffff;
min-width: 120px;
} }
/* 调整 Checkbox 对齐 */ /* 调整 Checkbox 对齐 */
:deep(.el-checkbox) { :deep(.el-checkbox) {
margin-right: 8px; margin-right: 8px;
......
...@@ -332,6 +332,12 @@ const handleEditMaterial = (item) => { ...@@ -332,6 +332,12 @@ const handleEditMaterial = (item) => {
drawer.value = true; drawer.value = true;
}; };
// 刷新列表数据
const handleRefreshList = () => {
getMaterialList();
getCategoryList();
};
// 预览素材 // 预览素材
const handlePreviewMaterial = (item) => { const handlePreviewMaterial = (item) => {
if (item.fileUrl) { if (item.fileUrl) {
...@@ -730,10 +736,12 @@ onMounted(() => { ...@@ -730,10 +736,12 @@ onMounted(() => {
<el-drawer v-model="drawer" :with-header="true" size="70%" :show-close="false"> <el-drawer v-model="drawer" :with-header="true" size="70%" :show-close="false">
<template #header="{ close, titleId, titleClass }"> <template #header="{ close, titleId, titleClass }">
<div class="flex items-center justify-between border-b border-[#E5E5E5] p-[20px]">
<p :id="titleId" :class="[titleClass, 'drawer-title']">编辑素材</p> <p :id="titleId" :class="[titleClass, 'drawer-title']">编辑素材</p>
<img src="/images/icon-close.png" alt="" srcset="" class="el-icon--left w-[20px] h-[20px] cursor-pointer" @click="close"> <img src="/images/icon-close.png" alt="" srcset="" class="el-icon--left w-[20px] h-[20px] cursor-pointer" @click="close">
</div>
</template> </template>
<AddUpdate :is-standalone="false" :material="currentMaterial" @close="drawer = false" /> <AddUpdate :is-standalone="false" :material="currentMaterial" @close="drawer = false" @refresh="handleRefreshList" />
</el-drawer> </el-drawer>
</div> </div>
</template> </template>
...@@ -755,7 +763,8 @@ onMounted(() => { ...@@ -755,7 +763,8 @@ onMounted(() => {
} }
:deep(.el-drawer__header) { :deep(.el-drawer__header) {
margin-bottom: 0; margin: 0;
padding: 0;
} }
.drawer-title { .drawer-title {
...@@ -763,4 +772,6 @@ onMounted(() => { ...@@ -763,4 +772,6 @@ onMounted(() => {
font-size: 16px; font-size: 16px;
font-weight: bold; font-weight: bold;
} }
</style> </style>
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* 配置中心管理 * 配置中心管理
* 使用 fetch 解决 axios 提前实例化导致 sign 里面的 secret 不能通过配置中心动态获取 * 使用 fetch 解决 axios 提前实例化导致 sign 里面的 secret 不能通过配置中心动态获取
*/ */
import { Request } from 'glsk-toolkit'; import { Request, Defaults } from 'glsk-toolkit';
import { getToken } from '@/utils/auth';
// 配置数据 // 配置数据
let baseConfig: any = {}; let baseConfig: any = {};
let routerConfig: any = {}; let routerConfig: any = {};
...@@ -38,8 +38,6 @@ export function getGscApi(): null | Request { ...@@ -38,8 +38,6 @@ export function getGscApi(): null | Request {
return gscApiInstance; return gscApiInstance;
} }
/** /**
* 等待配置加载完成 * 等待配置加载完成
* @returns Promise<void> * @returns Promise<void>
...@@ -69,18 +67,22 @@ export async function fetchConfig(): Promise<any> { ...@@ -69,18 +67,22 @@ export async function fetchConfig(): Promise<any> {
window.$fetchConfig = configData; window.$fetchConfig = configData;
// 统一初始化 GSC API(无论 code 是什么,只要有配置就初始化) // 统一初始化 GSC API(无论 code 是什么,只要有配置就初始化)
const gscConfig = configData?.gsc || configData; const gscConfig = configData?.gsc || configData;
if (gscConfig) { if(gscConfig){
// 创建请求实例,存储在模块级变量中,不挂载到 window // 创建全局默认配置
gscApiInstance = new Request({ const globalDefaults = new Defaults({
...gscConfig, ...gscConfig,
session: { session: {
requiresSession: false, requiresSession: false,
sessionId: 'd5629aee-28c7-4def-a8fa-95d76c978dc7', sessionId: 'd5629aee-28c7-4def-a8fa-95d76c978dc7',
}, },
headers: { headers: {
'Authorization': '472b403095cd439d81d258c89267c7db',
'X-App-Version': '1.0.0' 'X-App-Version': '1.0.0'
}, },
retry: {
retries: 2,
retryDelay: 500,
shouldResetTimeout: true
},
events: { events: {
error: (error: any, requestConfig: any) => { error: (error: any, requestConfig: any) => {
console.error('[配置中心] GSC API 错误:', error, requestConfig); console.error('[配置中心] GSC API 错误:', error, requestConfig);
...@@ -89,21 +91,71 @@ export async function fetchConfig(): Promise<any> { ...@@ -89,21 +91,71 @@ export async function fetchConfig(): Promise<any> {
console.log('[配置中心] GSC API 登出:', response, requestConfig); console.log('[配置中心] GSC API 登出:', response, requestConfig);
}, },
}, },
// Sentry 配置
// sentry: {
// enable: true, // 是否启用Sentry错误上报
// dsn: 'https://ace1d827739e4229887b78468bd8a385@sentry.glsx.com.cn/48'
// }
}); });
gscApiInstance = new Request(globalDefaults);
// 配置请求拦截器,动态添加 Authorization
gscApiInstance.interceptors.request.use(
(config: any) => {
// 动态获取 token 并添加到请求头
const token = getToken();
if (token) {
config.headers = {
...config.headers,
'Authorization': token
};
}
return config;
},
(error: any) => {
console.error('[配置中心] 请求拦截器错误:', error);
return Promise.reject(error);
}
);
// 通知配置已就绪
if (configReadyResolve) { if (configReadyResolve) {
configReadyResolve(); configReadyResolve();
configReadyResolve = null; configReadyResolve = null;
} }
} else { } else {
console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例'); console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
} }
// if (gscConfig) {
// // 创建请求实例,存储在模块级变量中,不挂载到 window
// gscApiInstance = new Request({
// ...gscConfig,
// session: {
// requiresSession: false,
// sessionId: 'd5629aee-28c7-4def-a8fa-95d76c978dc7',
// },
// headers: {
// 'Authorization': '237f1ca886db4a0fbde44ef446ec74bb',
// 'X-App-Version': '1.0.0'
// },
// events: {
// error: (error: any, requestConfig: any) => {
// console.error('[配置中心] GSC API 错误:', error, requestConfig);
// },
// logout: (response: any, requestConfig: any) => {
// console.log('[配置中心] GSC API 登出:', response, requestConfig);
// },
// },
// // Sentry 配置
// // sentry: {
// // enable: true, // 是否启用Sentry错误上报
// // dsn: 'https://ace1d827739e4229887b78468bd8a385@sentry.glsx.com.cn/48'
// // }
// });
// // 通知配置已就绪
// if (configReadyResolve) {
// configReadyResolve();
// configReadyResolve = null;
// }
// } else {
// console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
// }
return configData; return configData;
} catch (error) { } catch (error) {
......
/** /**
* GSC 请求封装 * GSC 请求封装
* Authorization 通过请求拦截器统一处理,无需手动添加
*/ */
import { getGscApi } from './center'; import { getGscApi } from './center';
import { getToken } from '@/utils/auth';
/** /**
* 方案1:在每次请求时动态添加 token(推荐) * GSC POST 请求
* 优点:简单直接,每次请求都使用最新的 token * @param url 请求地址
* @param data 请求数据
* @param config 请求配置(可选)
*/ */
export const gscPost = (url: string, data: any, _config: any = {}) => { export const gscPost = (url: string, data: any, config: any = {}) => {
const gscApi = getGscApi(); const gscApi = getGscApi();
if (!gscApi) { if (!gscApi) {
...@@ -19,18 +21,28 @@ export const gscPost = (url: string, data: any, _config: any = {}) => { ...@@ -19,18 +21,28 @@ export const gscPost = (url: string, data: any, _config: any = {}) => {
return Promise.reject(error); return Promise.reject(error);
} }
// 动态获取 token 并添加到请求配置中
const token = getToken();
const configWithAuth = {
..._config,
headers: {
...(_config.headers || {}),
...(token ? { Authorization: `${token}` } : {}),
},
};
console.log('[GSC请求] 发起请求:', url, data); console.log('[GSC请求] 发起请求:', url, data);
return gscApi.post(url, data, configWithAuth); return gscApi.post(url, data, config);
};
/**
* GSC GET 请求
* @param url 请求地址
* @param config 请求配置(可选)
*/
export const gscGet = (url: string, config: any = {}) => {
const gscApi = getGscApi();
if (!gscApi) {
const error = new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成',
);
console.error(error);
return Promise.reject(error);
}
console.log('[GSC请求] 发起请求:', url);
return gscApi.get(url, config);
}; };
// 默认导出 // 默认导出
......
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
registerMicroApps, registerMicroApps,
start, start,
} from 'qiankun'; } from 'qiankun';
import { ElMessage } from 'element-plus';
import { microApps } from './apps'; // 微应用信息配置 import { microApps } from './apps'; // 微应用信息配置
import { communicationManager } from './communication'; // 通信管理器 import { communicationManager } from './communication'; // 通信管理器
...@@ -47,8 +48,11 @@ export function setupQiankun() { ...@@ -47,8 +48,11 @@ export function setupQiankun() {
// 可以在这里做一些全局错误处理 // 可以在这里做一些全局错误处理
// 例如:错误上报、错误提示等 // 例如:错误上报、错误提示等
const { message } = event as any; const { message } = event as any;
console.log(message);
if (message && message.includes('died in status')) { if (message && message.includes('died in status')) {
console.error('[qiankun] 微应用加载失败,请检查微应用是否正常运行'); console.error('[qiankun] 微应用加载失败,请检查微应用是否正常运行');
// 显示错误弹框提示
ElMessage.error('微应用加载失败,请检查微应用是否正常运行');
} }
}); });
......
...@@ -29,7 +29,7 @@ service.interceptors.request.use( ...@@ -29,7 +29,7 @@ service.interceptors.request.use(
// 添加 token // 添加 token
const token = getToken(); const token = getToken();
if (token && config.headers) { if (token && config.headers) {
config.headers.Authorization = `Bearer ${token}`; config.headers.Authorization = `${token}`;
} }
// 添加时间戳防止缓存 // 添加时间戳防止缓存
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!