添加项目权限校验方法

This commit is contained in:
lcj
2025-03-10 09:58:54 +08:00
parent 55df453d4c
commit 3e3f6f8aab
7 changed files with 216 additions and 205 deletions

View File

@ -65,16 +65,20 @@
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['materials:materials:add']">新增</el-button>
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['materials:materials:add']"> 新增 </el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['materials:materials:edit']">修改</el-button>
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['materials:materials:edit']"
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['materials:materials:remove']">删除</el-button>
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['materials:materials:remove']"
>删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['materials:materials:export']">导出</el-button>
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['materials:materials:export']">导出 </el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@ -88,10 +92,10 @@
<!-- <el-table-column label="公司id" align="center" prop="companyId" /> -->
<el-table-column label="公司名称" align="center" prop="companyVo.companyName" />
<el-table-column label="项目名称" align="center" prop="">
<template #default="scope">
{{ getProjectName(scope.row.projectId) }}
</template>
</el-table-column>
<template #default="scope">
{{ getProjectName(scope.row.projectId) }}
</template>
</el-table-column>
<el-table-column label="规格型号名称" align="center" prop="typeSpecificationName" />
<el-table-column label="规格型号文件路径" align="center" prop="typeSpecificationUrl" />
<el-table-column label="合格证编号名称" align="center" prop="certificateConformityName" />
@ -106,15 +110,17 @@
<el-table-column label="计量单位" align="center" prop="weightId" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="预计材料数量" align="center" prop="quantityCount" />
<el-table-column label="状态" align="center" prop="status" >
<el-table-column label="状态" align="center" prop="status">
<template #default="{ row }">
<span :style="{
color: row.status === 0 ? 'green' : 'red',
backgroundColor: row.status === 0 ? '#E6F9E6' : '#FDE2E2',
padding: '5px 10px',
borderRadius: '5px',
display: 'inline-block'
}">
<span
:style="{
color: row.status === 0 ? 'green' : 'red',
backgroundColor: row.status === 0 ? '#E6F9E6' : '#FDE2E2',
padding: '5px 10px',
borderRadius: '5px',
display: 'inline-block'
}"
>
{{ row.status === 0 ? '正常' : '异常' }}
</span>
</template>
@ -241,10 +247,10 @@ const initFormData: MaterialsForm = {
weightId: undefined,
remark: undefined,
quantityCount: undefined,
status: undefined,
}
status: undefined
};
const data = reactive<PageData<MaterialsForm, MaterialsQuery>>({
form: {...initFormData},
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
@ -266,13 +272,10 @@ const data = reactive<PageData<MaterialsForm, MaterialsQuery>>({
weightId: undefined,
quantityCount: undefined,
status: undefined,
params: {
}
params: {}
},
rules: {
id: [
{ required: true, message: "主键id不能为空", trigger: "blur" }
],
id: [{ required: true, message: '主键id不能为空', trigger: 'blur' }]
}
});
@ -282,58 +285,58 @@ const { queryParams, form, rules } = toRefs(data);
const getList = async () => {
loading.value = true;
const res = await listMaterials(queryParams.value);
materialsList.value = res.records;
materialsList.value = res.data.records;
total.value = res.total;
loading.value = false;
}
};
/** 取消按钮 */
const cancel = () => {
reset();
dialog.visible = false;
}
};
/** 表单重置 */
const reset = () => {
form.value = {...initFormData};
form.value = { ...initFormData };
materialsFormRef.value?.resetFields();
}
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
}
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
}
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: MaterialsVO[]) => {
ids.value = selection.map(item => item.id);
ids.value = selection.map((item) => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
};
/** 新增按钮操作 */
const handleAdd = () => {
reset();
dialog.visible = true;
dialog.title = "添加材料名称";
}
dialog.title = '添加材料名称';
};
/** 修改按钮操作 */
const handleUpdate = async (row?: MaterialsVO) => {
reset();
const _id = row?.id || ids.value[0]
const _id = row?.id || ids.value[0];
const res = await getMaterials(_id);
Object.assign(form.value, res.data);
dialog.visible = true;
dialog.title = "修改材料名称";
}
dialog.title = '修改材料名称';
};
/** 提交按钮 */
const submitForm = () => {
@ -341,33 +344,36 @@ const submitForm = () => {
if (valid) {
buttonLoading.value = true;
if (form.value.id) {
await updateMaterials(form.value).finally(() => buttonLoading.value = false);
await updateMaterials(form.value).finally(() => (buttonLoading.value = false));
} else {
await addMaterials(form.value).finally(() => buttonLoading.value = false);
await addMaterials(form.value).finally(() => (buttonLoading.value = false));
}
proxy?.$modal.msgSuccess("操作成功");
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
}
});
}
};
/** 删除按钮操作 */
const handleDelete = async (row?: MaterialsVO) => {
const _ids = row?.id || ids.value;
await proxy?.$modal.confirm('是否确认删除材料名称编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
await proxy?.$modal.confirm('是否确认删除材料名称编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
await delMaterials(_ids);
proxy?.$modal.msgSuccess("删除成功");
proxy?.$modal.msgSuccess('删除成功');
await getList();
}
};
/** 导出按钮操作 */
const handleExport = () => {
proxy?.download('materials/materials/export', {
...queryParams.value
}, `materials_${new Date().getTime()}.xlsx`)
}
proxy?.download(
'materials/materials/export',
{
...queryParams.value
},
`materials_${new Date().getTime()}.xlsx`
);
};
import { useUserStoreHook } from '@/store/modules/user';
// 获取用户 store
@ -379,16 +385,14 @@ const currentProject = computed(() => userStore.selectedProject);
const materialsInventoryList = computed(() => {
// 如果有选中的项目,则只显示该项目的数据
if (currentProject.value && currentProject.value.id) {
return materialsList.value.filter(item =>
item.projectId === currentProject.value.id
);
return materialsList.value.filter((item) => item.projectId === currentProject.value.id);
}
// 没有选中项目则显示所有数据
return materialsList.value;
});
// 根据 projectId 获取对应的 projectName
const getProjectName = (projectId) => {
const project = projectList.value.find(p => p.id === projectId);
const project = projectList.value.find((p) => p.id === projectId);
return project ? project.name : projectId; // 如果找不到对应的项目名,则显示 ID
};