rename index.js to usertool.js
This commit is contained in:
		
							parent
							
								
									8b501429d3
								
							
						
					
					
						commit
						6eceb821ee
					
				| @ -2,7 +2,7 @@ | ||||
|   "name": "user.tool.uniapp", | ||||
|   "version": "1.0.0", | ||||
|   "description": "uniapp people side tools", | ||||
|   "main": "index.js", | ||||
|   "main": "usertool.js", | ||||
|   "scripts": { | ||||
|     "test": "echo \"Error: no test specified\" && exit 1" | ||||
|   }, | ||||
|  | ||||
| @ -18,7 +18,7 @@ export default { | ||||
|   RESPONSIVE_TABBAR_ALWAYSHIDE: false, | ||||
|   BACKEND: 'SERVER', // 通过变量来动态切换后台类型:服务器 SERVER 或云服务 UNICLOUD. 应当根据实际需要,在前端所用的 unitool 里覆盖。
 | ||||
| 
 | ||||
|   thisPage() { | ||||
|   this.thisPage() { | ||||
|     return this.constructor.name==='VueComponent' ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 
 | ||||
|       : ( getCurrentPages()[getCurrentPages().length - 1] // [20220401] 发现在 topWindow 里, getCurrentPages 是 undefined。
 | ||||
|         || {} ) // 用 {} 做备份是为了在 App.vue 中使用时,getCurrentPages() 有可能获取不到。
 | ||||
| @ -57,8 +57,8 @@ export default { | ||||
|   }, | ||||
| 
 | ||||
|   localizeText(i18nText) { | ||||
|     const mylang = getApp().$store.state.i18n.mylang // thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全
 | ||||
|     i18nText = i18nText || thisPage()?.i18nText // 如果本方法直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果挂载到 wo 下,那么 this.i18nText 就报错了。因此安全起见,通过 pageNow.i18nText 访问。
 | ||||
|     const mylang = getApp().$store.state.i18n.mylang // this.thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全
 | ||||
|     i18nText = i18nText || this.thisPage()?.i18nText // 如果本方法直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果挂载到 wo 下,那么 this.i18nText 就报错了。因此安全起见,通过 pageNow.i18nText 访问。
 | ||||
|     if (i18nText && typeof (i18nText) === 'object' && mylang) { | ||||
|       return i18nText[mylang] || '' | ||||
|     } | ||||
| @ -69,7 +69,7 @@ export default { | ||||
|   }, | ||||
| 
 | ||||
|   localeText() { | ||||
|     return thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {} | ||||
|     return this.thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {} | ||||
|   }, | ||||
| 
 | ||||
|   setBarTitles ({ windowTitle, pageTitle } = {}) { | ||||
| @ -171,7 +171,7 @@ export default { | ||||
|    * - CLINET_BACKEND_EXCEPTION: 前端发现后台异常 | ||||
|   **/ | ||||
|    async callBackend({ backend = this.BACKEND, httpMethod = 'POST', apiVersion = 'api', apiWho, apiTodo, apiWhat = {} }) { | ||||
|     const thisRoute = this.thisPage()?.route || 'VueApp' // 立刻保存 thisPage().route,因为在调用后台后,可能已切换到了其他页面。
 | ||||
|     const thisRoute = this.thisPage()?.route || 'VueApp' // 立刻保存 this.thisPage().route,因为在调用后台后,可能已切换到了其他页面。
 | ||||
|     const startTime = new Date().toJSON() | ||||
|     let result = {} | ||||
|     if (backend === 'UNICLOUD') { | ||||
| @ -435,7 +435,7 @@ export default { | ||||
|     }) | ||||
|    */ | ||||
|   showToast({ tool, type, image, title, duration = 2000, ...rest }) { | ||||
|     const pageNow = thisPage() | ||||
|     const pageNow = this.thisPage() | ||||
|     if (tool === 'uni' || ! pageNow?.$refs?.toast) { | ||||
|       // #ifdef APP-PLUS
 | ||||
|       uni.showToast({ icon: 'none', title, duration, ...rest }) | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user