RegulationTable.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="search-table-container">
  3. <header>
  4. <!-- 按钮 -->
  5. <el-button
  6. v-if="trafficManagementPermission"
  7. type="primary"
  8. class="search-table-container--button"
  9. :icon="Plus"
  10. @click="handleCreateRegulation"
  11. >
  12. 新建管理规定
  13. </el-button>
  14. <div class="regulation-search">
  15. <el-input
  16. class="regulation-search-input"
  17. v-model="searchData.searchName"
  18. placeholder="输入规定标题或文件名称"
  19. :prefix-icon="Search"
  20. clearable
  21. >
  22. </el-input>
  23. <el-button type="primary" @click="handleSearch"> 查询 </el-button>
  24. </div>
  25. </header>
  26. <!-- 表格 -->
  27. <BasicTable
  28. :tableConfig="tableConfig"
  29. :tableData="tableData"
  30. @update:pageSize="handleSizeChange"
  31. @update:pageNumber="handleCurrentChange"
  32. >
  33. <template #attachment="scope">
  34. <div class="file-container--div" v-for="item in unformatAttachment(scope.row.attachment)" :key="item.fileId">
  35. <img
  36. class="file-container--div__icon"
  37. @click="previewOnline(item.fileUrl, item.fileType as keyof typeof FILE_TYPE_ICON)"
  38. :src="FILE_TYPE_ICON[item.fileType]"
  39. />
  40. <span
  41. class="file-container--div__name"
  42. @click="previewOnline(item.fileUrl, item.fileType as keyof typeof FILE_TYPE_ICON)"
  43. >{{ item.fileName }}</span
  44. >
  45. <img
  46. class="file-container--div__download"
  47. :src="DownloadIcon"
  48. @click="downloadFile(item.fileUrl, item.fileName)"
  49. />
  50. </div>
  51. </template>
  52. <template #effectState="scope">
  53. <div class="effect-state" v-if="scope.row.effectState === 1">
  54. <div style="background-color: #52c41a; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px"></div>
  55. <span>已生效</span>
  56. </div>
  57. <div class="effect-state" v-else-if="scope.row.effectState === 0">
  58. <div style="background-color: #ff4d4f; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px"></div>
  59. <span>未生效</span>
  60. </div>
  61. </template>
  62. <template #action="scope">
  63. <div class="action-container--div" style="justify-content: left">
  64. <ActionButton v-if="scope.row.effectState === 0" text="编辑" @click="handleEditRegulation(scope.row.id)" />
  65. <ActionButton
  66. v-if="scope.row.effectState === 0"
  67. text="发布"
  68. :popconfirm="{
  69. title: '确定要发布吗?',
  70. }"
  71. @confirm="
  72. handleChangeRegulationState({
  73. id: scope.row.id,
  74. managementType: 1,
  75. name: scope.row.name,
  76. attachment: scope.row.attachment,
  77. isPush: scope.row.isPush,
  78. effectState: 1,
  79. })
  80. "
  81. />
  82. <ActionButton
  83. v-if="scope.row.effectState === 1"
  84. text="撤回"
  85. :popconfirm="{
  86. title: '确定要撤回吗?',
  87. }"
  88. @confirm="
  89. handleChangeRegulationState({
  90. id: scope.row.id,
  91. managementType: 1,
  92. name: scope.row.name,
  93. attachment: scope.row.attachment,
  94. isPush: scope.row.isPush,
  95. effectState: 0,
  96. })
  97. "
  98. />
  99. <ActionButton
  100. text="删除"
  101. :popconfirm="{
  102. title: '确定要删除?',
  103. }"
  104. @confirm="handleDelete(scope.row.id)"
  105. />
  106. </div>
  107. </template>
  108. </BasicTable>
  109. <PreviewOnline ref="previewOnlineRef" />
  110. </div>
  111. </template>
  112. <script setup lang="ts">
  113. import BasicTable from '@/components/BasicTable.vue';
  114. import useTableConfig from '@/hooks/useTableConfigHook';
  115. import ActionButton from '@/components/ActionButton.vue';
  116. import { ElMessage } from 'element-plus';
  117. import { ref, reactive, onMounted } from 'vue';
  118. import { useRouter } from 'vue-router';
  119. import { Search, Plus } from '@element-plus/icons-vue';
  120. import type { QueryPageRequest } from '@/types/basic-query';
  121. import { getRegulationList, updateRegulation, deleteRegulation } from '@/api/traffic-regulation/traffic-regulation';
  122. import { TABLE_OPTIONS, REGULATION_TABLE_COLUMNS, REGULATION_TABLE_COLUMNS_CHECKONLY } from '../configs/tables';
  123. import type { UpdateRegulationQuery, RegulationDetailResponse, TableSearchQuery } from '../types';
  124. import DownloadIcon from '@/views/disaster/disaster-control/src/svg/download.svg';
  125. import { downloadFile } from '@/views/disaster/utils';
  126. import PreviewOnline from '@/views/disaster/components/PreviewOnline.vue';
  127. import { FILE_TYPE_ICON } from '@/views/disaster/constant';
  128. import { unformatAttachment } from '../utils';
  129. import { useUserInfoHook } from '@/hooks/useUserInfoHook';
  130. import { TRAFFIC_MANAGEMENT_PERMISSION } from '../constants';
  131. const { permissions } = useUserInfoHook();
  132. const trafficManagementPermission = ref<Boolean>(
  133. Boolean(permissions.find((item: { code: string }) => item.code === TRAFFIC_MANAGEMENT_PERMISSION)),
  134. );
  135. const router = useRouter();
  136. // 搜索栏
  137. const searchData = reactive<TableSearchQuery>({
  138. searchName: null,
  139. managementType: 1,
  140. });
  141. function handleSearch() {
  142. tableQuery.value.queryParam = searchData;
  143. getTableData();
  144. }
  145. // 表格
  146. const { tableConfig, pagination } = useTableConfig(
  147. trafficManagementPermission.value ? REGULATION_TABLE_COLUMNS : REGULATION_TABLE_COLUMNS_CHECKONLY,
  148. TABLE_OPTIONS,
  149. );
  150. const tableData = ref<RegulationDetailResponse[]>([]);
  151. const tableQuery = ref<QueryPageRequest<TableSearchQuery>>({
  152. pageNumber: pagination.pageNumber,
  153. pageSize: pagination.pageSize,
  154. queryParam: searchData,
  155. });
  156. const handleSizeChange = (value: number) => {
  157. pagination.pageSize = value;
  158. tableQuery.value.pageSize = value;
  159. getTableData();
  160. };
  161. const handleCurrentChange = (value: number) => {
  162. pagination.pageNumber = value;
  163. tableQuery.value.pageNumber = value;
  164. getTableData();
  165. };
  166. async function getTableData() {
  167. tableConfig.loading = true;
  168. const res = await getRegulationList(tableQuery.value);
  169. tableData.value = res.records;
  170. pagination.total = res.totalRow;
  171. tableConfig.loading = false;
  172. }
  173. // 预览
  174. const previewOnlineRef = ref<InstanceType<typeof PreviewOnline>>();
  175. const previewOnline = (url: string | undefined, type: keyof typeof FILE_TYPE_ICON) => {
  176. if (url) {
  177. previewOnlineRef.value?.open(url, type);
  178. }
  179. };
  180. onMounted(async () => {
  181. getTableData();
  182. });
  183. function handleCreateRegulation() {
  184. router.push({
  185. name: 'traffic-regulation-item',
  186. query: {
  187. operate: 'regulation-create',
  188. },
  189. });
  190. }
  191. function handleEditRegulation(id: number) {
  192. router.push({
  193. name: 'traffic-regulation-item',
  194. query: {
  195. id,
  196. operate: 'regulation-edit',
  197. },
  198. });
  199. }
  200. async function handleChangeRegulationState(data: UpdateRegulationQuery) {
  201. tableConfig.loading = true;
  202. try {
  203. await updateRegulation(data);
  204. } catch (e) {
  205. ElMessage.error('修改失败');
  206. return;
  207. } finally {
  208. tableConfig.loading = false;
  209. }
  210. getTableData();
  211. }
  212. async function handleDelete(id: number) {
  213. tableConfig.loading = true;
  214. try {
  215. await deleteRegulation(id);
  216. } catch (e) {
  217. ElMessage.error('删除失败');
  218. return;
  219. } finally {
  220. tableConfig.loading = false;
  221. }
  222. getTableData();
  223. }
  224. </script>
  225. <style scoped lang="scss">
  226. @use '@/styles/page-main-layout.scss' as *;
  227. @use '@/styles/basic-table-action.scss' as *;
  228. @use '@/styles/basic-table-file.scss' as *;
  229. .regulation-search-input {
  230. max-width: 500px;
  231. }
  232. .regulation-search {
  233. display: flex;
  234. align-items: center;
  235. justify-content: space-between;
  236. width: 100%;
  237. }
  238. .effect-state {
  239. display: flex;
  240. align-items: center;
  241. justify-self: center;
  242. }
  243. </style>