Skip to content

Commit 01103de

Browse files
authored
fix:修复多端vue2环境下删除tabs切换显示异常 (#3886)
1 parent de8cd73 commit 01103de

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

packages/renderless/src/picker/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
import { toDate1, getDateWithNewTimezone, getStrTimezone, getLocalTimezone, paeseIso8601 } from '@opentiny/utils'
13+
import { toDate1, getDateWithNewTimezone, getStrTimezone, getLocalTimezone, parseIso8601 } from '@opentiny/utils'
1414
import { isNumber, isDate } from '@opentiny/utils'
1515
import { userPopper } from '@opentiny/vue-hooks'
1616
import { DATEPICKER } from '@opentiny/utils'
@@ -177,7 +177,7 @@ const ignoreTimezone = (value) => {
177177

178178
const ignoreTimezoneFn = (value) => {
179179
let date = value
180-
const iso8601 = paeseIso8601(value)
180+
const iso8601 = parseIso8601(value)
181181
if (iso8601) {
182182
const { year, month, day, hours, minutes, seconds } = iso8601
183183
date = new Date(year, month, day, hours, minutes, seconds)

packages/renderless/src/tabs-mf/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ export const clickMore = (api) => (name) => {
133133
}
134134

135135
export const removeItem =
136-
({ props, state, emit }) =>
136+
({ props, state, emit, api }) =>
137137
(name, silent = false) => {
138138
const itemIndex = state.items.findIndex((item) => item.name === name)
139139
const navIndex = state.navs.findIndex((item) => item.name === name)
140+
const isCurrent = state.currentItem && state.currentItem.name === name
141+
const nextNav = state.navs[navIndex - 1] || state.navs[navIndex + 1]
140142

141143
if (!~itemIndex) return
142144

@@ -148,6 +150,12 @@ export const removeItem =
148150
state.navs.splice(navIndex, 1)
149151
state.navs = [...state.navs]
150152

153+
if (isCurrent) {
154+
const nextName = nextNav ? nextNav.name : state.items[0]?.name || ''
155+
api.changeCurrentName(nextName)
156+
state.currentItem = state.items.find((item) => item.name === nextName) || null
157+
}
158+
151159
if (!silent) {
152160
// Emits the close event
153161
emit('edit', name, 'remove')

packages/renderless/src/tabs-mf/vue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const renderless = (props, hooks, { vm, emit, nextTick }) => {
5757
addItem: addItem(state),
5858
addNav: addNav(state),
5959
scrollTo: scrollTo({ vm, state }),
60-
removeItem: removeItem({ props, state, emit }),
60+
removeItem: removeItem({ props, state, emit, api }),
6161
changeCurrentName: changeCurrentName({ state, emit }),
6262
clickMore: clickMore(api),
6363
beforeCarouselSwipe: beforeCarouselSwipe({ api, state, vm }),

packages/utils/src/date/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const timezone2 = '-00:00,+00:00,+01:00,+02:00,+03:00,+03:30,+04:00,+04:30,+05:0
5656
const timezone3 = '+06:30,+07:00,+08:00,+09:00,+10:00,+10:30,+11:00,+11:30,+12:00,+12:45,+13:00,+14:00'
5757
const timezones: string[] = [...timezone1.split(','), ...timezone2.split(','), ...timezone3.split(',')]
5858

59-
export const paeseIso8601 = (str: string) => {
59+
export const parseIso8601 = (str: string) => {
6060
const m = iso8601Reg.exec(str)
6161
if (m && m.length === 25) {
6262
const year = Number(m[1])

packages/utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export {
1919
getWeekOfFirstDay,
2020
getLocalTimezone,
2121
getStrTimezone,
22-
paeseIso8601
22+
parseIso8601
2323
} from './date'
2424

2525
// 与 date.ts 合并一下, 有几个重名变量,待整理, 如果功能一致就合并

0 commit comments

Comments
 (0)