ResourceList.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="page-container">
  3. <div class="page-head">
  4. <div>
  5. <div class="crumb">资源中枢 <b>/</b> <b>资源台账</b></div>
  6. <h1>资源台账</h1>
  7. </div>
  8. <div class="head-tools">
  9. <span class="filter-search">
  10. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg>
  11. <input v-model="query.name" placeholder="搜索资源名称 / 关联项目…" @keyup.enter="handleSearch" />
  12. </span>
  13. <el-button type="primary" @click="openCreate">+ 新增资源</el-button>
  14. </div>
  15. </div>
  16. <div class="page-card">
  17. <div class="card-head">
  18. <div>
  19. <h2>资源列表</h2>
  20. <span class="hint">共 {{ total }} 条</span>
  21. </div>
  22. <el-button @click="handleExport">导出Excel</el-button>
  23. </div>
  24. <el-form :model="query" inline class="filter-form">
  25. <el-form-item label="类型">
  26. <el-select v-model="query.typeId" placeholder="全部" clearable style="width: 140px">
  27. <el-option v-for="t in typeOptions" :key="t.id" :label="t.name" :value="t.id" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="负责人">
  31. <el-select v-model="query.ownerId" placeholder="全部" clearable filterable style="width: 120px">
  32. <el-option v-for="u in userOptions" :key="u.id" :label="u.realName" :value="u.id" />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="状态">
  36. <el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
  37. <el-option label="使用中" :value="1" />
  38. <el-option label="即将到期" :value="2" />
  39. <el-option label="已过期" :value="3" />
  40. <el-option label="已停用" :value="0" />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" @click="handleSearch">查询</el-button>
  45. <el-button @click="handleReset">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-table :data="list" v-loading="loading">
  49. <el-table-column label="序号" width="60" header-align="right" align="right">
  50. <template #default="{ $index }">{{ (query.pageNum - 1) * query.pageSize + $index + 1 }}</template>
  51. </el-table-column>
  52. <el-table-column prop="name" label="资源名称" min-width="150">
  53. <template #default="{ row }">
  54. <a class="link-name" @click="goDetail(row.id)">{{ row.name }}</a>
  55. </template>
  56. </el-table-column>
  57. <el-table-column prop="typeName" label="类型" width="110" />
  58. <el-table-column prop="providerName" label="服务商" width="100" />
  59. <el-table-column prop="purchaseDurationText" label="购买时长" width="90" />
  60. <el-table-column label="关联项目" min-width="160">
  61. <template #default="{ row }">
  62. <el-tag v-for="p in row.projects" :key="p.id" size="small" style="margin-right: 4px">{{ p.name }}</el-tag>
  63. <span v-if="!row.projects?.length" class="muted-tip">-</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="ownerName" label="负责人" width="90" />
  67. <el-table-column label="到期日期" width="160">
  68. <template #default="{ row }">
  69. <span class="mono-num">{{ row.expireDate || '-' }}</span>
  70. <span v-if="row.daysToExpire != null && row.daysToExpire >= 0 && row.daysToExpire <= 30" class="muted-tip">
  71. (剩{{ row.daysToExpire }}天)
  72. </span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="状态" width="100">
  76. <template #default="{ row }">
  77. <span :class="['status-badge', statusClass(row.status)]">{{ row.statusText }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" width="150" fixed="right">
  81. <template #default="{ row }">
  82. <el-button link type="primary" @click="openEdit(row.id)">编辑</el-button>
  83. <el-popconfirm title="确定删除该资源吗?" @confirm="handleDelete(row.id)">
  84. <template #reference>
  85. <el-button link type="danger">删除</el-button>
  86. </template>
  87. </el-popconfirm>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <el-pagination
  92. style="margin-top: 16px; justify-content: flex-end"
  93. v-model:current-page="query.pageNum"
  94. v-model:page-size="query.pageSize"
  95. :total="total"
  96. layout="total, prev, pager, next"
  97. @current-change="loadList"
  98. />
  99. </div>
  100. <ResourceForm v-model:visible="formVisible" :resource-id="editingId" @saved="loadList" />
  101. </div>
  102. </template>
  103. <script setup>
  104. import { ref, reactive, onMounted } from 'vue'
  105. import { useRouter } from 'vue-router'
  106. import { ElMessage } from 'element-plus'
  107. import ResourceForm from './ResourceForm.vue'
  108. import { resourcePageApi, resourceDeleteApi, resourceExportApi } from '@/api/resource'
  109. import { resourceTypeListApi } from '@/api/dict'
  110. import { userEnabledListApi } from '@/api/user'
  111. import { resourceStatusClass } from '@/utils/status'
  112. import { useScrollRestore } from '@/composables/useScrollRestore'
  113. useScrollRestore()
  114. const router = useRouter()
  115. const query = reactive({ pageNum: 1, pageSize: 10, name: '', typeId: null, ownerId: null, status: null })
  116. const list = ref([])
  117. const total = ref(0)
  118. const loading = ref(false)
  119. const typeOptions = ref([])
  120. const userOptions = ref([])
  121. const formVisible = ref(false)
  122. const editingId = ref(null)
  123. function statusClass(status) {
  124. return resourceStatusClass(status)
  125. }
  126. async function loadList() {
  127. loading.value = true
  128. try {
  129. const res = await resourcePageApi(query)
  130. list.value = res.data.records
  131. total.value = res.data.total
  132. } finally {
  133. loading.value = false
  134. }
  135. }
  136. function handleSearch() {
  137. query.pageNum = 1
  138. loadList()
  139. }
  140. function handleReset() {
  141. Object.assign(query, { pageNum: 1, pageSize: 10, name: '', typeId: null, ownerId: null, status: null })
  142. loadList()
  143. }
  144. function openCreate() {
  145. editingId.value = null
  146. formVisible.value = true
  147. }
  148. function goDetail(id) {
  149. router.push(`/resource/${id}`)
  150. }
  151. function openEdit(id) {
  152. editingId.value = id
  153. formVisible.value = true
  154. }
  155. async function handleDelete(id) {
  156. await resourceDeleteApi(id)
  157. ElMessage.success('删除成功')
  158. loadList()
  159. }
  160. async function handleExport() {
  161. const blob = await resourceExportApi(query)
  162. const url = window.URL.createObjectURL(new Blob([blob]))
  163. const link = document.createElement('a')
  164. link.href = url
  165. link.download = '资源列表.xlsx'
  166. link.click()
  167. window.URL.revokeObjectURL(url)
  168. }
  169. onMounted(async () => {
  170. loadList()
  171. const [t, u] = await Promise.all([resourceTypeListApi(), userEnabledListApi()])
  172. typeOptions.value = t.data
  173. userOptions.value = u.data
  174. })
  175. </script>
  176. <style scoped>
  177. .filter-form {
  178. margin: 4px 0 16px;
  179. }
  180. .muted-tip {
  181. color: var(--color-text-placeholder);
  182. font-size: 12px;
  183. }
  184. .link-name {
  185. color: var(--color-primary);
  186. cursor: pointer;
  187. }
  188. .link-name:hover {
  189. text-decoration: underline;
  190. }
  191. </style>