Просмотр исходного кода

开单列表添加缓存机制

jf 5 лет назад
Родитель
Сommit
52b64a3ca1
2 измененных файлов с 22 добавлено и 3 удалено
  1. 3 0
      hdApp/src/App.vue
  2. 19 3
      hdApp/src/mixins/product.js

+ 3 - 0
hdApp/src/App.vue

@@ -10,6 +10,9 @@ export default {
   // 有坑 分包里的页面访问不到
   globalData: {},
   onLaunch () {
+			uni.removeStorageSync('suitInfoList');
+			uni.removeStorageSync('productInfoList');
+			uni.removeStorageSync('pxClassInfoList');
     // #ifdef H5
     // H5开发环境无法微信授权,使用固定的用户 shish 2020.4.30
     if (process.env.NODE_ENV == "development") {

+ 19 - 3
hdApp/src/mixins/product.js

@@ -30,9 +30,22 @@ export default {
 			if(this.isGhsProduct){
 				this.initGhsData(id,shopId);//采购-进店下单
 			}else{
-				this.initGoodsData();//成品
-				this.initData();//组合
-				this.initPxClassData();//课程
+				/*缓存处理*/
+				if(uni.getStorageSync('suitInfoList')){
+					this.suitInfo = uni.getStorageSync('suitInfoList');
+				}else{
+					this.initGoodsData();//成品
+				}
+				if(uni.getStorageSync('productInfoList')){
+					this.productInfo = uni.getStorageSync('productInfoList');
+				}else{
+					this.initData();//组合
+				}
+				if(uni.getStorageSync('pxClassInfoList')){
+					this.pxClassInfo = uni.getStorageSync('pxClassInfoList');
+				}else{
+					this.initPxClassData();//课程
+				}
 			}
 		}
 	},
@@ -245,6 +258,7 @@ export default {
 							child.className = element.className;
 						});
 				});
+				uni.setStorageSync('productInfoList',data);
 				this.productInfo = data;
 				this.classIndex = 0;
 			} catch (error) {
@@ -285,6 +299,7 @@ export default {
 						child.className = element.className;
 					});
 				});
+				uni.setStorageSync('suitInfoList',data);
 				this.suitInfo = data;
 				this.suitClassIndex = 0;
 			} catch (error) {
@@ -741,6 +756,7 @@ export default {
 		async initPxClassData() {
 			try {
 				const { data } = await getPxClassDataApi({pageSize:50});
+				uni.setStorageSync('pxClassInfoList',data.list);
 				this.pxClassInfo = data.list;
 			} catch (error) {
 			} finally {