diff --git a/package.json b/package.json index f5232a8..41d216a 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "js-cookie": "3.0.5", "jsencrypt": "3.3.2", "lodash-es": "^4.17.21", + "mitt": "^3.0.1", "nprogress": "0.2.0", "pinia": "3.0.2", "splitpanes": "4.0.4", diff --git a/src/api/common.js b/src/api/common.js new file mode 100644 index 0000000..c5b1531 --- /dev/null +++ b/src/api/common.js @@ -0,0 +1,27 @@ +import request from '@/utils/request' + +// 公共下拉选数据 - 获取人员所属 +export function getInspectionStationSelectAPI(query = { category: 0 }) { + return request({ + url: '/personnel/getInspectionStationSelect', + method: 'GET', + params: query, + }) +} +// 公共下拉选数据 - 获取岗位 +export function getPositionSelectAPI(query = { category: 0 }) { + return request({ + url: '/personnel/getInspectionStationSelect', + method: 'GET', + params: query, + }) +} + +// 公共下拉选数据 - 获取人员性质和人员分类 +export function getPersonNatureAndCategorySelectAPI(data) { + return request({ + url: '/personnel/getPersonnelClassificationSelect', + method: 'GET', + params: data, + }) +} diff --git a/src/api/personManage/person.js b/src/api/personManage/person.js new file mode 100644 index 0000000..03c6c3f --- /dev/null +++ b/src/api/personManage/person.js @@ -0,0 +1,37 @@ +import request from '@/utils/request' + +// 人员管理- 查询列表 +export function listPersonAPI(query) { + return request({ + url: '/personnel/getPersonnelList', + method: 'GET', + params: query, + }) +} + +// 人员管理- 新增 +export function addPersonAPI(data) { + return request({ + url: '/personnel/addPersonnel', + method: 'POST', + data, + }) +} + +// 人员管理- 修改 +export function updatePersonAPI(data) { + return request({ + url: '/personnel/updatePersonnel', + method: 'POST', + data, + }) +} + +// 人员管理- 删除 +export function delPersonAPI(data) { + return request({ + url: `/personnel/delPersonnel`, + method: 'POST', + data, + }) +} diff --git a/src/components/ComDialog/index.vue b/src/components/ComDialog/index.vue index d5edfb1..cd5c9b2 100644 --- a/src/components/ComDialog/index.vue +++ b/src/components/ComDialog/index.vue @@ -73,9 +73,9 @@ const handleCloseInner = () => { flex-direction: column; margin: 0; position: absolute; - top: 50%; + top: 25%; left: 50%; - transform: translate(-50%, -75%); + transform: translate(-50%, -25%); min-height: var(--com-dialog-min-height); max-height: var(--com-dialog-max-height); border-radius: 16px; diff --git a/src/hooks/useOptions.js b/src/hooks/useOptions.js new file mode 100644 index 0000000..1adcc08 --- /dev/null +++ b/src/hooks/useOptions.js @@ -0,0 +1,48 @@ +import { ref, onMounted, onUnmounted } from 'vue' +import { bus, BUS_EVENTS } from '@/utils/bus' + +import useOptionsStore from '@/store/modules/options' + +export function useOptions(type, apiFn, params = {}) { + const options = ref([]) + const optionStore = useOptionsStore() + + const fetchOptions = async (force = false) => { + // 1. 如果不是强制刷新,且 Store 中已有值,直接取 Store + if (!force && optionStore[type] && optionStore[type].length > 0) { + options.value = optionStore[type] + return + } + + // 2. 否则调接口 + try { + const res = await apiFn(params) + const data = res.rows || res.data || [] + options.value = data + // 3. 更新 Store 缓存 + optionStore.setOptions(type, data) + } catch (error) { + console.error(`获取${type}下拉失败:`, error) + } + } + + // 监听刷新信号 + const handleRefresh = (refreshType) => { + if (refreshType === type || refreshType === 'all') { + fetchOptions(true) // 强制刷新 + } + } + + onMounted(() => { + fetchOptions() + bus.on(BUS_EVENTS.REFRESH_OPTIONS, handleRefresh) + }) + + onUnmounted(() => { + bus.off(BUS_EVENTS.REFRESH_OPTIONS, handleRefresh) + }) + + return { + options, + } +} diff --git a/src/store/modules/options.js b/src/store/modules/options.js new file mode 100644 index 0000000..ece98ce --- /dev/null +++ b/src/store/modules/options.js @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia' + +const useOptionsStore = defineStore('options', { + state: () => ({ + positionOptions: [], // 人员岗位 + personNatureOptions: [], // 人员性质 + personCategoryOptions: [], // 人员分类 + inspectionStationOptions: [], // 运检站 + }), + actions: { + // 通用的设置方法,方便 Hook 调用 + setOptions(type, options) { + this[type] = options + }, + // 清空特定缓存 + clearOptions(type) { + this[type] = [] + }, + }, +}) + +export default useOptionsStore diff --git a/src/utils/bus.js b/src/utils/bus.js new file mode 100644 index 0000000..3d4cb73 --- /dev/null +++ b/src/utils/bus.js @@ -0,0 +1,7 @@ +import mitt from 'mitt' +export const bus = mitt() + +// 定义事件名称常量 +export const BUS_EVENTS = { + REFRESH_OPTIONS: 'REFRESH_OPTIONS', // 刷新下拉选项信号 +} diff --git a/src/views/basicManage/inspectionStation/index.vue b/src/views/basicManage/inspectionStation/index.vue index 8e26c7f..9b99396 100644 --- a/src/views/basicManage/inspectionStation/index.vue +++ b/src/views/basicManage/inspectionStation/index.vue @@ -66,6 +66,7 @@ import { delInspectionStationAPI, updateInspectionStationAPI, } from '@/api/basicManage/inspectionStation' +import { bus, BUS_EVENTS } from '@/utils/bus' import config from './config' import ComTable from '@/components/ComTable/index.vue' import ComButton from '@/components/ComButton/index.vue' @@ -120,6 +121,7 @@ const actionColumns = [ }) if (result.code === 200) { proxy.$modal.msgSuccess('删除成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'inspectionStationOptions') // 刷新运检站下拉缓存 comTableRef.value?.refresh() // 刷新表格 } }) @@ -157,6 +159,7 @@ const onHandleSave = async () => { const result = await API(params) if (result.code === 200) { proxy.$modal.msgSuccess(editId.value ? '编辑成功' : '新增成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'inspectionStationOptions') // 刷新运检站下拉缓存 addAndEditFormRef.value.resetFields() // 重置表单 dialogConfig.outerVisible = false comTableRef.value?.refresh() // 刷新表格 diff --git a/src/views/basicManage/personCategory/index.vue b/src/views/basicManage/personCategory/index.vue index 1d146f5..7fe68da 100644 --- a/src/views/basicManage/personCategory/index.vue +++ b/src/views/basicManage/personCategory/index.vue @@ -66,6 +66,7 @@ import { delPersonCategoryAPI, updatePersonCategoryAPI, } from '@/api/basicManage/personCategory' +import { bus, BUS_EVENTS } from '@/utils/bus' import config from './config' import ComTable from '@/components/ComTable/index.vue' import ComButton from '@/components/ComButton/index.vue' @@ -121,6 +122,7 @@ const actionColumns = [ }) if (result.code === 200) { proxy.$modal.msgSuccess('删除成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'personCategoryOptions') // 刷新人员分类下拉缓存 comTableRef.value?.refresh() // 刷新表格 } }) @@ -158,6 +160,7 @@ const onHandleSave = async () => { const result = await API(params) if (result.code === 200) { proxy.$modal.msgSuccess(editId.value ? '编辑成功' : '新增成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'personCategoryOptions') // 刷新人员分类下拉缓存 addAndEditFormRef.value.resetFields() // 重置表单 dialogConfig.outerVisible = false comTableRef.value?.refresh() // 刷新表格 diff --git a/src/views/basicManage/personNature/index.vue b/src/views/basicManage/personNature/index.vue index 6c6bb08..ecd0b7f 100644 --- a/src/views/basicManage/personNature/index.vue +++ b/src/views/basicManage/personNature/index.vue @@ -66,6 +66,7 @@ import { delPersonNatureAPI, updatePersonNatureAPI, } from '@/api/basicManage/personNature' +import { bus, BUS_EVENTS } from '@/utils/bus' import config from './config' import ComTable from '@/components/ComTable/index.vue' import ComButton from '@/components/ComButton/index.vue' @@ -121,6 +122,7 @@ const actionColumns = [ }) if (result.code === 200) { proxy.$modal.msgSuccess('删除成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'personNatureOptions') // 刷新人员性质下拉缓存 comTableRef.value?.refresh() // 刷新表格 } }) @@ -158,6 +160,7 @@ const onHandleSave = async () => { const result = await API(params) if (result.code === 200) { proxy.$modal.msgSuccess(editId.value ? '编辑成功' : '新增成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'personNatureOptions') // 刷新人员性质下拉缓存 addAndEditFormRef.value.resetFields() // 重置表单 dialogConfig.outerVisible = false comTableRef.value?.refresh() // 刷新表格 diff --git a/src/views/basicManage/position/index.vue b/src/views/basicManage/position/index.vue index 07fd451..f0d6751 100644 --- a/src/views/basicManage/position/index.vue +++ b/src/views/basicManage/position/index.vue @@ -66,6 +66,7 @@ import { delPositionAPI, updatePositionAPI, } from '@/api/basicManage/position' +import { bus, BUS_EVENTS } from '@/utils/bus' import config from './config' import ComTable from '@/components/ComTable/index.vue' import ComButton from '@/components/ComButton/index.vue' @@ -119,6 +120,7 @@ const actionColumns = [ }) if (result.code === 200) { proxy.$modal.msgSuccess('删除成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'positionOptions') comTableRef.value?.refresh() // 刷新表格 } }) @@ -156,6 +158,7 @@ const onHandleSave = async () => { const result = await API(params) if (result.code === 200) { proxy.$modal.msgSuccess(editId.value ? '编辑成功' : '新增成功') + bus.emit(BUS_EVENTS.REFRESH_OPTIONS, 'positionOptions') // 刷新岗位下拉缓存 addAndEditFormRef.value.resetFields() // 重置表单 dialogConfig.outerVisible = false comTableRef.value?.refresh() // 刷新表格 diff --git a/src/views/personManage/Person/addAndEditForm.vue b/src/views/personManage/Person/addAndEditForm.vue new file mode 100644 index 0000000..aacb471 --- /dev/null +++ b/src/views/personManage/Person/addAndEditForm.vue @@ -0,0 +1,181 @@ + + + + + diff --git a/src/views/personManage/Person/config.js b/src/views/personManage/Person/config.js new file mode 100644 index 0000000..d803002 --- /dev/null +++ b/src/views/personManage/Person/config.js @@ -0,0 +1,53 @@ +import { reactive } from 'vue' +export default { + formColumns: [ + { + type: 'input', + prop: 'personName', + placeholder: '请输入姓名', + }, + ], + tableColumns: [ + { + prop: 'orgName', + label: '人员所属', + }, + { + prop: 'personName', + label: '姓名', + }, + { + prop: 'gender', + label: '性别', + type: 'dict', // 假设有字典处理 + dictData: [ + { label: '男', value: 0 }, + { label: '女', value: 1 }, + ], + }, + { + prop: 'phone', + label: '电话', + }, + { + prop: 'positionName', + label: '岗位', + }, + { + prop: 'natureName', + label: '人员性质', + }, + { + prop: 'categoryName', + label: '人员分类', + }, + ], + + dialogConfig: reactive({ + outerVisible: false, + outerTitle: '新增人员', + outerWidth: '640px', // 根据图片缩小宽度更美观 + minHeight: '400px', + maxHeight: '80vh', + }), +} diff --git a/src/views/personManage/Person/index.vue b/src/views/personManage/Person/index.vue index 9fed1ae..472fd2f 100644 --- a/src/views/personManage/Person/index.vue +++ b/src/views/personManage/Person/index.vue @@ -1,7 +1,140 @@ - +