Skip to content

Commit

Permalink
优化部分写法
Browse files Browse the repository at this point in the history
  • Loading branch information
adaex committed Aug 4, 2021
1 parent 90b1b0d commit 6314080
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/iwx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const async = <T = any>(
args?: any,
self?: WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance
) =>
new Promise((resolve) =>
new Promise<T | undefined>((resolve) =>
func(
{
...args,
Expand All @@ -30,7 +30,7 @@ const async = <T = any>(
},
self
)
) as Promise<T>
)

const async_void = (func: (...args: any[]) => any, args?: any) =>
new Promise((resolve) =>
Expand Down Expand Up @@ -268,7 +268,7 @@ export default new (class {
}

async checkLoginCode(arg?: WechatMiniprogram.LoginOption) {
const res = await this.login(arg)
const res = (await this.login(arg)) || { code: '' }
return res.code || error('微信登陆失败,无法获取code')
}

Expand Down
10 changes: 5 additions & 5 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '../config'
import { Dic } from '../typing'
import { iwx } from '../index'
import { Dic } from '../typing'

export default new (class {
go(path: string, isRedirect = false) {
Expand All @@ -15,7 +15,7 @@ export default new (class {
const realPath = path.substr(colonIndex + 1)

// 本小程序页面
if (appId === config.selfAppId) return this.goInner(realPath, isRedirect)
if (appId === config.selfAppId) return this._goInner(realPath, isRedirect)

const accountInfo = iwx.getAccountInfoSync() || ({} as any)
const miniProgram = accountInfo.miniProgram || {}
Expand All @@ -26,10 +26,10 @@ export default new (class {
}

//以'/'或者'./'开头则为内部链接
if (path.startsWith('/') || path.startsWith('./')) return this.goInner(path, isRedirect)
if (path.startsWith('/') || path.startsWith('./')) return this._goInner(path, isRedirect)

//以http://或者https:// 则为外部h5链接
if (path.startsWith('http://') || path.startsWith('https://')) return this.goInner(`/web/pages/link?link=${encodeURIComponent(path)}`, isRedirect)
if (path.startsWith('http://') || path.startsWith('https://')) return this._goInner(`/web/pages/link?link=${encodeURIComponent(path)}`, isRedirect)

// 不是以上情况则警告
console.warn('please provide correct path')
Expand Down Expand Up @@ -94,7 +94,7 @@ export default new (class {
return '/' + (route + querySting).replace(/\?$/g, '').replace(/&$/g, '')
}

private goInner(path: string, isRedirect = false) {
_goInner(path: string, isRedirect = false) {
//重定向 关闭当前页面
if (isRedirect)
return wx.redirectTo({ url: path, fail: (e) => wx.switchTab({ url: path, fail: (e) => console.warn('please provide correct inner path') }) })
Expand Down

0 comments on commit 6314080

Please sign in to comment.