Skip to content

Commit

Permalink
fix(h5): 统一运行时 router & tabbar 工具方法
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Jul 25, 2022
1 parent 3cfa157 commit fa415fb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/taro-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@stencil/core": "~2.13.0",
"@stencil/sass": "1.5.2",
"@tarojs/taro": "workspace:*",
"@tarojs/router": "workspace:*",
"better-scroll": "^1.14.1",
"classnames": "^2.2.5",
"hls.js": "^1.1.5",
Expand Down
14 changes: 1 addition & 13 deletions packages/taro-components/src/components/tabbar/tabbar.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { Component, Prop, h, ComponentInterface, Host, State, Event, EventEmitter, Element } from '@stencil/core'
import Taro from '@tarojs/taro'
import { addLeadingSlash, stripBasename, stripSuffix } from '@tarojs/router/dist/utils'
import { IH5RouterConfig } from '@tarojs/taro/types/compile'
import classNames from 'classnames'
import resolvePathname from 'resolve-pathname'

import { splitUrl } from '../../utils'
import { TabbarItem } from './tabbar-item'

// const removeLeadingSlash = str => str.replace(/^\.?\//, '')
// const removeTrailingSearch = str => str.replace(/\?[\s\S]*$/, '')
const addLeadingSlash = (str = '') => str[0] === '/' ? str : `/${str}`

const hasBasename = (path = '', prefix = '') =>
new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path)

const stripBasename = (path = '', prefix = '') =>
hasBasename(path, prefix) ? path.substr(prefix.length) : path

const stripSuffix = (path = '', suffix = '') =>
path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path

const STATUS_SHOW = 0
const STATUS_HIDE = 1
const STATUS_SLIDEOUT = 2
Expand Down
1 change: 0 additions & 1 deletion packages/taro-h5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@tarojs/router": "workspace:*",
"@tarojs/runtime": "workspace:*",
"base64-js": "^1.3.0",
"dingtalk-jsapi": "~2.15.2",
"jsonp-retry": "^1.0.3",
"query-string": "^7.1.1",
"whatwg-fetch": "^3.4.0"
Expand Down
1 change: 1 addition & 0 deletions packages/taro-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@tarojs/runtime": "workspace:*",
"@tarojs/taro": "workspace:*",
"dingtalk-jsapi": "~2.15.2",
"history": "^5.1.0",
"mobile-detect": "^1.4.2",
"query-string": "^7.1.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-router/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')

export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url)

export const hasBasename = (path = '', prefix = '') =>
new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix

export const stripBasename = (path = '', prefix = '') =>
hasBasename(path, prefix) ? path.substr(prefix.length) : path
hasBasename(path, prefix) ? path.substring(prefix.length) : path

export const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '')

export const stripSuffix = (path = '', suffix = '') =>
path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path

class RoutesAlias {
conf: Array<string[]> = []

Expand Down
2 changes: 1 addition & 1 deletion packages/taro-webpack-runner/src/config/base.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (_appPath: string, _config: Partial<BuildConfig>) => {
alias: {
'@tarojs/taro': '@tarojs/taro-h5',
// 开发组件库时 link 到本地调试,runtime 包需要指向本地 node_modules 顶层的 runtime,保证闭包值 Current 一致,shared 也一样
'@tarojs/router': require.resolve('@tarojs/router'),
'@tarojs/router$': require.resolve('@tarojs/router'),
'@tarojs/runtime': require.resolve('@tarojs/runtime'),
'@tarojs/shared': require.resolve('@tarojs/shared/dist/shared.esm.js')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-webpack5-runner/src/webpack/H5BaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class H5BaseConfig extends BaseConfig {
alias: {
'@tarojs/taro': '@tarojs/taro-h5',
// 开发组件库时 link 到本地调试,runtime 包需要指向本地 node_modules 顶层的 runtime,保证闭包值 Current 一致,shared 也一样
'@tarojs/router': require.resolve('@tarojs/router'),
'@tarojs/router$': require.resolve('@tarojs/router'),
'@tarojs/runtime': require.resolve('@tarojs/runtime'),
'@tarojs/shared': require.resolve('@tarojs/shared/dist/shared.esm.js')
}
Expand Down
10 changes: 6 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa415fb

Please sign in to comment.