Jelajahi Sumber

修改我的收藏

zs 1 tahun lalu
induk
melakukan
7acceaa0b4
3 mengubah file dengan 131 tambahan dan 51 penghapusan
  1. 7 4
      src/layout/index.vue
  2. 23 0
      src/store/api/platform/tool.js
  3. 101 47
      src/views/search/index.vue

+ 7 - 4
src/layout/index.vue

@@ -37,7 +37,7 @@
         <el-col :span="5">
           <el-row :gutter="20">
             <el-col :span="6" class="top_2">
-              <el-button :icon="Search" size="small" @click="toCommon(0)">搜索</el-button>
+              <el-button :icon="Search" size="small" @click="toSearch('search')">搜索</el-button>
             </el-col>
             <el-col :span="6" class="top_2">
               <el-dropdown>
@@ -64,7 +64,7 @@
                   <el-dropdown-menu>
                     <el-dropdown-item @click="toOpen">管理中心</el-dropdown-item>
                     <el-dropdown-item @click="toCommon(2)">个人中心</el-dropdown-item>
-                    <el-dropdown-item @click="toCommon(0)">我的收藏</el-dropdown-item>
+                    <el-dropdown-item @click="toSearch('collection')">我的收藏</el-dropdown-item>
                     <el-dropdown-item @click="toCommon(3)">我的报名</el-dropdown-item>
                     <el-dropdown-item @click="toLogout">注销</el-dropdown-item>
                   </el-dropdown-menu>
@@ -188,11 +188,14 @@ const toOpen = async () => {
 }
 // 基础跳转
 const toCommon = (type) => {
-  if (type == '0') router.push('/search')
-  else if (type == '1') router.push('/chat')
+  if (type == '1') router.push('/chat')
   else if (type == '2') router.push('/center')
   else if (type == '3') router.push('/sign')
 }
+// 收藏搜索
+const toSearch = (type) => {
+  router.push({ path: '/search', query: { type } })
+}
 // 发布
 const toRelease = (type) => {
   router.push({ path: '/release', query: { type } })

+ 23 - 0
src/store/api/platform/tool.js

@@ -0,0 +1,23 @@
+import { defineStore } from 'pinia'
+import { AxiosWrapper } from '@/utils/axios-wrapper'
+const url = '/tool'
+const axios = new AxiosWrapper()
+
+export const ToolStore = defineStore('tool', () => {
+  const getCollection = async ({ skip = 0, limit = undefined, ...info } = {}) => {
+    let cond = {}
+    if (skip) cond.skip = skip
+    if (limit) cond.limit = limit
+    cond = { ...cond, ...info }
+    const res = await axios.$get(`${url}/MyCollection`, cond)
+    return res
+  }
+  const getTotal = async () => {
+    const res = await axios.$get(`${url}/CollectionTotal`)
+    return res
+  }
+  return {
+    getCollection,
+    getTotal
+  }
+})

+ 101 - 47
src/views/search/index.vue

@@ -14,28 +14,7 @@
         </el-col>
         <el-col :span="24" class="one">
           <a-tabs v-model:activeKey="activeKey" centered @change="toChange">
-            <a-tab-pane key="1" :tab="`成果(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="2" :tab="`需求(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="3" :tab="`项目(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="4" :tab="`赛事(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="5" :tab="`资讯(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="6" :tab="`单位(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="7" :tab="`企业(${total})`">
-              <List></List>
-            </a-tab-pane>
-            <a-tab-pane key="8" :tab="`专家(${total})`">
+            <a-tab-pane v-for="item in actList" :key="item.value" :tab="item.label">
               <List></List>
             </a-tab-pane>
           </a-tabs>
@@ -53,38 +32,39 @@ import List from './parts/list.vue'
 import { SearchOutlined } from '@ant-design/icons-vue'
 // 接口
 import { AchievementStore } from '@/store/api/platform/achievement'
+import { ToolStore } from '@/store/api/platform/tool'
 import { DemandStore } from '@/store/api/platform/demand'
 import { DictDataStore } from '@/store/api/system/dictData'
 const achieveStore = AchievementStore()
 const demandStore = DemandStore()
+const toolStore = ToolStore()
 const dictDataStore = DictDataStore()
 // 图片引入
 import searchOne from '@/assets/search.jpeg'
 // 路由
 const router = useRouter()
+const route = useRoute()
 // 加载中
 const loading = ref(false)
-const activeKey = ref('1')
-// const actList = ref([
-//   { label: '成果', value: 'achievement' },
-//   { label: '需求', value: 'demand' },
-//   { label: '项目', value: 'project' },
-//   { label: '赛事', value: 'match' },
-//   { label: '资讯', value: 'news' },
-//   { label: '单位', value: 'unit' },
-//   { label: '企业', value: 'company' },
-//   { label: '专家', value: 'expert' }
-// ])
+const activeKey = ref('achievement')
+const actList = ref([
+  { label: '成果', value: 'achievement' },
+  { label: '需求', value: 'demand' },
+  { label: '项目', value: 'project' },
+  { label: '赛事', value: 'match' },
+  { label: '资讯', value: 'news' },
+  { label: '单位', value: 'unit' },
+  { label: '企业', value: 'company' },
+  { label: '专家', value: 'expert' }
+])
 const searchForm = ref({})
 // 字典表
 const fieldList = ref([])
-//
-const fields = ref([
-  { label: '名称', model: 'name', type: 'name' },
-  { label: '技术领域:', model: 'field', type: 'dict' },
-  { label: '成果地区:', model: 'area', type: 'area' },
-  { label: '单位:', model: 'user' }
+const typeList = ref([
+  { value: '0', label: '供给' },
+  { value: '1', label: '需求' }
 ])
+const fields = ref([])
 // 列表
 const list = ref([])
 let skip = 0
@@ -94,10 +74,57 @@ const currentPage = ref(1)
 // 请求
 onMounted(async () => {
   loading.value = true
+  await searchField()
   await searchOther()
-  await search({ skip, limit })
+  if (route.query && route.query.type == 'collection') await searchActive()
+  else await search({ skip, limit })
   loading.value = false
 })
+const searchField = async () => {
+  if (activeKey.value == 'achievement') {
+    fields.value = [
+      { label: '成果名称', model: 'name', type: 'name' },
+      { label: '技术领域:', model: 'field', type: 'dict' },
+      { label: '成果地区:', model: 'area', type: 'area' },
+      { label: '参考价格:', model: 'money' }
+    ]
+  } else if (activeKey.value == 'demand') {
+    fields.value = [
+      { label: '需求名称', model: 'name', type: 'name' },
+      { label: '技术领域:', model: 'field', type: 'dict' },
+      { label: '类型:', model: 'type', type: 'dict' },
+      { label: '需求地区:', model: 'area', type: 'area' }
+    ]
+  } else if (activeKey.value == 'project') {
+    fields.value = [
+      { label: '项目名称', model: 'name', type: 'name' },
+      { label: '技术领域:', model: 'field', type: 'dict' },
+      { label: '项目地区:', model: 'area', type: 'area' },
+      { label: '发布时间:', model: 'time' }
+    ]
+  } else if (activeKey.value == 'match') {
+    fields.value = [
+      { label: '比赛名称', model: 'name', type: 'name' },
+      { label: '比赛金额:', model: 'money' },
+      { label: '比赛日期:', model: 'time', type: 'time' },
+      { label: '赛事状态:', model: 'match_status', type: 'dict' }
+    ]
+  } else if (activeKey.value == 'company') {
+    fields.value = [
+      { label: '企业名称', model: 'name', type: 'name' },
+      { label: '法定代表人:', model: 'representative' },
+      { label: '企业地区:', model: 'area', type: 'area' },
+      { label: '成立时间:', model: 'time' }
+    ]
+  } else if (activeKey.value == 'expert') {
+    fields.value = [
+      { label: '专家姓名', model: 'name', type: 'name' },
+      { label: '技术领域:', model: 'field', type: 'dict' },
+      { label: '所在地区:', model: 'area', type: 'area' },
+      { label: '研究方向:', model: 'direction' }
+    ]
+  }
+}
 const search = async (query = { skip: 0, limit }) => {
   const info = {
     skip: query.skip,
@@ -107,8 +134,25 @@ const search = async (query = { skip: 0, limit }) => {
     status: '1'
   }
   let res
-  if (activeKey.value == '1') res = await achieveStore.query(info)
-  else if (activeKey.value == '2') res = await demandStore.query(info)
+  if (activeKey.value == 'achievement') res = await achieveStore.query(info)
+  else if (activeKey.value == 'demand') res = await demandStore.query(info)
+  if (res.errcode == '0') {
+    list.value = res.data
+    total.value = res.total
+  }
+}
+const searchActive = async () => {
+  const menu = await toolStore.getTotal()
+  if (menu.errcode == '0') actList.value = menu.data
+  await searchCollection({ skip, limit })
+}
+const searchCollection = async (query = { skip: 0, limit }) => {
+  const info = {
+    skip: query.skip,
+    limit: query.limit,
+    type: activeKey.value
+  }
+  const res = await toolStore.getCollection(info)
   if (res.errcode == '0') {
     list.value = res.data
     total.value = res.total
@@ -124,6 +168,7 @@ const searchOther = async () => {
 const getDict = (data, model) => {
   let res
   if (model == 'field') res = fieldList.value.find((f) => f.value == data)
+  if (model == 'type') res = typeList.value.find((f) => f.value == data)
   return get(res, 'label')
 }
 // 地区显示
@@ -134,23 +179,32 @@ const getArea = (data) => {
 // 查看
 const toView = (item) => {
   let path
-  if (activeKey.value == '1') path = '/achievement/detail'
-  else if (activeKey.value == '2') path = '/demand/detail'
+  if (activeKey.value == 'achievement') path = '/achievement/detail'
+  else if (activeKey.value == 'demand') path = '/demand/detail'
+  else if (activeKey.value == 'project') path = '/project/detail'
+  else if (activeKey.value == 'match') path = '/innovation/detail'
+  else if (activeKey.value == 'company') path = '/company/detail'
+  else if (activeKey.value == 'expert') path = '/expert/detail'
   router.push({ path, query: { id: item.id || item._id } })
 }
 // 切换标签页
 const toChange = (key) => {
   activeKey.value = key
-  search({ skip, limit })
+  if (route.query && route.query.type == 'collection') searchCollection({ skip, limit })
+  else search({ skip, limit })
+  searchField()
 }
 // 分页
 const changePage = (page = currentPage.value) => {
-  search({ skip: (page - 1) * limit, limit: limit })
+  if (route.query && route.query.type == 'collection')
+    searchCollection({ skip: (page - 1) * limit, limit: limit })
+  else search({ skip: (page - 1) * limit, limit: limit })
 }
 const sizeChange = (limits) => {
   limit = limits
   currentPage.value = 1
-  search({ skip: 0, limit: limit })
+  if (route.query && route.query.type == 'collection') searchCollection({ skip, limit })
+  else search({ skip, limit })
 }
 // provide
 provide('fields', fields)