PageDefenseNotice.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class="disaster-precaution-container">
  3. <header class="disaster-precaution-container__header">
  4. <span class="disaster-precaution-container__title">防御通知管理列表</span>
  5. </header>
  6. <main class="disaster-precaution-container__main">
  7. <div class="disaster-precaution">
  8. <header class="disaster-precaution__header">
  9. <el-button
  10. type="primary"
  11. class="disaster-precaution__header--button"
  12. :icon="Plus"
  13. @click="handleCreateDefenseNotice"
  14. v-if="defenseNoticePermissions"
  15. >创建灾害防御通知
  16. </el-button>
  17. <Search
  18. :searchConfig="DEFENSE_NOTICE_SEARCH_CONFIG"
  19. :searchData="searchData"
  20. @update:searchData="handleSearch"
  21. />
  22. </header>
  23. <BasicTable
  24. :tableConfig="tableConfig"
  25. :tableData="tableData"
  26. @update:pageSize="handleSizeChange"
  27. @update:pageNumber="handleCurrentChange"
  28. >
  29. <template #disasterType="scope">
  30. <span>{{ formatDisasterType(scope.row.disasterType) }}</span>
  31. </template>
  32. <template #disasterLevel="scope">
  33. <span>{{ formatDisasterLevel(scope.row.disasterLevel) }}</span>
  34. </template>
  35. <template #effectState="scope">
  36. <div class="active-status--div">
  37. <div
  38. class="dot"
  39. :style="{ backgroundColor: ACTIVE_STATUS_COLOR[scope.row.effectState as ACTIVE_STATUS] }"
  40. />
  41. <span>{{ ACTIVE_STATUS_MAP[scope.row.effectState] }}</span>
  42. </div>
  43. </template>
  44. <template #isPush="scope">
  45. <span :style="{ color: scope.row.isPush === PUSH_STATUS.PUSHED ? '' : '#ff4d4f' }">
  46. {{ PUSH_STATUS_MAP[scope.row.isPush as PUSH_STATUS] }}
  47. </span>
  48. </template>
  49. <template #action="scope">
  50. <ActionButton
  51. text="编辑"
  52. v-if="scope.row.effectState === ACTIVE_STATUS.NOT_EFFECTIVE && defenseNoticePermissions"
  53. @click="handleEditDefenseNotice(scope.row.id)"
  54. />
  55. <ActionButton text="查看" @click="handleViewDefenseNotice(scope.row.id)" />
  56. <ActionButton
  57. text="发布"
  58. :popconfirm="{
  59. title: '确定要发布?',
  60. }"
  61. v-if="scope.row.effectState === ACTIVE_STATUS.NOT_EFFECTIVE && defenseNoticePermissions"
  62. @confirm="handlePublishDefenseNotice(scope.row.id, scope.row.effectState)"
  63. />
  64. <ActionButton
  65. text="撤回"
  66. :popconfirm="{
  67. title: '确定要撤回?',
  68. }"
  69. v-else-if="scope.row.effectState === ACTIVE_STATUS.ACTIVE && defenseNoticePermissions"
  70. @confirm="handlePublishDefenseNotice(scope.row.id, scope.row.effectState)"
  71. />
  72. <ActionButton
  73. text="删除"
  74. :popconfirm="{
  75. title: '确定要删除?',
  76. }"
  77. @confirm="handleDeleteDefenseNotice(scope.row.id)"
  78. v-if="defenseNoticePermissions"
  79. />
  80. </template>
  81. </BasicTable>
  82. </div>
  83. </main>
  84. </div>
  85. </template>
  86. <script lang="ts" setup>
  87. import { ref, onMounted, reactive } from 'vue';
  88. import { Plus } from '@element-plus/icons-vue';
  89. import Search from '@/views/disaster/components/Search.vue';
  90. import BasicTable from '@/components/BasicTable.vue';
  91. import ActionButton from '@/components/ActionButton.vue';
  92. import useTableConfig from '@/hooks/useTableConfigHook';
  93. import { getDefenseNoticeList, deleteDefenseNoticeItem } from '@/api/disaster-warning';
  94. import type { DefenseNoticeListResponse, DefenseNoticeListQuery } from '@/types/disaster-warning';
  95. import type { QueryPageRequest } from '@/types/disaster';
  96. import {
  97. ACTIVE_STATUS,
  98. ACTIVE_STATUS_COLOR,
  99. ACTIVE_STATUS_MAP,
  100. DISASTER_PERMISSIONS,
  101. } from '@/views/disaster/constant';
  102. import { PUSH_STATUS_MAP, PUSH_STATUS } from './src/constant';
  103. import {
  104. DEFENSE_NOTICE_SEARCH_CONFIG,
  105. TABLE_OPTIONS,
  106. DEFENSE_NOTICE_TABLE_COLUMNS,
  107. TABLE_HEIGHT_DEFAULT,
  108. TABLE_HEIGHT_PREMISSION,
  109. } from './src/config';
  110. import { formatDisasterLevel, formatDisasterType } from '@/views/disaster/utils/formatTable';
  111. import { useRouter } from 'vue-router';
  112. import { ElMessage } from 'element-plus';
  113. import { publishDefenseNoticeItem } from '@/api/disaster-warning';
  114. import { useUserInfoHook } from '@/views/disaster/hooks/userInfo';
  115. const { permissions } = useUserInfoHook();
  116. const defenseNoticePermissions = ref<Boolean>(false);
  117. const tableData = ref<DefenseNoticeListResponse[]>([]);
  118. const router = useRouter();
  119. const defaultPath = '/disaster-prevention/disaster-warning/defense-notice-item';
  120. const handleEditDefenseNotice = (id: number) => {
  121. router.push({
  122. path: defaultPath,
  123. query: { id, operate: 'edit' },
  124. });
  125. };
  126. const handleCreateDefenseNotice = () => {
  127. router.push({
  128. path: defaultPath,
  129. query: {
  130. operate: 'create',
  131. },
  132. });
  133. };
  134. const handleViewDefenseNotice = (id: number) => {
  135. router.push({
  136. path: defaultPath,
  137. query: { id },
  138. });
  139. };
  140. const handlePublishDefenseNotice = async (id: number, effectState: number) => {
  141. const message = effectState === ACTIVE_STATUS.ACTIVE ? '撤回成功' : '发布成功';
  142. const effectStateStatus = effectState === ACTIVE_STATUS.ACTIVE ? ACTIVE_STATUS.NOT_EFFECTIVE : ACTIVE_STATUS.ACTIVE;
  143. await publishDefenseNoticeItem({ id, effectState: effectStateStatus });
  144. await getTableData();
  145. ElMessage.success(message);
  146. };
  147. const handleDeleteDefenseNotice = async (id: number) => {
  148. await deleteDefenseNoticeItem(id);
  149. await getTableData();
  150. ElMessage.success('删除成功');
  151. };
  152. const searchData = reactive({
  153. disasterType: '',
  154. disasterLevel: '',
  155. effectState: '',
  156. });
  157. const { tableConfig, pagination } = useTableConfig(DEFENSE_NOTICE_TABLE_COLUMNS, TABLE_OPTIONS);
  158. let defenseNoticeListQuery: QueryPageRequest<DefenseNoticeListQuery> = {
  159. pageNumber: pagination.pageNumber,
  160. pageSize: pagination.pageSize,
  161. queryParam: {},
  162. };
  163. const handleSearch = () => {
  164. defenseNoticeListQuery.queryParam = {};
  165. if (searchData.disasterLevel !== '') {
  166. defenseNoticeListQuery.queryParam.disasterLevel = searchData.disasterLevel;
  167. }
  168. if (searchData.effectState !== '') {
  169. defenseNoticeListQuery.queryParam.effectState = searchData.effectState;
  170. }
  171. if (searchData.disasterType !== '') {
  172. defenseNoticeListQuery.queryParam.disasterType = searchData.disasterType;
  173. }
  174. getTableData();
  175. };
  176. const handleSizeChange = (value: number) => {
  177. pagination.pageSize = value;
  178. getTableData();
  179. };
  180. const handleCurrentChange = (value: number) => {
  181. pagination.pageNumber = value;
  182. getTableData();
  183. };
  184. const getTableData = async () => {
  185. tableConfig.loading = true;
  186. const res = await getDefenseNoticeList(defenseNoticeListQuery);
  187. tableData.value = res.records;
  188. pagination.total = res.totalRow;
  189. tableConfig.loading = false;
  190. };
  191. onMounted(() => {
  192. getTableData();
  193. defenseNoticePermissions.value = Boolean(
  194. permissions.find((item: { code: string }) => item.code === DISASTER_PERMISSIONS.DEFENSE_NOTICE),
  195. );
  196. tableConfig.height = defenseNoticePermissions.value ? TABLE_HEIGHT_PREMISSION : TABLE_HEIGHT_DEFAULT;
  197. });
  198. </script>
  199. <style lang="scss" scoped>
  200. @use '../style/disaster.scss' as *;
  201. @use './src/common.scss' as *;
  202. </style>