collection.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <div class="one_left">
  7. <span>收藏分类</span>
  8. <el-select v-model="searchForm.type" placeholder="请选择" style="width: 240px" @change="search">
  9. <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
  10. </el-select>
  11. </div>
  12. <div class="one_right">
  13. <el-input v-model="searchForm.name" style="width: 250px" size="large" placeholder="搜索" @change="search" :suffix-icon="Search" />
  14. </div>
  15. </el-col>
  16. <el-col :span="24" class="two">
  17. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  18. <template #empty>
  19. <el-empty description="暂无数据" />
  20. </template>
  21. <el-table-column prop="source_name" align="center" label="名称" />
  22. <el-table-column prop="created_time" align="center" label="收藏时间" width="180" />
  23. <el-table-column prop="status" align="center" label="来源" width="180">
  24. <template #default="scope">
  25. <div>{{ getDict(scope.row.type, 'type') }}</div>
  26. </template>
  27. </el-table-column>
  28. <el-table-column align="center" label="操作" width="180">
  29. <template #default="{ row }">
  30. <el-link :underline="false" type="primary" size="mini" @click="toView(row)" style="margin-right: 10px">查看</el-link>
  31. <el-link :underline="false" type="danger" size="mini" @click="toDelete(row)"> 取消收藏 </el-link>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </el-col>
  36. <el-col :span="24" class="thr">
  37. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  38. </el-col>
  39. </el-col>
  40. </el-row>
  41. </div>
  42. </template>
  43. <script setup>
  44. import { Search } from '@element-plus/icons-vue'
  45. import { get } from 'lodash-es'
  46. const $checkRes = inject('$checkRes')
  47. import { UserStore } from '@/store/user'
  48. const userStore = UserStore()
  49. const user = computed(() => userStore.user)
  50. // 路由
  51. const router = useRouter()
  52. // 接口
  53. import { CollectionStore } from '@/store/api/platform/collection'
  54. const store = CollectionStore()
  55. import { DictDataStore } from '@/store/api/system/dictData'
  56. const dictDataStore = DictDataStore()
  57. // 加载中
  58. const loading = ref(false)
  59. // 列表
  60. const list = ref([])
  61. let skip = 0
  62. let limit = inject('limit')
  63. const total = ref(0)
  64. const currentPage = ref(1)
  65. const searchForm = ref({})
  66. // 字典表
  67. const typeList = ref([])
  68. // 请求
  69. onMounted(async () => {
  70. loading.value = true
  71. await searchOther()
  72. await search()
  73. loading.value = false
  74. })
  75. const search = async (query = { skip, limit }) => {
  76. skip = query.skip
  77. limit = query.limit
  78. const info = {
  79. skip: query.skip,
  80. limit: query.limit,
  81. user: user.value.id,
  82. ...searchForm.value
  83. }
  84. const res = await store.list(info)
  85. if (res.errcode == '0') {
  86. list.value = res.data
  87. total.value = res.total
  88. }
  89. }
  90. const searchOther = async () => {
  91. let result
  92. // 类型
  93. result = await dictDataStore.query({ code: 'collectType', is_use: '0' })
  94. if ($checkRes(result)) typeList.value = result.data
  95. }
  96. // 字典数据转换
  97. const getDict = (data, model) => {
  98. if (data) {
  99. let res
  100. if (model == 'type') res = typeList.value.find((f) => f.value == data)
  101. return get(res, 'label')
  102. }
  103. }
  104. // 查看
  105. const toView = (data) => {
  106. if (data.type == 'achievement') router.push({ path: '/achievement/detail', query: { id: data.source } })
  107. if (data.type == 'company') router.push({ path: '/company/detail', query: { id: data.source } })
  108. if (data.type == 'demand') router.push({ path: '/demand/detail', query: { id: data.source } })
  109. if (data.type == 'expert') router.push({ path: '/expert/detail', query: { id: data.source } })
  110. if (data.type == 'match') router.push({ path: '/match/detail', query: { id: data.source } })
  111. if (data.type == 'news') router.push({ path: '/news/detail', query: { id: data.source } })
  112. if (data.type == 'footplate') router.push({ path: '/platform/detail', query: { id: data.source } })
  113. if (data.type == 'project') router.push({ path: '/project/detail', query: { id: data.source } })
  114. if (data.type == 'support') router.push({ path: '/service/detail', query: { id: data.source } })
  115. if (data.type == 'supply') router.push({ path: '/supply/detail', query: { id: data.source } })
  116. }
  117. // 删除
  118. const toDelete = (data) => {
  119. ElMessageBox.confirm(`您确认取消收藏?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  120. .then(async () => {
  121. const res = await store.del(data.id)
  122. if ($checkRes(res, true)) {
  123. search({ skip, limit })
  124. }
  125. })
  126. .catch(() => {})
  127. }
  128. // 分页
  129. const changePage = (page = currentPage.value) => {
  130. search({ skip: (page - 1) * limit, limit: limit })
  131. }
  132. const sizeChange = (limits) => {
  133. limit = limits
  134. currentPage.value = 1
  135. search({ skip: 0, limit: limit })
  136. }
  137. </script>
  138. <style scoped lang="scss">
  139. .main {
  140. .one {
  141. height: 50px;
  142. display: flex;
  143. justify-content: space-between;
  144. align-items: center;
  145. margin: 0 0 10px 0;
  146. .one_left {
  147. display: flex;
  148. align-items: center;
  149. span {
  150. font-size: $global-font-size-16;
  151. margin: 0 5px 0 0;
  152. color: #606266;
  153. }
  154. }
  155. }
  156. .thr {
  157. display: flex;
  158. justify-content: center;
  159. margin: 20px 0 0 0;
  160. }
  161. }
  162. </style>