Browse Source

全站搜索封面优化

codeMan 1 year ago
parent
commit
a1bde8d160
1 changed files with 21 additions and 2 deletions
  1. 21 2
      cloud/globalSearch/index.vue

+ 21 - 2
cloud/globalSearch/index.vue

@@ -18,7 +18,7 @@
                     v-for="item in list" :key="item.sa_fadid"
                     hover-class="navigator-hover">
                         <view class="item">
-                            <u--image radius="5" :lazy-load="true" :width="tovw(100)" :height="tovw(100)" :src="item.attinfos.length ? item.attinfos[0].url : avatar">
+                            <u--image radius="5" :lazy-load="true" :width="tovw(100)" :height="tovw(100)" :src="calcImage(item)">
                                 <template v-slot:loading>
                                     <u-loading-icon color="red"></u-loading-icon>
                                 </template>
@@ -37,6 +37,7 @@
 </template>
 
 <script>
+import { formattedFiles } from '../../utils/settleFiles.js'
 export default {
     data() {
         return {
@@ -94,11 +95,14 @@ export default {
                 }).then(res => {
                     this.$refs.List.setHeight()
                     this.$refs.List.RefreshToComplete()
-                    console.log("获取产品列表", res)
                     resolve();
                     if (this.cutoff(res.msg)) return;
+                    res.data.forEach(item => {
+                        item.attinfos = formattedFiles(item.attinfos)
+                    })
                     this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                     this.content = this.$refs.List.paging(this.content, res)
+                    console.log(this.list,'数据');
                 })
             })
         },
@@ -123,6 +127,21 @@ export default {
                         break;
                 }
             }
+        },
+        calcImage () {
+            return (data) => {
+                if (data.attinfos.length) {
+                    if (data.attinfos[0].fileType == 'video') {
+                        return data.attinfos[0].subfiles[0].url
+                    } else if (data.attinfos[0].fileType == 'image') {
+                        return data.attinfos[0].url
+                    } else {
+                        return this.avatar
+                    }
+                } else {
+                    return this.avatar
+                }
+            }
         }
     },
     onLoad () {