优化
This commit is contained in:
@ -1,104 +1,95 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item label="周期范围" prop="scope">
|
||||
<el-date-picker
|
||||
clearable
|
||||
v-model="queryParams.scopeDate"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始时间"
|
||||
end-placeholder="结束时间"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="system-busWeeklySecurityReport-container">
|
||||
<el-card shadow="hover">
|
||||
<div class="system-busWeeklySecurityReport-search mb15">
|
||||
<el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="100px">
|
||||
<el-row>
|
||||
<el-col :span="1.5">
|
||||
<el-form-item label="周期范围" prop="scopeDate">
|
||||
<el-date-picker
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
v-model="scopeDate"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始时间"
|
||||
end-placeholder="结束时间"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="onSearch"
|
||||
><el-icon><ele-Search /></el-icon>搜索</el-button
|
||||
>
|
||||
<el-button @click="resetQuery(queryRef)"
|
||||
><el-icon><ele-Refresh /></el-icon>重置</el-button
|
||||
>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['safety:safetyWeeklyReport:add']">新增 </el-button>
|
||||
<el-button type="primary" @click="handleAdd" v-auth="'api/v1/system/busWeeklySecurityReport/add'"
|
||||
><el-icon><ele-Plus /></el-icon>新增</el-button
|
||||
>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete()"
|
||||
v-hasPermi="['safety:safetyWeeklyReport:remove']"
|
||||
<el-button type="danger" :disabled="multiple" @click="handleDelete(null)" v-auth="'api/v1/system/busWeeklySecurityReport/delete'"
|
||||
><el-icon><ele-Delete /></el-icon>删除</el-button
|
||||
>
|
||||
批量删除
|
||||
</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="safetyWeeklyReportList" @selection-change="handleSelectionChange">
|
||||
</div>
|
||||
<el-table v-loading="loading" :data="tableData.data" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="序号" type="index" width="60" align="center" />
|
||||
<el-table-column label="周期" align="center" prop="week" />
|
||||
<el-table-column label="周期范围" align="center" prop="scope" width="260">
|
||||
<el-table-column label="序号" align="center" type="index" min-width="50px" />
|
||||
<el-table-column label="周" align="center" prop="week" min-width="100px" />
|
||||
<el-table-column label="周期范围" align="center" prop="scope" min-width="200px">
|
||||
<template #default="scope">
|
||||
<span>{{ parseTime(scope.row.scope, '{y}-{m}-{d}') }} 至 {{ parseTime(scope.row.scopeEnd, '{y}-{m}-{d}') }}</span>
|
||||
<span>{{ scope.row.scope + '至' + scope.row.scopeEnd }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createdAt" />
|
||||
<!-- <el-table-column label="备注" align="center" prop="remark" /> -->
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<!-- <el-table-column label="文件位置" align="center" prop="path" min-width="100px" /> -->
|
||||
<el-table-column label="创建时间" align="center" prop="createdAt" min-width="100px">
|
||||
<template #default="scope">
|
||||
<el-space>
|
||||
<el-button link type="success" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['safety:safetyWeeklyReport:edit']">
|
||||
修改
|
||||
</el-button>
|
||||
<el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['safety:safetyWeeklyReport:remove']">
|
||||
删除
|
||||
</el-button>
|
||||
</el-space>
|
||||
<span>{{ scope.row.createdAt }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding" min-width="200px" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link @click="handleView(scope.row)"
|
||||
><el-icon><ele-View /></el-icon>预览</el-button
|
||||
>
|
||||
<el-button type="success" link @click="handleUpdate(scope.row)" v-auth="'api/v1/system/busWeeklySecurityReport/edit'"
|
||||
><el-icon><ele-EditPen /></el-icon>修改</el-button
|
||||
>
|
||||
<el-button type="danger" link @click="handleDelete(scope.row)" v-auth="'api/v1/system/busWeeklySecurityReport/delete'"
|
||||
><el-icon><ele-DeleteFilled /></el-icon>删除</el-button
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||||
<pagination
|
||||
v-show="tableData.total > 0"
|
||||
:total="tableData.total"
|
||||
v-model:page="tableData.param.pageNum"
|
||||
v-model:limit="tableData.param.pageSize"
|
||||
@pagination="busWeeklySecurityReportList"
|
||||
/>
|
||||
</el-card>
|
||||
<!-- 添加或修改安全周报对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="safetyWeeklyReportFormRef" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="周期范围" prop="timeRange">
|
||||
<el-date-picker
|
||||
v-model="form.timeRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
format="YYYY-MM-DD"
|
||||
start-placeholder="开始时间"
|
||||
end-placeholder="结束时间"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<apiV1SystemBusWeeklySecurityReportAdd
|
||||
ref="addRef"
|
||||
@busWeeklySecurityReportList="busWeeklySecurityReportList"
|
||||
></apiV1SystemBusWeeklySecurityReportAdd>
|
||||
<documentsEdit ref="documentsEditRef" v-if="documentsEditShow" @onClose="documentsEditShow = false"></documentsEdit>
|
||||
<documentsDetail ref="documentsDetailRef" v-if="documentsDetailShow" @onClose="documentsDetailShow = false"></documentsDetail>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="SafetyWeeklyReport" lang="ts">
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, onMounted, ref, defineComponent, computed, getCurrentInstance, toRaw, nextTick } from 'vue';
|
||||
import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
|
||||
import {
|
||||
addSafetyWeeklyReport,
|
||||
delSafetyWeeklyReport,
|
||||
@ -106,175 +97,170 @@ import {
|
||||
listSafetyWeeklyReport,
|
||||
updateSafetyWeeklyReport
|
||||
} from '@/api/safety/safetyWeeklyReport';
|
||||
import { SafetyWeeklyReportForm, SafetyWeeklyReportQuery, SafetyWeeklyReportVO } from '@/api/safety/safetyWeeklyReport/types';
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
import { dayjs } from 'element-plus';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
|
||||
import apiV1SystemBusWeeklySecurityReportAdd from './component/add.vue';
|
||||
// 预览文档
|
||||
import documentsDetail from './component/documentsDetail/index.vue';
|
||||
// 编辑文档
|
||||
import documentsEdit from './component/documentsEdit/index.vue';
|
||||
// 获取用户 store
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
const userStore = useUserStoreHook();
|
||||
// 从 store 中获取项目列表和当前选中的项目
|
||||
const currentProject = computed(() => userStore.selectedProject);
|
||||
const safetyWeeklyReportList = ref<SafetyWeeklyReportVO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const safetyWeeklyReportFormRef = ref<ElFormInstance>();
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData: SafetyWeeklyReportForm = {
|
||||
id: undefined,
|
||||
projectId: currentProject.value?.goId,
|
||||
week: undefined,
|
||||
scope: undefined,
|
||||
scopeEnd: undefined,
|
||||
path: undefined,
|
||||
remark: undefined
|
||||
};
|
||||
const data = reactive<PageData<SafetyWeeklyReportForm, SafetyWeeklyReportQuery>>({
|
||||
form: { ...initFormData },
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
id: undefined,
|
||||
projectId: currentProject.value?.goId,
|
||||
week: undefined,
|
||||
scopeDate: undefined,
|
||||
remark: undefined,
|
||||
params: {}
|
||||
export default defineComponent({
|
||||
name: 'index',
|
||||
components: {
|
||||
apiV1SystemBusWeeklySecurityReportAdd,
|
||||
documentsDetail,
|
||||
documentsEdit
|
||||
},
|
||||
rules: {
|
||||
id: [{ required: true, message: '主键id不能为空', trigger: 'blur' }],
|
||||
projectId: [{ required: true, message: '项目id不能为空', trigger: 'blur' }],
|
||||
timeRange: [{ required: true, message: '周期范围不能为空', trigger: 'blur' }]
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询安全周报列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listSafetyWeeklyReport(queryParams.value);
|
||||
safetyWeeklyReportList.value = res.data.list;
|
||||
total.value = res.data.total;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = { ...initFormData };
|
||||
safetyWeeklyReportFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: SafetyWeeklyReportVO[]) => {
|
||||
ids.value = selection.map((item) => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = () => {
|
||||
reset();
|
||||
dialog.visible = true;
|
||||
dialog.title = '添加安全周报';
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: SafetyWeeklyReportVO) => {
|
||||
return;
|
||||
reset();
|
||||
const _id = row?.id || ids.value[0];
|
||||
// const res = await getSafetyWeeklyReport(_id);
|
||||
// Object.assign(form.value, res.data);
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改安全周报';
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
safetyWeeklyReportFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
form.value.projectId = currentProject.value?.goId;
|
||||
if (form.value.id) {
|
||||
await updateSafetyWeeklyReport(form.value).finally(() => (buttonLoading.value = false));
|
||||
setup() {
|
||||
const { proxy } = <any>getCurrentInstance();
|
||||
const loading = ref(false);
|
||||
const queryRef = ref();
|
||||
const addRef = ref();
|
||||
// 是否显示所有搜索选项
|
||||
const showAll = ref(false);
|
||||
const documentsDetailRef = ref(false);
|
||||
const documentsEditRef = ref(false);
|
||||
// 非单个禁用
|
||||
const single = ref(true);
|
||||
// 非多个禁用
|
||||
const multiple = ref(true);
|
||||
// 字典选项数据
|
||||
const state = reactive({
|
||||
ids: [],
|
||||
documentsDetailShow: false,
|
||||
documentsEditShow: false,
|
||||
tableData: {
|
||||
data: [],
|
||||
total: 0,
|
||||
loading: false,
|
||||
param: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
id: undefined,
|
||||
projectId: currentProject.value?.goId,
|
||||
projectName: undefined,
|
||||
scope: undefined,
|
||||
scopeEnd: undefined,
|
||||
path: undefined,
|
||||
createBy: undefined,
|
||||
updateBy: undefined,
|
||||
createdAt: undefined,
|
||||
dateRange: [],
|
||||
scopeDate: ''
|
||||
}
|
||||
},
|
||||
projectList: [],
|
||||
scopeDate: [] //时间范围
|
||||
});
|
||||
// 页面加载时
|
||||
onMounted(() => {
|
||||
initTableData();
|
||||
});
|
||||
// 初始化表格数据
|
||||
const initTableData = () => {
|
||||
busWeeklySecurityReportList();
|
||||
};
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
state.scopeDate = [];
|
||||
state.tableData.param.scopeDate = '';
|
||||
formEl.resetFields();
|
||||
busWeeklySecurityReportList();
|
||||
};
|
||||
const onSearch = () => {
|
||||
state.tableData.param.scopeDate = state.scopeDate.join(',');
|
||||
busWeeklySecurityReportList();
|
||||
};
|
||||
// 获取列表数据
|
||||
const busWeeklySecurityReportList = () => {
|
||||
loading.value = true;
|
||||
listSafetyWeeklyReport(state.tableData.param).then((res: any) => {
|
||||
let list = res.data.list ?? [];
|
||||
state.tableData.data = list;
|
||||
state.tableData.total = res.data.total;
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
// 多选框选中数据
|
||||
const handleSelectionChange = (selection) => {
|
||||
state.ids = selection.map((item) => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
const handleAdd = () => {
|
||||
addRef.value.openDialog();
|
||||
};
|
||||
const handleUpdate = (row) => {
|
||||
state.documentsEditShow = true;
|
||||
nextTick(() => {
|
||||
documentsEditRef.value.openDialog(row);
|
||||
});
|
||||
};
|
||||
const handleDelete = (row) => {
|
||||
let msg = '你确定要删除所选数据?';
|
||||
let id: number[] = [];
|
||||
if (row) {
|
||||
msg = `此操作将永久删除数据,是否继续?`;
|
||||
id = [row.id];
|
||||
} else {
|
||||
form.value.timeRange = form.value.timeRange.map((d) => dayjs(d).format('YYYY-MM-DD')).join(',');
|
||||
await addSafetyWeeklyReport(form.value).finally(() => (buttonLoading.value = false));
|
||||
id = state.ids;
|
||||
}
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
if (id.length === 0) {
|
||||
ElMessage.error('请选择要删除的数据。');
|
||||
return;
|
||||
}
|
||||
ElMessageBox.confirm(msg, '提示', {
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
delSafetyWeeklyReport(id).then(() => {
|
||||
ElMessage.success('删除成功');
|
||||
busWeeklySecurityReportList();
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
const handleView = (row) => {
|
||||
state.documentsDetailShow = true;
|
||||
nextTick(() => {
|
||||
documentsDetailRef.value.openDialog(row);
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: SafetyWeeklyReportVO) => {
|
||||
const _ids = row?.id || ids.value;
|
||||
await proxy?.$modal.confirm('是否确认删除安全周报编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
|
||||
await delSafetyWeeklyReport(_ids);
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
await getList();
|
||||
};
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
proxy?.download(
|
||||
'safety/safetyWeeklyReport/export',
|
||||
{
|
||||
...queryParams.value
|
||||
},
|
||||
`safetyWeeklyReport_${new Date().getTime()}.xlsx`
|
||||
);
|
||||
};
|
||||
|
||||
//监听项目id刷新数据
|
||||
const listeningProject = watch(
|
||||
() => currentProject.value?.goId,
|
||||
(nid, oid) => {
|
||||
queryParams.value.projectId = nid;
|
||||
form.value.projectId = nid;
|
||||
getList();
|
||||
return {
|
||||
proxy,
|
||||
addRef,
|
||||
showAll,
|
||||
loading,
|
||||
single,
|
||||
multiple,
|
||||
documentsEditRef,
|
||||
documentsDetailRef,
|
||||
queryRef,
|
||||
resetQuery,
|
||||
onSearch,
|
||||
busWeeklySecurityReportList,
|
||||
handleSelectionChange,
|
||||
handleAdd,
|
||||
handleUpdate,
|
||||
handleDelete,
|
||||
handleView,
|
||||
...toRefs(state)
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
onUnmounted(() => {
|
||||
listeningProject();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.colBlock {
|
||||
display: block;
|
||||
}
|
||||
.colNone {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user