Skip to content

Commit 6ca9a48

Browse files
authored
feat(Image): add props tId (#2658)
* feat(image): props-t-id * docs(image): props-t-id
1 parent b582fa5 commit 6ca9a48

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

src/image/README.en-US.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
:: BASE_DOC ::
22

33
## API
4+
45
### Image Props
56

67
name | type | default | description | required
78
-- | -- | -- | -- | --
9+
t-id | String | - | `1.2.10`. image tag id | N
810
error | String / Slot | 'default' | \- | N
911
external-classes | Array | - | `['t-class', 't-class-load']` | N
1012
height | String / Number | - | \- | N
@@ -24,12 +26,12 @@ name | params | description
2426
error | \- | \-
2527
load | \- | \-
2628

27-
2829
### CSS Variables
30+
2931
The component provides the following CSS variables, which can be used to customize styles.
30-
Name | Default Value | Description
32+
Name | Default Value | Description
3133
-- | -- | --
32-
--td-image-color | @font-gray-3 | -
33-
--td-image-loading-bg-color | @bg-color-secondarycontainer | -
34-
--td-image-loading-color | @font-gray-3 | -
35-
--td-image-round-radius | @radius-default | -
34+
--td-image-color | @font-gray-3 | -
35+
--td-image-loading-bg-color | @bg-color-secondarycontainer | -
36+
--td-image-loading-color | @font-gray-3 | -
37+
--td-image-round-radius | @radius-default | -

src/image/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ isComponent: true
3939
</p>
4040
</details>
4141

42-
4342
## API
43+
4444
### Image Props
4545

4646
名称 | 类型 | 默认值 | 说明 | 必传
4747
-- | -- | -- | -- | --
48+
t-id | String | - | `1.2.10`。图片标签id | N
4849
error | String / Slot | 'default' | 加载失败时显示的内容。值为 `default` 则表示使用默认加载失败风格;值为空或者 `slot` 表示使用插槽渲染,插槽名称为 `error`;值为其他则表示普通文本内容,如“加载失败” | N
4950
height | String / Number | - | 高度,默认单位为`px` | N
5051
lazy | Boolean | false | 是否开启图片懒加载 | N
@@ -64,16 +65,18 @@ error | \- | 图片加载失败时触发
6465
load | \- | 图片加载完成时触发
6566

6667
### Image 外部样式类
68+
6769
类名 | 说明
68-
-- | --
70+
-- | --
6971
t-class | 根节点样式类
7072
t-class-load | 加载样式类
7173

7274
### CSS 变量
75+
7376
组件提供了下列 CSS 变量,可用于自定义样式。
74-
名称 | 默认值 | 描述
77+
名称 | 默认值 | 描述
7578
-- | -- | --
76-
--td-image-color | @font-gray-3 | -
77-
--td-image-loading-bg-color | @bg-color-secondarycontainer | -
78-
--td-image-loading-color | @font-gray-3 | -
79-
--td-image-round-radius | @radius-default | -
79+
--td-image-color | @font-gray-3 | -
80+
--td-image-loading-bg-color | @bg-color-secondarycontainer | -
81+
--td-image-loading-color | @font-gray-3 | -
82+
--td-image-round-radius | @radius-default | -

src/image/image.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class Image extends SuperComponent {
3939
onLoaded(e: any) {
4040
const sdkVersion = wx.getSystemInfoSync().SDKVersion;
4141
const versionArray = sdkVersion.split('.').map((v) => parseInt(v, 10));
42-
const { mode } = this.properties;
42+
const { mode, tId } = this.properties;
4343
const isInCompatible =
4444
versionArray[0] < 2 ||
4545
(versionArray[0] === 2 && versionArray[1] < 10) ||
@@ -48,7 +48,7 @@ export default class Image extends SuperComponent {
4848
if (mode === 'heightFix' && isInCompatible) {
4949
// 实现heightFix模式,保持高度和宽高比,设置对应的宽度
5050
const { height: picHeight, width: picWidth } = e.detail;
51-
getRect(this, '#image').then((rect) => {
51+
getRect(this, `#${tId ?? 'image'}`).then((rect) => {
5252
const { height } = rect;
5353
const resultWidth = ((height / picHeight) * picWidth).toFixed(2);
5454
this.setData({ innerStyle: `height: ${addUnit(height)}; width: ${resultWidth}px;` });

src/image/image.wxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</view>
3737
<!-- 图片 -->
3838
<image
39-
id="image"
39+
id="{{tId||'image'}}"
4040
hidden="{{isLoading || isFailed}}"
4141
class="class {{prefix}}-class {{classPrefix}} {{classPrefix}}--shape-{{shape}}"
4242
src="{{src}}"

src/image/props.ts

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
import { TdImageProps } from './type';
88
const props: TdImageProps = {
9+
/** id,默认为null */
10+
tId: {
11+
type: String,
12+
value: null,
13+
},
914
/** 加载失败时显示的内容。值为 `default` 则表示使用默认加载失败风格;值为空或者 `slot` 表示使用插槽渲染,插槽名称为 `error`;值为其他则表示普通文本内容,如“加载失败” */
1015
error: {
1116
type: String,

src/image/type.ts

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
* */
66

77
export interface TdImageProps {
8+
/**
9+
* 自定义组件id
10+
* @default null
11+
*/
12+
tId?: {
13+
type: StringConstructor;
14+
value?: string;
15+
};
816
/**
917
* 自定义组件样式
1018
* @default ''

0 commit comments

Comments
 (0)