index.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="公司" prop="companyId">
  12. <el-select
  13. v-model="queryParams.companyId"
  14. placeholder="请选择公司"
  15. clearable
  16. class="!w-240px"
  17. >
  18. <el-option
  19. v-for="item in companyDeptList"
  20. :key="item.id"
  21. :label="item.name"
  22. :value="item.id"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="客户名称" prop="manufactureName">
  27. <el-input
  28. v-model="queryParams.manufactureName"
  29. placeholder="请输入客户名称"
  30. clearable
  31. @keyup.enter="handleQuery"
  32. class="!w-240px"
  33. />
  34. </el-form-item>
  35. <el-form-item label="合同名称" prop="contractName">
  36. <el-input
  37. v-model="queryParams.contractName"
  38. placeholder="请输入合同名称"
  39. clearable
  40. @keyup.enter="handleQuery"
  41. class="!w-240px"
  42. />
  43. </el-form-item>
  44. <el-form-item label="合同编号" prop="contractCode">
  45. <el-input
  46. v-model="queryParams.contractCode"
  47. placeholder="请输入合同编号"
  48. clearable
  49. @keyup.enter="handleQuery"
  50. class="!w-240px"
  51. />
  52. </el-form-item>
  53. <el-form-item label="井号" prop="wellName">
  54. <el-input
  55. v-model="queryParams.wellName"
  56. placeholder="请输入井号"
  57. clearable
  58. @keyup.enter="handleQuery"
  59. class="!w-240px"
  60. />
  61. </el-form-item>
  62. <el-form-item label="平台井" prop="platformFlag">
  63. <el-select
  64. v-model="queryParams.platformFlag"
  65. placeholder="请选择平台井"
  66. clearable
  67. class="!w-240px"
  68. @change="handleQuery"
  69. >
  70. <el-option label="全部" value="A" />
  71. <el-option label="是" value="Y" />
  72. <el-option label="否" value="N" />
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item label="创建时间" prop="createTime">
  76. <el-date-picker
  77. v-model="queryParams.createTime"
  78. value-format="YYYY-MM-DD HH:mm:ss"
  79. type="daterange"
  80. start-placeholder="开始日期"
  81. end-placeholder="结束日期"
  82. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  83. class="!w-220px"
  84. />
  85. </el-form-item>
  86. <el-form-item>
  87. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  88. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  89. <!--
  90. <el-button
  91. type="primary"
  92. plain
  93. @click="openForm('create')"
  94. v-hasPermi="['rq:iot-project-task:create']"
  95. >
  96. <Icon icon="ep:plus" class="mr-5px" /> 新增
  97. </el-button> -->
  98. <el-button
  99. type="success"
  100. plain
  101. @click="handleExport"
  102. :loading="exportLoading"
  103. v-hasPermi="['rq:iot-project-task:export']"
  104. >
  105. <Icon icon="ep:download" class="mr-5px" /> 导出
  106. </el-button>
  107. </el-form-item>
  108. </el-form>
  109. </ContentWrap>
  110. <!-- 列表 -->
  111. <ContentWrap ref="tableContainerRef">
  112. <div class="table-container">
  113. <el-table ref="tableRef" v-loading="loading" :data="list" :stripe="true" style="width: 100%" :cell-style="{padding: '5px'}">
  114. <el-table-column :label="t('iotDevice.serial')" :width="columnWidths.serial" align="center" v-if="false">
  115. <template #default="scope">
  116. {{ scope.$index + 1 }}
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="客户名称" align="center" prop="manufactureName" :width="columnWidths.manufactureName" show-overflow-tooltip/>
  120. <el-table-column label="合同名称" align="center" prop="contractName" :width="columnWidths.contractName" show-overflow-tooltip/>
  121. <el-table-column label="合同编号" align="center" prop="contractCode" :width="columnWidths.contractCode" />
  122. <el-table-column label="井号" align="center" prop="wellName" :width="columnWidths.wellName" />
  123. <!-- <el-table-column label="井型/井别" align="center" prop="wellType" />
  124. <el-table-column :label="t('project.wellType')" align="center" prop="wellType" :width="columnWidths.wellType">
  125. <template #default="scope">
  126. <dict-tag :type="DICT_TYPE.PMS_PROJECT_WELL_TYPE" :value="scope.row.wellType" />
  127. </template>
  128. </el-table-column> -->
  129. <el-table-column label="施工地点" align="center" prop="location" :width="columnWidths.location" />
  130. <el-table-column label="施工队伍" align="center" prop="deptNames" :width="columnWidths.deptNames" />
  131. <!-- <el-table-column :label="t('project.technology')" align="center" prop="technique" :width="columnWidths.technique">
  132. <template #default="scope">
  133. <dict-tag :type="DICT_TYPE.PMS_PROJECT_TECHNOLOGY" :value="scope.row.technique" />
  134. </template>
  135. </el-table-column>
  136. <el-table-column label="设计工作量" align="center" prop="workloadDesign" :width="columnWidths.workloadDesign"/> -->
  137. <el-table-column
  138. label="创建时间"
  139. align="center"
  140. prop="createTime"
  141. :formatter="dateFormatter"
  142. :width="columnWidths.createTime"
  143. />
  144. <!--
  145. <el-table-column label="备注" align="center" prop="remark" /> -->
  146. <el-table-column label="操作" align="center" :width="columnWidths.operation" fixed="right">
  147. <template #default="scope">
  148. <el-button
  149. link
  150. type="primary"
  151. @click="openPlanDialog(scope.row)"
  152. v-hasPermi="['rq:iot-project-task:update']"
  153. >
  154. 计划
  155. </el-button>
  156. <el-button
  157. link
  158. type="primary"
  159. @click="openForm('update', scope.row.id,scope.row.projectId)"
  160. v-hasPermi="['rq:iot-project-task:update']"
  161. >
  162. 编辑
  163. </el-button>
  164. <el-button
  165. link
  166. type="danger"
  167. @click="handleDelete(scope.row.id)"
  168. v-hasPermi="['rq:iot-project-task:delete']"
  169. >
  170. 删除
  171. </el-button>
  172. </template>
  173. </el-table-column>
  174. </el-table>
  175. </div>
  176. <!-- 分页 -->
  177. <Pagination
  178. :total="total"
  179. v-model:page="queryParams.pageNo"
  180. v-model:limit="queryParams.pageSize"
  181. @pagination="getList"
  182. />
  183. </ContentWrap>
  184. <!-- 计划 Dialog -->
  185. <el-dialog
  186. v-model="planDialogVisible"
  187. :title="`${currentRow?.contractName} - ${currentRow?.wellName} - 任务计划`"
  188. width="80%"
  189. >
  190. <div class="mb-15px">
  191. <el-button type="primary" @click="addNewRow">
  192. <Icon icon="ep:plus" class="mr-5px" /> 新增行
  193. </el-button>
  194. </div>
  195. <el-table :data="planList" border stripe>
  196. <el-table-column label="序号" width="60" align="center">
  197. <template #default="scope">
  198. {{ scope.$index + 1 }}
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="施工状态" min-width="200">
  202. <template #default="scope">
  203. <el-select
  204. v-model="scope.row.status"
  205. placeholder="请选择施工状态"
  206. clearable
  207. class="w-full"
  208. @change="onStatusChange(scope.row)"
  209. >
  210. <el-option
  211. v-for="dict in workProgressDictOptions"
  212. :key="dict.value"
  213. :label="dict.label"
  214. :value="dict.value"
  215. />
  216. </el-select>
  217. </template>
  218. </el-table-column>
  219. <el-table-column label="开始时间" min-width="200">
  220. <template #default="scope">
  221. <el-date-picker
  222. v-model="scope.row.startTime"
  223. type="datetime"
  224. placeholder="选择开始时间"
  225. value-format="YYYY-MM-DD HH:mm"
  226. format="YYYY-MM-DD HH:mm"
  227. class="w-full"
  228. />
  229. </template>
  230. </el-table-column>
  231. <el-table-column label="结束时间" min-width="200">
  232. <template #default="scope">
  233. <el-date-picker
  234. v-model="scope.row.endTime"
  235. type="datetime"
  236. placeholder="选择结束时间"
  237. value-format="YYYY-MM-DD HH:mm"
  238. format="YYYY-MM-DD HH:mm"
  239. class="w-full"
  240. v-if="rowShowEndTime(scope.row)"
  241. />
  242. </template>
  243. </el-table-column>
  244. <el-table-column label="操作" width="100" align="center">
  245. <template #default="scope">
  246. <el-button link type="danger" @click="removeRow(scope.$index)">
  247. 删除
  248. </el-button>
  249. </template>
  250. </el-table-column>
  251. </el-table>
  252. <template #footer>
  253. <span class="dialog-footer">
  254. <el-button @click="planDialogVisible = false">取消</el-button>
  255. <el-button type="primary" @click="savePlan" :loading="saveLoading">
  256. 保存
  257. </el-button>
  258. </span>
  259. </template>
  260. </el-dialog>
  261. </template>
  262. <script setup lang="ts">
  263. import { dateFormatter } from '@/utils/formatTime'
  264. import download from '@/utils/download'
  265. import { IotProjectTaskScheduleApi } from '@/api/pms/iotprojecttaskschedule'
  266. import { IotProjectTaskApi, IotProjectTaskVO} from '@/api/pms/iotprojecttask'
  267. import dayjs from 'dayjs'
  268. import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
  269. import { ref, reactive, onMounted, computed, nextTick, watch, onUnmounted } from 'vue'
  270. import { useRouter } from 'vue-router'
  271. import * as DeptApi from "@/api/system/dept"; // 引入部门API
  272. /** 项目信息任务拆分 列表 */
  273. defineOptions({ name: 'IotProjectTask' })
  274. const message = useMessage() // 消息弹窗
  275. const { t } = useI18n() // 国际化
  276. const loading = ref(true) // 列表的加载中
  277. const list = ref<IotProjectTaskVO[]>([]) // 列表的数据
  278. const total = ref(0) // 列表的总页数
  279. const queryParams = reactive({
  280. pageNo: 1,
  281. pageSize: 10,
  282. companyId: undefined,
  283. projectId: undefined,
  284. wellName: undefined,
  285. wellType: undefined,
  286. location: undefined,
  287. technique: undefined,
  288. workloadDesign: undefined,
  289. createTime: [],
  290. userName: undefined,
  291. userId: undefined,
  292. manufactureName: '',
  293. platformFlag: '',
  294. remark: undefined,
  295. })
  296. const dictQueryParams = reactive({
  297. pageNo: 1,
  298. pageSize: 50,
  299. label: '',
  300. status: undefined,
  301. dictType: 'constructionStatus'
  302. })
  303. const queryFormRef = ref() // 搜索的表单
  304. const exportLoading = ref(false) // 导出的加载中
  305. const { push } = useRouter() // 路由跳转
  306. const COMPLETED_STATUS = 'wg';
  307. // 表格引用
  308. const tableRef = ref()
  309. // 表格容器引用
  310. const tableContainerRef = ref()
  311. // 列宽度配置
  312. const columnWidths = ref({
  313. serial: '50px',
  314. manufactureName: '200px',
  315. contractName: '200px',
  316. contractCode: '120px',
  317. wellName: '100px',
  318. wellType: '100px',
  319. location: '120px',
  320. deptNames: '120px',
  321. technique: '100px',
  322. workloadDesign: '100px',
  323. createTime: '150px',
  324. operation: '200px'
  325. })
  326. // 计算文本宽度
  327. const getTextWidth = (text: string, fontSize = 14) => {
  328. const span = document.createElement('span');
  329. span.style.visibility = 'hidden';
  330. span.style.position = 'absolute';
  331. span.style.whiteSpace = 'nowrap';
  332. span.style.fontSize = `${fontSize}px`;
  333. span.style.fontFamily = 'inherit';
  334. span.innerText = text;
  335. document.body.appendChild(span);
  336. const width = span.offsetWidth;
  337. document.body.removeChild(span);
  338. return width;
  339. };
  340. // 计划相关状态
  341. const planDialogVisible = ref(false)
  342. // const planList = ref<Array<{name: string, value: string, startTime: string, endTime: string}>>([])
  343. const planList = ref<Array<{id?: number, status: string, startTime: string, endTime: string, showEndTime: boolean}>>([])
  344. const saveLoading = ref(false)
  345. const currentRow = ref<IotProjectTaskVO | null>(null)
  346. const workProgressDictOptions = ref<any[]>([]) // 施工进度字典选项
  347. const companyDeptList = ref<any[]>([]) // 在公司级部门列表
  348. const wellTypeDictOptions = ref<any[]>([]) // 井型字典选项
  349. const technologyDictOptions = ref<any[]>([]) // 施工工艺字典选项
  350. /** 获取井型字典数据 */
  351. const getWellTypeDictOptions = async () => {
  352. try {
  353. wellTypeDictOptions.value = getIntDictOptions(DICT_TYPE.PMS_PROJECT_WELL_TYPE)
  354. } catch (error) {
  355. console.error('获取井型字典失败:', error)
  356. wellTypeDictOptions.value = []
  357. }
  358. }
  359. /** 获取施工工艺字典数据 */
  360. const getTechnologyDictOptions = async () => {
  361. try {
  362. technologyDictOptions.value = getIntDictOptions(DICT_TYPE.PMS_PROJECT_TECHNOLOGY)
  363. } catch (error) {
  364. console.error('获取施工工艺字典失败:', error)
  365. technologyDictOptions.value = []
  366. }
  367. }
  368. /** 时间戳转换为日期时间字符串(使用dayjs处理) */
  369. const timestampToDateTime = (timestamp: number | string | null | undefined): string => {
  370. if (timestamp === null || timestamp === undefined || timestamp === '') {
  371. return '';
  372. }
  373. // 转换为数字
  374. let ts = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp;
  375. // 检查是否为有效数字
  376. if (isNaN(ts)) {
  377. console.warn('无效的时间戳:', timestamp);
  378. return '';
  379. }
  380. // 如果时间戳是秒级,转换为毫秒级
  381. if (ts < 1000000000000) {
  382. ts *= 1000;
  383. }
  384. return dayjs(ts).format('YYYY-MM-DD HH:mm')
  385. }
  386. /** 获取施工进度字典数据 */
  387. const getWorkProgressDictOptions = async () => {
  388. try {
  389. workProgressDictOptions.value = getStrDictOptions(DICT_TYPE.PMS_PROJECT_TASK_SCHEDULE)
  390. } catch (error) {
  391. console.error('获取施工进度字典失败:', error)
  392. workProgressDictOptions.value = []
  393. }
  394. }
  395. /** 打开计划对话框 */
  396. const openPlanDialog = async (row: IotProjectTaskVO) => {
  397. currentRow.value = row
  398. planList.value = [] // 清空计划列表
  399. try {
  400. // 获取施工进度字典选项
  401. await getWorkProgressDictOptions()
  402. // 获取已有计划数据
  403. const taskSchedules = await IotProjectTaskScheduleApi.getIotProjectTaskSchedules({ taskId: row.id })
  404. if (taskSchedules && taskSchedules.length > 0) {
  405. // 如果有数据,则使用接口返回的数据初始化表格
  406. planList.value = taskSchedules.map((plan: any) => {
  407. const statusNum = plan.status;
  408. return {
  409. id: plan.id,
  410. status: statusNum,
  411. startTime: timestampToDateTime(plan.startTime),
  412. endTime: timestampToDateTime(plan.endTime),
  413. showEndTime: statusNum !== COMPLETED_STATUS // 如果已是完工状态,则不显示结束时间列
  414. }
  415. })
  416. }
  417. // 如果没有数据,planList.value保持为空数组
  418. planDialogVisible.value = true
  419. } catch (error) {
  420. message.error('获取计划数据失败')
  421. console.error('获取计划数据失败:', error)
  422. }
  423. }
  424. /** 判断某一行是否应该显示结束时间列 */
  425. const rowShowEndTime = (row) => {
  426. return row.showEndTime;
  427. }
  428. /** 处理施工状态变化 */
  429. const onStatusChange = (row) => {
  430. // 当状态变为“完工”时,隐藏结束时间列并清空结束时间;否则显示
  431. if (row.status === COMPLETED_STATUS) {
  432. row.showEndTime = false;
  433. row.endTime = ''; // 清空结束时间
  434. } else {
  435. row.showEndTime = true;
  436. }
  437. }
  438. /** 新增行 */
  439. const addNewRow = () => {
  440. planList.value.push({
  441. status: '', // 默认值或空值
  442. startTime: '',
  443. endTime: '',
  444. showEndTime: true
  445. })
  446. }
  447. /** 删除行 */
  448. const removeRow = (index: number) => {
  449. planList.value.splice(index, 1)
  450. }
  451. /** 保存计划 */
  452. const savePlan = async () => {
  453. try {
  454. saveLoading.value = true
  455. // 验证数据
  456. for (let i = 0; i < planList.value.length; i++) {
  457. const item = planList.value[i]
  458. if (!item.status) {
  459. message.error(`第${i + 1}行请选择施工状态`)
  460. return
  461. }
  462. }
  463. // 准备提交数据
  464. const submitData = planList.value.map(item => ({
  465. id: item.id, // 更新时使用
  466. taskId: currentRow.value?.id,
  467. status: item.status,
  468. startTime: item.startTime ? new Date(item.startTime).getTime() : null,
  469. endTime: (item.status !== COMPLETED_STATUS && item.endTime) ? new Date(item.endTime).getTime() : null
  470. }))
  471. // 调用保存接口
  472. await IotProjectTaskScheduleApi.saveTaskSchedule(submitData)
  473. message.success('保存成功')
  474. planDialogVisible.value = false
  475. } catch (error) {
  476. message.error('保存失败')
  477. console.error('保存失败:', error)
  478. } finally {
  479. saveLoading.value = false
  480. }
  481. }
  482. /** 查询列表 */
  483. const getList = async () => {
  484. loading.value = true
  485. try {
  486. const data = await IotProjectTaskApi.getIotProjectTaskList(queryParams)
  487. list.value = data.list
  488. total.value = data.total
  489. // 获取数据后计算列宽
  490. nextTick(() => {
  491. calculateColumnWidths();
  492. });
  493. } finally {
  494. loading.value = false
  495. }
  496. }
  497. // 计算列宽度
  498. const calculateColumnWidths = () => {
  499. const MIN_WIDTH = 80; // 最小列宽
  500. const PADDING = 25; // 列内边距
  501. const FLEXIBLE_COLUMNS = ['contractCode', 'wellName', 'location']; // 可伸缩列
  502. // 确保表格容器存在
  503. if (!tableContainerRef.value?.$el) return;
  504. const container = tableContainerRef.value.$el;
  505. const containerWidth = container.clientWidth;
  506. // 固定列的宽度
  507. const FIXED_COLUMNS = {
  508. manufactureName: 200,
  509. contractName: 200
  510. };
  511. // 1. 计算所有列的最小宽度
  512. const minWidths: Record<string, number> = {};
  513. let totalMinWidth = 0;
  514. // 设置固定列的宽度
  515. Object.keys(FIXED_COLUMNS).forEach(key => {
  516. minWidths[key] = FIXED_COLUMNS[key];
  517. totalMinWidth += FIXED_COLUMNS[key];
  518. });
  519. // 计算列最小宽度的函数
  520. const calculateColumnMinWidth = (key: string, label: string, getValue: Function) => {
  521. // 如果是固定列,跳过计算
  522. if (FIXED_COLUMNS[key]) return;
  523. const headerWidth = getTextWidth(label) * 1.2;
  524. let contentMaxWidth = 0;
  525. // 计算内容最大宽度
  526. list.value.forEach((row, index) => {
  527. const text = String(getValue ? getValue(row, index) : (row[key] || ''));
  528. const textWidth = getTextWidth(text);
  529. if (textWidth > contentMaxWidth) contentMaxWidth = textWidth;
  530. });
  531. const minWidth = Math.max(headerWidth, contentMaxWidth, MIN_WIDTH) + PADDING;
  532. minWidths[key] = minWidth;
  533. totalMinWidth += minWidth;
  534. return minWidth;
  535. };
  536. // 计算各列最小宽度
  537. calculateColumnMinWidth('serial', t('iotDevice.serial'), (row: any, index: number) => `${index + 1}`);
  538. // calculateColumnMinWidth('manufactureName', '客户名称', (row: any) => row.manufactureName);
  539. // calculateColumnMinWidth('contractName', '合同名称', (row: any) => row.contractName);
  540. calculateColumnMinWidth('contractCode', '合同编号', (row: any) => row.contractCode);
  541. calculateColumnMinWidth('wellName', '井号', (row: any) => row.wellName);
  542. calculateColumnMinWidth('wellType', t('project.wellType'), (row: any) => {
  543. const dict = wellTypeDictOptions.value.find(d => d.value === row.wellType);
  544. return dict ? dict.label : '';
  545. });
  546. calculateColumnMinWidth('location', '施工地点', (row: any) => row.location);
  547. calculateColumnMinWidth('deptNames', '施工队伍', (row: any) => row.deptNames);
  548. calculateColumnMinWidth('technique', t('project.technology'), (row: any) => {
  549. const dict = technologyDictOptions.value.find(d => d.value === row.technique);
  550. return dict ? dict.label : '';
  551. });
  552. calculateColumnMinWidth('workloadDesign', '设计工作量', (row: any) => row.workloadDesign);
  553. calculateColumnMinWidth('createTime', '创建时间', (row: any) => dateFormatter(null, null, row.createTime));
  554. // 操作列固定宽度
  555. minWidths.operation = 200;
  556. totalMinWidth += 200;
  557. // 2. 计算可伸缩列最终宽度
  558. const newWidths: Record<string, string> = {};
  559. const availableWidth = containerWidth - 17; // 减去滚动条宽度
  560. // 应用最小宽度到所有列
  561. Object.keys(minWidths).forEach(key => {
  562. if (FIXED_COLUMNS[key]) {
  563. newWidths[key] = `${FIXED_COLUMNS[key]}px`;
  564. } else {
  565. newWidths[key] = `${minWidths[key]}px`;
  566. }
  567. });
  568. // 计算可伸缩列需要的宽度
  569. if (totalMinWidth < availableWidth) {
  570. // 有剩余空间:按比例分配给可伸缩列
  571. const extraSpace = availableWidth - totalMinWidth;
  572. const flexibleColumnCount = FLEXIBLE_COLUMNS.length;
  573. const spacePerColumn = Math.floor(extraSpace / flexibleColumnCount);
  574. FLEXIBLE_COLUMNS.forEach(key => {
  575. if (!FIXED_COLUMNS[key]) { // 确保不是固定列
  576. newWidths[key] = `${minWidths[key] + spacePerColumn}px`;
  577. }
  578. });
  579. }
  580. // 3. 更新列宽配置
  581. columnWidths.value = newWidths;
  582. // 4. 触发表格重新布局
  583. nextTick(() => {
  584. tableRef.value?.doLayout();
  585. });
  586. };
  587. /** 搜索按钮操作 */
  588. const handleQuery = () => {
  589. queryParams.pageNo = 1
  590. getList()
  591. }
  592. /** 重置按钮操作 */
  593. const resetQuery = () => {
  594. queryFormRef.value.resetFields()
  595. handleQuery()
  596. }
  597. /** 添加/修改操作 */
  598. const formRef = ref()
  599. const openForm = (type: string, id?: number,projectId?:number) => {
  600. if(id===undefined){
  601. push({ name: 'IotProjectTaskInfo', params: { type} })
  602. }else{
  603. push({ name: 'IotProjectTaskInfo', params: { type,id,projectId} })
  604. }
  605. }
  606. /** 删除按钮操作 */
  607. const handleDelete = async (id: number) => {
  608. try {
  609. // 删除的二次确认
  610. await message.delConfirm()
  611. // 发起删除
  612. await IotProjectTaskApi.deleteIotProjectTask(id)
  613. message.success(t('common.delSuccess'))
  614. // 刷新列表
  615. await getList()
  616. } catch {}
  617. }
  618. /** 导出按钮操作 */
  619. const handleExport = async () => {
  620. try {
  621. // 导出的二次确认
  622. await message.exportConfirm()
  623. // 发起导出
  624. exportLoading.value = true
  625. const data = await IotProjectTaskApi.exportIotProjectTask(queryParams)
  626. download.excel(data, '项目信息任务拆分.xls')
  627. } catch {
  628. } finally {
  629. exportLoading.value = false
  630. }
  631. }
  632. // 声明 ResizeObserver 实例
  633. let resizeObserver: ResizeObserver | null = null;
  634. /** 初始化 **/
  635. onMounted(async () => {
  636. // 获取公司级的部门 用于 公司 筛选 管理员使用
  637. companyDeptList.value = await DeptApi.companyLevelDepts()
  638. getList()
  639. // 预加载字典数据
  640. getWorkProgressDictOptions()
  641. getWellTypeDictOptions()
  642. getTechnologyDictOptions()
  643. // 创建 ResizeObserver 监听表格容器尺寸变化
  644. if (tableContainerRef.value?.$el) {
  645. resizeObserver = new ResizeObserver(() => {
  646. // 使用防抖避免频繁触发
  647. clearTimeout((window as any).resizeTimer);
  648. (window as any).resizeTimer = setTimeout(() => {
  649. calculateColumnWidths();
  650. }, 100);
  651. });
  652. resizeObserver.observe(tableContainerRef.value.$el);
  653. }
  654. })
  655. onUnmounted(() => {
  656. // 清除 ResizeObserver
  657. if (resizeObserver && tableContainerRef.value?.$el) {
  658. resizeObserver.unobserve(tableContainerRef.value.$el);
  659. resizeObserver = null;
  660. }
  661. // 清除定时器
  662. if ((window as any).resizeTimer) {
  663. clearTimeout((window as any).resizeTimer);
  664. }
  665. })
  666. // 监听列表数据变化重新计算列宽
  667. watch(list, () => {
  668. nextTick(calculateColumnWidths)
  669. }, { deep: true })
  670. </script>
  671. <style scoped>
  672. /* 表格容器样式,确保水平滚动 */
  673. .table-container {
  674. width: 100%;
  675. overflow-x: auto;
  676. }
  677. /* 确保表格单元格内容不换行 */
  678. :deep(.el-table .cell) {
  679. white-space: nowrap;
  680. }
  681. /* 确保表格列标题不换行 */
  682. :deep(.el-table th > .cell) {
  683. white-space: nowrap;
  684. }
  685. /* 调整表格最小宽度,确保内容完全显示 */
  686. :deep(.el-table) {
  687. min-width: 100%;
  688. }
  689. /* 为特定列设置省略号,但保持其他列正常显示 */
  690. :deep(.el-table td.el-table__cell),
  691. :deep(.el-table th.el-table__cell) {
  692. overflow: hidden !important;
  693. }
  694. :deep(.el-table .cell) {
  695. overflow: hidden !important;
  696. text-overflow: ellipsis !important;
  697. }
  698. /* 确保操作列的内容完全显示(不应用省略号) */
  699. :deep(.el-table-column--operation .cell) {
  700. overflow: visible !important;
  701. text-overflow: clip !important;
  702. }
  703. </style>