@tarojs/components-react 4.1.5 → 4.1.6-beta.1

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.
@@ -2,9 +2,41 @@ import { __rest } from 'tslib';
2
2
  import './style/index.css.js';
3
3
  import classNames from 'classnames';
4
4
  import { createForwardRefComponent } from '../../utils/index.js';
5
- import { useRef, useState, useCallback, useEffect } from '../../utils/hooks.react.js';
5
+ import { useRef, useState, useEffect, useCallback } from '../../utils/hooks.react.js';
6
6
  import { jsx } from 'react/jsx-runtime';
7
7
 
8
+ const LEGO_CDN_URL = 'http://ossin.jd.com/swm-plus/h5Tag/tag.js';
9
+ // 检查CDN脚本是否已加载
10
+ const isLegoScriptLoaded = () => {
11
+ return document.querySelector(`script[src="${LEGO_CDN_URL}"]`) !== null;
12
+ };
13
+ // 插入CDN脚本
14
+ const insertLegoScript = () => {
15
+ if (isLegoScriptLoaded()) return;
16
+ const script = document.createElement('script');
17
+ script.type = 'module';
18
+ script.src = LEGO_CDN_URL;
19
+ document.head.appendChild(script);
20
+ };
21
+ // 解析lego协议URL
22
+ const parseLegoUrl = src => {
23
+ if (!src.startsWith('lego://')) return null;
24
+ try {
25
+ // 移除 'lego://' 前缀
26
+ const urlWithoutProtocol = src.substring(7);
27
+ // 分割tagId和参数
28
+ const [tagId, params] = urlWithoutProtocol.split('?');
29
+ // 解析参数
30
+ const text = params ? new URLSearchParams(params).get('text') || '' : '';
31
+ return {
32
+ tagId,
33
+ text
34
+ };
35
+ } catch (error) {
36
+ console.warn('Failed to parse lego URL:', src, error);
37
+ return null;
38
+ }
39
+ };
8
40
  function Image(props) {
9
41
  const imgRef = useRef(null);
10
42
  const observer = useRef({});
@@ -19,7 +51,18 @@ function Image(props) {
19
51
  imgProps,
20
52
  forwardedRef
21
53
  } = props,
22
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
54
+ reset = __rest(props
55
+ // 检查是否为lego模式
56
+ , ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
57
+ // 检查是否为lego模式
58
+ const legoData = parseLegoUrl(src);
59
+ const isLegoMode = legoData !== null;
60
+ // 如果是lego模式,确保CDN脚本已加载
61
+ useEffect(() => {
62
+ if (isLegoMode) {
63
+ insertLegoScript();
64
+ }
65
+ }, [isLegoMode]);
23
66
  const cls = classNames('taro-img', {
24
67
  'taro-img__widthfix': mode === 'widthFix'
25
68
  }, className);
@@ -58,6 +101,21 @@ function Image(props) {
58
101
  (_b = (_a = observer.current) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
59
102
  };
60
103
  }, [lazyLoad, src]);
104
+ // 如果是lego模式,渲染canvas-tag
105
+ if (isLegoMode && legoData) {
106
+ return /*#__PURE__*/jsx("div", {
107
+ className: cls,
108
+ style: style,
109
+ ref: forwardedRef,
110
+ ...reset,
111
+ children: /*#__PURE__*/jsx("canvas-tag", {
112
+ tagId: legoData.tagId,
113
+ text: legoData.text,
114
+ ...imgProps
115
+ })
116
+ });
117
+ }
118
+ // 普通图片模式
61
119
  return /*#__PURE__*/jsx("div", {
62
120
  className: cls,
63
121
  style: style,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.css'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n ...reset\n } = props\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAmBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,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MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KAAS,CACb,gBAEFiC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAK/C,MAAM,CAACiC,OAAO,GAAGc,GAAK;AACnC1C,MAAAA,SAAS,EAAEY,MAAO;AAClBV,MAAAA,GAAG,EAAEA,GAAI;AACTgB,MAAAA,MAAM,EAAEH,WAAY;AACpBX,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAeqC,yBAAyB,CAAClD,KAAK,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.css'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\n// CDN脚本URL\nconst LEGO_CDN_URL = 'http://ossin.jd.com/swm-plus/h5Tag/tag.js'\n\n// 检查CDN脚本是否已加载\nconst isLegoScriptLoaded = (): boolean => {\n return document.querySelector(`script[src=\"${LEGO_CDN_URL}\"]`) !== null\n}\n\n// 插入CDN脚本\nconst insertLegoScript = (): void => {\n if (isLegoScriptLoaded()) return\n\n const script = document.createElement('script')\n script.type = 'module'\n script.src = LEGO_CDN_URL\n document.head.appendChild(script)\n}\n\n// 解析lego协议URL\nconst parseLegoUrl = (src: string): { tagId: string, text: string } | null => {\n if (!src.startsWith('lego://')) return null\n\n try {\n // 移除 'lego://' 前缀\n const urlWithoutProtocol = src.substring(7)\n\n // 分割tagId和参数\n const [tagId, params] = urlWithoutProtocol.split('?')\n\n // 解析参数\n const text = params ? new URLSearchParams(params).get('text') || '' : ''\n\n return { tagId, text }\n } catch (error) {\n console.warn('Failed to parse lego URL:', src, error)\n return null\n }\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n ...reset\n } = props\n\n // 检查是否为lego模式\n const legoData = parseLegoUrl(src)\n const isLegoMode = legoData !== null\n\n // 如果是lego模式,确保CDN脚本已加载\n useEffect(() => {\n if (isLegoMode) {\n insertLegoScript()\n }\n }, [isLegoMode])\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n // 如果是lego模式,渲染canvas-tag\n if (isLegoMode && legoData) {\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n <canvas-tag\n tagId={legoData.tagId}\n text={legoData.text}\n {...imgProps}\n />\n </div>\n )\n }\n\n // 普通图片模式\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["LEGO_CDN_URL","isLegoScriptLoaded","document","querySelector","insertLegoScript","script","createElement","type","src","head","appendChild","parseLegoUrl","startsWith","urlWithoutProtocol","substring","tagId","params","split","text","URLSearchParams","get","error","console","warn","Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","mode","onError","lazyLoad","imgProps","forwardedRef","reset","__rest","legoData","isLegoMode","useEffect","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAoBA,MAAMA,YAAY,GAAG,2CAA2C;AAEhE;AACA,MAAMC,kBAAkB,GAAGA,MAAc;EACvC,OAAOC,QAAQ,CAACC,aAAa,CAAC,eAAeH,YAAY,CAAA,EAAA,CAAI,CAAC,KAAK,IAAI;AACzE,CAAC;AAED;AACA,MAAMI,gBAAgB,GAAGA,MAAW;EAClC,IAAIH,kBAAkB,EAAE,EAAE;AAE1B,EAAA,MAAMI,MAAM,GAAGH,QAAQ,CAACI,aAAa,CAAC,QAAQ,CAAC;EAC/CD,MAAM,CAACE,IAAI,GAAG,QAAQ;EACtBF,MAAM,CAACG,GAAG,GAAGR,YAAY;AACzBE,EAAAA,QAAQ,CAACO,IAAI,CAACC,WAAW,CAACL,MAAM,CAAC;AACnC,CAAC;AAED;AACA,MAAMM,YAAY,GAAIH,GAAW,IAA4C;EAC3E,IAAI,CAACA,GAAG,CAACI,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,IAAI;EAE3C,IAAI;AACF;AACA,IAAA,MAAMC,kBAAkB,GAAGL,GAAG,CAACM,SAA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AAS,CACb,gBAEFmC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAKhD,MAAM,CAACkC,OAAO,GAAGc,GAAK;AACnC3C,MAAAA,SAAS,EAAEc,MAAO;AAClBrC,MAAAA,GAAG,EAAEA,GAAI;AACT2C,MAAAA,MAAM,EAAEH,WAAY;AACpBd,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAeuC,yBAAyB,CAACnD,KAAK,CAAC;;;;"}
@@ -9,6 +9,17 @@ import { jsx, jsxs } from 'react/jsx-runtime';
9
9
 
10
10
  const EMPTY_ARRAY = [];
11
11
  const EMPTY_OBJECT = {};
12
+ // 语言映射函数
13
+ function getLanguageText(lang) {
14
+ const isEnglish = lang === 'en-US' || lang === 'en-GB';
15
+ return {
16
+ confirm: isEnglish ? 'Confirm' : '确定',
17
+ cancel: isEnglish ? 'Cancel' : '取消',
18
+ year: isEnglish ? 'Year ' : '年',
19
+ month: isEnglish ? 'Month ' : '月',
20
+ day: isEnglish ? 'Day ' : '日'
21
+ };
22
+ }
12
23
  // 数据验证函数
13
24
  function validateRegionData(data) {
14
25
  let componentName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Picker';
@@ -109,14 +120,15 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
109
120
  level = 'region',
110
121
  regionData,
111
122
  textProps = EMPTY_OBJECT,
123
+ colors = EMPTY_OBJECT,
112
124
  onChange,
113
125
  onColumnChange,
114
126
  onCancel,
115
127
  children,
116
- style,
117
- formType
128
+ formType,
129
+ lang
118
130
  } = props,
119
- restProps = __rest(props, ["mode", "disabled", "range", "rangeKey", "value", "start", "end", "fields", "headerText", "level", "regionData", "textProps", "onChange", "onColumnChange", "onCancel", "children", "style", "formType"]);
131
+ restProps = __rest(props, ["mode", "disabled", "range", "rangeKey", "value", "start", "end", "fields", "headerText", "level", "regionData", "textProps", "colors", "onChange", "onColumnChange", "onCancel", "children", "formType", "lang"]);
120
132
  const indexRef = React__default.useRef([]);
121
133
  const pickerDateRef = React__default.useRef();
122
134
  // 记录是否是用户滚动
@@ -171,8 +183,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
171
183
  } else if (mode === 'date') {
172
184
  const val = value;
173
185
  let _value = verifyDate(val) || new Date(new Date().setHours(0, 0, 0, 0));
174
- const _start = verifyDate(start) || new Date('1970/01/01');
175
- const _end = verifyDate(end) || new Date('2999/01/01');
186
+ const _start = verifyDate(start) || new Date('1875/01/01');
187
+ const _end = verifyDate(end) || new Date('2100/01/01');
176
188
  if (!(_start <= _end)) {
177
189
  throw new Error(`Picker start time must be less than end time.`);
178
190
  }
@@ -264,15 +276,18 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
264
276
  // 隐藏 Picker
265
277
  const hidePicker = React__default.useCallback(() => {
266
278
  isInitializationCompletedRef.current = false;
279
+ // 动画暂时不支持,暂时屏蔽相关样式挂载逻辑
280
+ // setState(prev => ({ ...prev, fadeOut: true }))
281
+ // setTimeout(() => {
282
+ // setState(prev => ({
283
+ // ...prev,
284
+ // hidden: true,
285
+ // fadeOut: false
286
+ // }))
287
+ // }, 350)
267
288
  setState(prev => Object.assign(Object.assign({}, prev), {
268
- fadeOut: true
289
+ hidden: true
269
290
  }));
270
- setTimeout(() => {
271
- setState(prev => Object.assign(Object.assign({}, prev), {
272
- hidden: true,
273
- fadeOut: false
274
- }));
275
- }, 350);
276
291
  }, []);
277
292
  // 更新索引
278
293
  const updateIndex = React__default.useCallback(function (index, columnId) {
@@ -586,6 +601,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
586
601
  onColumnChange: handleColumnChange,
587
602
  columnId: String(index),
588
603
  selectedIndex: state.selectedIndices[index] // 传递对应列的selectedIndex
604
+ ,
605
+ colors: colors
589
606
  }, index));
590
607
  }
591
608
  case 'time':
@@ -596,12 +613,16 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
596
613
  updateIndex: updateIndex,
597
614
  columnId: "0",
598
615
  selectedIndex: state.selectedIndices[0] // 传递小时列的selectedIndex
616
+ ,
617
+ colors: colors
599
618
  }, `hour-${state.timestamp}`), /*#__PURE__*/jsx(PickerGroup, {
600
619
  mode: "time",
601
620
  range: minutesRange,
602
621
  updateIndex: updateIndex,
603
622
  columnId: "1",
604
623
  selectedIndex: state.selectedIndices[1] // 传递分钟列的selectedIndex
624
+ ,
625
+ colors: colors
605
626
  }, `minute-${state.timestamp}`)];
606
627
  }
607
628
  case 'date':
@@ -614,9 +635,11 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
614
635
  } = pickerDateRef.current;
615
636
  const currentYear = _updateValue[0];
616
637
  const currentMonth = _updateValue[1];
617
- const yearRange = getYearRange(_start.getFullYear(), _end.getFullYear()).map(item => `${item}年`);
618
- const monthRange = getMonthRange(_start, _end, currentYear).map(item => `${item < 10 ? `0${item}` : item}月`);
619
- const dayRange = getDayRange(_start, _end, currentYear, currentMonth).map(item => `${item < 10 ? `0${item}` : item}日`);
638
+ const langText = getLanguageText(lang);
639
+ const isEnglish = lang === 'en-US' || lang === 'en-GB';
640
+ const yearRange = getYearRange(_start.getFullYear(), _end.getFullYear()).map(item => isEnglish ? `${langText.year}${item}` : `${item}${langText.year}`);
641
+ const monthRange = getMonthRange(_start, _end, currentYear).map(item => isEnglish ? `${langText.month}${item < 10 ? `0${item}` : item}` : `${item < 10 ? `0${item}` : item}${langText.month}`);
642
+ const dayRange = getDayRange(_start, _end, currentYear, currentMonth).map(item => isEnglish ? `${langText.day}${item < 10 ? `0${item}` : item}` : `${item < 10 ? `0${item}` : item}${langText.day}`);
620
643
  const renderView = [/*#__PURE__*/jsx(PickerGroup, {
621
644
  mode: "date",
622
645
  range: yearRange,
@@ -624,6 +647,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
624
647
  updateIndex: updateIndex,
625
648
  columnId: "0",
626
649
  selectedIndex: state.selectedIndices[0] // 传递年份列的selectedIndex
650
+ ,
651
+ colors: colors
627
652
  }, `year`)];
628
653
  if (fields === 'month' || fields === 'day') {
629
654
  renderView.push(/*#__PURE__*/jsx(PickerGroup, {
@@ -633,6 +658,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
633
658
  updateIndex: updateIndex,
634
659
  columnId: "1",
635
660
  selectedIndex: state.selectedIndices[1] // 传递月份列的selectedIndex
661
+ ,
662
+ colors: colors
636
663
  }, `month`));
637
664
  }
638
665
  if (fields === 'day') {
@@ -643,6 +670,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
643
670
  updateIndex: updateIndex,
644
671
  columnId: "2",
645
672
  selectedIndex: state.selectedIndices[2] // 传递日期列的selectedIndex
673
+ ,
674
+ colors: colors
646
675
  }, `day`));
647
676
  }
648
677
  return renderView;
@@ -676,7 +705,8 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
676
705
  rangeKey: "value",
677
706
  updateIndex: updateIndex,
678
707
  columnId: String(i),
679
- selectedIndex: state.selectedIndices[i]
708
+ selectedIndex: state.selectedIndices[i],
709
+ colors: colors
680
710
  }, `region-${i}`));
681
711
  }
682
712
  return columns;
@@ -688,9 +718,11 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
688
718
  updateIndex: updateIndex,
689
719
  columnId: "0",
690
720
  selectedIndex: state.selectedIndices[0] // 传递selector模式的selectedIndex
721
+ ,
722
+ colors: colors
691
723
  });
692
724
  }
693
- }, [mode, range, rangeKey, fields, updateIndex, updateDay, handleColumnChange, pickerDateRef.current, level, regionData, state.selectedIndices, columnsCount]);
725
+ }, [mode, range, rangeKey, fields, updateIndex, updateDay, handleColumnChange, pickerDateRef.current, level, regionData, state.selectedIndices, columnsCount, lang, colors]);
694
726
  // 动画类名控制逻辑
695
727
  const clsMask = classNames('taro-picker__mask-overlay', 'taro-picker__animate-fade-in', {
696
728
  'taro-picker__animate-fade-out': state.fadeOut
@@ -703,14 +735,15 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
703
735
  showPicker,
704
736
  hidePicker
705
737
  }));
738
+ // 获取语言文本
739
+ const langText = getLanguageText(lang);
706
740
  return /*#__PURE__*/jsxs(View, {
707
741
  ref: ref // 直接绑定 ref
708
742
  ,
709
- style: style,
710
743
  ...(formType ? {
711
744
  'data-form-type': formType
712
745
  } : {}),
713
- ...omit(restProps, ['mode', 'disabled', 'range', 'rangeKey', 'value', 'start', 'end', 'fields', 'name', 'textProps', 'onChange', 'onColumnChange', 'onCancel', 'children', 'style', 'formType']),
746
+ ...omit(restProps, ['mode', 'disabled', 'range', 'rangeKey', 'value', 'start', 'end', 'fields', 'name', 'textProps', 'onChange', 'onColumnChange', 'onCancel', 'children', 'formType']),
714
747
  children: [/*#__PURE__*/jsx(View, {
715
748
  onClick: showPicker,
716
749
  children: children
@@ -726,14 +759,20 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
726
759
  children: [/*#__PURE__*/jsx(View, {
727
760
  className: "taro-picker__action",
728
761
  onClick: handleCancel,
729
- children: (_a = textProps.cancelText) !== null && _a !== void 0 ? _a : '取消'
762
+ style: {
763
+ color: colors.cancelButtonColor
764
+ },
765
+ children: (_a = textProps.cancelText) !== null && _a !== void 0 ? _a : langText.cancel
730
766
  }), headerText && /*#__PURE__*/jsx(View, {
731
767
  className: "taro-picker__title",
732
768
  children: headerText
733
769
  }), /*#__PURE__*/jsx(View, {
734
770
  className: "taro-picker__action",
735
771
  onClick: handleChange,
736
- children: (_b = textProps.okText) !== null && _b !== void 0 ? _b : '确定'
772
+ style: {
773
+ color: colors.confirmButtonColor
774
+ },
775
+ children: (_b = textProps.okText) !== null && _b !== void 0 ? _b : langText.confirm
737
776
  })]
738
777
  }), /*#__PURE__*/jsx(View, {
739
778
  className: "taro-picker__bd",