浏览代码

优化首页逻辑

xiaohaizhao 1 年之前
父节点
当前提交
06e5f84155
共有 4 个文件被更改,包括 123 次插入48 次删除
  1. 77 5
      pages/index/cloud/dataBank.vue
  2. 36 34
      pages/index/cloud/school.vue
  3. 6 5
      pages/index/index.vue
  4. 4 4
      pages/index/modules/bottomSuspensionFrame.vue

+ 77 - 5
pages/index/cloud/dataBank.vue

@@ -1,6 +1,17 @@
 <template>
-    <My_listbox>
-        <app-list model="资料库" />
+    <My_listbox ref="List" @getlist="getList" :isShowEmpty="false" :bottomHeight="70">
+        <view class="box">
+            <navigator class="nav-box" v-for="item in appList" :key="item.name" :url="item.path"
+                hover-class="navigator-hover">
+                <image v-if="item.cover" class="image" :src="item.cover" mode="aspectFill" lazy-load="false" />
+                <text v-else>{{ item.remark }}</text>
+            </navigator>
+            <navigator class="nav-box" v-for="item in list" :url="'/packageA/resourceLibrary/index?id=' + item.parentid"
+                :key="item.name" hover-class="navigator-hover">
+                <image v-if="item.cover" class="image" :src="item.cover" mode="aspectFill" lazy-load="false" />
+                <text v-else>{{ item.title }}</text>
+            </navigator>
+        </view>
     </My_listbox>
 </template>
 
@@ -8,11 +19,72 @@
 export default {
     data() {
         return {
+            appList: [],
+            list: [],
+            "content": {
+                "pageNumber": 1,
+                "pageSize": 20,
+                "isDataAuth": true,//小程序默认传true
+                "where": {
+                    "condition": "",
+                    "sat_sharematerial_classids": [],
+                }
+            }
         }
     },
-    created() {
-    }
+    methods: {
+        init(callBack) {
+            try {
+                this.appList = this.getApps('资料库')
+            } catch (error) {
+                console.log("未获取到授权")
+            }
+            this.getList().then(res => {
+                callBack()
+            })
+        },
+        getList(init = false) {
+            return new Promise((resolve, reject) => {
+                if (this.paging(this.content, init)) return resolve();
+                this.$Http.basic({
+                    "id": "20240407094702",
+                    content: this.content
+                }).then(res => {
+                    console.log("获取装备资源库一级分类", res)
+                    this.$refs.List.RefreshToComplete()
+                    resolve()
+                    if (this.cutoff(res.msg)) return;
+                    res.data = res.data.map(v => {
+                        v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => v.usetype == "avatar")) : "";
+                        return v
+                    });
+                    this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
+                    this.content = this.$refs.List.paging(this.content, res)
+                })
+            })
+        },
+    },
 }
 </script>
 
-<style lang="scss"></style>
+<style lang="scss">
+.box {
+    padding: 0 10px;
+    box-sizing: border-box;
+    display: flex;
+    justify-content: space-between;
+    flex-wrap: wrap;
+
+    .nav-box {
+        width: 172.5px;
+        height: 104px;
+        flex-shrink: 0;
+        margin-top: 10px;
+
+        .image {
+            width: 100%;
+            height: 100%;
+        }
+    }
+}
+</style>

+ 36 - 34
pages/index/cloud/school.vue

@@ -1,5 +1,5 @@
 <template>
-    <My_listbox ref="List" @getlist="getList">
+    <My_listbox ref="List" @getlist="getList" :isShowEmpty="false" :bottomHeight="70">
         <view class="box">
             <navigator class="nav-box" v-for="item in list" :key="item.sat_courseware_classid"
                 :url="'/packageA/course/index?id=' + item.sat_courseware_classid + '&classname=' + item.classname"
@@ -7,7 +7,6 @@
                 <image v-if="item.cover" class="image" :src="item.cover" mode="aspectFill" lazy-load="false" />
                 <text v-else>{{ item.classname }}</text>
             </navigator>
-
             <navigator class="nav-box" v-for="item in appList" :key="item.name" :url="item.path"
                 hover-class="navigator-hover">
                 <block v-if="item.cover">
@@ -15,7 +14,6 @@
                 </block>
                 <text v-else>{{ item.remark }}</text>
             </navigator>
-
         </view>
     </My_listbox>
 </template>
@@ -25,40 +23,44 @@ export default {
     data() {
         return {
             list: [],
-            appList: []
-        }
-    },
-    created() {
-        this.getList()
-    },
-    mounted() {
-        try {
-            this.appList = this.getApps('商学院')
-            console.log('商学院', this.appList)
-        } catch (error) {
-            console.log("未获取到授权信息")
+            appList: [],
+            "content": {
+                "parentid": 0,
+                "where": {
+                    "isenable": 1
+                }
+            }
         }
-
     },
     methods: {
-        getList() {
-            this.$Http.basic({
-                "id": "20221102143302",
-                "content": {
-                    "parentid": 0,
-                    pageSize: 9999,
-                    "where": {
-                        "isenable": 1
-                    }
-                }
-            }).then(res => {
-                console.log("课程分类", res)
-                this.$refs.List.RefreshToComplete()
-                if (this.cutoff(res.msg)) return;
-                this.list = res.data.map(v => {
-                    v.cover = this.getSpecifiedImage(v.attinfos[0] || {})
-                    return v
-                });
+        init(callBack) {
+            try {
+                this.appList = this.getApps('商学院')
+            } catch (error) {
+                console.log("未获取到授权信息")
+            }
+            this.getList().then(res => {
+                callBack()
+            })
+        },
+        getList(init = false) {
+            return new Promise((resolve, reject) => {
+                if (this.paging(this.content, init)) return resolve();
+                this.$Http.basic({
+                    "id": "20221102143302",
+                    content: this.content
+                }).then(res => {
+                    console.log("课程分类", res)
+                    this.$refs.List.RefreshToComplete()
+                    resolve()
+                    if (this.cutoff(res.msg)) return;
+                    res.data = res.data.map(v => {
+                        v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => v.usetype == "avatar")) : "";
+                        return v
+                    });
+                    this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
+                    this.content = this.$refs.List.paging(this.content, res)
+                })
             })
         }
     },

+ 6 - 5
pages/index/index.vue

@@ -21,8 +21,6 @@ export default {
 			page: '资料库'
 		}
 	},
-	onLoad() {
-	},
 	onShow() {
 		// #ifdef MP-WEIXIN
 		this.updatePageData(this.swiperItemID, this.page)
@@ -33,12 +31,15 @@ export default {
 			this.$refs.pages.onClick(itemId, page)
 		},
 		pageChange(detail) {
-			// this.$refs[detail.name]
 			uni.setNavigationBarTitle({
 				title: detail.name,
 			})
-			setTimeout(() => { detail.callBack() }, 300)
-			this.page = detail.name
+			this.page = detail.name;
+			try {
+				this.$refs[detail.name].init(detail.callBack)
+			} catch (error) {
+				detail.callBack()
+			}
 			console.log("切换页面", detail)
 		}
 	}

+ 4 - 4
pages/index/modules/bottomSuspensionFrame.vue

@@ -66,7 +66,8 @@ export default {
     },
     methods: {
         onClick(current, name, update = false) {
-            const item = this[current].find(v => v.name == name)
+            const item = this[current].find(v => v.name == name),
+                that = this;
             if (typeof item.loading != 'boolean' || update) {
                 item.loading = true;
                 update = true;
@@ -74,13 +75,12 @@ export default {
             this[current + 'LastPage'] = name;
             this.current = current;
             this.showPageName = name;
-
             this.$emit("onChange", {
-                current, name, update, callBack: callBack.bind(this)
+                current, name, update, callBack
             })
             function callBack(loading = false) {
                 item.loading = loading;
-                this[current] = JSON.parse(JSON.stringify(this[current]));
+                that[current] = JSON.parse(JSON.stringify(that[current]));
             }
         },
         update() {