rename libraries 'basend-*' to 'wo-base-*', 'corend-*' to 'wo-core-*', 'usend-*' to 'wo-user-*'
This commit is contained in:
		
							parent
							
								
									e2822974bf
								
							
						
					
					
						commit
						93dd43a1c4
					
				| @ -1,5 +1,5 @@ | ||||
| { | ||||
|   "name": "usend-toolkit-uniapp", | ||||
|   "name": "wo-user-toolkit-uniapp", | ||||
|   "version": "1.0.0", | ||||
|   "description": "uniapp people side tools", | ||||
|   "main": "unitool.js", | ||||
| @ -8,7 +8,7 @@ | ||||
|   }, | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "https://git.faronear.org/npm/usend-toolkit-uniapp.git" | ||||
|     "url": "https://git.faronear.org/npm/wo-user-toolkit-uniapp.git" | ||||
|   }, | ||||
|   "author": "", | ||||
|   "license": "ISC" | ||||
|  | ||||
							
								
								
									
										42
									
								
								unitool.js
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								unitool.js
									
									
									
									
									
								
							| @ -1,7 +1,7 @@ | ||||
| // uniapp people side tools
 | ||||
| 
 | ||||
| import './ican-H5Api.js' // 对齐H5Api: https://ext.dcloud.net.cn/plugin?id=415 // 注意要取消默认自带的 showToast https://uniapp.dcloud.io/api/system/clipboard?id=%e6%b3%a8%e6%84%8f
 | ||||
| const BASEND_TYPE_DEFAULT = 'SERVER' // one of { SERVER: 服务器, UNICLOUD_FUNC: 云函数, UNICLOUD_OBJECT: 云对象 }
 | ||||
| const BASE_TYPE_DEFAULT = 'SERVER' // one of { SERVER: 服务器, UNICLOUD_FUNC: 云函数, UNICLOUD_OBJECT: 云对象 }
 | ||||
| 
 | ||||
| export default { | ||||
|   // 用直观的色彩,代替 uview 的命名方式:
 | ||||
| @ -151,12 +151,12 @@ export default { | ||||
| 
 | ||||
|   /** 统一 uni.request 和 uniCloud.callFunction 的调用方法,提供统一、透明的后台调用 | ||||
|    * 返回值:{ _state, 成功结果或错误结果 },其中 _state 除了后台返回的,还可以是 | ||||
|    * - CLIENT_BASEND_BROKEN: 前端发现后台断线 | ||||
|    * - CLIENT_BASEND_TIMEOUT: 前端发现后台超时 | ||||
|    * - CLINET_BASEND_EXCEPTION: 前端发现后台异常 | ||||
|    * - CLIENT_WOBASE_BROKEN: 前端发现后台断线 | ||||
|    * - CLIENT_WOBASE_TIMEOUT: 前端发现后台超时 | ||||
|    * - CLINET_WOBASE_EXCEPTION: 前端发现后台异常 | ||||
|    **/ | ||||
|   async callBasend ({ | ||||
|     basendType = this.envar?.basendTypeDefault || wo?.envar?.basendTypeDefault || BASEND_TYPE_DEFAULT, | ||||
|   async callBase ({ | ||||
|     baseType = this.envar?.baseTypeDefault || wo?.envar?.baseTypeDefault || BASE_TYPE_DEFAULT, | ||||
|     httpMethod = 'POST', | ||||
|     apiVersion = 'api', | ||||
|     apiWho, | ||||
| @ -167,14 +167,14 @@ export default { | ||||
|     const startTime = new Date().toJSON() | ||||
|     let url = undefined | ||||
|     let result = {} | ||||
|     if (basendType === 'UNICLOUD_OBJECT') { | ||||
|     if (baseType === 'UNICLOUD_OBJECT') { | ||||
|       const uniObj = uniCloud.importObject(apiWho) | ||||
|       try { | ||||
|         result = await uniObj[apiTodo](apiWhat) | ||||
|       } catch (error) { | ||||
|         result = { _state: 'CLINET_BASEND_EXCEPTION', error } | ||||
|         result = { _state: 'CLINET_WOBASE_EXCEPTION', error } | ||||
|       } | ||||
|     } else if (basendType === 'UNICLOUD_FUNC') { | ||||
|     } else if (baseType === 'UNICLOUD_FUNC') { | ||||
|       let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud | ||||
|         .callFunction({ | ||||
|           name: apiWho, | ||||
| @ -189,14 +189,14 @@ export default { | ||||
|           // {errMsg, stack} = error
 | ||||
|           if (/request:fail/.test(error.errMsg)) { | ||||
|             // 后台云服务无法连接
 | ||||
|             return { _state: 'CLIENT_BASEND_BROKEN', error } | ||||
|             return { _state: 'CLIENT_WOBASE_BROKEN', error } | ||||
|           } else { | ||||
|             // 后台云服务返回异常
 | ||||
|             return { _state: 'CLIENT_BASEND_EXCEPTION', error } | ||||
|             return { _state: 'CLIENT_WOBASE_EXCEPTION', error } | ||||
|           } | ||||
|         }) | ||||
|       result = resultCloud | ||||
|     } else if (basendType === 'SERVER') { | ||||
|     } else if (baseType === 'SERVER') { | ||||
|       if (httpMethod === 'GET') { | ||||
|         // 如果不是 POST 方法,要额外把参数JSON化
 | ||||
|         for (let key in apiWhat) { | ||||
| @ -213,19 +213,19 @@ export default { | ||||
|       if (error) { | ||||
|         if (error.errMsg === 'request:fail') { | ||||
|           // 后台服务器无法连接
 | ||||
|           result = { _state: 'CLIENT_BASEND_BROKEN', error } | ||||
|           result = { _state: 'CLIENT_WOBASE_BROKEN', error } | ||||
|         } else if (error.errMsg === 'request:fail timeout') { | ||||
|           // 后台服务器超时
 | ||||
|           result = { _state: 'CLIENT_BASEND_TIMEOUT', error } | ||||
|           result = { _state: 'CLIENT_WOBASE_TIMEOUT', error } | ||||
|         } else { | ||||
|           // 后台服务器返回异常
 | ||||
|           result = { _state: 'CLIENT_BASEND_EXCEPTION', error } | ||||
|           result = { _state: 'CLIENT_WOBASE_EXCEPTION', error } | ||||
|         } | ||||
|       } else { | ||||
|         result = resultServer | ||||
|       } | ||||
|     } else { | ||||
|       result = { _state: 'CLIENT_BASEND_TYPE_UNKNOWN' } | ||||
|       result = { _state: 'CLIENT_WOBASE_TYPE_UNKNOWN' } | ||||
|     } | ||||
|     // 注意1,resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。
 | ||||
|     // 注意2,虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null,那么 resultServer/resultCloud 也是 null。
 | ||||
| @ -234,7 +234,7 @@ export default { | ||||
|         '%c ' + | ||||
|           JSON.stringify({ startTime: startTime, page: thisRoute, endTime: new Date().toJSON() }) + | ||||
|           ' %c ' + | ||||
|           JSON.stringify({ basendType, apiWho, apiTodo, apiWhat, url }) + | ||||
|           JSON.stringify({ baseType, apiWho, apiTodo, apiWhat, url }) + | ||||
|           ' %c ' + | ||||
|           JSON.stringify(result), | ||||
|         'color:blue;background:lightgrey', | ||||
| @ -367,7 +367,7 @@ export default { | ||||
|   }, | ||||
| 
 | ||||
|   async pickupFile ({ | ||||
|     basendType = this.envar?.basendTypeDefault || wo?.envar?.basendTypeDefault || BASEND_TYPE_DEFAULT, | ||||
|     baseType = this.envar?.baseTypeDefault || wo?.envar?.baseTypeDefault || BASE_TYPE_DEFAULT, | ||||
|     mediaType = 'image', | ||||
|     count = 1, | ||||
|     sizeType = ['original', 'compressed'], | ||||
| @ -378,14 +378,14 @@ export default { | ||||
|     formData = {}, | ||||
|     name = 'file', | ||||
|   } = {}) { | ||||
|     if (/^UNICLOUD/.test(basendType)) { | ||||
|     if (/^UNICLOUD/.test(baseType)) { | ||||
|       const resultCloud = await this.pickupFile2Cloud({ mediaType, count, sizeType, sourceType, maxDuration }) | ||||
|       return resultCloud | ||||
|     } else if (basendType === 'SERVER') { | ||||
|     } else if (baseType === 'SERVER') { | ||||
|       const resultServer = await this.pickupFile2Server({ mediaType, count, sizeType, sourceType, maxDuration, url, header, formData, name }) | ||||
|       return resultServer | ||||
|     } else { | ||||
|       return { _state: 'CLEINT_FAIL_UNKNOWN_BASEND_TYPE', basendType } | ||||
|       return { _state: 'CLEINT_FAIL_UNKNOWN_WOBASE_TYPE', baseType } | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user