NoticeTable.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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="handleCreateNotice"
  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: 5px; height: 5px; 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: 5px; height: 5px; 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 text="查看" @click="handleViewNotice(scope.row.id)" />
  65. <ActionButton
  66. text="编辑"
  67. v-if="trafficManagementPermission && scope.row.effectState === 0"
  68. @click="handleEditNotice(scope.row.id)"
  69. />
  70. <ActionButton
  71. v-if="trafficManagementPermission && scope.row.effectState === 0"
  72. text="发布"
  73. :popconfirm="{
  74. title: '确定要发布吗?',
  75. }"
  76. @confirm="
  77. handleChangeNoticeState({
  78. id: scope.row.id,
  79. managementType: 2,
  80. name: scope.row.name,
  81. content: scope.row.content,
  82. attachment: scope.row.attachment,
  83. isPush: scope.row.isPush,
  84. effectState: 1,
  85. remark: scope.row.remark,
  86. userGroupList: scope.row.userGroupList,
  87. })
  88. "
  89. />
  90. <ActionButton
  91. v-if="trafficManagementPermission && scope.row.effectState === 1"
  92. text="撤回"
  93. :popconfirm="{
  94. title: '确定要撤回吗?',
  95. }"
  96. @confirm="
  97. handleChangeNoticeState({
  98. id: scope.row.id,
  99. managementType: 2,
  100. name: scope.row.name,
  101. content: scope.row.content,
  102. attachment: scope.row.attachment,
  103. isPush: scope.row.isPush,
  104. effectState: 0,
  105. remark: scope.row.remark,
  106. userGroupList: scope.row.userGroupList,
  107. })
  108. "
  109. />
  110. <ActionButton
  111. v-if="trafficManagementPermission"
  112. text="删除"
  113. :popconfirm="{
  114. title: '确定要删除?',
  115. }"
  116. @confirm="handleDelete(scope.row.id)"
  117. />
  118. </div>
  119. </template>
  120. </BasicTable>
  121. <PreviewOnline ref="previewOnlineRef" />
  122. </div>
  123. </template>
  124. <script setup lang="ts">
  125. import BasicTable from '@/components/BasicTable.vue';
  126. import useTableConfig from '@/hooks/useTableConfigHook';
  127. import ActionButton from '@/components/ActionButton.vue';
  128. import { ElMessage } from 'element-plus';
  129. import { TABLE_OPTIONS, NOTICE_TABLE_COLUMNS, NOTICE_TABLE_COLUMNS_CHECKONLY } from '../configs/tables';
  130. import { ref, reactive, onMounted } from 'vue';
  131. import { Search, Plus } from '@element-plus/icons-vue';
  132. import { useRouter } from 'vue-router';
  133. import type { QueryPageRequest } from '@/types/basic-query';
  134. import type { UpdateNoticeQuery, RegulationDetailResponse, TableSearchQuery } from '../types';
  135. import { getNoticeList, updateNotice, deleteNotice } from '@/api/traffic-regulation/traffic-regulation';
  136. import DownloadIcon from '@/views/disaster/disaster-control/src/svg/download.svg';
  137. import { downloadFile } from '@/views/disaster/utils';
  138. import PreviewOnline from '@/views/disaster/components/PreviewOnline.vue';
  139. import { FILE_TYPE_ICON } from '@/components/UploadFiles/constants';
  140. import { unformatAttachment } from '@/components/UploadFiles/utils';
  141. import { useUserInfoHook } from '@/hooks/useUserInfoHook';
  142. import { TRAFFIC_MANAGEMENT_PERMISSION } from '../constants';
  143. const { permissions } = useUserInfoHook();
  144. const trafficManagementPermission = ref<Boolean>(
  145. Boolean(permissions.find((item: { code: string }) => item.code === TRAFFIC_MANAGEMENT_PERMISSION)),
  146. );
  147. const router = useRouter();
  148. // 搜索栏
  149. const searchData = reactive<TableSearchQuery>({
  150. searchName: null,
  151. managementType: 2, // 1-管理规定,2-管理通知
  152. });
  153. function handleSearch() {
  154. tableQuery.value.queryParam = searchData;
  155. getTableData();
  156. }
  157. // 表格
  158. const { tableConfig, pagination } = useTableConfig(
  159. trafficManagementPermission.value ? NOTICE_TABLE_COLUMNS : NOTICE_TABLE_COLUMNS_CHECKONLY,
  160. TABLE_OPTIONS,
  161. );
  162. const tableData = ref<RegulationDetailResponse[]>([]);
  163. const tableQuery = ref<QueryPageRequest<TableSearchQuery>>({
  164. pageNumber: pagination.pageNumber,
  165. pageSize: pagination.pageSize,
  166. queryParam: searchData,
  167. });
  168. const handleSizeChange = (value: number) => {
  169. pagination.pageSize = value;
  170. tableQuery.value.pageSize = value;
  171. getTableData();
  172. };
  173. const handleCurrentChange = (value: number) => {
  174. pagination.pageNumber = value;
  175. tableQuery.value.pageNumber = value;
  176. getTableData();
  177. };
  178. async function getTableData() {
  179. const res = await getNoticeList(tableQuery.value);
  180. tableData.value = res.records;
  181. tableData.value = res.records;
  182. pagination.total = res.totalRow;
  183. tableConfig.loading = false;
  184. }
  185. // 预览
  186. const previewOnlineRef = ref<InstanceType<typeof PreviewOnline>>();
  187. const previewOnline = (url: string | undefined, type: keyof typeof FILE_TYPE_ICON) => {
  188. if (url) {
  189. previewOnlineRef.value?.open(url, type);
  190. }
  191. };
  192. onMounted(async () => {
  193. getTableData();
  194. });
  195. function handleCreateNotice() {
  196. router.push({
  197. name: 'traffic-regulation-item',
  198. query: {
  199. operate: 'notice-create',
  200. },
  201. });
  202. }
  203. function handleViewNotice(id: number) {
  204. router.push({
  205. name: 'traffic-regulation-item',
  206. query: {
  207. id,
  208. operate: 'notice-view',
  209. },
  210. });
  211. }
  212. function handleEditNotice(id: number) {
  213. router.push({
  214. name: 'traffic-regulation-item',
  215. query: {
  216. id,
  217. operate: 'notice-edit',
  218. },
  219. });
  220. }
  221. async function handleChangeNoticeState(data: UpdateNoticeQuery) {
  222. tableConfig.loading = true;
  223. try {
  224. await updateNotice(data);
  225. } catch (e) {
  226. ElMessage.error('修改失败');
  227. return;
  228. } finally {
  229. tableConfig.loading = false;
  230. }
  231. getTableData();
  232. }
  233. async function handleDelete(id: number) {
  234. tableConfig.loading = true;
  235. try {
  236. await deleteNotice(id);
  237. } catch (e) {
  238. ElMessage.error('删除失败');
  239. return;
  240. } finally {
  241. tableConfig.loading = false;
  242. }
  243. getTableData();
  244. }
  245. </script>
  246. <style scoped lang="scss">
  247. @use '@/styles/page-main-layout.scss' as *;
  248. @use '@/styles/basic-table-action.scss' as *;
  249. @use '@/styles/basic-table-file.scss' as *;
  250. .regulation-search-input {
  251. max-width: 500px;
  252. }
  253. .regulation-search {
  254. display: flex;
  255. align-items: center;
  256. justify-content: space-between;
  257. width: 100%;
  258. }
  259. .effect-state {
  260. display: flex;
  261. align-items: center;
  262. justify-self: center;
  263. }
  264. </style>