index.vue 24 KB

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