safetyTraining.vue 11 KB

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