Skip to content

Commit

Permalink
perf(message-item): logical fault tolerance exception handling (#2704)
Browse files Browse the repository at this point in the history
* perf(message-item): logical fault tolerance exception handling

* test(message-item): logical fault tolerance exception handling
  • Loading branch information
betavs authored Apr 22, 2024
1 parent 0f0c132 commit 8efdf67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ export const getInstance = function (context?: Context, selector?: string) {
return instance;
};

export const unitConvert = (value: number | string): number => {
export const unitConvert = (value: number | string | null | undefined): number => {
if (typeof value === 'string') {
if (value.includes('rpx')) {
return (parseInt(value, 10) * (systemInfo?.screenWidth ?? 750)) / 750;
}
return parseInt(value, 10);
}
return value;
return value ?? 0;
};

export const setIcon = (iconName, icon, defaultIcon) => {
Expand Down
2 changes: 1 addition & 1 deletion src/message/__test__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`message props : style && customStyle 1`] = `
ariaRole="alert"
class="t-message class t-class t-message--warning "
id="t-message_0"
style="z-index:15000;top:20px;right:32rpx;left:32rpx; color: red; font-size: 9px;"
style="z-index:15000;top:20px;left:20rpx;right:32rpx; color: red; font-size: 9px;"
>
<wx-view
class="t-message__icon--left"
Expand Down
13 changes: 9 additions & 4 deletions src/message/message-item/message.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ var changeNumToStr = function (arr) {
};

var getMessageStyles = function (zIndex, offset, wrapTop) {
var arr = changeNumToStr(offset);
var arr = changeNumToStr(offset || [0, 0]);
var left = arr[0] || 0;
var right = arr[1] || 0;

var zIndexStyle = zIndex ? 'z-index:' + zIndex + ';' : '';
var styleOffset = '';

styleOffset += 'top:' + wrapTop + 'px;';
styleOffset += 'right:' + arr[1] + ';';
styleOffset += 'left:' + arr[1] + ';';
var zIndexStyle = zIndex ? 'z-index:' + zIndex + ';' : '';
styleOffset += 'left:' + left + ';';
styleOffset += 'right:' + right + ';';

return zIndexStyle + styleOffset;
};

Expand Down

0 comments on commit 8efdf67

Please sign in to comment.