list.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <hc-new-card v-loading="tableLoading" id-ref="hc-project-list" div-p="12px" scrollbar>
  3. <template #header>
  4. <div class="w-[354px]">
  5. <el-select v-model="projectId" filterable clearable block placeholder="选择项目" @change="projectClick">
  6. <el-option v-for="item in projectData" :key="item.id" :label="item.projectAlias" :value="item.id" />
  7. </el-select>
  8. </div>
  9. </template>
  10. <template #extra>
  11. <el-button hc-btn type="primary" @click="addProjectClick">创建项目</el-button>
  12. </template>
  13. <hc-card-item v-for="item in tableData" :key="item.id" class="hc-project-list-card" @click="projectClick(item.id)">
  14. <div class="alias">{{ item.projectAlias }}</div>
  15. <div class="name">{{ item.projectName }}</div>
  16. <div class="footer">
  17. <div class="id">{{ item.id }}</div>
  18. <div class="time">{{ item.updateTime }}</div>
  19. </div>
  20. </hc-card-item>
  21. <template #action>
  22. <hc-pages :pages="searchForm" @change="pageChange" />
  23. </template>
  24. <!-- 查看项目信息 -->
  25. <InfoDialog v-model="isProjectInfoDialog" :ids="projectInfoId" />
  26. <!-- 创建或编辑项目信息 -->
  27. <hc-new-drawer v-model="isProjectDrawer" is-close to-id="hc-project-list">
  28. 创建或编辑项目信息
  29. </hc-new-drawer>
  30. </hc-new-card>
  31. </template>
  32. <script setup>
  33. import { nextTick, onActivated, ref } from 'vue'
  34. import { getArrValue } from 'js-fast-way'
  35. import InfoDialog from './modules/list/info-dialog.vue'
  36. import mainApi from '~api/project/project'
  37. defineOptions({
  38. name: 'ProjectList',
  39. })
  40. //激活
  41. onActivated(() => {
  42. getDataApi()
  43. })
  44. const getDataApi = async () => {
  45. await getProjectData()
  46. searchClick()
  47. }
  48. //项目列表
  49. const projectData = ref([])
  50. const projectId = ref('')
  51. const getProjectData = async () => {
  52. const { data } = await mainApi.page({
  53. current: 1,
  54. size: 999,
  55. })
  56. projectData.value = getArrValue(data?.records)
  57. }
  58. //搜索条件
  59. const searchForm = ref({ current: 1, size: 20, total: 0 })
  60. //搜索
  61. const searchClick = () => {
  62. searchForm.value.current = 1
  63. getTableData()
  64. }
  65. //分页
  66. const pageChange = ({ current, size }) => {
  67. searchForm.value.current = current
  68. searchForm.value.size = size
  69. getTableData()
  70. }
  71. //项目数据
  72. const tableData = ref([])
  73. //获取表格数据
  74. const tableLoading = ref(true)
  75. const getTableData = async () => {
  76. tableData.value = []
  77. tableLoading.value = true
  78. const { error, code, data } = await mainApi.page({
  79. ...searchForm.value,
  80. total: null,
  81. })
  82. tableLoading.value = false
  83. if (!error && code === 200) {
  84. tableData.value = getArrValue(data['records'])
  85. searchForm.value.total = data['total']
  86. } else {
  87. tableData.value = []
  88. searchForm.value.total = 0
  89. }
  90. }
  91. //查看项目信息
  92. const isProjectInfoDialog = ref(false)
  93. const projectInfoId = ref('')
  94. //项目被选择
  95. const projectClick = (id) => {
  96. projectInfoId.value = id
  97. nextTick(() => {
  98. isProjectInfoDialog.value = true
  99. })
  100. }
  101. //创建项目或修改项目
  102. const isProjectDrawer = ref(false)
  103. const projectDrawerId = ref('')
  104. //创建项目
  105. const addProjectClick = () => {
  106. projectDrawerId.value = ''
  107. nextTick(() => {
  108. isProjectDrawer.value = true
  109. })
  110. }
  111. </script>
  112. <style lang="scss">
  113. .hc-card-item-box.hc-project-list-card {
  114. width: 354px;
  115. height: 120px;
  116. display: inline-block;
  117. border-radius: 4px;
  118. margin-right: 14px;
  119. margin-bottom: 14px;
  120. cursor: pointer;
  121. background: #f3f3f3 !important;
  122. transition: all 0.3s;
  123. .alias {
  124. font-size: 16px;
  125. white-space:nowrap;
  126. overflow:hidden;
  127. text-overflow:ellipsis;
  128. }
  129. .name {
  130. font-size: 14px;
  131. color: #747474;
  132. margin-top: 10px;
  133. overflow: hidden;
  134. text-overflow: ellipsis; /* 超出部分省略号 */
  135. word-break: break-all; /* 设置省略字母数字 */
  136. display: -webkit-box;
  137. -webkit-box-orient: vertical;
  138. -webkit-line-clamp: 2; /* 显示的行数 */
  139. }
  140. .footer {
  141. position: absolute;
  142. color: #747474;
  143. display: flex;
  144. align-items: center;
  145. font-size: 14px;
  146. justify-content: space-between;
  147. bottom: 0;
  148. width: 100%;
  149. }
  150. &:hover {
  151. box-shadow: 2px 2px var(--el-color-primary-light-7);
  152. }
  153. }
  154. </style>