From 98a9fbaffa47c165fa42313ee8d826628500ed9c Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期一, 02 十一月 2026 11:49:30 +0800
Subject: [PATCH] feat(safety): 安全生产二期 - 安全风险分级管控前端
---
src/views/safety/risk/unit/modules/form.vue | 84 ++++
src/views/safety/risk/list/modules/form.vue | 121 ++++++
src/views/safety/risk/unit/data.ts | 178 ++++++++
src/views/safety/risk/list/data.ts | 346 +++++++++++++++++
src/api/safety/risk/unit/index.ts | 68 +++
src/views/safety/risk/shared.ts | 21 +
src/api/safety/risk/list/index.ts | 82 ++++
src/packages/constants/src/dict-enum.ts | 4
src/views/safety/risk/list/index.vue | 127 ++++++
src/views/safety/risk/unit/index.vue | 126 ++++++
10 files changed, 1,157 insertions(+), 0 deletions(-)
diff --git a/src/api/safety/risk/list/index.ts b/src/api/safety/risk/list/index.ts
new file mode 100644
index 0000000..6b7e5d5
--- /dev/null
+++ b/src/api/safety/risk/list/index.ts
@@ -0,0 +1,82 @@
+import type { PageParam, PageResult } from '#/packages/effects/request/src';
+
+import { requestClient } from '#/api/request';
+
+export namespace MesSafetyRiskApi {
+ /** 椋庨櫓娓呭崟 */
+ export interface Risk {
+ id?: number;
+ unitId?: number;
+ unitName?: string;
+ workshopName?: string;
+ code?: string;
+ name?: string;
+ accidentType?: number;
+ possibleConsequence?: string;
+ likelihood?: number;
+ exposure?: number;
+ consequence?: number;
+ riskValue?: number;
+ riskLevel?: number;
+ riskLevelName?: string;
+ controlEngineering?: string;
+ controlManagement?: string;
+ controlTraining?: string;
+ controlPpe?: string;
+ controlEmergency?: string;
+ evaluateDate?: string;
+ nextEvaluateDate?: string;
+ chargeUserId?: number;
+ chargeUserName?: string;
+ status?: number;
+ remark?: string;
+ createTime?: string;
+ }
+
+ /** 鍒嗛〉鍙傛暟 */
+ export interface RiskPageParam extends PageParam {
+ code?: string;
+ name?: string;
+ unitId?: number;
+ accidentType?: number;
+ riskLevel?: number;
+ status?: number;
+ }
+}
+
+/** 鏌ヨ椋庨櫓娓呭崟鍒嗛〉 */
+export function getRiskPage(params: MesSafetyRiskApi.RiskPageParam) {
+ return requestClient.get<PageResult<MesSafetyRiskApi.Risk>>(
+ '/mes/safety/risk/page',
+ { params },
+ );
+}
+
+/** 鏌ヨ椋庨櫓娓呭崟璇︽儏 */
+export function getRisk(id: number) {
+ return requestClient.get<MesSafetyRiskApi.Risk>(
+ `/mes/safety/risk/get?id=${id}`,
+ );
+}
+
+/** 鏌ヨ鎸囧畾椋庨櫓鍗曞厓涓嬬殑椋庨櫓娓呭崟 */
+export function getRiskListByUnit(unitId: number) {
+ return requestClient.get<MesSafetyRiskApi.Risk[]>(
+ `/mes/safety/risk/list-by-unit?unitId=${unitId}`,
+ );
+}
+
+/** 鍒涘缓椋庨櫓娓呭崟 */
+export function createRisk(data: MesSafetyRiskApi.Risk) {
+ return requestClient.post<number>('/mes/safety/risk/create', data);
+}
+
+/** 鏇存柊椋庨櫓娓呭崟 */
+export function updateRisk(data: MesSafetyRiskApi.Risk) {
+ return requestClient.put<boolean>('/mes/safety/risk/update', data);
+}
+
+/** 鍒犻櫎椋庨櫓娓呭崟 */
+export function deleteRisk(id: number) {
+ return requestClient.delete<boolean>(`/mes/safety/risk/delete?id=${id}`);
+}
diff --git a/src/api/safety/risk/unit/index.ts b/src/api/safety/risk/unit/index.ts
new file mode 100644
index 0000000..1ebee97
--- /dev/null
+++ b/src/api/safety/risk/unit/index.ts
@@ -0,0 +1,68 @@
+import type { PageParam, PageResult } from '#/packages/effects/request/src';
+
+import { requestClient } from '#/api/request';
+
+export namespace MesSafetyRiskUnitApi {
+ /** 椋庨櫓鍗曞厓 */
+ export interface RiskUnit {
+ id?: number;
+ code?: string;
+ name?: string;
+ workshopId?: number;
+ workshopName?: string;
+ location?: string;
+ riskCategory?: number;
+ chargeUserId?: number;
+ chargeUserName?: string;
+ status?: number;
+ riskCount?: number;
+ remark?: string;
+ createTime?: string;
+ }
+
+ /** 鍒嗛〉鍙傛暟 */
+ export interface RiskUnitPageParam extends PageParam {
+ code?: string;
+ name?: string;
+ workshopId?: number;
+ riskCategory?: number;
+ status?: number;
+ }
+}
+
+/** 鏌ヨ椋庨櫓鍗曞厓鍒嗛〉 */
+export function getRiskUnitPage(params: MesSafetyRiskUnitApi.RiskUnitPageParam) {
+ return requestClient.get<PageResult<MesSafetyRiskUnitApi.RiskUnit>>(
+ '/mes/safety/risk-unit/page',
+ { params },
+ );
+}
+
+/** 鏌ヨ椋庨櫓鍗曞厓璇︽儏 */
+export function getRiskUnit(id: number) {
+ return requestClient.get<MesSafetyRiskUnitApi.RiskUnit>(
+ `/mes/safety/risk-unit/get?id=${id}`,
+ );
+}
+
+/** 鏌ヨ椋庨櫓鍗曞厓绮剧畝鍒楄〃锛堜笅鎷夌敤锛� */
+export function getRiskUnitSimpleList() {
+ return requestClient.get<MesSafetyRiskUnitApi.RiskUnit[]>(
+ '/mes/safety/risk-unit/simple-list',
+ );
+}
+
+/** 鍒涘缓椋庨櫓鍗曞厓 */
+export function createRiskUnit(data: MesSafetyRiskUnitApi.RiskUnit) {
+ return requestClient.post<number>('/mes/safety/risk-unit/create', data);
+}
+
+/** 鏇存柊椋庨櫓鍗曞厓 */
+export function updateRiskUnit(data: MesSafetyRiskUnitApi.RiskUnit) {
+ return requestClient.put<boolean>('/mes/safety/risk-unit/update', data);
+}
+
+/** 鍒犻櫎椋庨櫓鍗曞厓 */
+export function deleteRiskUnit(id: number) {
+ return requestClient.delete<boolean>(`/mes/safety/risk-unit/delete?id=${id}`);
+}
diff --git a/src/packages/constants/src/dict-enum.ts b/src/packages/constants/src/dict-enum.ts
index 082d48f..9f081b0 100644
--- a/src/packages/constants/src/dict-enum.ts
+++ b/src/packages/constants/src/dict-enum.ts
@@ -305,6 +305,10 @@
MES_EM_ALERT_LEVEL: 'mes_em_alert_level', // MES 鑳借�楅璀︾骇鍒�
MES_EM_ALERT_STATUS: 'mes_em_alert_status', // MES 鑳借�楅璀﹀鐞嗙姸鎬�
MES_PRO_EMERGENCY_PLAN_TYPE: 'mes_pro_emergency_plan_type', // MES 搴旀�ュ缃妗堢被鍨�
+ MES_SAFETY_RISK_LEVEL: 'mes_safety_risk_level', // 瀹夊叏鐢熶骇-椋庨櫓绛夌骇
+ MES_SAFETY_RISK_CATEGORY: 'mes_safety_risk_category', // 瀹夊叏鐢熶骇-椋庨櫓绫诲埆
+ MES_SAFETY_ACCIDENT_TYPE: 'mes_safety_accident_type', // 瀹夊叏鐢熶骇-浜嬫晠绫诲瀷
+ MES_SAFETY_UNIT_STATUS: 'mes_safety_unit_status', // 瀹夊叏鐢熶骇-椋庨櫓鍗曞厓鐘舵��
} as const;
/** ========== WMS - 浠撳偍绠$悊妯″潡 ========== */
diff --git a/src/views/safety/risk/list/data.ts b/src/views/safety/risk/list/data.ts
new file mode 100644
index 0000000..90c0b4f
--- /dev/null
+++ b/src/views/safety/risk/list/data.ts
@@ -0,0 +1,346 @@
+import type { VbenFormSchema } from '#/adapter/form';
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesSafetyRiskApi } from '#/api/safety/risk/list';
+
+import { DICT_TYPE } from '#/packages/constants/src';
+import { getDictOptions } from '#/packages/effects/hooks/src';
+
+import { z } from '#/adapter/form';
+import { getRiskUnitSimpleList } from '#/api/safety/risk/unit';
+import { getSimpleUserList } from '../shared';
+
+/** L / E / C 鏍囧噯鍙栧�硷紙LEC 鏍奸浄鍘勫-閲戝凹娉曪級 */
+export const LIKELIHOOD_OPTIONS = [
+ { label: '10 - 瀹屽叏鍙互棰勬枡', value: 10 },
+ { label: '6 - 鐩稿綋鍙兘', value: 6 },
+ { label: '3 - 鍙兘锛屼絾涓嶇粡甯�', value: 3 },
+ { label: '1 - 鍙兘鎬у皬锛屽畬鍏ㄦ剰澶�', value: 1 },
+];
+
+export const EXPOSURE_OPTIONS = [
+ { label: '10 - 杩炵画鏆撮湶', value: 10 },
+ { label: '6 - 姣忓ぉ宸ヤ綔鏃堕棿鍐呮毚闇�', value: 6 },
+ { label: '3 - 姣忓懆涓�娆℃垨鍋剁劧鏆撮湶', value: 3 },
+ { label: '2 - 姣忔湀涓�娆℃毚闇�', value: 2 },
+ { label: '1 - 姣忓勾鍑犳鏆撮湶', value: 1 },
+ { label: '0.5 - 闈炲父缃曡鍦版毚闇�', value: 0.5 },
+];
+
+export const CONSEQUENCE_OPTIONS = [
+ { label: '100 - 澶х伨闅撅紝璁稿浜烘浜�', value: 100 },
+ { label: '40 - 鐏鹃毦锛屾暟浜烘浜�', value: 40 },
+ { label: '15 - 闈炲父涓ラ噸锛屼竴浜烘浜�', value: 15 },
+ { label: '7 - 涓ラ噸锛岄噸浼�', value: 7 },
+ { label: '5 - 閲嶅ぇ锛岃嚧娈�', value: 5 },
+ { label: '3 - 杈冨ぇ锛岃交浼�', value: 3 },
+ { label: '1 - 寮曚汉娉ㄧ洰锛岄渶瑕佹晳鎶�', value: 1 },
+];
+
+/** 鎸夐闄╁�� D 璁$畻椋庨櫓绛夌骇锛氣墺320 閲嶅ぇ(1)锛涒墺160 杈冨ぇ(2)锛涒墺70 涓�鑸�(3)锛涘叾浣欎綆(4) */
+export function calcRiskLevel(riskValue?: number): number | undefined {
+ if (riskValue === undefined || riskValue === null) {
+ return undefined;
+ }
+ if (riskValue >= 320) return 1;
+ if (riskValue >= 160) return 2;
+ if (riskValue >= 70) return 3;
+ return 4;
+}
+
+/** 椋庨櫓绛夌骇鍚嶇О */
+export function riskLevelName(level?: number): string {
+ switch (level) {
+ case 1: return '閲嶅ぇ椋庨櫓';
+ case 2: return '杈冨ぇ椋庨櫓';
+ case 3: return '涓�鑸闄�';
+ case 4: return '浣庨闄�';
+ default: return '';
+ }
+}
+
+/** 椋庨櫓绛夌骇瀵瑰簲鐨勬爣绛鹃鑹� */
+export function riskLevelColor(level?: number): string {
+ switch (level) {
+ case 1: return 'error';
+ case 2: return 'warning';
+ case 3: return 'processing';
+ case 4: return 'success';
+ default: return 'default';
+ }
+}
+
+/** 鍒楄〃鐨勬悳绱㈣〃鍗� */
+export function useGridFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'code',
+ label: '椋庨櫓缂栫爜',
+ component: 'Input',
+ componentProps: { allowClear: true, placeholder: '璇疯緭鍏ラ闄╃紪鐮�' },
+ },
+ {
+ fieldName: 'name',
+ label: '椋庨櫓鍚嶇О',
+ component: 'Input',
+ componentProps: { allowClear: true, placeholder: '璇疯緭鍏ラ闄╁悕绉�' },
+ },
+ {
+ fieldName: 'unitId',
+ label: '椋庨櫓鍗曞厓',
+ component: 'ApiSelect',
+ componentProps: {
+ allowClear: true,
+ api: getRiskUnitSimpleList,
+ labelField: 'name',
+ valueField: 'id',
+ placeholder: '璇烽�夋嫨椋庨櫓鍗曞厓',
+ },
+ },
+ {
+ fieldName: 'riskLevel',
+ label: '椋庨櫓绛夌骇',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_RISK_LEVEL, 'number'),
+ placeholder: '璇烽�夋嫨椋庨櫓绛夌骇',
+ },
+ },
+ ];
+}
+
+/** 鏂板/淇敼鐨勮〃鍗� */
+export function useFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'id',
+ component: 'Input',
+ dependencies: { triggerFields: [''], show: () => false },
+ },
+ {
+ fieldName: 'unitId',
+ label: '椋庨櫓鍗曞厓',
+ component: 'ApiSelect',
+ componentProps: {
+ api: getRiskUnitSimpleList,
+ labelField: 'name',
+ valueField: 'id',
+ placeholder: '璇烽�夋嫨椋庨櫓鍗曞厓',
+ },
+ rules: 'selectRequired',
+ },
+ {
+ fieldName: 'code',
+ label: '椋庨櫓缂栫爜',
+ component: 'Input',
+ componentProps: { placeholder: '濡� FX-001-01' },
+ rules: 'required',
+ },
+ {
+ fieldName: 'name',
+ label: '椋庨櫓鍚嶇О',
+ component: 'Input',
+ componentProps: { placeholder: '濡� 鐑樼几瓒呭帇鐖嗙偢' },
+ rules: 'required',
+ },
+ {
+ fieldName: 'accidentType',
+ label: '浜嬫晠绫诲瀷',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_ACCIDENT_TYPE, 'number'),
+ placeholder: '璇烽�夋嫨鍙兘瀵艰嚧鐨勪簨鏁呯被鍨�',
+ },
+ },
+ {
+ fieldName: 'possibleConsequence',
+ label: '鍙兘鍚庢灉',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 浜哄憳浼や骸銆佽澶囨崯姣�', rows: 2 },
+ },
+ {
+ fieldName: 'likelihood',
+ label: 'L 鍙兘鎬�',
+ component: 'Select',
+ componentProps: {
+ options: LIKELIHOOD_OPTIONS,
+ placeholder: '璇烽�夋嫨 L',
+ },
+ help: 'D = L 脳 E 脳 C',
+ },
+ {
+ fieldName: 'exposure',
+ label: 'E 鏆撮湶棰戠巼',
+ component: 'Select',
+ componentProps: {
+ options: EXPOSURE_OPTIONS,
+ placeholder: '璇烽�夋嫨 E',
+ },
+ },
+ {
+ fieldName: 'consequence',
+ label: 'C 鍚庢灉涓ラ噸鎬�',
+ component: 'Select',
+ componentProps: {
+ options: CONSEQUENCE_OPTIONS,
+ placeholder: '璇烽�夋嫨 C',
+ },
+ },
+ {
+ fieldName: 'riskValue',
+ label: 'D 椋庨櫓鍊�',
+ component: 'InputNumber',
+ componentProps: {
+ class: '!w-full',
+ disabled: true,
+ placeholder: '鐢� L脳E脳C 鑷姩璁$畻',
+ },
+ },
+ {
+ fieldName: 'riskLevel',
+ label: '椋庨櫓绛夌骇',
+ component: 'Select',
+ componentProps: {
+ disabled: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_RISK_LEVEL, 'number'),
+ placeholder: '鐢遍闄╁�艰嚜鍔ㄥ垽瀹�',
+ },
+ },
+ {
+ fieldName: 'controlEngineering',
+ label: '宸ョ▼鎶�鏈帾鏂�',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 瀹夎瀹夊叏闃�銆佽仈閿佷繚鎶�', rows: 2 },
+ },
+ {
+ fieldName: 'controlManagement',
+ label: '绠$悊鎺柦',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 瀹氭湡宸℃銆佷綔涓氱エ瀹℃壒', rows: 2 },
+ },
+ {
+ fieldName: 'controlTraining',
+ label: '鍩硅鏁欒偛鎺柦',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 宀楀墠鍩硅銆佷笓椤瑰煿璁�', rows: 2 },
+ },
+ {
+ fieldName: 'controlPpe',
+ label: '涓綋闃叉姢鎺柦',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 瀹夊叏甯姐�侀槻鎶ゆ墜濂�', rows: 2 },
+ },
+ {
+ fieldName: 'controlEmergency',
+ label: '搴旀�ュ缃帾鏂�',
+ component: 'Textarea',
+ componentProps: { placeholder: '濡� 绔嬪嵆鍋滄満銆佺枏鏁d汉鍛�', rows: 2 },
+ },
+ {
+ fieldName: 'chargeUserId',
+ label: '绠℃帶璐d换浜�',
+ component: 'ApiSelect',
+ componentProps: {
+ allowClear: true,
+ api: getSimpleUserList,
+ labelField: 'nickname',
+ valueField: 'id',
+ placeholder: '璇烽�夋嫨绠℃帶璐d换浜�',
+ },
+ },
+ {
+ fieldName: 'evaluateDate',
+ label: '鏈璇勪及鏃ユ湡',
+ component: 'DatePicker',
+ componentProps: {
+ class: '!w-full',
+ format: 'YYYY-MM-DD',
+ valueFormat: 'YYYY-MM-DD',
+ placeholder: '璇烽�夋嫨璇勪及鏃ユ湡',
+ },
+ },
+ {
+ fieldName: 'nextEvaluateDate',
+ label: '涓嬫璇勪及鏃ユ湡',
+ component: 'DatePicker',
+ componentProps: {
+ class: '!w-full',
+ format: 'YYYY-MM-DD',
+ valueFormat: 'YYYY-MM-DD',
+ placeholder: '璇烽�夋嫨涓嬫璇勪及鏃ユ湡',
+ },
+ },
+ {
+ fieldName: 'status',
+ label: '鐘舵��',
+ component: 'RadioGroup',
+ componentProps: {
+ buttonStyle: 'solid',
+ optionType: 'button',
+ options: [
+ { label: '鏈夋晥', value: 1 },
+ { label: '宸插け鏁�', value: 0 },
+ ],
+ },
+ rules: z.number().default(1),
+ },
+ {
+ fieldName: 'remark',
+ label: '澶囨敞',
+ component: 'Textarea',
+ formItemClass: 'col-span-2',
+ componentProps: { placeholder: '璇疯緭鍏ュ娉�', rows: 2 },
+ },
+ ];
+}
+
+/** 鍒楄〃鐨勫瓧娈� */
+export function useGridColumns(): VxeTableGridOptions<MesSafetyRiskApi.Risk>['columns'] {
+ return [
+ { field: 'code', title: '椋庨櫓缂栫爜', width: 130 },
+ { field: 'name', title: '椋庨櫓鍚嶇О', minWidth: 180 },
+ { field: 'unitName', title: '椋庨櫓鍗曞厓', minWidth: 150 },
+ { field: 'workshopName', title: '鎵�灞炶溅闂�', width: 110 },
+ {
+ field: 'accidentType',
+ title: '浜嬫晠绫诲瀷',
+ width: 110,
+ cellRender: {
+ name: 'CellDict',
+ props: { type: DICT_TYPE.MES_SAFETY_ACCIDENT_TYPE },
+ },
+ },
+ {
+ field: 'riskValue',
+ title: '椋庨櫓鍊� D',
+ width: 100,
+ align: 'right',
+ formatter: 'formatAmount2',
+ },
+ {
+ field: 'riskLevel',
+ title: '椋庨櫓绛夌骇',
+ width: 110,
+ slots: { default: 'riskLevel' },
+ },
+ { field: 'chargeUserName', title: '绠℃帶璐d换浜�', width: 110 },
+ {
+ field: 'evaluateDate',
+ title: '璇勪及鏃ユ湡',
+ width: 120,
+ },
+ {
+ field: 'status',
+ title: '鐘舵��',
+ width: 90,
+ slots: { default: 'status' },
+ },
+ {
+ title: '鎿嶄綔',
+ width: 200,
+ fixed: 'right',
+ slots: { default: 'actions' },
+ },
+ ];
+}
diff --git a/src/views/safety/risk/list/index.vue b/src/views/safety/risk/list/index.vue
new file mode 100644
index 0000000..a03a774
--- /dev/null
+++ b/src/views/safety/risk/list/index.vue
@@ -0,0 +1,127 @@
+<script lang="ts" setup>
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesSafetyRiskApi } from '#/api/safety/risk/list';
+
+import { Page } from '#/packages/effects/common-ui/src';
+
+import { message, Tag } from 'ant-design-vue';
+
+import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
+import { deleteRisk, getRiskPage } from '#/api/safety/risk/list';
+import { useVbenModal } from '@vben/common-ui';
+
+import { riskLevelColor, riskLevelName, useGridColumns, useGridFormSchema } from './data';
+import Form from './modules/form.vue';
+
+defineOptions({ name: 'SafetyRiskList' });
+
+const [FormModal, formModalApi] = useVbenModal({
+ connectedComponent: Form,
+ destroyOnClose: true,
+});
+
+const [Grid, gridApi] = useVbenVxeGrid({
+ formOptions: {
+ schema: useGridFormSchema(),
+ },
+ gridOptions: {
+ columns: useGridColumns(),
+ height: 'auto',
+ keepSource: true,
+ proxyConfig: {
+ ajax: {
+ query: async ({ page }, formValues) =>
+ await getRiskPage({
+ pageNo: page.currentPage,
+ pageSize: page.pageSize,
+ ...formValues,
+ }),
+ },
+ },
+ rowConfig: {
+ keyField: 'id',
+ isHover: true,
+ },
+ toolbarConfig: {
+ refresh: true,
+ search: true,
+ },
+ } as VxeTableGridOptions<MesSafetyRiskApi.Risk>,
+});
+
+function handleCreate() {
+ formModalApi.setData({ formType: 'create' }).open();
+}
+
+function handleEdit(row: MesSafetyRiskApi.Risk) {
+ formModalApi.setData({ formType: 'update', id: row.id }).open();
+}
+
+function handleRefresh() {
+ gridApi.query();
+}
+
+async function handleDelete(row: MesSafetyRiskApi.Risk) {
+ await deleteRisk(row.id!);
+ message.success('鍒犻櫎鎴愬姛');
+ gridApi.query();
+}
+</script>
+
+<template>
+ <Page auto-content-height>
+ <FormModal @success="handleRefresh" />
+ <Grid>
+ <template #toolbar-tools>
+ <TableAction
+ :actions="[
+ {
+ label: '鏂板椋庨櫓',
+ type: 'primary',
+ icon: ACTION_ICON.ADD,
+ auth: ['mes:safety-risk:create'],
+ onClick: handleCreate,
+ },
+ ]"
+ />
+ </template>
+
+ <template #riskLevel="{ row }">
+ <Tag :color="riskLevelColor(row.riskLevel)">
+ {{ row.riskLevelName || riskLevelName(row.riskLevel) || '-' }}
+ </Tag>
+ </template>
+
+ <template #status="{ row }">
+ <Tag :color="row.status === 1 ? 'success' : 'default'">
+ {{ row.status === 1 ? '鏈夋晥' : '宸插け鏁�' }}
+ </Tag>
+ </template>
+
+ <template #actions="{ row }">
+ <TableAction
+ :actions="[
+ {
+ label: '缂栬緫',
+ type: 'link',
+ icon: ACTION_ICON.EDIT,
+ auth: ['mes:safety-risk:update'],
+ onClick: handleEdit.bind(null, row),
+ },
+ {
+ label: '鍒犻櫎',
+ type: 'link',
+ danger: true,
+ icon: ACTION_ICON.DELETE,
+ auth: ['mes:safety-risk:delete'],
+ popConfirm: {
+ title: '纭畾鍒犻櫎璇ラ闄╄褰曞悧锛�',
+ confirm: handleDelete.bind(null, row),
+ },
+ },
+ ]"
+ />
+ </template>
+ </Grid>
+ </Page>
+</template>
diff --git a/src/views/safety/risk/list/modules/form.vue b/src/views/safety/risk/list/modules/form.vue
new file mode 100644
index 0000000..776aa09
--- /dev/null
+++ b/src/views/safety/risk/list/modules/form.vue
@@ -0,0 +1,121 @@
+<script lang="ts" setup>
+import type { MesSafetyRiskApi } from '#/api/safety/risk/list';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { Alert, message } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+import { createRisk, getRisk, updateRisk } from '#/api/safety/risk/list';
+
+import { calcRiskLevel, riskLevelName, useFormSchema } from '../data';
+
+const emit = defineEmits(['success']);
+
+const formType = ref<'create' | 'update'>('create');
+const isUpdate = computed(() => formType.value === 'update');
+const getTitle = computed(() =>
+ isUpdate.value ? '淇敼椋庨櫓娓呭崟' : '鏂板椋庨櫓娓呭崟',
+);
+
+/** 瀹炴椂灞曠ず鐨勮瘎浼扮粨鏋� */
+const riskValue = ref<number>();
+const riskLevel = ref<number>();
+
+const [Form, formApi] = useVbenForm({
+ commonConfig: {
+ componentProps: { class: 'w-full' },
+ formItemClass: 'col-span-2',
+ labelWidth: 120,
+ },
+ wrapperClass: 'grid-cols-2',
+ layout: 'horizontal',
+ schema: useFormSchema(),
+ showDefaultActions: false,
+ // L / E / C 浠讳竴鍙樺寲鏃讹紝鑷姩閲嶇畻 D 涓庨闄╃瓑绾�
+ handleValuesChange: (values, changedFields) => {
+ const lecFields = ['likelihood', 'exposure', 'consequence'];
+ if (!lecFields.some((f) => changedFields.includes(f))) {
+ return;
+ }
+ const { likelihood, exposure, consequence } = values as MesSafetyRiskApi.Risk;
+ if (
+ likelihood === undefined ||
+ likelihood === null ||
+ exposure === undefined ||
+ exposure === null ||
+ consequence === undefined ||
+ consequence === null
+ ) {
+ riskValue.value = undefined;
+ riskLevel.value = undefined;
+ return;
+ }
+ const d = Number((likelihood * exposure * consequence).toFixed(2));
+ riskValue.value = d;
+ riskLevel.value = calcRiskLevel(d);
+ formApi.setFieldValue('riskValue', d);
+ formApi.setFieldValue('riskLevel', riskLevel.value);
+ },
+});
+
+const [Modal, modalApi] = useVbenModal({
+ async onConfirm() {
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ modalApi.lock();
+ const data = (await formApi.getValues()) as MesSafetyRiskApi.Risk;
+ try {
+ await (isUpdate.value ? updateRisk(data) : createRisk(data));
+ emit('success');
+ message.success('鎿嶄綔鎴愬姛');
+ await modalApi.close();
+ } finally {
+ modalApi.unlock();
+ }
+ },
+ async onOpenChange(isOpen: boolean) {
+ if (!isOpen) {
+ riskValue.value = undefined;
+ riskLevel.value = undefined;
+ return;
+ }
+ const data = modalApi.getData<{
+ formType: 'create' | 'update';
+ id?: number;
+ }>();
+ formType.value = data.formType;
+ await formApi.resetForm();
+ if (data?.id) {
+ modalApi.lock();
+ try {
+ const risk = await getRisk(data.id);
+ await formApi.setValues(risk);
+ riskValue.value = risk?.riskValue;
+ riskLevel.value = risk?.riskLevel;
+ } finally {
+ modalApi.unlock();
+ }
+ } else {
+ formApi.setFieldValue('status', 1);
+ }
+ },
+});
+</script>
+
+<template>
+ <Modal :title="getTitle" class="w-2/3">
+ <Form class="mx-4" />
+ <div v-if="riskValue !== undefined" class="mx-4 mt-2">
+ <Alert
+ :type="riskLevel === 1 ? 'error' : riskLevel === 2 ? 'warning' : 'info'"
+ show-icon
+ :message="`椋庨櫓璇勪及缁撴灉锛欴 = ${riskValue}锛屽垽瀹氫负銆�${riskLevelName(riskLevel)}銆峘"
+ />
+ </div>
+ </Modal>
+</template>
diff --git a/src/views/safety/risk/shared.ts b/src/views/safety/risk/shared.ts
new file mode 100644
index 0000000..b3b2f78
--- /dev/null
+++ b/src/views/safety/risk/shared.ts
@@ -0,0 +1,21 @@
+import { requestClient } from '#/api/request';
+
+/**
+ * 杞﹂棿涓嬫媺閫夐」
+ *
+ * 澶嶇敤鑳借�楁ā鍧楀凡鎻愪緵鐨勮溅闂撮�夐」鎺ュ彛锛堣繑鍥� MES 杞﹂棿琛ㄧ殑鍩虹鏁版嵁锛�
+ */
+export function getWorkshopOptions() {
+ return requestClient.get<Array<{ code?: string; id: number; name: string }>>(
+ '/mes/em/meter/workshop-options',
+ );
+}
+
+/**
+ * 鐢ㄦ埛绮剧畝鍒楄〃锛堢敤浜庤矗浠讳汉涓嬫媺锛�
+ */
+export function getSimpleUserList() {
+ return requestClient.get<
+ Array<{ id: number; nickname: string; username?: string }>
+ >('/system/user/simple-list');
+}
diff --git a/src/views/safety/risk/unit/data.ts b/src/views/safety/risk/unit/data.ts
new file mode 100644
index 0000000..affaec9
--- /dev/null
+++ b/src/views/safety/risk/unit/data.ts
@@ -0,0 +1,178 @@
+import type { VbenFormSchema } from '#/adapter/form';
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesSafetyRiskUnitApi } from '#/api/safety/risk/unit';
+
+import { DICT_TYPE } from '#/packages/constants/src';
+import { getDictOptions } from '#/packages/effects/hooks/src';
+
+import { z } from '#/adapter/form';
+import { getSimpleUserList, getWorkshopOptions } from '../shared';
+
+/** 鍒楄〃鐨勬悳绱㈣〃鍗� */
+export function useGridFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'code',
+ label: '鍗曞厓缂栫爜',
+ component: 'Input',
+ componentProps: { allowClear: true, placeholder: '璇疯緭鍏ラ闄╁崟鍏冪紪鐮�' },
+ },
+ {
+ fieldName: 'name',
+ label: '鍗曞厓鍚嶇О',
+ component: 'Input',
+ componentProps: { allowClear: true, placeholder: '璇疯緭鍏ラ闄╁崟鍏冨悕绉�' },
+ },
+ {
+ fieldName: 'riskCategory',
+ label: '椋庨櫓绫诲埆',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_RISK_CATEGORY, 'number'),
+ placeholder: '璇烽�夋嫨椋庨櫓绫诲埆',
+ },
+ },
+ {
+ fieldName: 'status',
+ label: '鐘舵��',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_UNIT_STATUS, 'number'),
+ placeholder: '璇烽�夋嫨鐘舵��',
+ },
+ },
+ ];
+}
+
+/** 鏂板/淇敼鐨勮〃鍗� */
+export function useFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'id',
+ component: 'Input',
+ dependencies: { triggerFields: [''], show: () => false },
+ },
+ {
+ fieldName: 'code',
+ label: '鍗曞厓缂栫爜',
+ component: 'Input',
+ componentProps: { placeholder: '濡� FX-001' },
+ rules: 'required',
+ },
+ {
+ fieldName: 'name',
+ label: '鍗曞厓鍚嶇О',
+ component: 'Input',
+ componentProps: { placeholder: '濡� 閫犵焊杞﹂棿1#鐑樼几' },
+ rules: 'required',
+ },
+ {
+ fieldName: 'workshopId',
+ label: '鎵�灞炶溅闂�',
+ component: 'ApiSelect',
+ componentProps: {
+ allowClear: true,
+ api: getWorkshopOptions,
+ labelField: 'name',
+ valueField: 'id',
+ placeholder: '璇烽�夋嫨鎵�灞炶溅闂�',
+ },
+ },
+ {
+ fieldName: 'location',
+ label: '鍏蜂綋浣嶇疆',
+ component: 'Input',
+ componentProps: { placeholder: '濡� 閫犵焊杞﹂棿涓滀晶' },
+ },
+ {
+ fieldName: 'riskCategory',
+ label: '椋庨櫓绫诲埆',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_RISK_CATEGORY, 'number'),
+ placeholder: '璇烽�夋嫨椋庨櫓绫诲埆',
+ },
+ },
+ {
+ fieldName: 'chargeUserId',
+ label: '璐d换浜�',
+ component: 'ApiSelect',
+ componentProps: {
+ allowClear: true,
+ api: getSimpleUserList,
+ labelField: 'nickname',
+ valueField: 'id',
+ placeholder: '璇烽�夋嫨璐d换浜�',
+ },
+ },
+ {
+ fieldName: 'status',
+ label: '鐘舵��',
+ component: 'RadioGroup',
+ componentProps: {
+ buttonStyle: 'solid',
+ optionType: 'button',
+ options: getDictOptions(DICT_TYPE.MES_SAFETY_UNIT_STATUS, 'number'),
+ },
+ rules: z.number().default(1),
+ },
+ {
+ fieldName: 'remark',
+ label: '澶囨敞',
+ component: 'Textarea',
+ formItemClass: 'col-span-2',
+ componentProps: { placeholder: '璇疯緭鍏ュ娉�', rows: 3 },
+ },
+ ];
+}
+
+/** 鍒楄〃鐨勫瓧娈� */
+export function useGridColumns(): VxeTableGridOptions<MesSafetyRiskUnitApi.RiskUnit>['columns'] {
+ return [
+ { field: 'code', title: '鍗曞厓缂栫爜', width: 130 },
+ { field: 'name', title: '鍗曞厓鍚嶇О', minWidth: 180 },
+ { field: 'workshopName', title: '鎵�灞炶溅闂�', width: 120 },
+ { field: 'location', title: '鍏蜂綋浣嶇疆', minWidth: 150 },
+ {
+ field: 'riskCategory',
+ title: '椋庨櫓绫诲埆',
+ width: 110,
+ cellRender: {
+ name: 'CellDict',
+ props: { type: DICT_TYPE.MES_SAFETY_RISK_CATEGORY },
+ },
+ },
+ { field: 'chargeUserName', title: '璐d换浜�', width: 100 },
+ {
+ field: 'riskCount',
+ title: '椋庨櫓鏉℃暟',
+ width: 100,
+ align: 'right',
+ slots: { default: 'riskCount' },
+ },
+ {
+ field: 'status',
+ title: '鐘舵��',
+ width: 90,
+ cellRender: {
+ name: 'CellDict',
+ props: { type: DICT_TYPE.MES_SAFETY_UNIT_STATUS },
+ },
+ },
+ {
+ field: 'createTime',
+ title: '鍒涘缓鏃堕棿',
+ width: 180,
+ formatter: 'formatDateTime',
+ },
+ {
+ title: '鎿嶄綔',
+ width: 160,
+ fixed: 'right',
+ slots: { default: 'actions' },
+ },
+ ];
+}
diff --git a/src/views/safety/risk/unit/index.vue b/src/views/safety/risk/unit/index.vue
new file mode 100644
index 0000000..7c5e8f2
--- /dev/null
+++ b/src/views/safety/risk/unit/index.vue
@@ -0,0 +1,126 @@
+<script lang="ts" setup>
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesSafetyRiskUnitApi } from '#/api/safety/risk/unit';
+
+import { Page } from '#/packages/effects/common-ui/src';
+
+import { Tag } from 'ant-design-vue';
+
+import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
+import { deleteRiskUnit, getRiskUnitPage } from '#/api/safety/risk/unit';
+import { useVbenModal } from '@vben/common-ui';
+
+import { message } from 'ant-design-vue';
+
+import { useGridColumns, useGridFormSchema } from './data';
+import Form from './modules/form.vue';
+
+defineOptions({ name: 'SafetyRiskUnit' });
+
+const [FormModal, formModalApi] = useVbenModal({
+ connectedComponent: Form,
+ destroyOnClose: true,
+});
+
+const [Grid, gridApi] = useVbenVxeGrid({
+ formOptions: {
+ schema: useGridFormSchema(),
+ },
+ gridOptions: {
+ columns: useGridColumns(),
+ height: 'auto',
+ keepSource: true,
+ proxyConfig: {
+ ajax: {
+ query: async ({ page }, formValues) =>
+ await getRiskUnitPage({
+ pageNo: page.currentPage,
+ pageSize: page.pageSize,
+ ...formValues,
+ }),
+ },
+ },
+ rowConfig: {
+ keyField: 'id',
+ isHover: true,
+ },
+ toolbarConfig: {
+ refresh: true,
+ search: true,
+ },
+ } as VxeTableGridOptions<MesSafetyRiskUnitApi.RiskUnit>,
+});
+
+/** 鏂板 */
+function handleCreate() {
+ formModalApi.setData({ formType: 'create' }).open();
+}
+
+/** 缂栬緫 */
+function handleEdit(row: MesSafetyRiskUnitApi.RiskUnit) {
+ formModalApi.setData({ formType: 'update', id: row.id }).open();
+}
+
+/** 鍒锋柊 */
+function handleRefresh() {
+ gridApi.query();
+}
+
+/** 鍒犻櫎 */
+async function handleDelete(row: MesSafetyRiskUnitApi.RiskUnit) {
+ await deleteRiskUnit(row.id!);
+ message.success('鍒犻櫎鎴愬姛');
+ gridApi.query();
+}
+</script>
+
+<template>
+ <Page auto-content-height>
+ <FormModal @success="handleRefresh" />
+ <Grid>
+ <template #toolbar-tools>
+ <TableAction
+ :actions="[
+ {
+ label: '鏂板椋庨櫓鍗曞厓',
+ type: 'primary',
+ icon: ACTION_ICON.ADD,
+ auth: ['mes:safety-risk-unit:create'],
+ onClick: handleCreate,
+ },
+ ]"
+ />
+ </template>
+
+ <template #riskCount="{ row }">
+ <Tag v-if="row.riskCount > 0" color="processing">{{ row.riskCount }}</Tag>
+ <span v-else class="text-gray-400">0</span>
+ </template>
+
+ <template #actions="{ row }">
+ <TableAction
+ :actions="[
+ {
+ label: '缂栬緫',
+ type: 'link',
+ icon: ACTION_ICON.EDIT,
+ auth: ['mes:safety-risk-unit:update'],
+ onClick: handleEdit.bind(null, row),
+ },
+ {
+ label: '鍒犻櫎',
+ type: 'link',
+ danger: true,
+ icon: ACTION_ICON.DELETE,
+ auth: ['mes:safety-risk-unit:delete'],
+ popConfirm: {
+ title: '纭畾鍒犻櫎璇ラ闄╁崟鍏冨悧锛�',
+ confirm: handleDelete.bind(null, row),
+ },
+ },
+ ]"
+ />
+ </template>
+ </Grid>
+ </Page>
+</template>
diff --git a/src/views/safety/risk/unit/modules/form.vue b/src/views/safety/risk/unit/modules/form.vue
new file mode 100644
index 0000000..e4cc218
--- /dev/null
+++ b/src/views/safety/risk/unit/modules/form.vue
@@ -0,0 +1,84 @@
+<script lang="ts" setup>
+import type { MesSafetyRiskUnitApi } from '#/api/safety/risk/unit';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { message } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+import {
+ createRiskUnit,
+ getRiskUnit,
+ updateRiskUnit,
+} from '#/api/safety/risk/unit';
+
+import { useFormSchema } from '../data';
+
+const emit = defineEmits(['success']);
+
+const formType = ref<'create' | 'update'>('create');
+const isUpdate = computed(() => formType.value === 'update');
+const getTitle = computed(() =>
+ isUpdate.value ? '淇敼椋庨櫓鍗曞厓' : '鏂板椋庨櫓鍗曞厓',
+);
+
+const [Form, formApi] = useVbenForm({
+ commonConfig: {
+ componentProps: { class: 'w-full' },
+ formItemClass: 'col-span-1',
+ labelWidth: 100,
+ },
+ wrapperClass: 'grid-cols-2',
+ layout: 'horizontal',
+ schema: useFormSchema(),
+ showDefaultActions: false,
+});
+
+const [Modal, modalApi] = useVbenModal({
+ async onConfirm() {
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ modalApi.lock();
+ const data = (await formApi.getValues()) as MesSafetyRiskUnitApi.RiskUnit;
+ try {
+ await (isUpdate.value
+ ? updateRiskUnit(data)
+ : createRiskUnit(data));
+ emit('success');
+ message.success('鎿嶄綔鎴愬姛');
+ await modalApi.close();
+ } finally {
+ modalApi.unlock();
+ }
+ },
+ async onOpenChange(isOpen: boolean) {
+ if (!isOpen) {
+ return;
+ }
+ const data = modalApi.getData<{ formType: 'create' | 'update'; id?: number }>();
+ formType.value = data.formType;
+ await formApi.resetForm();
+ if (data?.id) {
+ modalApi.lock();
+ try {
+ const unit = await getRiskUnit(data.id);
+ await formApi.setValues(unit);
+ } finally {
+ modalApi.unlock();
+ }
+ } else {
+ formApi.setFieldValue('status', 1);
+ }
+ },
+});
+</script>
+
+<template>
+ <Modal :title="getTitle" class="w-1/2">
+ <Form class="mx-4" />
+ </Modal>
+</template>
--
Gitblit v1.9.3