doubleSystemManagement.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="safety-platform-container">
  3. <header class="safety-platform-container__header">
  4. <div class="breadcrumb-title"> 双体系建设管理 </div>
  5. </header>
  6. <main class="safety-platform-container__main">
  7. <div class="search-table-container">
  8. <header>
  9. <div style="position: relative">
  10. <el-button type="primary" class="search-table-container--button" @click="handleCreate">
  11. 添加
  12. </el-button>
  13. <el-button plain class="search-table-container--button" @click="handleImport">
  14. 导入
  15. </el-button>
  16. <el-button plain class="search-table-container--button" @click="handleDownload">
  17. 导出
  18. </el-button>
  19. </div>
  20. <div class="act-search">
  21. <section class="select-box">
  22. <div class="select-box--item">
  23. <span>文件名称/编号:</span>
  24. <el-input
  25. v-model="queryParams.keyword"
  26. placeholder="搜索文件名称或编号"
  27. class="act-search-input"
  28. />
  29. </div>
  30. <div class="select-box--item">
  31. <span>分类:</span>
  32. <el-select
  33. v-model="queryParams.classifyName"
  34. placeholder="请选择分类"
  35. clearable
  36. >
  37. <el-option label="外部文件" value="外部文件" />
  38. <el-option label="内部文件" value="内部文件" />
  39. </el-select>
  40. </div>
  41. <div class="select-box--item">
  42. <span>状态:</span>
  43. <el-select
  44. v-model="queryParams.status"
  45. placeholder="请选择状态"
  46. clearable
  47. >
  48. <el-option label="启用" :value="1" />
  49. <el-option label="禁用" :value="0" />
  50. </el-select>
  51. </div>
  52. <div class="select-box--item">
  53. <span>上传日期范围:</span>
  54. <el-date-picker
  55. v-model="uploadDateRange"
  56. type="daterange"
  57. range-separator="至"
  58. start-placeholder="开始日期"
  59. end-placeholder="结束日期"
  60. value-format="YYYY-MM-DD"
  61. format="YYYY-MM-DD"
  62. />
  63. </div>
  64. </section>
  65. <section class="search-btn">
  66. <el-button type="primary" @click="handleSearch">查询</el-button>
  67. <el-button @click="handleReset">重置</el-button>
  68. </section>
  69. </div>
  70. </header>
  71. <div class="batch-table">
  72. <BasicTable
  73. ref="basicTableRef"
  74. :tableData="tableData"
  75. :tableConfig="tableConfig"
  76. @update:pageSize="handleSizeChange"
  77. @update:pageNumber="handleCurrentChange"
  78. >
  79. <template #status="scope">
  80. <span>
  81. {{ scope.row.status === 1 ? '启用' : scope.row.status === 0 ? '禁用' : '-' }}
  82. </span>
  83. </template>
  84. <template #action="scope">
  85. <div class="action-container--div" style="justify-content: left">
  86. <ActionButton text="编辑" @click="handleEdit(scope.row.id)" />
  87. <ActionButton
  88. text="删除"
  89. :popconfirm="{
  90. title: '确定要删除?',
  91. }"
  92. @confirm="handleDelete(scope.row.id)"
  93. />
  94. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  95. <ActionButton text="下载" @click="handleDownloadFile(scope.row)" />
  96. </div>
  97. </template>
  98. </BasicTable>
  99. </div>
  100. </div>
  101. </main>
  102. <BatchImport
  103. v-if="batchImportVisible"
  104. :visible="batchImportVisible"
  105. :import-api-url="importApiUrl"
  106. :template-url="templateUrl"
  107. template-name="下载模板"
  108. :show-template="false"
  109. @close="batchImportVisible = false"
  110. @update="handleUpdate"
  111. />
  112. </div>
  113. </template>
  114. <script setup lang="ts">
  115. import { onMounted, reactive, ref } from 'vue';
  116. import { ElMessage } from 'element-plus';
  117. import BasicTable from '@/components/BasicTable.vue';
  118. import useTableConfig from '@/hooks/useTableConfigHook';
  119. import ActionButton from '@/components/ActionButton.vue';
  120. import { TABLE_OPTIONS, INVENTORY_TABLE_COLUMNS } from './configs/tables';
  121. import { useRouter } from 'vue-router';
  122. import {
  123. queryDualSystemPage,
  124. deleteDualSystem,
  125. exportDualSystem,
  126. type ProductionSafetyFileQuery,
  127. type ProductionSafetyFilePageQuery,
  128. } from '@/api/production-safety-system';
  129. import { downloadByData } from '@/utils/file/download';
  130. import BatchImport from '@/components/batch-import/BatchImport.vue';
  131. import { useGlobSetting } from '@/hooks/setting';
  132. import urlJoin from 'url-join';
  133. const router = useRouter();
  134. // 表格
  135. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  136. const { tableConfig, pagination } = useTableConfig(INVENTORY_TABLE_COLUMNS, TABLE_OPTIONS);
  137. const tableData = ref<any[]>([]);
  138. const queryParams = reactive<ProductionSafetyFileQuery>({
  139. keyword: '', // 文件名称/编号(模糊查询)
  140. status: undefined, // 状态:1-启用,0-禁用
  141. classifyName: '', // 分类名称:外部文件/内部文件
  142. startDate: '', // 上传日期范围-开始日期
  143. endDate: '', // 上传日期范围-结束日期
  144. });
  145. // 上传日期范围(用于日期选择器)
  146. const uploadDateRange = ref<[string, string] | null>(null);
  147. const handleSizeChange = (value: number) => {
  148. pagination.pageSize = value;
  149. getTableData();
  150. };
  151. const handleCurrentChange = (value: number) => {
  152. pagination.pageNumber = value;
  153. getTableData();
  154. };
  155. async function getTableData() {
  156. tableConfig.loading = true;
  157. try {
  158. const pageQuery: ProductionSafetyFilePageQuery = {
  159. pageNumber: pagination.pageNumber,
  160. pageSize: pagination.pageSize,
  161. queryParam: {
  162. keyword: queryParams.keyword || undefined,
  163. status: queryParams.status,
  164. classifyName: queryParams.classifyName || undefined,
  165. startDate: queryParams.startDate || undefined,
  166. endDate: queryParams.endDate || undefined,
  167. },
  168. };
  169. const res = await queryDualSystemPage(pageQuery, queryParams.classifyName || undefined);
  170. if (res) {
  171. // 映射返回数据字段到表格字段
  172. tableData.value = res.records.map((item) => ({
  173. id: item.id,
  174. fileName: item.fileName, // 文件名称
  175. fileCode: item.fileCode, // 文件编号
  176. classifyName: item.classifyName, // 分类名称
  177. fileVersion: item.fileVersion, // 文件版本号
  178. fileFormat: item.fileFormat, // 文件格式
  179. releaseDate: item.releaseDate, // 发布日期
  180. status: item.status, // 状态:1-启用,0-禁用
  181. fileUrl: item.fileUrl, // 文件地址
  182. uploadTime: item.uploadTime || item.createdAt, // 上传时间
  183. }));
  184. pagination.total = res.totalRow || 0;
  185. }
  186. } catch (e) {
  187. console.error('获取双体系建设列表失败:', e);
  188. tableData.value = [];
  189. pagination.total = 0;
  190. } finally {
  191. tableConfig.loading = false;
  192. }
  193. }
  194. const handleSearch = () => {
  195. // 处理日期范围
  196. if (uploadDateRange.value && uploadDateRange.value.length === 2) {
  197. queryParams.startDate = uploadDateRange.value[0];
  198. queryParams.endDate = uploadDateRange.value[1];
  199. } else {
  200. queryParams.startDate = '';
  201. queryParams.endDate = '';
  202. }
  203. pagination.pageNumber = 1;
  204. getTableData();
  205. };
  206. const handleReset = () => {
  207. queryParams.keyword = '';
  208. queryParams.status = undefined;
  209. queryParams.classifyName = '';
  210. queryParams.startDate = '';
  211. queryParams.endDate = '';
  212. uploadDateRange.value = null;
  213. handleSearch();
  214. };
  215. // 批量导入
  216. const batchImportVisible = ref(false);
  217. const { urlPrefix } = useGlobSetting();
  218. const importApiUrl = ref(urlJoin(urlPrefix, '/productionSafety/dualSystem/import'));
  219. const templateUrl = ref('./skyeye-file-upload/sfysecurity/TEMPLATE/import-dual-system-template.xlsx');
  220. const handleImport = () => {
  221. batchImportVisible.value = true;
  222. };
  223. const handleUpdate = () => {
  224. batchImportVisible.value = false;
  225. getTableData();
  226. };
  227. const handleDownload = async () => {
  228. try {
  229. const exportParams: ProductionSafetyFileQuery = {
  230. keyword: queryParams.keyword || undefined,
  231. status: queryParams.status,
  232. classifyName: queryParams.classifyName || undefined,
  233. startDate: queryParams.startDate || undefined,
  234. endDate: queryParams.endDate || undefined,
  235. };
  236. const response = await exportDualSystem(exportParams, queryParams.classifyName || undefined);
  237. if (response) {
  238. const fileName = `双体系建设管理_${new Date().toISOString().split('T')[0]}.xlsx`;
  239. downloadByData(response, fileName);
  240. ElMessage.success('导出成功');
  241. }
  242. } catch (e) {
  243. console.error('导出双体系建设失败:', e);
  244. ElMessage.error('导出失败,请重试');
  245. }
  246. };
  247. // 文件下载
  248. const handleDownloadFile = (row: any) => {
  249. const url = row?.fileUrl;
  250. if (!url) {
  251. ElMessage.warning('暂无文件可下载');
  252. return;
  253. }
  254. window.open(url, '_blank');
  255. };
  256. const handleCreate = () => {
  257. router.push({
  258. name: 'DoubleSystemManagementItem',
  259. query: {
  260. operate: 'dual-system-create',
  261. },
  262. });
  263. };
  264. const handleEdit = (id: number) => {
  265. router.push({
  266. name: 'DoubleSystemManagementItem',
  267. query: {
  268. id,
  269. operate: 'dual-system-edit',
  270. },
  271. });
  272. };
  273. const handleDelete = async (id: number) => {
  274. try {
  275. await deleteDualSystem(id);
  276. ElMessage.success('删除成功');
  277. getTableData();
  278. } catch (e) {
  279. console.error('删除双体系建设失败:', e);
  280. ElMessage.error('删除失败,请重试');
  281. }
  282. };
  283. const handleView = (id: number) => {
  284. router.push({
  285. name: 'DoubleSystemManagementItem',
  286. query: {
  287. id,
  288. operate: 'dual-system-view',
  289. },
  290. });
  291. };
  292. onMounted(() => {
  293. getTableData();
  294. });
  295. </script>
  296. <style scoped lang="scss">
  297. @use '@/styles/page-details-layout.scss' as *;
  298. @use '@/styles/page-main-layout.scss' as *;
  299. @use '@/styles/basic-table-action.scss' as *;
  300. @use '@/views/traffic/violation/style/act-search-table.scss' as *;
  301. </style>