PageWarningInfo.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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="handleCreateWarningInfo"
  14. v-if="warningInfoPermissions"
  15. >
  16. 创建灾害预警信息
  17. </el-button>
  18. <Search
  19. :searchConfig="WARNING_INFO_SEARCH_CONFIG"
  20. :searchData="searchData"
  21. @update:searchData="handleSearch"
  22. />
  23. </header>
  24. <BasicTable
  25. :tableConfig="tableConfig"
  26. :tableData="tableData"
  27. @update:pageSize="handleSizeChange"
  28. @update:pageNumber="handleCurrentChange"
  29. >
  30. <template #warningIcon="scope">
  31. <img :src="getWarningIcon(scope.row.disasterType)" alt="预警图标" class="weather-warning-icon" />
  32. </template>
  33. <template #disasterType="scope">
  34. <span>{{ formatDisasterType(scope.row.disasterType) }}</span>
  35. </template>
  36. <template #disasterLevel="scope">
  37. <span>{{ formatDisasterLevel(scope.row.disasterLevel) }}</span>
  38. </template>
  39. <template #effectState="scope">
  40. <div class="active-status--div">
  41. <div
  42. class="dot"
  43. :style="{ backgroundColor: ACTIVE_STATUS_COLOR[scope.row.effectState as ACTIVE_STATUS] }"
  44. />
  45. <span>{{ ACTIVE_STATUS_MAP[scope.row.effectState] }}</span>
  46. </div>
  47. </template>
  48. <template #isPush="scope">
  49. <span :style="{ color: scope.row.isPush === PUSH_STATUS.PUSHED ? '' : '#ff4d4f' }">
  50. {{ PUSH_STATUS_MAP[scope.row.isPush as PUSH_STATUS] }}
  51. </span>
  52. </template>
  53. <template #action="scope">
  54. <ActionButton
  55. text="编辑"
  56. @click="handleEditWarningInfo(scope.row.id)"
  57. v-if="scope.row.effectState === ACTIVE_STATUS.NOT_EFFECTIVE"
  58. />
  59. <ActionButton
  60. text="发布"
  61. :popconfirm="{
  62. title: '确定要发布?',
  63. }"
  64. v-if="scope.row.effectState === ACTIVE_STATUS.NOT_EFFECTIVE"
  65. @confirm="handlePublishWarningInfo(scope.row.id, scope.row.effectState)"
  66. />
  67. <ActionButton
  68. text="撤回"
  69. :popconfirm="{
  70. title: '确定要撤回?',
  71. }"
  72. v-else-if="scope.row.effectState === ACTIVE_STATUS.ACTIVE"
  73. @confirm="handlePublishWarningInfo(scope.row.id, scope.row.effectState)"
  74. />
  75. <ActionButton
  76. text="删除"
  77. :popconfirm="{
  78. title: '确定要删除?',
  79. }"
  80. @confirm="handleDeleteWarningInfo(scope.row.id)"
  81. />
  82. </template>
  83. </BasicTable>
  84. </div>
  85. </main>
  86. </div>
  87. </template>
  88. <script lang="ts" setup>
  89. import { ref, onMounted, reactive } from 'vue';
  90. import { Plus } from '@element-plus/icons-vue';
  91. import Search from '@/views/disaster/components/Search.vue';
  92. import BasicTable from '@/components/BasicTable.vue';
  93. import ActionButton from '@/components/ActionButton.vue';
  94. import useTableConfig from '@/hooks/useTableConfigHook';
  95. import { getWarningInfoList } from '@/api/disaster-warning';
  96. import type { WarningInfoListResponse } from '@/types/disaster-warning';
  97. import {
  98. ACTIVE_STATUS,
  99. ACTIVE_STATUS_COLOR,
  100. ACTIVE_STATUS_MAP,
  101. DISASTER_PERMISSIONS,
  102. } from '@/views/disaster/constant';
  103. import PlaceHolderWeather from './src/images/placeholder-weather@1X.png';
  104. import { PUSH_STATUS_MAP, PUSH_STATUS, WEATHER_DISASTER_ALERT_TYPE } from './src/constant';
  105. import {
  106. WARNING_INFO_SEARCH_CONFIG,
  107. TABLE_OPTIONS,
  108. WARNING_INFO_TABLE_COLUMNS_DEFAULT,
  109. WARNING_INFO_TABLE_COLUMNS_PERMISSION,
  110. TABLE_HEIGHT_DEFAULT,
  111. TABLE_HEIGHT_PREMISSION,
  112. } from './src/config';
  113. import { useRouter } from 'vue-router';
  114. import type { QueryPageRequest } from '@/types/disaster';
  115. import type { WarningInfoListQuery } from '@/types/disaster-warning';
  116. import { formatDisasterLevel } from '@/views/disaster/utils/formatTable';
  117. import { formatDisasterType } from './src/util';
  118. import { deleteWarningInfoItem, publishWarningInfoItem } from '@/api/disaster-warning';
  119. import { ElMessage } from 'element-plus';
  120. import { useUserInfoHook } from '@/views/disaster/hooks/userInfo';
  121. const { permissions } = useUserInfoHook();
  122. const router = useRouter();
  123. const searchData = reactive({
  124. disasterType: '',
  125. disasterLevel: '',
  126. });
  127. const getWarningIcon = (disasterType: string) => {
  128. const icon = WEATHER_DISASTER_ALERT_TYPE.find((item) => item.label === disasterType)?.icon;
  129. return icon ?? PlaceHolderWeather;
  130. };
  131. const defaultPath = '/disaster-prevention/disaster-warning/warning-info-item';
  132. const handleCreateWarningInfo = () => {
  133. router.push({
  134. path: defaultPath,
  135. query: {
  136. operate: 'create',
  137. },
  138. });
  139. };
  140. const handleEditWarningInfo = (id: number) => {
  141. router.push({
  142. path: defaultPath,
  143. query: {
  144. operate: 'edit',
  145. id,
  146. },
  147. });
  148. };
  149. const handlePublishWarningInfo = async (id: number, effectState: number) => {
  150. const message = effectState === ACTIVE_STATUS.ACTIVE ? '撤回成功' : '发布成功';
  151. const effectStateStatus = effectState === ACTIVE_STATUS.ACTIVE ? ACTIVE_STATUS.NOT_EFFECTIVE : ACTIVE_STATUS.ACTIVE;
  152. await publishWarningInfoItem({ id, effectState: effectStateStatus });
  153. await getTableData();
  154. ElMessage.success(message);
  155. };
  156. const handleDeleteWarningInfo = async (id: number) => {
  157. await deleteWarningInfoItem(id);
  158. getTableData();
  159. ElMessage.success('删除成功');
  160. };
  161. const tableData = ref<WarningInfoListResponse[]>([]);
  162. const warningInfoPermissions = ref<Boolean>(false);
  163. const { tableConfig, pagination } = useTableConfig(WARNING_INFO_TABLE_COLUMNS_DEFAULT, TABLE_OPTIONS);
  164. let wanrningInfoListQuery: QueryPageRequest<WarningInfoListQuery> = {
  165. pageNumber: pagination.pageNumber,
  166. pageSize: pagination.pageSize,
  167. queryParam: {},
  168. };
  169. const handleSearch = () => {
  170. wanrningInfoListQuery.queryParam = {};
  171. if (searchData.disasterLevel !== '') {
  172. wanrningInfoListQuery.queryParam.disasterLevel = searchData.disasterLevel;
  173. }
  174. if (searchData.disasterType !== '') {
  175. wanrningInfoListQuery.queryParam.disasterType = searchData.disasterType;
  176. }
  177. getTableData();
  178. };
  179. const handleSizeChange = (value: number) => {
  180. pagination.pageSize = value;
  181. getTableData();
  182. };
  183. const handleCurrentChange = (value: number) => {
  184. pagination.pageNumber = value;
  185. getTableData();
  186. };
  187. const getTableData = async () => {
  188. tableConfig.loading = true;
  189. const res = await getWarningInfoList(wanrningInfoListQuery);
  190. tableData.value = res.records;
  191. pagination.total = res.totalRow;
  192. tableConfig.loading = false;
  193. };
  194. onMounted(() => {
  195. getTableData();
  196. warningInfoPermissions.value = Boolean(
  197. permissions.find((item: { code: string }) => item.code === DISASTER_PERMISSIONS.WARNING_INFO),
  198. );
  199. tableConfig.height = warningInfoPermissions.value ? TABLE_HEIGHT_PREMISSION : TABLE_HEIGHT_DEFAULT;
  200. if (warningInfoPermissions.value) {
  201. tableConfig.columns = WARNING_INFO_TABLE_COLUMNS_PERMISSION;
  202. }
  203. });
  204. </script>
  205. <style lang="scss" scoped>
  206. @use '../style/disaster.scss' as *;
  207. @use './src/common.scss' as *;
  208. .weather-warning-icon {
  209. width: 50cpx;
  210. height: 50cpx;
  211. }
  212. </style>