Vehicle.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div class="safety-platform-container">
  3. <div class="safety-platform-container__header">
  4. <div class="breadcrumb-title">车辆信息管理</div>
  5. </div>
  6. <div class="safety-platform-container__main">
  7. <div class="search-table-container">
  8. <header class="disaster-precaution__header">
  9. <el-button
  10. v-if="vehicleManagePermission"
  11. class="search-table-container--button"
  12. type="primary"
  13. :icon="Plus"
  14. @click="handleAddVehicleInfo"
  15. >
  16. 添加车辆信息记录
  17. </el-button>
  18. <el-button
  19. v-if="vehicleManagePermission"
  20. class="search-table-container--button"
  21. @click="batchImportVisible = true"
  22. >
  23. 批量导入
  24. </el-button>
  25. <div class="search-container">
  26. <el-input
  27. v-model="searchKeyword"
  28. :placeholder="`请输入${curSearchTypeLabel}进行搜索`"
  29. clearable
  30. @input="handleSearch"
  31. @clear="handleClear"
  32. @keyup.enter="handleSearch"
  33. style="width: 340px"
  34. >
  35. <template #prefix>
  36. <el-icon color="#1777ff"><Search /></el-icon>
  37. </template>
  38. <template #prepend>
  39. <el-select
  40. v-model="searchSelectedType"
  41. placeholder="选择搜索项"
  42. @change="handleSelectedTypeChange"
  43. style="width: 90px"
  44. >
  45. <el-option
  46. v-for="item in vehicleQueryOptions"
  47. :key="item.value"
  48. :label="item.label"
  49. :value="item.value"
  50. />
  51. </el-select>
  52. </template>
  53. </el-input>
  54. <div class="search-container-btn">
  55. <el-button type="primary" @click="handleSearch">查询</el-button>
  56. <el-button @click="handleReset">重置</el-button>
  57. <el-button @click="handleExport">导出</el-button>
  58. </div>
  59. </div>
  60. </header>
  61. <div class="batch-table">
  62. <div class="batch-operation--div" v-show="vehicleManagePermission && selectionItems.length > 0">
  63. <span>已选{{ selectionItems.length }}项</span>
  64. <div class="batch-operation--div--close">
  65. <div class="batch-operation--div--button">
  66. <el-button class="custom-el-button" @click="handleBatchDelete">批量删除</el-button>
  67. </div>
  68. <el-icon class="close-icon" @click="handleCloseBatchOperation"><Close /></el-icon>
  69. </div>
  70. </div>
  71. <BasicTable
  72. ref="basicTableRef"
  73. :tableData="tableData"
  74. :tableConfig="tableConfig"
  75. @update:page-number="handleCurrentPageChange"
  76. @update:page-size="handlePageSizeChange"
  77. @update:selection="handleSelectionChange"
  78. >
  79. <template #phoneNum="scope">
  80. <span>{{ scope.row.phoneNum ? scope.row.phoneNum : '-' }}</span>
  81. </template>
  82. <template #action="scope">
  83. <div class="action-container--div">
  84. <ActionButton text="编辑" @click="handleEditVehicleInfo(scope.row)" />
  85. <ActionButton
  86. text="删除"
  87. :popconfirm="{
  88. title: '是否删除该车辆信息?',
  89. }"
  90. @confirm="handleDeleteVehicleInfo(scope.row)"
  91. />
  92. </div>
  93. </template>
  94. </BasicTable>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. <ManageDrawer v-if="drawerVisible" :type="drawerType" :initial-data="initialData" @close="handleCloseDrawer" />
  100. <BatchImport
  101. :visible="batchImportVisible"
  102. :importApiUrl="importApiUrl"
  103. :templateUrl="templateUrl"
  104. :templateName="'车辆信息管理-批量导入模版'"
  105. @close="handleClose"
  106. @update="handleUpdate"
  107. />
  108. </template>
  109. <script setup lang="ts">
  110. import { computed, onMounted, ref } from 'vue';
  111. import urlJoin from 'url-join';
  112. import { ElMessage } from 'element-plus';
  113. import { Plus, Search, Close } from '@element-plus/icons-vue';
  114. import { openMessageBox } from '@/utils/element-plus/messageBox';
  115. import BasicTable from '@/components/BasicTable.vue';
  116. import ActionButton from '@/components/ActionButton.vue';
  117. import ManageDrawer from './components/ManageDrawer.vue';
  118. import { BatchImport } from '@/components/batch-import';
  119. import { downloadByData } from '@/utils/file/download';
  120. import { msgConfirm } from '@/utils/element-plus/messageBox';
  121. import { getCurrentDateTimeString } from '@/utils/dateUtil';
  122. import type { QueryPageRequest } from '@/types/basic-query';
  123. import { useGlobSetting } from '@/hooks/setting';
  124. import useTableConfig from '@/hooks/useTableConfigHook';
  125. import { useUserInfoHook } from '@/hooks/useUserInfoHook';
  126. import { TRAFFIC_PERMISSIONS } from '@/views/traffic/constant';
  127. import {
  128. VEHICLE_LIST_TABLE_MAX_HEIGHT_DEFAULT,
  129. VEHICLE_LIST_TABLE_MAX_HEIGHT_PERMISSION,
  130. VEHICLE_LIST_TABLE_OPTIONS,
  131. VEHICLE_LIST_TABLE_COLUMNS,
  132. } from './config';
  133. import { FIELDTYPE, FIELD_CONTENT, vehicleQueryOptions } from './constant';
  134. import {
  135. VehicleListQuery,
  136. VehicleInfoStruct,
  137. getVehicleInfoList,
  138. deleteVehicleInfo,
  139. exportVehicleInfo,
  140. } from '@/api/traffic-vehicle';
  141. const { tableConfig, pagination } = useTableConfig(VEHICLE_LIST_TABLE_COLUMNS, VEHICLE_LIST_TABLE_OPTIONS);
  142. const { permissions } = useUserInfoHook();
  143. const vehicleManagePermission = ref<boolean>(false);
  144. const searchSelectedType = ref(FIELDTYPE.VEHICLE_NUMBER);
  145. const searchKeyword = ref('');
  146. const curSearchTypeLabel = computed(() => {
  147. const option = vehicleQueryOptions.find((item) => item.value === searchSelectedType.value);
  148. return option ? option.label : FIELD_CONTENT[searchSelectedType.value];
  149. });
  150. const vehicleTableQuery: QueryPageRequest<VehicleListQuery> = {
  151. pageNumber: pagination.pageNumber,
  152. pageSize: pagination.pageSize,
  153. queryParam: {},
  154. };
  155. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  156. const tableData = ref<VehicleInfoStruct[]>([]);
  157. const selectionItems = ref<any[]>([]);
  158. // add or edit
  159. const drawerVisible = ref(false);
  160. const drawerType = ref('');
  161. const initialData = ref<VehicleInfoStruct>({});
  162. const handleSelectedTypeChange = () => {
  163. searchKeyword.value = '';
  164. };
  165. const handleSearch = () => {
  166. if (!searchKeyword.value.trim()) {
  167. handleClear();
  168. return;
  169. }
  170. getTableData();
  171. };
  172. const handleClear = () => {
  173. searchKeyword.value = '';
  174. getTableData();
  175. };
  176. const handleReset = () => {
  177. searchSelectedType.value = FIELDTYPE.VEHICLE_NUMBER;
  178. searchKeyword.value = '';
  179. getTableData();
  180. };
  181. // 导出
  182. const handleExport = () => {
  183. msgConfirm('确定导出所查询数据?', '导出', {
  184. confirmButtonText: '确定',
  185. showCancelButton: true,
  186. type: 'warning',
  187. })
  188. .then(() => {
  189. exportVehicleInfo(vehicleTableQuery.queryParam).then(async (responnse) => {
  190. if (!responnse) {
  191. throw new Error('下载文件失败');
  192. }
  193. downloadByData(responnse, `车辆信息记录_${getCurrentDateTimeString()}.xlsx`);
  194. ElMessage.success('下载文件成功');
  195. });
  196. })
  197. .catch(() => {
  198. ElMessage({
  199. type: 'info',
  200. message: '取消导出',
  201. });
  202. });
  203. };
  204. const handleCurrentPageChange = (pageNumber: number) => {
  205. pagination.pageNumber = pageNumber;
  206. vehicleTableQuery.pageNumber = pageNumber;
  207. getTableData();
  208. };
  209. const handlePageSizeChange = (pageSize: number) => {
  210. pagination.pageSize = pageSize;
  211. vehicleTableQuery.pageSize = pageSize;
  212. getTableData();
  213. };
  214. const handleAddVehicleInfo = () => {
  215. drawerVisible.value = true;
  216. drawerType.value = 'add';
  217. initialData.value = {};
  218. };
  219. const handleEditVehicleInfo = (row: VehicleInfoStruct) => {
  220. drawerVisible.value = true;
  221. drawerType.value = 'edit';
  222. initialData.value = row;
  223. };
  224. const handleCloseDrawer = () => {
  225. drawerVisible.value = false;
  226. getTableData();
  227. };
  228. const handleDeleteVehicleInfo = (row: VehicleInfoStruct) => {
  229. if (!row.id) return;
  230. deleteVehicleInfo({ vehicleInfoIds: [row.id] }).then(() => {
  231. ElMessage.success('删除成功');
  232. getTableData();
  233. });
  234. };
  235. // 批量删除
  236. const handleSelectionChange = (selection: any[]) => {
  237. selectionItems.value = selection;
  238. };
  239. const handleCloseBatchOperation = () => {
  240. if (!basicTableRef.value) return;
  241. basicTableRef.value.clearSelection();
  242. };
  243. const handleBatchDelete = async () => {
  244. const confirmed = await openMessageBox('', '删除后信息不可恢复,确认删除吗?', 'warning');
  245. if (!confirmed) return;
  246. const deleteIds = selectionItems.value.map((item) => item.id);
  247. if (!deleteIds.length) return;
  248. deleteVehicleInfo({ vehicleInfoIds: deleteIds }).then(() => {
  249. ElMessage.success('批量删除成功');
  250. getTableData();
  251. });
  252. };
  253. // 批量导入
  254. const batchImportVisible = ref(false);
  255. const { urlPrefix } = useGlobSetting();
  256. const importApiUrl = ref(urlJoin(urlPrefix, '/vehicleInfo/importVehicleInfo'));
  257. const templateUrl = ref('./skyeye-file-upload/sfysecurity/TEMPLATE/import-vehicle-template.xlsx');
  258. const handleUpdate = () => {
  259. // update 事件只用于更新数据,不关闭弹窗
  260. getTableData();
  261. };
  262. const handleClose = () => {
  263. // close 事件用于关闭弹窗
  264. batchImportVisible.value = false;
  265. };
  266. const getTableData = () => {
  267. tableConfig.loading = true;
  268. vehicleTableQuery.queryParam = {
  269. fieldType: searchSelectedType.value,
  270. fieldContent: searchKeyword.value,
  271. };
  272. getVehicleInfoList(vehicleTableQuery).then((res) => {
  273. tableData.value = res?.records || [];
  274. pagination.total = res?.totalRow || 0;
  275. });
  276. tableConfig.loading = false;
  277. };
  278. // 动态生成表格列配置
  279. const getTableColumns = () => {
  280. if (vehicleManagePermission.value) {
  281. return VEHICLE_LIST_TABLE_COLUMNS;
  282. } else {
  283. // 过滤掉操作列
  284. return VEHICLE_LIST_TABLE_COLUMNS.filter((column) => column.prop !== 'action' && column.type !== 'selection');
  285. }
  286. };
  287. onMounted(() => {
  288. getTableData();
  289. vehicleManagePermission.value = Boolean(
  290. permissions.find((item: { code: string }) => item.code === TRAFFIC_PERMISSIONS.VEHICLE_MANAGE),
  291. );
  292. tableConfig.maxHeight = vehicleManagePermission.value
  293. ? VEHICLE_LIST_TABLE_MAX_HEIGHT_PERMISSION
  294. : VEHICLE_LIST_TABLE_MAX_HEIGHT_DEFAULT;
  295. tableConfig.columns = getTableColumns();
  296. });
  297. </script>
  298. <style scoped lang="scss">
  299. @use '@/styles/page-main-layout.scss' as *;
  300. @use '@/styles/page-details-layout.scss' as *;
  301. @use '@/styles/basic-table-action.scss' as *;
  302. .search-container {
  303. display: flex;
  304. .search-container-btn {
  305. margin-left: auto;
  306. }
  307. }
  308. .batch-table {
  309. position: relative;
  310. width: 100%;
  311. height: 100%;
  312. }
  313. .batch-operation--div {
  314. @include flex-center;
  315. justify-content: flex-start;
  316. position: absolute;
  317. top: 0;
  318. left: 0;
  319. gap: 60px;
  320. width: 100%;
  321. height: 48px;
  322. border: 4px;
  323. padding: 16px 25px;
  324. background-color: #ddefff;
  325. z-index: 100;
  326. &--close {
  327. @include flex-center;
  328. justify-content: space-between;
  329. flex: 1;
  330. }
  331. .close-icon {
  332. font-size: 20px;
  333. color: #ff4d4f;
  334. cursor: pointer;
  335. }
  336. }
  337. </style>