Skip to content

Commit

Permalink
fix: the last column is not display when column sum is 6
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyhom committed Jun 24, 2023
1 parent 508a63d commit 7965ff5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ <h1>mobile-select demo</h1>
{ data: numArr },
{ data: numArr },
{ data: numArr },
{ data: numArr },
{ data: numArr }
],
position: [0, 1, 0, 1, 0],
Expand Down
11 changes: 6 additions & 5 deletions src/ms-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CascadeData,
OptionData
} from "./types";
import { checkIsPC } from "./utils/tools";
import { checkIsPC, getFloorFloatStr } from "./utils/tools";
import "./style/mobile-select.less";

export default class MobileSelect {
Expand Down Expand Up @@ -614,21 +614,22 @@ export default class MobileSelect {
}

fixRowStyle(): void {
// 自定义列宽度比例 用width不用flex的原因是可以做transition过渡
// 自定义列宽度比例
// 用width而不用flex的原因: flex虽然可以从num1到num2做transition宽度过渡, 但新增一列时,存量列的宽度无过渡效果
if (
this.initColWidth.length &&
this.initColWidth.length === this.wheelList.length
) {
const widthSum = this.initColWidth.reduce((cur, pre) => cur + pre, 0);
this.initColWidth.forEach((item, index) => {
this.wheelList[index].style.width =
((item / widthSum) * 100).toFixed(2) + "%";
getFloorFloatStr(item / widthSum) + "%";
});
return;
}
const width = (100 / this.wheelList.length).toFixed(2);
const itemWidthStyle = getFloorFloatStr(100 / this.wheelList.length) + "%";
for (let i = 0; i < this.wheelList.length; i++) {
this.wheelList[i].style.width = width + "%";
this.wheelList[i].style.width = itemWidthStyle;
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/utils/tools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
export function checkIsPC() {
export function checkIsPC(): boolean {
return !navigator.userAgent
.toLowerCase()
.match(
/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/
);
}

/**
* 获取向下取整的小数
* @param num 待处理的数 e.g. 16.999
* @param digits 保留位数 2
* @returns '16.99'
*/
export function getFloorFloatStr(num: number, digits = 2): string {
return (Math.floor(num * 100) / 100).toFixed(digits);
}

0 comments on commit 7965ff5

Please # to comment.