u
This commit is contained in:
		
							parent
							
								
									a5cfcbb992
								
							
						
					
					
						commit
						3a28b3405d
					
				
							
								
								
									
										16
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								index.js
									
									
									
									
									
								
							@ -33,13 +33,13 @@ module.exports = {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  thisPage(){
 | 
					  thisPage(){
 | 
				
			||||||
    return this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
 | 
					    return getCurrentPages()[getCurrentPages().length - 1] // 准备挂在到 window 下使用,因此不必探测 this.$store 了,肯定不存在。
 | 
				
			||||||
      : getCurrentPages()[getCurrentPages().length - 1]
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  localizeText(i18nText) {
 | 
					  localizeText(i18nText) {
 | 
				
			||||||
    // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
 | 
					    // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
 | 
				
			||||||
    const thisPage = thisPage()
 | 
					    const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
 | 
				
			||||||
 | 
					      : getCurrentPages()[getCurrentPages().length - 1]
 | 
				
			||||||
    if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
 | 
					    if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
 | 
				
			||||||
      return i18nText[thisPage.$store.state.i18n.mylang] || ''
 | 
					      return i18nText[thisPage.$store.state.i18n.mylang] || ''
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -53,7 +53,8 @@ module.exports = {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  localeText() {
 | 
					  localeText() {
 | 
				
			||||||
    const thisPage = thisPage() // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
 | 
					    const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
 | 
				
			||||||
 | 
					    : getCurrentPages()[getCurrentPages().length - 1]
 | 
				
			||||||
    return thisPage.i18nText[thisPage.$store.state.i18n.mylang]
 | 
					    return thisPage.i18nText[thisPage.$store.state.i18n.mylang]
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -381,8 +382,9 @@ module.exports = {
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  showToast({ tool, type, image, title, duration = 2000, ...rest }) {
 | 
					  showToast({ tool, type, image, title, duration = 2000, ...rest }) {
 | 
				
			||||||
    const pageNow = thisPage()
 | 
					    const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
 | 
				
			||||||
    if (tool === 'uni' || !(pageNow.$refs && pageNow.$refs.toast)) {
 | 
					      : getCurrentPages()[getCurrentPages().length - 1]
 | 
				
			||||||
 | 
					    if (tool === 'uni' || !(thisPage.$refs && thisPage.$refs.toast)) {
 | 
				
			||||||
      // #ifdef APP-PLUS
 | 
					      // #ifdef APP-PLUS
 | 
				
			||||||
      uni.showToast({ icon: 'none', title, duration, ...rest })
 | 
					      uni.showToast({ icon: 'none', title, duration, ...rest })
 | 
				
			||||||
      // #endif
 | 
					      // #endif
 | 
				
			||||||
@ -391,7 +393,7 @@ module.exports = {
 | 
				
			|||||||
      // #endif
 | 
					      // #endif
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      // 根据 html 中不同的组件 <ucToast/> 或 <toast/> 而不同。
 | 
					      // 根据 html 中不同的组件 <ucToast/> 或 <toast/> 而不同。
 | 
				
			||||||
      pageNow.$refs.toast.show({ type, title, duration, ...rest })
 | 
					      thisPage.$refs.toast.show({ type, title, duration, ...rest })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user