rename index.js to usertool.js

This commit is contained in:
陆柯 2022-04-01 21:37:12 +08:00
parent 8b501429d3
commit 6eceb821ee
2 changed files with 7 additions and 7 deletions

View File

@ -2,7 +2,7 @@
"name": "user.tool.uniapp", "name": "user.tool.uniapp",
"version": "1.0.0", "version": "1.0.0",
"description": "uniapp people side tools", "description": "uniapp people side tools",
"main": "index.js", "main": "usertool.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },

View File

@ -18,7 +18,7 @@ export default {
RESPONSIVE_TABBAR_ALWAYSHIDE: false, RESPONSIVE_TABBAR_ALWAYSHIDE: false,
BACKEND: 'SERVER', // 通过变量来动态切换后台类型:服务器 SERVER 或云服务 UNICLOUD. 应当根据实际需要,在前端所用的 unitool 里覆盖。 BACKEND: 'SERVER', // 通过变量来动态切换后台类型:服务器 SERVER 或云服务 UNICLOUD. 应当根据实际需要,在前端所用的 unitool 里覆盖。
thisPage() { this.thisPage() {
return this.constructor.name==='VueComponent' ? this // 对于组件内定义的 i18nText要使用 this 来获得组建内的 i18nText而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 return this.constructor.name==='VueComponent' ? this // 对于组件内定义的 i18nText要使用 this 来获得组建内的 i18nText而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
: ( getCurrentPages()[getCurrentPages().length - 1] // [20220401] 发现在 topWindow 里, getCurrentPages 是 undefined。 : ( getCurrentPages()[getCurrentPages().length - 1] // [20220401] 发现在 topWindow 里, getCurrentPages 是 undefined。
|| {} ) // 用 {} 做备份是为了在 App.vue 中使用时getCurrentPages() 有可能获取不到。 || {} ) // 用 {} 做备份是为了在 App.vue 中使用时getCurrentPages() 有可能获取不到。
@ -57,8 +57,8 @@ export default {
}, },
localizeText(i18nText) { localizeText(i18nText) {
const mylang = getApp().$store.state.i18n.mylang // thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全 const mylang = getApp().$store.state.i18n.mylang // this.thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全
i18nText = i18nText || thisPage()?.i18nText // 如果本方法直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果挂载到 wo 下,那么 this.i18nText 就报错了。因此安全起见,通过 pageNow.i18nText 访问。 i18nText = i18nText || this.thisPage()?.i18nText // 如果本方法直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果挂载到 wo 下,那么 this.i18nText 就报错了。因此安全起见,通过 pageNow.i18nText 访问。
if (i18nText && typeof (i18nText) === 'object' && mylang) { if (i18nText && typeof (i18nText) === 'object' && mylang) {
return i18nText[mylang] || '' return i18nText[mylang] || ''
} }
@ -69,7 +69,7 @@ export default {
}, },
localeText() { localeText() {
return thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {} return this.thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {}
}, },
setBarTitles ({ windowTitle, pageTitle } = {}) { setBarTitles ({ windowTitle, pageTitle } = {}) {
@ -171,7 +171,7 @@ export default {
* - CLINET_BACKEND_EXCEPTION: 前端发现后台异常 * - CLINET_BACKEND_EXCEPTION: 前端发现后台异常
**/ **/
async callBackend({ backend = this.BACKEND, httpMethod = 'POST', apiVersion = 'api', apiWho, apiTodo, apiWhat = {} }) { 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() const startTime = new Date().toJSON()
let result = {} let result = {}
if (backend === 'UNICLOUD') { if (backend === 'UNICLOUD') {
@ -435,7 +435,7 @@ export default {
}) })
*/ */
showToast({ tool, type, image, title, duration = 2000, ...rest }) { showToast({ tool, type, image, title, duration = 2000, ...rest }) {
const pageNow = thisPage() const pageNow = this.thisPage()
if (tool === 'uni' || ! pageNow?.$refs?.toast) { if (tool === 'uni' || ! pageNow?.$refs?.toast) {
// #ifdef APP-PLUS // #ifdef APP-PLUS
uni.showToast({ icon: 'none', title, duration, ...rest }) uni.showToast({ icon: 'none', title, duration, ...rest })