| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | class HttpUtil { | 
					
						
							|  |  |  |     static _handleMsg(msg) { | 
					
						
							|  |  |  |         if (!(msg instanceof Msg)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (msg.msg === "") { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (msg.success) { | 
					
						
							|  |  |  |             Vue.prototype.$message.success(msg.msg); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             Vue.prototype.$message.error(msg.msg); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static _respToMsg(resp) { | 
					
						
							|  |  |  |         const data = resp.data; | 
					
						
							|  |  |  |         if (data == null) { | 
					
						
							|  |  |  |             return new Msg(true); | 
					
						
							|  |  |  |         } else if (typeof data === 'object') { | 
					
						
							|  |  |  |             if (data.hasOwnProperty('success')) { | 
					
						
							|  |  |  |                 return new Msg(data.success, data.msg, data.obj); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return data; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return new Msg(false, 'unknown data:', data); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static async get(url, data, options) { | 
					
						
							|  |  |  |         let msg; | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             const resp = await axios.get(url, data, options); | 
					
						
							|  |  |  |             msg = this._respToMsg(resp); | 
					
						
							|  |  |  |         } catch (e) { | 
					
						
							|  |  |  |             msg = new Msg(false, e.toString()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this._handleMsg(msg); | 
					
						
							|  |  |  |         return msg; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static async post(url, data, options) { | 
					
						
							|  |  |  |         let msg; | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             const resp = await axios.post(url, data, options); | 
					
						
							|  |  |  |             msg = this._respToMsg(resp); | 
					
						
							|  |  |  |         } catch (e) { | 
					
						
							|  |  |  |             msg = new Msg(false, e.toString()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this._handleMsg(msg); | 
					
						
							|  |  |  |         return msg; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static async postWithModal(url, data, modal) { | 
					
						
							|  |  |  |         if (modal) { | 
					
						
							|  |  |  |             modal.loading(true); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const msg = await this.post(url, data); | 
					
						
							|  |  |  |         if (modal) { | 
					
						
							|  |  |  |             modal.loading(false); | 
					
						
							|  |  |  |             if (msg instanceof Msg && msg.success) { | 
					
						
							|  |  |  |                 modal.close(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return msg; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PromiseUtil { | 
					
						
							|  |  |  |     static async sleep(timeout) { | 
					
						
							|  |  |  |         await new Promise(resolve => { | 
					
						
							|  |  |  |             setTimeout(resolve, timeout) | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-07 09:15:58 +00:00
										 |  |  | const seq = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); | 
					
						
							| 
									
										
										
										
											2023-04-10 16:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | class RandomUtil { | 
					
						
							|  |  |  |     static randomIntRange(min, max) { | 
					
						
							| 
									
										
										
										
											2023-05-22 13:11:41 +00:00
										 |  |  |         return Math.floor(Math.random() * (max - min) + min); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static randomInt(n) { | 
					
						
							|  |  |  |         return this.randomIntRange(0, n); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static randomSeq(count) { | 
					
						
							|  |  |  |         let str = ''; | 
					
						
							|  |  |  |         for (let i = 0; i < count; ++i) { | 
					
						
							|  |  |  |             str += seq[this.randomInt(62)]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return str; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |     static randomShortId() { | 
					
						
							| 
									
										
										
										
											2023-04-10 16:28:52 +00:00
										 |  |  |         let str = ''; | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |         for (let i = 0; i < 8; ++i) { | 
					
						
							| 
									
										
										
										
											2023-06-07 09:15:58 +00:00
										 |  |  |             str += seq[this.randomInt(16)]; | 
					
						
							| 
									
										
										
										
											2023-04-10 16:28:52 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         return str; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |     static randomLowerAndNum(len) { | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |         let str = ''; | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |         for (let i = 0; i < len; ++i) { | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |             str += seq[this.randomInt(36)]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return str; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static randomUUID() { | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |         const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; | 
					
						
							|  |  |  |         return template.replace(/[xy]/g, function (c) { | 
					
						
							|  |  |  |           const randomValues = new Uint8Array(1); | 
					
						
							|  |  |  |           crypto.getRandomValues(randomValues); | 
					
						
							|  |  |  |           let randomValue = randomValues[0] % 16; | 
					
						
							|  |  |  |           let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8); | 
					
						
							|  |  |  |           return calculatedValue.toString(16); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2023-06-09 12:34:57 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-04-18 18:04:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 13:34:12 +00:00
										 |  |  |     static randomShadowsocksPassword() { | 
					
						
							| 
									
										
										
										
											2023-05-06 16:51:14 +00:00
										 |  |  |         let array = new Uint8Array(32); | 
					
						
							|  |  |  |         window.crypto.getRandomValues(array); | 
					
						
							|  |  |  |         return btoa(String.fromCharCode.apply(null, array)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ObjectUtil { | 
					
						
							|  |  |  |     static getPropIgnoreCase(obj, prop) { | 
					
						
							|  |  |  |         for (const name in obj) { | 
					
						
							|  |  |  |             if (!obj.hasOwnProperty(name)) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (name.toLowerCase() === prop.toLowerCase()) { | 
					
						
							|  |  |  |                 return obj[name]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return undefined; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static deepSearch(obj, key) { | 
					
						
							|  |  |  |         if (obj instanceof Array) { | 
					
						
							|  |  |  |             for (let i = 0; i < obj.length; ++i) { | 
					
						
							|  |  |  |                 if (this.deepSearch(obj[i], key)) { | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (obj instanceof Object) { | 
					
						
							|  |  |  |             for (let name in obj) { | 
					
						
							|  |  |  |                 if (!obj.hasOwnProperty(name)) { | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (this.deepSearch(obj[name], key)) { | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-02-20 17:29:55 +00:00
										 |  |  |             return obj.toString().toLowerCase().indexOf(key.toLowerCase()) >= 0; | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static isEmpty(obj) { | 
					
						
							|  |  |  |         return obj === null || obj === undefined || obj === ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static isArrEmpty(arr) { | 
					
						
							|  |  |  |         return !this.isEmpty(arr) && arr.length === 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static copyArr(dest, src) { | 
					
						
							|  |  |  |         dest.splice(0); | 
					
						
							|  |  |  |         for (const item of src) { | 
					
						
							|  |  |  |             dest.push(item); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static clone(obj) { | 
					
						
							|  |  |  |         let newObj; | 
					
						
							|  |  |  |         if (obj instanceof Array) { | 
					
						
							|  |  |  |             newObj = []; | 
					
						
							|  |  |  |             this.copyArr(newObj, obj); | 
					
						
							|  |  |  |         } else if (obj instanceof Object) { | 
					
						
							|  |  |  |             newObj = {}; | 
					
						
							|  |  |  |             for (const key of Object.keys(obj)) { | 
					
						
							|  |  |  |                 newObj[key] = obj[key]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             newObj = obj; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return newObj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static deepClone(obj) { | 
					
						
							|  |  |  |         let newObj; | 
					
						
							|  |  |  |         if (obj instanceof Array) { | 
					
						
							|  |  |  |             newObj = []; | 
					
						
							|  |  |  |             for (const item of obj) { | 
					
						
							|  |  |  |                 newObj.push(this.deepClone(item)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (obj instanceof Object) { | 
					
						
							|  |  |  |             newObj = {}; | 
					
						
							|  |  |  |             for (const key of Object.keys(obj)) { | 
					
						
							|  |  |  |                 newObj[key] = this.deepClone(obj[key]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             newObj = obj; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return newObj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static cloneProps(dest, src, ...ignoreProps) { | 
					
						
							|  |  |  |         if (dest == null || src == null) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const ignoreEmpty = this.isArrEmpty(ignoreProps); | 
					
						
							|  |  |  |         for (const key of Object.keys(src)) { | 
					
						
							|  |  |  |             if (!src.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } else if (!dest.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } else if (src[key] === undefined) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (ignoreEmpty) { | 
					
						
							|  |  |  |                 dest[key] = src[key]; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 let ignore = false; | 
					
						
							|  |  |  |                 for (let i = 0; i < ignoreProps.length; ++i) { | 
					
						
							|  |  |  |                     if (key === ignoreProps[i]) { | 
					
						
							|  |  |  |                         ignore = true; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (!ignore) { | 
					
						
							|  |  |  |                     dest[key] = src[key]; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static delProps(obj, ...props) { | 
					
						
							|  |  |  |         for (const prop of props) { | 
					
						
							|  |  |  |             if (prop in obj) { | 
					
						
							|  |  |  |                 delete obj[prop]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static execute(func, ...args) { | 
					
						
							|  |  |  |         if (!this.isEmpty(func) && typeof func === 'function') { | 
					
						
							|  |  |  |             func(...args); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static orDefault(obj, defaultValue) { | 
					
						
							|  |  |  |         if (obj == null) { | 
					
						
							|  |  |  |             return defaultValue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return obj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static equals(a, b) { | 
					
						
							|  |  |  |         for (const key in a) { | 
					
						
							|  |  |  |             if (!a.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (!b.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } else if (a[key] !== b[key]) { | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |