tntd 1.4.9 → 1.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import { useState, useEffect, useRef } from 'react';
2
- import styled, { withTheme } from 'styled-components';
3
- import cn from 'classnames';
4
- import { get } from 'lodash';
5
- import Icon from '../Icon';
1
+ import { useState, useEffect, useRef } from "react";
2
+ import styled, { withTheme } from "styled-components";
3
+ import cn from "classnames";
4
+ import { get } from "lodash";
5
+ import Icon from "../Icon";
6
6
 
7
7
  const TabsContainer = styled.div`
8
8
  display: flex;
@@ -69,8 +69,8 @@ const Tabs = styled.ul`
69
69
  flex: 1;
70
70
  white-space: nowrap;
71
71
  padding-right: 40px;
72
- transition: transform .25s linear;
73
- position:absolute;
72
+ transition: transform 0.25s linear;
73
+ position: absolute;
74
74
  `;
75
75
  const TabItem = styled.li`
76
76
  position: relative;
@@ -78,7 +78,7 @@ const TabItem = styled.li`
78
78
  padding: 0 20px 0 10px;
79
79
  cursor: pointer;
80
80
  display: inline-block;
81
- line-height: ${props => props.theme.size === 'large' ? '46px' : '36px'};
81
+ line-height: ${props => (props.theme.size === "large" ? "46px" : "36px")};
82
82
  /* transition: background-color .5; */
83
83
  width: 130px;
84
84
  color: rgba(255,255,255,.6);
@@ -120,7 +120,7 @@ const TabItem = styled.li`
120
120
 
121
121
  a {
122
122
  font-size: 14px;
123
- color: ${props=>props.theme.headerActionsColor};//rgba(255,255,255,.6);
123
+ color: ${props => props.theme.headerActionsColor};//rgba(255,255,255,.6);
124
124
  text-rendering: optimizeLegibility;
125
125
  -webkit-font-smoothing: antialiased;
126
126
  -moz-osx-font-smoothing: grayscale;
@@ -163,8 +163,20 @@ const TabItem = styled.li`
163
163
  `;
164
164
 
165
165
  export const HeaderTabs = withTheme(
166
- ({ theme, className, tabs = [], onTabChange, onTabSelect, onTabClose, appListVisible, orgListVisible, orgAppListVisible, ...props }) => {
167
- const [selectedKey, setSelectedKey] = useState(props.selectedKey || get(tabs, '0.key'));
166
+ ({
167
+ theme,
168
+ className,
169
+ tabs = [],
170
+ onTabChange,
171
+ onTabSelect,
172
+ onTabClose,
173
+ appListVisible,
174
+ orgListVisible,
175
+ orgAppListVisible,
176
+ language,
177
+ ...props
178
+ }) => {
179
+ const [selectedKey, setSelectedKey] = useState(props.selectedKey || get(tabs, "0.key"));
168
180
  const [tabItems, setTabItems] = useState(tabs || []);
169
181
  const [arrowVisible, setArrowVisible] = useState(false);
170
182
  const [tabsPositionFlags, setTabsPositionFlags] = useState({ start: true, end: true });
@@ -172,8 +184,7 @@ export const HeaderTabs = withTheme(
172
184
 
173
185
  const getTabsDom = () => tabsRef.current;
174
186
 
175
- const onTabClick = (tab,index) => {
176
-
187
+ const onTabClick = (tab, index) => {
177
188
  setSelectedKey(tab.key);
178
189
  onTabSelect?.(tab);
179
190
 
@@ -191,84 +202,86 @@ export const HeaderTabs = withTheme(
191
202
  newSelectedKey = index === 0 ? newTabItems[0]?.key : newTabItems[index - 1]?.key;
192
203
  setSelectedKey(newSelectedKey);
193
204
  }
194
- onTabClose?.(tab, newTabItems, newTabItems.find(({ key }) => key === newSelectedKey));
205
+ onTabClose?.(
206
+ tab,
207
+ newTabItems,
208
+ newTabItems.find(({ key }) => key === newSelectedKey)
209
+ );
195
210
  };
196
211
  const onMoveToLeft = () => {
197
212
  const tabsDom = getTabsDom();
198
213
  const parentBBox = tabsDom.parentNode.getBoundingClientRect();
199
214
  const parentWidth = parentBBox.width - 32;
200
- let x = Math.abs(+tabsDom.style.transform.replace(/[^\d.-]/g, ''));
201
- const index = Math.ceil(x/130);
202
- const trueX = index*130;
203
- let newX = Math.min(0,-(trueX - parentWidth));
215
+ let x = Math.abs(+tabsDom.style.transform.replace(/[^\d.-]/g, ""));
216
+ const index = Math.ceil(x / 130);
217
+ const trueX = index * 130;
218
+ let newX = Math.min(0, -(trueX - parentWidth));
204
219
  tabsDom.style.transform = `translateX(${newX}px)`;
205
220
 
206
- const width = tabItems.length*130;
221
+ const width = tabItems.length * 130;
207
222
  setTabsPositionFlags({
208
- start: newX<0,
209
- end: Math.abs(newX)<(width-parentWidth)
223
+ start: newX < 0,
224
+ end: Math.abs(newX) < width - parentWidth,
210
225
  });
211
226
  };
212
227
  const onMoveToRight = () => {
213
228
  const tabsDom = getTabsDom();
214
229
  const parentBBox = tabsDom.parentNode.getBoundingClientRect();
215
230
  const parentWidth = parentBBox.width - 32;
216
- const width = tabItems.length*130;
231
+ const width = tabItems.length * 130;
217
232
 
218
- let x = Math.abs(+tabsDom.style.transform.replace(/[^\d.-]/g, ''));
219
- const index = Math.floor(x/130);
220
- const trueX = index*130;
221
- let newX = Math.max(-(width-parentWidth),-(trueX + parentWidth));
233
+ let x = Math.abs(+tabsDom.style.transform.replace(/[^\d.-]/g, ""));
234
+ const index = Math.floor(x / 130);
235
+ const trueX = index * 130;
236
+ let newX = Math.max(-(width - parentWidth), -(trueX + parentWidth));
222
237
  tabsDom.style.transform = `translateX(${newX}px)`;
223
238
 
224
239
  setTabsPositionFlags({
225
- start: newX<0,
226
- end: Math.abs(newX)<(width-parentWidth)
240
+ start: newX < 0,
241
+ end: Math.abs(newX) < width - parentWidth,
227
242
  });
228
243
  };
229
244
 
230
245
  const translateTabsDom = (tabs, selectedKey) => {
231
- if(!selectedKey)return;
246
+ if (!selectedKey) return;
232
247
  const index = tabs.indexOf(tabs.find(({ key }) => key === selectedKey));
233
- if(index===-1) return;
248
+ if (index === -1) return;
234
249
  const tabsDom = getTabsDom();
235
- let x = -(+tabsDom.style.transform.replace(/[^\d.-]/g, ''));
250
+ let x = -+tabsDom.style.transform.replace(/[^\d.-]/g, "");
236
251
  const bbox = {
237
- left:index*130,
238
- right:(index+1)*130
252
+ left: index * 130,
253
+ right: (index + 1) * 130,
239
254
  };
240
255
  const parentBBox = tabsDom.parentNode.getBoundingClientRect();
241
256
  const parentWidth = parentBBox.width - 36;
242
- const width = tabItems.length*130;
257
+ const width = tabItems.length * 130;
243
258
 
244
- let tailX = x + parentWidth;//当前滑动窗口尾部坐标
259
+ let tailX = x + parentWidth; //当前滑动窗口尾部坐标
245
260
  let newX = -x;
246
- if(bbox.left<x){
261
+ if (bbox.left < x) {
247
262
  newX = -bbox.left;
248
- }else if(bbox.right>=tailX){
263
+ } else if (bbox.right >= tailX) {
249
264
  newX = parentWidth - bbox.right;
250
265
  }
251
- if(newX+width<parentWidth){
266
+ if (newX + width < parentWidth) {
252
267
  newX = -(width - parentWidth);
253
268
  }
254
- newX = Math.min(0,newX);
269
+ newX = Math.min(0, newX);
255
270
  tabsDom.style.transform = `translateX(${newX}px)`;
256
-
271
+
257
272
  setTabsPositionFlags({
258
- start: newX<0,
259
- end: Math.abs(newX)<(width-parentWidth)
273
+ start: newX < 0,
274
+ end: Math.abs(newX) < width - parentWidth,
260
275
  });
261
276
  };
262
277
 
263
278
  useEffect(() => {
264
- setSelectedKey(props.selectedKey || get(tabs, '0.key'));
279
+ setSelectedKey(props.selectedKey || get(tabs, "0.key"));
265
280
  // const t = [{'code':'tagdata','enName':'tagdata','icon':'layer-color','menuName':'打标数据管理打标数据管理打标数据管理','path':'/orion/tag/datalist','key':'tagdata','name':'打标数据管理打标数据管理打标数据管理'},{'code':'taglist','enName':'taglist','icon':'home','menuName':'标签管理','path':'http://baidu.com/orion/tag/list','key':'taglist','name':'标签管理'},{'code':'relation1','enName':'dadicasesearch1','icon':'home','menuName':'案件检索1','path':'/orion/case/relation1','key':'relation1','name':'案件检索1'},{'code':'dadicasesearch-0','enName':'dadicasesearch','icon':'home','menuName':'案件检索-0','path':'/orion/case/relation0','key':'dadicasesearch-0','name':'案件检索-0'},{'code':'dadicasesearch-1','enName':'dadicasesearch','icon':'home','menuName':'案件检索-1','path':'/orion/case/relation1','key':'dadicasesearch-1','name':'案件检索-1'},{'code':'dadicasesearch-2','enName':'dadicasesearch','icon':'home','menuName':'案件检索-2','path':'/orion/case/relation2','key':'dadicasesearch-2','name':'案件检索-2'},{'code':'dadicasesearch-3','enName':'dadicasesearch','icon':'home','menuName':'案件检索-3','path':'/orion/case/relation3','key':'dadicasesearch-3','name':'案件检索-3'},{'code':'dadicasesearch-4','enName':'dadicasesearch','icon':'home','menuName':'案件检索-4','path':'/orion/case/relation4','key':'dadicasesearch-4','name':'案件检索-4'},{'code':'dadicasesearch-5','enName':'dadicasesearch','icon':'home','menuName':'案件检索-5','path':'/orion/case/relation5','key':'dadicasesearch-5','name':'案件检索-5'},{'code':'dadicasesearch-6','enName':'dadicasesearch','icon':'home','menuName':'案件检索-6','path':'/orion/case/relation6','key':'dadicasesearch-6','name':'案件检索-6'},{'code':'dadicasesearch-7','enName':'dadicasesearch','icon':'home','menuName':'案件检索-7','path':'/orion/case/relation7','key':'dadicasesearch-7','name':'案件检索-7'},{'code':'dadicasesearch-8','enName':'dadicasesearch','icon':'home','menuName':'案件检索-8','path':'/orion/case/relation8','key':'dadicasesearch-8','name':'案件检索-8'}] ;
266
281
  setTabItems(tabs);
267
282
  }, [tabs, props.selectedKey]);
268
283
 
269
- useEffect(()=>{
270
-
271
- },[props.orgAppListVisible]);
284
+ useEffect(() => {}, [props.orgAppListVisible]);
272
285
 
273
286
  useEffect(() => {
274
287
  const tabsDom = getTabsDom();
@@ -283,38 +296,50 @@ export const HeaderTabs = withTheme(
283
296
  return (
284
297
  <TabsContainer
285
298
  {...props}
286
- className={cn('tnt-layout-header-tabs', { [className]: className })}
299
+ className={cn("tnt-layout-header-tabs", { [className]: className })}
287
300
  >
288
301
  <Tabs className="tnt-layout-header-tabs-content" ref={tabsRef}>
289
- {
290
- tabItems.map((tab, index) => (
291
- <TabItem
292
- key={tab.key}
293
- theme={theme}
294
- className={cn({
295
- active: selectedKey === tab.key,
296
- activeTabPreSibling: tabItems[index + 1]?.key === selectedKey
297
- })}
298
- onClick={() => onTabClick(tab,index)}
299
- >
300
- <a href={tab.key} onClick={evt => evt.preventDefault()}>{tab.name}</a>
302
+ {tabItems.map((tab, index) => (
303
+ <TabItem
304
+ key={tab.key}
305
+ theme={theme}
306
+ className={cn({
307
+ active: selectedKey === tab.key,
308
+ activeTabPreSibling: tabItems[index + 1]?.key === selectedKey,
309
+ })}
310
+ onClick={() => onTabClick(tab, index)}
311
+ >
312
+ <a href={tab.key} onClick={evt => evt.preventDefault()}>
301
313
  {
302
- tabItems.length > 1 && (
303
- <Icon type="close" onClick={closeTabHandle.bind(null, tab, index)} />
304
- )
314
+ {
315
+ cn: tab.name,
316
+ en: tab.enName || tab.name,
317
+ }[language || "cn"]
305
318
  }
306
- </TabItem>
307
- ))
308
- }
319
+ </a>
320
+ {tab.closable !== false && tabItems.length > 1 && (
321
+ <Icon
322
+ type="close"
323
+ onClick={closeTabHandle.bind(null, tab, index)}
324
+ />
325
+ )}
326
+ </TabItem>
327
+ ))}
309
328
  </Tabs>
310
- {
311
- arrowVisible && (
312
- <div className="tnt-layout-header-tabs-arrows">
313
- <Icon type="left" onClick={onMoveToLeft} disabled={!tabsPositionFlags.start} />
314
- <Icon type="right" onClick={onMoveToRight} disabled={!tabsPositionFlags.end} />
315
- </div>
316
- )
317
- }
329
+ {arrowVisible && (
330
+ <div className="tnt-layout-header-tabs-arrows">
331
+ <Icon
332
+ type="left"
333
+ onClick={onMoveToLeft}
334
+ disabled={!tabsPositionFlags.start}
335
+ />
336
+ <Icon
337
+ type="right"
338
+ onClick={onMoveToRight}
339
+ disabled={!tabsPositionFlags.end}
340
+ />
341
+ </div>
342
+ )}
318
343
  </TabsContainer>
319
344
  );
320
345
  }