Skip to content

Commit

Permalink
Merge pull request #40 from WeBankFinTech/branch_joy
Browse files Browse the repository at this point in the history
Branch joy
  • Loading branch information
mayinrain authored Apr 9, 2024
2 parents 7e89362 + 77187c9 commit 023f723
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docs/.vitepress/components/BSearch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ app.use(BSearch);
| advanceForm | 高级筛选表单数据 | Object | {} ||
| isAdvance | 是否展示高级筛选按钮 | Boolean | false ||
| isAdvanceCount | 是否统计高级筛选已填数量 | Boolean | true ||
| advanceCountFunc | 自定义高级筛选计数函数 | Function | (advanceForm) => {} ||
| isReset | 是否展示重置按钮 | Boolean | true ||
| isResetAllClear | 点击重置后是否做自动清空 | Boolean | true ||
| isLetgo | 是否为letgo开发 | Boolean | false ||

### Search Events
事件名称 | 说明 | 回调参数 |
Expand Down
10 changes: 8 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ export default defineConfig({
{
text: '函数',
link: '/utils/isIE'
}],
},
{
text: 'Easy Code',
link: 'https://mumblefe.cn/p/easycode/#/chat'
}
],
sidebar: {
'/components/': [
{
Expand Down Expand Up @@ -109,7 +114,8 @@ export default defineConfig({
{ text: 'getUrlParams', link: '/utils/getUrlParams' },
{ text: 'forceDownload', link: '/utils/forceDownload' },
{ text: 'formatterEmptyValue', link: '/utils/formatterEmptyValue' },
{ text: 'validate', link: '/utils/validate'}
{ text: 'validate', link: '/utils/validate'},
{ text: 'format', link: '/utils/format'}
]
}]
}
Expand Down
6 changes: 5 additions & 1 deletion docs/.vitepress/custom/components/exampleRepl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ const defaultFiles = {
'https://registry.npmmirror.com/@fesjs/fes-design/latest/files/dist/fes-design.esm-browser.js',
'@fesjs/fes-design/icon':
'https://registry.npmmirror.com/@fesjs/fes-design/latest/files/dist/fes-design.icon-browser.js',
// 切npm库
'@fesjs/traction-widget':
'https://cdn.jsdelivr.net/npm/@fesjs/traction-widget/dist/traction-widget.esm-browser.js'
'https://cdn.jsdelivr.net/npm/@fesjs/traction-widget/dist/traction-widget.esm-browser.js',
// 切本地库
// '@fesjs/traction-widget':
// 'http://127.0.0.1:8080/packages/traction-widget/dist/traction-widget.esm-browser.js'
},
}),
};
Expand Down
114 changes: 114 additions & 0 deletions docs/utils/format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# format
提供一个格式化对象,具有常见的格式化方法,分为表格格式化TABLE类和基本字符串或数字类型格式化NORMAL。

## 使用方式

```js
<template>
<div>
<f-table :data="tableAllLists">
<f-table-column prop="id" label="ID" :width="80" ellipsis />
<f-table-column prop="cn_name" label="中文名称" :width="160" ellipsis :formatter="format.TABLE.textValue"/>
<f-table-column prop="en_name" label="英文名称" :width="160" ellipsis />
<f-table-column prop="capacity" label="数据容量(GB)" :width="160" :formatter="format.TABLE.stdNumber" ellipsis />
<f-table-column prop="capacity2" label="数据容量2(GB)" :width="160" ellipsis />
<f-table-column prop="ratio" label="容量占比(%)" :width="160" :formatter="format.TABLE.stdNumberFix2" ellipsis />
<f-table-column prop="open" label="开启" :width="160" :formatter="format.TABLE.bool2string" ellipsis />
</f-table>
</div>
</template>
<script setup lang="ts">
import { FTable, FTableColumn, FPagination } from '@fesjs/fes-design';
import { ref} from 'vue';
import { format } from '@fesjs/traction-widget';

const generateData = () => {
const data = [];
for (let i=0; i<10; i++) {
const obj = {
id: String(i),
cn_name: '中文名'+ i,
en_name: format.NORMAL.convertToSnakeCase('enNameShow') + i,
ratio: i*10+0.1,
capacity: i*1000000,
capacity2: format.NORMAL.formatterStdNumberByString(i*1000000,true,3),
open: i%2,
};
data.push(obj);
}
return data
};
const tableAllLists = ref<any[]>(generateData());
</script>
```
## 具体内容
```js
export const format = {
// 表格格式化函数
TABLE: {
// 将空白格式化为'--'
textValue : ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0;
return cellValue || '--';
},
// 数字格式化函数,小数点前每3位打一个逗号
stdNumber : ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0;
if (isNaN(cellValue) || cellValue === null || cellValue === '') {
return '--';
}
const num = Number(cellValue);
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
},
// 数字格式化函数,小数点前每3位打一个逗号,严格保留两位小数
stdNumberFix2 : ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0.00;
if (isNaN(cellValue) || cellValue === null || cellValue === '') {
return '--';
}
const num = Number(cellValue).toFixed(2);
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
},
// 布尔量格式化函数,转是否
bool2string: ({ cellValue }: { cellValue: any }): any => {
if (['', null, undefined].includes(cellValue)) {
return '--'
}
return (([true, 'true', '', '1',1].includes(cellValue)) ? '' : '');
}
},
NORMAL: {
// 将字符串中大写字母转为下划线加小写
convertToSnakeCase : (str: string) => str.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`),
// 数值标准化,可指定保留几位小数,每隔3位打逗号
formatterStdNumberByString : (number: any, isFixed = false, fixNumber: number | undefined) => {
let num:number = Number(number);
if (isFixed) {
num = Number(number).toFixed(fixNumber);
}
if (isNaN(num)) {
return '--';
}
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
},
};
```

## 参数说明
| 属性 | 说明 | 类型 | 默认值 |
| ----- | -------------------------- | --------------------------------------- |------------------ |
| TABLE | 收纳常见的表格格式化 | `Function` |-|
| TABLE.textValue | 将空白内容格式化为'--' | `Function` |-|
| TABLE.stdNumber | 数字格式化,小数点前每3位打一个逗号 | `Function` |-|
| TABLE.stdNumberFix2 | 小数点前每3位打一个逗号,严格保留两位小数 | `Function` |-|
| TABLE.bool2string | 布尔量转是否 | `Function` |-|
| NORMAL | 常见数据类型格式化 | `Function`|-|
| NORMAL.convertToSnakeCase | 字符串中大写字母转为下划线加小写 | `Function`|-|
| NORMAL.formatterStdNumberByString | 数值标准化,可指定保留几位小数,每隔3位打逗号 | `Function`|-|
4 changes: 2 additions & 2 deletions docs/utils/validate.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ export const validate = {
## 参数说明
| 属性 | 说明 | 类型 | 默认值 |
| ----- | -------------------------- | --------------------------------------- |------------------ |
| REG | 正则表达式 | `RegExp` ||
| VALIDATOR | 常见校验函数 | `Function`||
| REG | 正则表达式 | `RegExp` |-|
| VALIDATOR | 常见校验函数 | `Function`|-|
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fesjs/traction-widget",
"version": "1.8.11",
"version": "1.9.0",
"description": "集合大型中台项目使用到的通用组件和工具函数",
"scripts": {
"docs:dev": "npm run build && node docs/.vitepress/scripts/generate-doc.js && vitepress dev docs",
Expand Down
36 changes: 27 additions & 9 deletions packages/traction-widget/components/Search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ const props = defineProps({
require: false,
default: true
},
// 是否自定义高级筛选统计数量函数
advanceCountFunc: {
type: Function,
require: false,
default: () => {}
},
// 高级筛选表单,仅用于统计填写数量
advanceForm: {
type: Object,
Expand All @@ -84,6 +90,12 @@ const props = defineProps({
require: false,
default: true
},
// 点击重置后是否做清空,默认会做清空,但有时会重置为默认值,所以提供跳过清空逻辑
isResetAllClear: {
type: Boolean,
require: false,
default: true
},
// 是否为letgo开发。letgo不支持FSpace嵌入slot
isLetgo: {
type: Boolean,
Expand All @@ -98,12 +110,16 @@ const prefixCls = getPrefixCls('search');
// 筛选条件数量的watch
const querySelectedCount = computed(() => {
return Object.values(props.advanceForm).filter((item) => {
if (item === 0) return true;
if (isBoolean(item)) return true;
if (Array.isArray(item) && item.length === 0) return false;
return !!item;
}).length;
if (props.advanceCountFunc.toString().trim() === '() => {}') {
return Object.values(props.advanceForm).filter((item) => {
if (item === 0) return true;
if (isBoolean(item)) return true;
if (Array.isArray(item) && item.length === 0) return false;
return !!item;
}).length;
} else {
return props.advanceCountFunc(props.advanceForm);
}
});
const handleSearch = () => {
Expand All @@ -124,9 +140,11 @@ const resetForm = (form) => {
};
const handleReset = () => {
resetForm(datasource.form);
if (datasource.advanceForm) {
resetForm(datasource.advanceForm);
if (props.isResetAllClear) {
resetForm(datasource.form);
if (datasource.advanceForm) {
resetForm(datasource.advanceForm);
}
}
emit('reset');
};
Expand Down
4 changes: 3 additions & 1 deletion packages/traction-widget/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BTagsPanel } from './TagsPanel';
import { BTableHeaderConfig } from './TableHeaderConfig';
import { BPageLoading } from './PageLoading';
import { BTagSelector } from './TagSelector';
import { getUrlParams, formatterEmptyValue, isIE, validate, dynamicFormOperate } from './utils';
import { getUrlParams, formatterEmptyValue, isIE, validate, dynamicFormOperate, format } from './utils';
import { BHorizontalLayout } from './HorizontalLayout';
import { BVerticalLayout } from './VerticalLayout';
import { BSearch } from './Search';
Expand Down Expand Up @@ -35,6 +35,7 @@ export {
getUrlParams,
formatterEmptyValue,
validate,
format,
dynamicFormOperate,
BTagsPanel,
BTableHeaderConfig,
Expand All @@ -54,6 +55,7 @@ export default {
getUrlParams,
formatterEmptyValue,
validate,
format,
dynamicFormOperate,
BTagsPanel,
BTableHeaderConfig,
Expand Down
57 changes: 57 additions & 0 deletions packages/traction-widget/components/utils/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export const format = {
// 表格格式化函数
TABLE: {
// 将空白格式化为'--'
textValue: ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0;
return cellValue || '--';
},
// 数字格式化函数,小数点前每3位打一个逗号
stdNumber: ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0;
if (isNaN(cellValue) || cellValue === null || cellValue === '') {
return '--';
}
const num = Number(cellValue);
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
},
// 数字格式化函数,小数点前每3位打一个逗号,严格保留两位小数
stdNumberFix2: ({ cellValue }: { cellValue: any }): any => {
if (cellValue === 0) return 0.00;
if (isNaN(cellValue) || cellValue === null || cellValue === '') {
return '--';
}
const num = Number(cellValue).toFixed(2);
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
},
// 布尔量格式化函数,转是否
bool2string: ({ cellValue }: { cellValue: any }): any => {
if (['', null, undefined].includes(cellValue)) {
return '--';
}
return (([true, 'true', '是', '1', 1].includes(cellValue)) ? '是' : '否');
}
},
NORMAL: {
// 将字符串中大写字母转为下划线加小写
convertToSnakeCase: (str: string) => str.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`),
// 数值标准化,可指定保留几位小数,每隔3位打逗号
formatterStdNumberByString: (number: any, isFixed = false, fixNumber: number | undefined) => {
let num: number = Number(number);
if (isFixed) {
num = Number(number).toFixed(fixNumber);
}
// eslint-disable-next-line no-restricted-globals
if (isNaN(num)) {
return '--';
}
const parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
}
};
1 change: 1 addition & 0 deletions packages/traction-widget/components/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './getUrlParams';
export * from './isIE';
export * from './forceDownload';
export * from './validate';
export * from './format';
export * from './dynamicFormOperate';
2 changes: 1 addition & 1 deletion packages/traction-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fesjs/traction-widget",
"version": "1.8.11",
"version": "1.9.0",
"description": "集合大型中台项目使用到的通用组件和工具函数",
"main": "dist/traction-widget.min.js",
"module": "es/components/index.js",
Expand Down

0 comments on commit 023f723

Please sign in to comment.