safetyStandardizationSystemManagement.vue 11 KB

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