fantasy-ngzorro 1.3.32 → 1.3.34
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.
- package/bundles/fantasy-ngzorro.umd.js +279 -101
- package/bundles/fantasy-ngzorro.umd.js.map +1 -1
- package/bundles/fantasy-ngzorro.umd.min.js +2 -2
- package/bundles/fantasy-ngzorro.umd.min.js.map +1 -1
- package/esm2015/hd-filter/hd-filter.component.js +2 -2
- package/esm2015/hd-filter/hd-filter.service.js +6 -3
- package/esm2015/utils.js +192 -101
- package/esm5/hd-filter/hd-filter.component.js +2 -2
- package/esm5/hd-filter/hd-filter.service.js +4 -2
- package/esm5/utils.js +278 -101
- package/fantasy-ngzorro.metadata.json +1 -1
- package/fesm2015/fantasy-ngzorro.js +196 -102
- package/fesm2015/fantasy-ngzorro.js.map +1 -1
- package/fesm5/fantasy-ngzorro.js +279 -101
- package/fesm5/fantasy-ngzorro.js.map +1 -1
- package/hd-filter/hd-filter.service.d.ts +2 -1
- package/package.json +1 -1
- package/utils.d.ts +29 -5
|
@@ -965,7 +965,7 @@ class HdFilterComponent {
|
|
|
965
965
|
HdFilterComponent.decorators = [
|
|
966
966
|
{ type: Component, args: [{
|
|
967
967
|
selector: 'hd-filter',
|
|
968
|
-
template: "<form nz-form [formGroup]=\"validateFilterForm\" class=\"ant-advanced-search-form hd-filter-container\">\n <!-- \u6574\u4F53\u7ED3\u6784 -->\n <div nz-row [nzGutter]=\"24\">\n <!-- \u5BF9\u7EC4\u4EF6\u5217\u8868\u5FAA\u73AF\u5904\u7406 -->\n <ng-container *ngFor=\"let filter of filterList\">\n <div nz-col [nzSpan]=\"6\" [hidden]=\"!filter.show\">\n <nz-form-item nzFlex>\n <nz-form-label class=\"hd-filter-label\"><span class=\"hd-red\" *ngIf=\"filter.require\">*</span>{{filter.label}}\n </nz-form-label>\n <nz-form-control class=\"hd-filter-control\">\n <ng-container [ngSwitch]=\"filter.type\">\n <!-- \u8FD9\u91CC\u6570\u5B57\u5BF9\u5E94\u679A\u4E3E\u7C7B\u578B\uFF0C\u53EF\u5728hd-filter.service.ts\u6587\u4EF6\u4E2D\u67E5\u770B\u5BF9\u5E94\u5173\u7CFB -->\n <ng-container *ngSwitchCase=\"0\">\n <nz-input-group [nzSuffix]=\"inputCleanTemplate\">\n <input nz-input [placeholder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u8F93\u5165' + filter.label\"\n
|
|
968
|
+
template: "<form nz-form [formGroup]=\"validateFilterForm\" class=\"ant-advanced-search-form hd-filter-container\">\n <!-- \u6574\u4F53\u7ED3\u6784 -->\n <div nz-row [nzGutter]=\"24\">\n <!-- \u5BF9\u7EC4\u4EF6\u5217\u8868\u5FAA\u73AF\u5904\u7406 -->\n <ng-container *ngFor=\"let filter of filterList\">\n <div nz-col [nzSpan]=\"6\" [hidden]=\"!filter.show\">\n <nz-form-item nzFlex>\n <nz-form-label class=\"hd-filter-label\"><span class=\"hd-red\" *ngIf=\"filter.require\">*</span>{{ filter.label }}\n </nz-form-label>\n <nz-form-control class=\"hd-filter-control\">\n <ng-container [ngSwitch]=\"filter.type\">\n <!-- \u8FD9\u91CC\u6570\u5B57\u5BF9\u5E94\u679A\u4E3E\u7C7B\u578B\uFF0C\u53EF\u5728hd-filter.service.ts\u6587\u4EF6\u4E2D\u67E5\u770B\u5BF9\u5E94\u5173\u7CFB -->\n <ng-container *ngSwitchCase=\"0\">\n <nz-input-group [nzSuffix]=\"inputCleanTemplate\">\n <input nz-input [placeholder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u8F93\u5165' + filter.label\"\n [formControlName]=\"filter.name\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\"/>\n </nz-input-group>\n <ng-template #inputCleanTemplate><i nz-icon nz-tooltip class=\"ant-input-clear-icon\" nzTheme=\"fill\"\n nzType=\"close-circle\"\n *ngIf=\"validateFilterForm.get(filter.name).value\"\n (click)=\"inputClean(filter)\"></i></ng-template>\n </ng-container>\n <ng-container *ngSwitchCase=\"1\">\n <nz-select\n [nzShowSearch]=\"filter.selectOption.hdShowSearch != null ? filter.selectOption.hdShowSearch : true\"\n [nzAllowClear]=\"filter.selectOption.hdAllowClear != null ? filter.selectOption.hdAllowClear : true\"\n [nzServerSearch]=\"filter.selectOption.hdServerSearch || false\"\n [nzDropdownMatchSelectWidth]=\"filter.selectOption.hdDropdownMatchSelectWidth ? filter.selectOption.hdDropdownMatchSelectWidth : false\"\n (nzOnSearch)=\"triggerEvent(filter.onSearchEvent || null, $event, filter.selectOption)\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n [formControlName]=\"filter.name\" (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\">\n <nz-option *ngFor=\"let selectItem of filter.selectOption.selectList\"\n [nzValue]=\"selectItem[filter.selectOption.value]\" [nzLabel]=\"filter.selectOption.showLabelAndValue ? '['+ selectItem[filter.selectOption.value] +']' +\n selectItem[filter.selectOption.label] : selectItem[filter.selectOption.label]\"></nz-option>\n </nz-select>\n </ng-container>\n <ng-container *ngSwitchCase=\"2\">\n <nz-date-picker *ngIf=\"filter.showTime\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n [formControlName]=\"filter.name\" [nzDisabledDate]=\"filter.hdDisabledDate\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\" nzShowTime\n nzFormat=\"yyyy-MM-dd HH:mm:ss\">\n </nz-date-picker>\n <nz-date-picker *ngIf=\"!filter.showTime\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n [formControlName]=\"filter.name\" [nzDisabledDate]=\"filter.hdDisabledDate\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\">\n </nz-date-picker>\n </ng-container>\n <ng-container *ngSwitchCase=\"3\">\n <nz-range-picker [nzPlaceHolder]=\"['\u5F00\u59CB\u65E5\u671F','\u7ED3\u675F\u65E5\u671F']\" [formControlName]=\"filter.name\">\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\"\n </nz-range-picker>\n </ng-container>\n <!-- \u591A\u9879\u9009\u62E9\u5668 -->\n <ng-container *ngSwitchCase=\"4\">\n <nz-select\n [nzDropdownMatchSelectWidth]=\"filter.selectOption.hdDropdownMatchSelectWidth ? filter.selectOption.hdDropdownMatchSelectWidth : false\"\n nzMode=\"multiple\"\n [nzShowSearch]=\"filter.selectOption.hdShowSearch != null ? filter.selectOption.hdShowSearch : true\"\n [nzAllowClear]=\"filter.selectOption.hdAllowClear != null ? filter.selectOption.hdAllowClear : true\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n [formControlName]=\"filter.name\" [nzServerSearch]=\"filter.selectOption.hdServerSearch || false\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\"\n (nzOnSearch)=\"triggerEvent(filter.onSearchEvent || null, $event)\">\n <nz-option *ngFor=\"let selectItem of filter.selectOption.selectList\"\n [nzValue]=\"selectItem[filter.selectOption.value]\" [nzLabel]=\"filter.selectOption.showLabelAndValue ? '['+ selectItem[filter.selectOption.value] +']' +\n selectItem[filter.selectOption.label] : selectItem[filter.selectOption.label]\"></nz-option>\n </nz-select>\n </ng-container>\n <ng-container *ngSwitchCase=\"5\">\n <nz-cascader [nzOptions]=\"filter.cascaderOption.options\" [formControlName]=\"filter.name\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\">\n </nz-cascader>\n </ng-container>\n <ng-container *ngSwitchCase=\"6\">\n <nz-month-picker [formControlName]=\"filter.name\"\n [nzPlaceHolder]=\"filter.placeholder ? filter.placeholder : '\u8BF7\u9009\u62E9' + filter.label\"\n (ngModelChange)=\"triggerEvent(filter.onChangeEvent || null, $event)\"></nz-month-picker>\n </ng-container>\n </ng-container>\n </nz-form-control>\n </nz-form-item>\n </div>\n </ng-container>\n\n <div class=\"hd-filter-btn\" nz-col [nzSpan]=\"6\" [nzOffset]=\"computeOffset()\">\n <a *ngIf=\"filterList.length > 7\" class=\"hd-filter-more\" (click)=\"showMore()\">\n {{ isShowMore ? '\u5C55\u5F00' : '\u6536\u8D77' }}\n <i nz-icon [nzType]=\"isShowMore ? 'down' : 'up'\"></i>\n </a>\n <hd-button type=\"primary\" (click)=\"submitForm()\">\u67E5\u8BE2</hd-button>\n <hd-button type=\"reset\" (click)=\"resetForm()\">\u91CD\u7F6E</hd-button>\n </div>\n </div>\n</form>\n",
|
|
969
969
|
styles: ["::ng-deep .common-btn-group>a{font-size:12px;font-weight:400;color:#12a34f!important;white-space:nowrap}::ng-deep .common-btn-group .common-danger-btn:hover{color:#f05b24!important}::ng-deep .common-btn-group>a:hover{color:#20bd62!important}::ng-deep .common-btn-group>a:not(:last-child)::after{content:'';margin:0 2px}::ng-deep .common-billNumber>a{color:#3b77e3}button{box-shadow:unset;text-shadow:unset}::ng-deep .ant-form-item-label>label{color:#4b504e}::ng-deep .ant-input-number-input{height:28px}::ng-deep .ant-input-number{height:28px}textarea.ant-input{height:auto;min-height:28px}::ng-deep .ant-select-selection--multiple{min-height:28px}::ng-deep .ant-select-selection__rendered>ul>li{height:22px!important;margin-top:3px!important;line-height:22px!important}::ng-deep .ant-advanced-search-form .ant-form-item{margin-bottom:0!important}::ng-deep .ant-select-selection--single{height:28px!important}::ng-deep .ant-input{height:28px}::ng-deep .ant-input[disabled]:hover{border-color:#d9d9d9!important}::ng-deep .ant-select-selection__rendered{line-height:28px!important}::ng-deep .ant-calendar-range-picker-input{text-align:left!important}::ng-deep .ant-calendar-picker{width:100%!important}::ng-deep .ant-row{margin-right:0!important;margin-left:0!important}::ng-deep .ant-col-6{padding-left:12px;padding-right:12px}::ng-deep .ant-col-12{padding-left:12px;padding-right:12px}::ng-deep .ant-col-18{padding-left:12px;padding-right:12px}::ng-deep .ant-col-24{padding-left:12px;padding-right:12px}::ng-deep .ant-alert-info{background-color:#f5f8f6;border:1px solid #cfe3d4}:host ::ng-deep th{background:#f5f8f6!important;font-weight:700!important;white-space:nowrap;font-size:12px;font-family:PingFangSC-Medium,PingFang SC;color:#2a3634;padding:8px!important;box-sizing:border-box}:host ::ng-deep td{font-weight:400;font-style:normal;font-size:12px;color:#2a3634;text-align:left;white-space:nowrap;padding:8px!important;box-sizing:border-box}::ng-deep .ant-pagination-options{display:inline-flex;align-items:center}::ng-deep .ant-time-picker{width:100%}.ant-input-number-disabled,.ant-input[disabled],.ant-select-disabled{color:#4b504e}.hd-filter-container{padding:20px 23px;background:#fff;box-shadow:0 0 12px 0 rgba(93,114,103,.08);border-radius:4px;margin-bottom:8px!important;font-size:12px}.hd-filter-container .ant-row{margin-right:0!important;margin-left:0!important}.hd-filter-container .ant-col-6{padding-left:0!important;padding-right:0!important}.hd-filter-container .hd-filter-label{width:108px;word-break:break-all}.hd-filter-container .hd-filter-control{width:calc(100% - 108px)}.hd-filter-container ::ng-deep .ant-calendar-picker{width:100%}.hd-filter-container .hd-filter-more{color:#12a34f}.hd-filter-container .hd-filter-btn{height:40px;display:inline-flex;align-items:center;justify-content:flex-end}.hd-filter-container hd-button{margin-left:12px}.hd-filter-container ::ng-deep .ant-advanced-search-form .ant-form-item{margin-bottom:0!important}.hd-filter-container ::ng-deep .ant-select-selection--single{height:28px!important}.hd-filter-container ::ng-deep .ant-input{height:28px!important}.hd-filter-container ::ng-deep .ant-calendar-range-picker-input{text-align:left!important}.hd-filter-container .ant-input-number{width:100%}.hd-filter-container .hd-red{color:red}"]
|
|
970
970
|
}] }
|
|
971
971
|
];
|
|
@@ -5054,7 +5054,8 @@ const FilterListType = {
|
|
|
5054
5054
|
Date: 2,
|
|
5055
5055
|
DateRange: 3,
|
|
5056
5056
|
MultipleSelect: 4,
|
|
5057
|
-
Cascader: 5
|
|
5057
|
+
Cascader: 5,
|
|
5058
|
+
Month: 6 // 月份选择
|
|
5058
5059
|
,
|
|
5059
5060
|
};
|
|
5060
5061
|
FilterListType[FilterListType.Input] = 'Input';
|
|
@@ -5063,8 +5064,10 @@ FilterListType[FilterListType.Date] = 'Date';
|
|
|
5063
5064
|
FilterListType[FilterListType.DateRange] = 'DateRange';
|
|
5064
5065
|
FilterListType[FilterListType.MultipleSelect] = 'MultipleSelect';
|
|
5065
5066
|
FilterListType[FilterListType.Cascader] = 'Cascader';
|
|
5067
|
+
FilterListType[FilterListType.Month] = 'Month';
|
|
5066
5068
|
class HdFilterService {
|
|
5067
|
-
constructor() {
|
|
5069
|
+
constructor() {
|
|
5070
|
+
}
|
|
5068
5071
|
}
|
|
5069
5072
|
HdFilterService.decorators = [
|
|
5070
5073
|
{ type: Injectable, args: [{
|
|
@@ -5219,75 +5222,97 @@ const StaticConst = {
|
|
|
5219
5222
|
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
5220
5223
|
*/
|
|
5221
5224
|
// 工具类
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
for (let i = 0; i < length; i++) {
|
|
5237
|
-
if (returnData[i].name === name) {
|
|
5238
|
-
returnData[i].selectOption.selectList = options;
|
|
5225
|
+
/** @type {?} */
|
|
5226
|
+
const Utils = {
|
|
5227
|
+
/**
|
|
5228
|
+
* 填充select控件选项
|
|
5229
|
+
* @param {?} formList 入参数组 Array<any>
|
|
5230
|
+
* @param {?} name 需要填充options的属性名称
|
|
5231
|
+
* @param {?} options 选项列表
|
|
5232
|
+
* @return {?}
|
|
5233
|
+
*/
|
|
5234
|
+
fillSelectOption(formList, name, options) {
|
|
5235
|
+
/** @type {?} */
|
|
5236
|
+
const returnData = formList;
|
|
5237
|
+
if (!returnData || !returnData.length) {
|
|
5238
|
+
return returnData;
|
|
5239
5239
|
}
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
*/
|
|
5247
|
-
function (list, obj) {
|
|
5248
|
-
/** @type {?} */
|
|
5249
|
-
let returnData = [];
|
|
5250
|
-
if (!list || !list.length) {
|
|
5251
|
-
return returnData;
|
|
5252
|
-
}
|
|
5253
|
-
/** @type {?} */
|
|
5254
|
-
const length = list.length;
|
|
5255
|
-
for (let i = 0; i < length; i++) {
|
|
5256
|
-
if (obj[list[i].name]) {
|
|
5257
|
-
list[i].value = obj[list[i].name];
|
|
5240
|
+
/** @type {?} */
|
|
5241
|
+
const length = formList.length;
|
|
5242
|
+
for (let i = 0; i < length; i++) {
|
|
5243
|
+
if (returnData[i].name === name) {
|
|
5244
|
+
returnData[i].selectOption.selectList = options;
|
|
5245
|
+
}
|
|
5258
5246
|
}
|
|
5259
|
-
}
|
|
5260
|
-
return list;
|
|
5261
|
-
}, ɵ2 = /**
|
|
5262
|
-
* @param {?} list
|
|
5263
|
-
* @param {?=} option
|
|
5264
|
-
* @return {?}
|
|
5265
|
-
*/
|
|
5266
|
-
function (list, option) {
|
|
5267
|
-
/** @type {?} */
|
|
5268
|
-
let returnData = [];
|
|
5269
|
-
if (!list || !list.length) {
|
|
5270
5247
|
return returnData;
|
|
5271
|
-
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5248
|
+
},
|
|
5249
|
+
/**
|
|
5250
|
+
* 填充FormItem数组:针对入参list的每一个FormItem,判断obj中是否有对应的name字段,如果有,则填充value。
|
|
5251
|
+
* @param {?} list 入参数组 Array<FormItem>
|
|
5252
|
+
* @param {?} obj 需要填充到list的属性
|
|
5253
|
+
* @return {?}
|
|
5254
|
+
*/
|
|
5255
|
+
fillArrayFormItem(list, obj) {
|
|
5256
|
+
/** @type {?} */
|
|
5257
|
+
const returnData = [];
|
|
5258
|
+
if (!list || !list.length) {
|
|
5259
|
+
return returnData;
|
|
5260
|
+
}
|
|
5261
|
+
/** @type {?} */
|
|
5262
|
+
const length = list.length;
|
|
5263
|
+
for (let i = 0; i < length; i++) {
|
|
5264
|
+
if (obj[list[i].name]) {
|
|
5265
|
+
list[i].value = obj[list[i].name];
|
|
5266
|
+
}
|
|
5267
|
+
}
|
|
5268
|
+
return list;
|
|
5269
|
+
},
|
|
5270
|
+
/**
|
|
5271
|
+
* 数组转换成选择器的选项数组
|
|
5272
|
+
* @param {?} list 入参数组 字符串数组或对象数组
|
|
5273
|
+
* @param {?=} option 转换选项
|
|
5274
|
+
* 注:list为字符串数组,option不需要传,按照标准的label、value转换
|
|
5275
|
+
* @return {?}
|
|
5276
|
+
*/
|
|
5277
|
+
arrayToSelectOptionList(list, option) {
|
|
5278
|
+
/** @type {?} */
|
|
5279
|
+
const returnData = [];
|
|
5280
|
+
if (!list || !list.length) {
|
|
5281
|
+
return returnData;
|
|
5282
|
+
}
|
|
5283
|
+
if (option) {
|
|
5284
|
+
if (option.labelTip && option.valueTip) {
|
|
5285
|
+
list.forEach((/**
|
|
5286
|
+
* @param {?} item
|
|
5287
|
+
* @return {?}
|
|
5288
|
+
*/
|
|
5289
|
+
(item) => {
|
|
5290
|
+
/** @type {?} */
|
|
5291
|
+
const returnItem = item;
|
|
5292
|
+
returnItem.label = item[option.label];
|
|
5293
|
+
returnItem.value = item[option.value];
|
|
5294
|
+
if (option.valueTip) {
|
|
5295
|
+
returnItem[option.valueTip] = item[option.value];
|
|
5296
|
+
}
|
|
5297
|
+
if (option.labelTip) {
|
|
5298
|
+
returnItem[option.labelTip] = item[option.label];
|
|
5299
|
+
}
|
|
5300
|
+
returnData.push(returnItem);
|
|
5301
|
+
}));
|
|
5302
|
+
}
|
|
5303
|
+
else {
|
|
5304
|
+
list.forEach((/**
|
|
5305
|
+
* @param {?} item
|
|
5306
|
+
* @return {?}
|
|
5307
|
+
*/
|
|
5308
|
+
(item) => {
|
|
5309
|
+
/** @type {?} */
|
|
5310
|
+
const returnItem = item;
|
|
5311
|
+
returnItem.label = item[option.label];
|
|
5312
|
+
returnItem.value = item[option.value];
|
|
5313
|
+
returnData.push(returnItem);
|
|
5314
|
+
}));
|
|
5315
|
+
}
|
|
5291
5316
|
}
|
|
5292
5317
|
else {
|
|
5293
5318
|
list.forEach((/**
|
|
@@ -5296,50 +5321,119 @@ function (list, option) {
|
|
|
5296
5321
|
*/
|
|
5297
5322
|
(item) => {
|
|
5298
5323
|
/** @type {?} */
|
|
5299
|
-
|
|
5300
|
-
returnItem.label = item
|
|
5301
|
-
returnItem.value = item
|
|
5324
|
+
const returnItem = {};
|
|
5325
|
+
returnItem.label = item;
|
|
5326
|
+
returnItem.value = item;
|
|
5302
5327
|
returnData.push(returnItem);
|
|
5303
5328
|
}));
|
|
5304
5329
|
}
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5330
|
+
return returnData;
|
|
5331
|
+
},
|
|
5332
|
+
/**
|
|
5333
|
+
* 求和
|
|
5334
|
+
* @param {?} nums 数组
|
|
5335
|
+
* @param {?=} precision 精度
|
|
5336
|
+
* @return {?}
|
|
5337
|
+
*/
|
|
5338
|
+
add(nums, precision = 2) {
|
|
5339
|
+
if (!Array.isArray(nums)) {
|
|
5340
|
+
throw new Error('参数必须是数组');
|
|
5341
|
+
}
|
|
5342
|
+
if (nums.some((/**
|
|
5343
|
+
* @param {?} num
|
|
5309
5344
|
* @return {?}
|
|
5310
5345
|
*/
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
}
|
|
5321
|
-
/** @type {?} */
|
|
5322
|
-
const Utils = {
|
|
5346
|
+
num => typeof num !== 'number'))) {
|
|
5347
|
+
throw new Error('数组元素必须是数字');
|
|
5348
|
+
}
|
|
5349
|
+
/** @type {?} */
|
|
5350
|
+
let result = 0;
|
|
5351
|
+
for (const num of nums) {
|
|
5352
|
+
result += num;
|
|
5353
|
+
}
|
|
5354
|
+
return round(result, precision);
|
|
5355
|
+
},
|
|
5323
5356
|
/**
|
|
5324
|
-
*
|
|
5325
|
-
* @param
|
|
5326
|
-
* @param
|
|
5327
|
-
* @
|
|
5357
|
+
* 减法
|
|
5358
|
+
* @param {?} nums 数组
|
|
5359
|
+
* @param {?=} precision 精度
|
|
5360
|
+
* @return {?}
|
|
5328
5361
|
*/
|
|
5329
|
-
|
|
5362
|
+
subtract(nums, precision = 2) {
|
|
5363
|
+
if (!Array.isArray(nums)) {
|
|
5364
|
+
throw new Error('参数必须是数组');
|
|
5365
|
+
}
|
|
5366
|
+
if (nums.some((/**
|
|
5367
|
+
* @param {?} num
|
|
5368
|
+
* @return {?}
|
|
5369
|
+
*/
|
|
5370
|
+
num => typeof num !== 'number'))) {
|
|
5371
|
+
throw new Error('数组元素必须是数字');
|
|
5372
|
+
}
|
|
5373
|
+
if (nums.length < 2) {
|
|
5374
|
+
throw new Error('减法入参数量至少要2个!');
|
|
5375
|
+
}
|
|
5376
|
+
/** @type {?} */
|
|
5377
|
+
let result = nums.shift();
|
|
5378
|
+
for (const num of nums) {
|
|
5379
|
+
result -= num;
|
|
5380
|
+
}
|
|
5381
|
+
return round(result, precision);
|
|
5382
|
+
},
|
|
5330
5383
|
/**
|
|
5331
|
-
*
|
|
5332
|
-
* @param
|
|
5333
|
-
* @param
|
|
5384
|
+
* 乘法
|
|
5385
|
+
* @param {?} nums 数组
|
|
5386
|
+
* @param {?=} precision 精度
|
|
5387
|
+
* @return {?}
|
|
5334
5388
|
*/
|
|
5335
|
-
|
|
5389
|
+
multiply(nums, precision = 2) {
|
|
5390
|
+
if (!Array.isArray(nums)) {
|
|
5391
|
+
throw new Error('参数必须是数组');
|
|
5392
|
+
}
|
|
5393
|
+
if (nums.some((/**
|
|
5394
|
+
* @param {?} num
|
|
5395
|
+
* @return {?}
|
|
5396
|
+
*/
|
|
5397
|
+
num => typeof num !== 'number'))) {
|
|
5398
|
+
throw new Error('数组元素必须是数字');
|
|
5399
|
+
}
|
|
5400
|
+
/** @type {?} */
|
|
5401
|
+
let result = 1;
|
|
5402
|
+
for (const num of nums) {
|
|
5403
|
+
result = result * num;
|
|
5404
|
+
}
|
|
5405
|
+
return round(result, precision);
|
|
5406
|
+
},
|
|
5336
5407
|
/**
|
|
5337
|
-
*
|
|
5338
|
-
* @param
|
|
5339
|
-
* @param
|
|
5340
|
-
*
|
|
5408
|
+
* 除法
|
|
5409
|
+
* @param {?} nums 数组
|
|
5410
|
+
* @param {?=} precision 精度
|
|
5411
|
+
* @return {?}
|
|
5341
5412
|
*/
|
|
5342
|
-
|
|
5413
|
+
divide(nums, precision = 2) {
|
|
5414
|
+
if (!Array.isArray(nums)) {
|
|
5415
|
+
throw new Error('参数必须是数组');
|
|
5416
|
+
}
|
|
5417
|
+
if (nums.some((/**
|
|
5418
|
+
* @param {?} num
|
|
5419
|
+
* @return {?}
|
|
5420
|
+
*/
|
|
5421
|
+
num => typeof num !== 'number'))) {
|
|
5422
|
+
throw new Error('数组元素必须是数字');
|
|
5423
|
+
}
|
|
5424
|
+
if (nums.length < 2) {
|
|
5425
|
+
throw new Error('除法入参数量至少要2个!');
|
|
5426
|
+
}
|
|
5427
|
+
/** @type {?} */
|
|
5428
|
+
let result = nums.shift();
|
|
5429
|
+
for (const num of nums) {
|
|
5430
|
+
if (num === 0) {
|
|
5431
|
+
throw new Error('除数不能为0!');
|
|
5432
|
+
}
|
|
5433
|
+
result = result / num;
|
|
5434
|
+
}
|
|
5435
|
+
return round(result, precision);
|
|
5436
|
+
}
|
|
5343
5437
|
};
|
|
5344
5438
|
|
|
5345
5439
|
/**
|