Browse Source

no message

张保健 3 years ago
parent
commit
33ede386ab

BIN
static/images/noAddress.png View File


BIN
static/images/noCart.png View File


BIN
static/images/noCollection.png View File


BIN
static/images/noCoupon.png View File


BIN
static/images/noEvaluate.png View File


BIN
static/images/noInvoice.png View File


BIN
static/images/noNews.png View File


BIN
static/images/noOrder.png View File


BIN
static/images/noSearch.png View File


BIN
static/images/noShopper.png View File


BIN
static/images/offline-result.png View File


BIN
static/images/one.png View File


BIN
static/images/open.gif View File


BIN
static/images/order2.png View File


BIN
static/images/order3.png View File


BIN
static/images/order4.png View File


BIN
static/images/order5.png View File


BIN
static/images/orderTime.png View File


BIN
static/images/phone_1.png View File


BIN
static/images/poster-close.png View File


BIN
static/images/posterbackgd.png View File


BIN
static/images/priceTag.png View File


BIN
static/images/pricetitle.jpg View File


BIN
static/images/record1.png View File


BIN
static/images/record2.png View File


BIN
static/images/record3.png View File


BIN
static/images/record4.png View File


BIN
static/images/red-packets.png View File


BIN
static/images/share-info.png View File


BIN
static/images/shuoming.png View File


BIN
static/images/sort-img.png View File


BIN
static/images/sort1.png View File


BIN
static/images/sort2.png View File


BIN
static/images/sort3.png View File


BIN
static/images/stop.png View File


+ 89 - 0
store/modules/app.js View File

@@ -0,0 +1,89 @@
1
+import {
2
+	getUserInfo
3
+} from "../../api/user.js";
4
+import {
5
+	LOGIN_STATUS,
6
+	LOGIN_TYPE,
7
+	UID
8
+} from '../../config/cache';
9
+import Cache from '../../utils/cache';
10
+import {
11
+	USER_INFO
12
+} from '../../config/cache';
13
+
14
+const state = {
15
+	token: Cache.get(LOGIN_STATUS) || false,
16
+	backgroundColor: "#fff",
17
+	userInfo: {},
18
+	uid: Cache.get(UID) || 0,
19
+	homeActive: false,
20
+	phoneStatus:true,
21
+	loginType:Cache.get(LOGIN_TYPE) || false,
22
+};
23
+
24
+const mutations = {
25
+	SETLOGINTYPE(state,opt){
26
+		state.loginType = opt.val;
27
+		Cache.set(LOGIN_TYPE, opt.val, opt.time);
28
+	},
29
+	SETPHONESTATUS(state,val){
30
+		state.phoneStatus = val;
31
+	},
32
+	LOGIN(state, opt) {
33
+		state.token = opt.token;
34
+		Cache.set(LOGIN_STATUS, opt.token, opt.time);
35
+	},
36
+	SETUID(state,val){
37
+		state.uid = val;
38
+		Cache.set(UID, val);
39
+	},
40
+	UPDATE_LOGIN(state, token) {
41
+		state.token = token;
42
+	},
43
+	LOGOUT(state) {
44
+		state.token = undefined;
45
+		state.uid = undefined
46
+		Cache.clear(LOGIN_STATUS);
47
+		Cache.clear(UID);
48
+	},
49
+	BACKGROUND_COLOR(state, color) {
50
+		state.color = color;
51
+		document.body.style.backgroundColor = color;
52
+	},
53
+	UPDATE_USERINFO(state, userInfo) {
54
+		state.userInfo = userInfo;
55
+		Cache.set(USER_INFO, userInfo);
56
+	},
57
+	OPEN_HOME(state) {
58
+		state.homeActive = true;
59
+	},
60
+	CLOSE_HOME(state) {
61
+		state.homeActive = false;
62
+	},
63
+};
64
+
65
+const actions = {
66
+	USERINFO({
67
+		state,
68
+		commit
69
+	}, force) {
70
+		if (state.userInfo !== null && !force)
71
+			return Promise.resolve(state.userInfo);
72
+		else
73
+			return new Promise(reslove => {
74
+				getUserInfo().then(res => {
75
+					commit("UPDATE_USERINFO", res.data);
76
+					Cache.set(USER_INFO, res.data);
77
+					reslove(res.data);
78
+				});
79
+			}).catch(() => {
80
+
81
+			});
82
+	}
83
+};
84
+
85
+export default {
86
+	state,
87
+	mutations,
88
+	actions
89
+};

+ 13 - 0
store/modules/hotWords.js View File

@@ -0,0 +1,13 @@
1
+export default {
2
+	namespaced: true,
3
+	state: {
4
+		// 搜索关键字
5
+		hotWord: []
6
+	},
7
+	getters: {},
8
+	mutations: {
9
+		setHotWord(state, hotWordList) {
10
+			state.hotWord = hotWordList;
11
+		}
12
+	}
13
+}

+ 8 - 0
store/modules/index.js View File

@@ -0,0 +1,8 @@
1
+import app from "./app";
2
+import hotWords from "./hotWords";
3
+import indexData from './indexData.js'
4
+export default {
5
+  app,
6
+  hotWords,
7
+	indexData
8
+};

+ 13 - 0
store/modules/indexData.js View File

@@ -0,0 +1,13 @@
1
+export default {
2
+	namespaced: true,
3
+	state: {
4
+		// 搜索关键字
5
+		indexDatas: {}
6
+	},
7
+	getters: {},
8
+	mutations: {
9
+		setIndexData(state, data) {
10
+			state.indexDatas = data;
11
+		}
12
+	}
13
+}

+ 217 - 0
utils/cache.js View File

@@ -0,0 +1,217 @@
1
+import {
2
+	EXPIRE
3
+} from '../config/app';
4
+
5
+class Cache {
6
+
7
+	constructor(handler) {
8
+		this.cacheSetHandler = uni.setStorageSync;
9
+		this.cacheGetHandler = uni.getStorageSync;
10
+		this.cacheClearHandler = uni.removeStorageSync;
11
+		this.cacheExpire = 'UNI-APP-CRMEB:TAG';
12
+		this.clearOverdue();
13
+	}
14
+
15
+	/**
16
+	 * 获取当前时间戳
17
+	 */
18
+	time() {
19
+		return Math.round(new Date() / 1000);
20
+	}
21
+	
22
+	/**
23
+	 * 字符串转时间戳
24
+	 * @param {Object} expiresTime
25
+	 */
26
+	strTotime(expiresTime){
27
+		let expires_time = expiresTime.substring(0, 19);
28
+		expires_time = expires_time.replace(/-/g, '/');
29
+		return Math.round(new Date(expires_time).getTime() / 1000);
30
+	}
31
+	
32
+
33
+	/**
34
+	 * 设置过期时间缓存
35
+	 * @param {Object} key
36
+	 * @param {Object} expire
37
+	 */
38
+	setExpireCaheTag(key, expire) {
39
+		expire = expire !== undefined ? expire : EXPIRE;
40
+		if (typeof expire === 'number') {
41
+			let tag = this.cacheGetHandler(this.cacheExpire), newTag = [],newKeys = [];
42
+			if (typeof tag === 'object' && tag.length) {
43
+				newTag = tag.map(item => {
44
+					newKeys.push(item.key);
45
+					if (item.key === key) {
46
+						item.expire = expire === 0 ? 0 : this.time() + expire;
47
+					}
48
+					return item;
49
+				});
50
+			} 
51
+			if (!newKeys.length || newKeys.indexOf(key) === -1) {
52
+				newTag.push({
53
+					key: key,
54
+					expire: expire === 0 ? 0 : this.time() + expire
55
+				});
56
+			}
57
+			this.cacheSetHandler(this.cacheExpire, newTag);
58
+		}
59
+	}
60
+
61
+	/**
62
+	 * 缓存是否过期,过期自动删除
63
+	 * @param {Object} key
64
+	 * @param {Object} $bool true = 删除,false = 不删除
65
+	 */
66
+	getExpireCahe(key, $bool) {
67
+		try {
68
+			let tag = this.cacheGetHandler(this.cacheExpire),time = 0,index = false;
69
+			if (typeof tag === 'object' && tag.length) {
70
+				tag.map((item,i) => {
71
+					if(item.key === key){
72
+						time = item.expire
73
+						index = i
74
+					}
75
+				});
76
+				if (time) {
77
+					let newTime = parseInt(time);
78
+					if (time && time < this.time() && !Number.isNaN(newTime)) {
79
+						if ($bool === undefined || $bool === true) {
80
+							this.cacheClearHandler(key);
81
+							if(index !== false){
82
+								tag.splice(index,1)
83
+								this.cacheClearHandler(this.cacheExpire,tag);
84
+							}
85
+						}
86
+						return false;
87
+					} else
88
+						return true;
89
+				} else {
90
+					return !!this.cacheGetHandler(key);
91
+				}
92
+			}
93
+			return false;
94
+		} catch (e) {
95
+			return false;
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * 设置缓存
101
+	 * @param {Object} key
102
+	 * @param {Object} data
103
+	 */
104
+	set(key, data, expire) {
105
+		if (data === undefined) {
106
+			return true;
107
+		}
108
+		if (typeof data === 'object')
109
+			data = JSON.stringify(data);
110
+		try {
111
+			this.setExpireCaheTag(key, expire);
112
+			return this.cacheSetHandler(key, data);
113
+		} catch (e) {
114
+			console.log(e);
115
+			return false;
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * 检测缓存是否存在
121
+	 * @param {Object} key
122
+	 */
123
+	has(key) {
124
+		this.clearOverdue();
125
+		return this.getExpireCahe(key);
126
+	}
127
+
128
+	/**
129
+	 * 获取缓存
130
+	 * @param {Object} key
131
+	 * @param {Object} $default
132
+	 * @param {Object} expire
133
+	 */
134
+	get(key, $default, expire) {
135
+		this.clearOverdue();
136
+		try {
137
+			let isBe = this.getExpireCahe(key);
138
+			let data = this.cacheGetHandler(key);
139
+			if (data && isBe) {
140
+				if (typeof $default === 'boolean')
141
+					return JSON.parse(data);
142
+				else
143
+					return data;
144
+			} else {
145
+				if (typeof $default === 'function') {
146
+					let value = $default();
147
+					this.set(key, value, expire);
148
+					return value;
149
+				} else {
150
+					this.set(key, $default, expire);
151
+					return $default;
152
+				}
153
+			}
154
+		} catch (e) {
155
+			return null;
156
+		}
157
+	}
158
+
159
+	/**
160
+	 * 删除缓存
161
+	 * @param {Object} key
162
+	 */
163
+	clear(key) {
164
+		try {
165
+			let cahceValue = this.cacheGetHandler(this.cacheExpire),
166
+				index = false;
167
+			if (cahceValue && typeof cahceValue === 'object' && cahceValue.length) {
168
+				cahceValue.map((item, i) => {
169
+					if (item.key === key) {
170
+						index = i;
171
+					}
172
+				});
173
+
174
+				if (index !== false) {
175
+					cahceValue.splice(index, 1);
176
+				}
177
+				this.cacheSetHandler(this.cacheExpire, cahceValue);
178
+			}
179
+			return this.cacheClearHandler(key);
180
+		} catch (e) {
181
+			return false;
182
+		}
183
+	}
184
+
185
+	/**
186
+	 * 清除过期缓存
187
+	 */
188
+	clearOverdue() {
189
+		let cahceValue = this.cacheGetHandler(this.cacheExpire),
190
+			time = this.time(),
191
+			newBeOverdueValue = [],
192
+			newTagValue = [];
193
+
194
+		if (cahceValue && typeof cahceValue === 'object' && cahceValue.length) {
195
+			cahceValue.map(item => {
196
+				if (item) {
197
+					if ((item.expire !== undefined && item.expire > time) || item.expire === 0) {
198
+						newTagValue.push(item);
199
+					} else {
200
+						newBeOverdueValue.push(item.key);
201
+					}
202
+				}
203
+			});
204
+		}
205
+		//保存没有过期的缓存标签
206
+		if (newTagValue.length !== cahceValue.length) {
207
+			this.cacheSetHandler(this.cacheExpire, newTagValue);
208
+		}
209
+		//删除过期缓存
210
+		newBeOverdueValue.forEach(k => {
211
+			this.cacheClearHandler(k);
212
+		})
213
+	}
214
+}
215
+
216
+
217
+export default new Cache;