swordpass-ui 1.0.0
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/LICENSE +21 -0
- package/README.md +37 -0
- package/lib/demo.html +10 -0
- package/lib/img/icon_found_img.c785c1b7.png +0 -0
- package/lib/sword-vue-ui.common.js +61402 -0
- package/lib/sword-vue-ui.css +1 -0
- package/lib/sword-vue-ui.umd.js +61412 -0
- package/lib/sword-vue-ui.umd.min.js +6 -0
- package/package.json +109 -0
- package/packages/AddQueryStrategy/index.js +7 -0
- package/packages/AddQueryStrategy/src/main.vue +236 -0
- package/packages/Autocomplete/index.js +7 -0
- package/packages/Autocomplete/src/main.vue +192 -0
- package/packages/Button/index.js +7 -0
- package/packages/Button/src/main.vue +90 -0
- package/packages/Cascader/index.js +7 -0
- package/packages/Cascader/src/main.vue +210 -0
- package/packages/Chart/index.js +7 -0
- package/packages/Chart/src/Chart.vue +831 -0
- package/packages/Checkbox/index.js +7 -0
- package/packages/Checkbox/src/main.vue +200 -0
- package/packages/Collapse/index.js +7 -0
- package/packages/Collapse/src/ClCollapse.vue +67 -0
- package/packages/Collapse/src/ClCollapseItem.vue +21 -0
- package/packages/CollapseItem/index.js +7 -0
- package/packages/CustomDialog/index.js +7 -0
- package/packages/CustomDialog/src/customDialog.js +99 -0
- package/packages/CustomDialog/src/main.vue +1944 -0
- package/packages/DataView/index.js +7 -0
- package/packages/DataView/src/DataView.vue +45 -0
- package/packages/Date/index.js +7 -0
- package/packages/Date/src/main.vue +180 -0
- package/packages/DatePicker/index.js +7 -0
- package/packages/DatePicker/src/main.vue +155 -0
- package/packages/Demension/index.js +7 -0
- package/packages/Demension/src/main.vue +379 -0
- package/packages/Dialog/index.js +7 -0
- package/packages/Dialog/src/main.vue +160 -0
- package/packages/Dictionary/index.js +7 -0
- package/packages/Dictionary/src/main.vue +204 -0
- package/packages/DimensionSelector/index.js +7 -0
- package/packages/DimensionSelector/src/main.vue +359 -0
- package/packages/DimensionSelectorInput/index.js +7 -0
- package/packages/DimensionSelectorInput/src/main.vue +79 -0
- package/packages/Divider/index.js +7 -0
- package/packages/Divider/src/main.vue +38 -0
- package/packages/Duration/index.js +7 -0
- package/packages/Duration/src/main.vue +172 -0
- package/packages/Editor/index.js +7 -0
- package/packages/Editor/src/main.vue +280 -0
- package/packages/Explain/index.js +7 -0
- package/packages/Explain/src/main.vue +55 -0
- package/packages/FieldTail/index.js +7 -0
- package/packages/FieldTail/src/main.vue +163 -0
- package/packages/File/index.js +7 -0
- package/packages/File/src/FileCard.vue +169 -0
- package/packages/File/src/FileList.vue +180 -0
- package/packages/File/src/FileTable.vue +223 -0
- package/packages/File/src/main.vue +467 -0
- package/packages/FileUpload/index.js +7 -0
- package/packages/FileUpload/src/main.vue +222 -0
- package/packages/FlowChart/index.js +7 -0
- package/packages/FlowChart/src/main.vue +386 -0
- package/packages/FormItem/index.js +7 -0
- package/packages/FormItem/src/main.vue +167 -0
- package/packages/Global/index.js +12 -0
- package/packages/Global/src/GlobalQuery.vue +200 -0
- package/packages/Global/src/GlobalValidate.vue +69 -0
- package/packages/Icon/index.js +7 -0
- package/packages/Icon/src/icons/ad.js +14 -0
- package/packages/Icon/src/icons/address-book.js +14 -0
- package/packages/Icon/src/icons/arrow.js +14 -0
- package/packages/Icon/src/icons/attachment.js +18 -0
- package/packages/Icon/src/icons/balance.js +14 -0
- package/packages/Icon/src/icons/ban.js +14 -0
- package/packages/Icon/src/icons/bell.js +14 -0
- package/packages/Icon/src/icons/block.js +26 -0
- package/packages/Icon/src/icons/book.js +14 -0
- package/packages/Icon/src/icons/bookmark.js +14 -0
- package/packages/Icon/src/icons/bug.js +22 -0
- package/packages/Icon/src/icons/bullhorn.js +14 -0
- package/packages/Icon/src/icons/calc.js +14 -0
- package/packages/Icon/src/icons/checkbox.js +14 -0
- package/packages/Icon/src/icons/circle.js +14 -0
- package/packages/Icon/src/icons/close.js +14 -0
- package/packages/Icon/src/icons/cloud-sun.js +14 -0
- package/packages/Icon/src/icons/coffee.js +14 -0
- package/packages/Icon/src/icons/component.js +14 -0
- package/packages/Icon/src/icons/compress.js +14 -0
- package/packages/Icon/src/icons/copyright.js +14 -0
- package/packages/Icon/src/icons/dialog.js +14 -0
- package/packages/Icon/src/icons/download.js +14 -0
- package/packages/Icon/src/icons/duration.js +14 -0
- package/packages/Icon/src/icons/excel.js +18 -0
- package/packages/Icon/src/icons/expand.js +14 -0
- package/packages/Icon/src/icons/export.js +21 -0
- package/packages/Icon/src/icons/eye-slash.js +14 -0
- package/packages/Icon/src/icons/eye.js +14 -0
- package/packages/Icon/src/icons/file.js +18 -0
- package/packages/Icon/src/icons/form.js +14 -0
- package/packages/Icon/src/icons/ganged.js +14 -0
- package/packages/Icon/src/icons/gaode.js +27 -0
- package/packages/Icon/src/icons/gift.js +14 -0
- package/packages/Icon/src/icons/home.js +14 -0
- package/packages/Icon/src/icons/image.js +14 -0
- package/packages/Icon/src/icons/import.js +18 -0
- package/packages/Icon/src/icons/index.js +67 -0
- package/packages/Icon/src/icons/info.js +21 -0
- package/packages/Icon/src/icons/laptop.js +14 -0
- package/packages/Icon/src/icons/line.js +34 -0
- package/packages/Icon/src/icons/lock.js +14 -0
- package/packages/Icon/src/icons/map.js +18 -0
- package/packages/Icon/src/icons/more.js +19 -0
- package/packages/Icon/src/icons/move.js +14 -0
- package/packages/Icon/src/icons/org.js +18 -0
- package/packages/Icon/src/icons/palette.js +14 -0
- package/packages/Icon/src/icons/plan.js +17 -0
- package/packages/Icon/src/icons/ppt.js +18 -0
- package/packages/Icon/src/icons/question.js +18 -0
- package/packages/Icon/src/icons/radio.js +14 -0
- package/packages/Icon/src/icons/refresh.js +14 -0
- package/packages/Icon/src/icons/search.js +14 -0
- package/packages/Icon/src/icons/select.js +14 -0
- package/packages/Icon/src/icons/setting.js +18 -0
- package/packages/Icon/src/icons/simple-collapse.js +18 -0
- package/packages/Icon/src/icons/simple-expand.js +14 -0
- package/packages/Icon/src/icons/sort.js +22 -0
- package/packages/Icon/src/icons/sword.js +26 -0
- package/packages/Icon/src/icons/table.js +14 -0
- package/packages/Icon/src/icons/time.js +14 -0
- package/packages/Icon/src/icons/tree.js +14 -0
- package/packages/Icon/src/icons/typography.js +18 -0
- package/packages/Icon/src/icons/upload.js +18 -0
- package/packages/Icon/src/icons/user.js +14 -0
- package/packages/Icon/src/icons/users.js +30 -0
- package/packages/Icon/src/icons/video.js +14 -0
- package/packages/Icon/src/icons/word.js +18 -0
- package/packages/Icon/src/main.vue +432 -0
- package/packages/Image/index.js +7 -0
- package/packages/Image/src/main.vue +66 -0
- package/packages/Input/index.js +7 -0
- package/packages/Input/src/main.vue +552 -0
- package/packages/JobSelector/index.js +7 -0
- package/packages/JobSelector/src/main.vue +339 -0
- package/packages/JobSelectorInput/index.js +7 -0
- package/packages/JobSelectorInput/src/main.vue +87 -0
- package/packages/Map/index.js +7 -0
- package/packages/Map/src/Map.vue +427 -0
- package/packages/Milepost/index.js +7 -0
- package/packages/Milepost/src/main.vue +45 -0
- package/packages/OnlineForm/index.js +7 -0
- package/packages/OnlineForm/src/Form.vue +359 -0
- package/packages/OrgPostDialog/index.js +7 -0
- package/packages/OrgPostDialog/src/main.vue +244 -0
- package/packages/OrgSelector/index.js +7 -0
- package/packages/OrgSelector/src/main.vue +493 -0
- package/packages/OrgSelectorInput/index.js +7 -0
- package/packages/OrgSelectorInput/src/OrgSelectorInput.vue +216 -0
- package/packages/PostSelector/index.js +7 -0
- package/packages/PostSelector/src/main.vue +463 -0
- package/packages/PostSelectorInput/index.js +7 -0
- package/packages/PostSelectorInput/src/PostSelectorInput.vue +200 -0
- package/packages/Preview/index.js +7 -0
- package/packages/Preview/src/FillPage.vue +311 -0
- package/packages/Preview/src/FrameViewer.vue +135 -0
- package/packages/Preview/src/Loading.vue +126 -0
- package/packages/Preview/src/PdfViewer.vue +125 -0
- package/packages/Preview/src/TextViewer.vue +99 -0
- package/packages/Preview/src/main.vue +242 -0
- package/packages/Preview/src/watermark.js +124 -0
- package/packages/ProcessRecord/index.js +7 -0
- package/packages/ProcessRecord/src/main.vue +392 -0
- package/packages/Qrcode/index.js +7 -0
- package/packages/Qrcode/src/Qrcode.vue +105 -0
- package/packages/QuerySqlPreview/index.js +7 -0
- package/packages/QuerySqlPreview/src/QuerySqlPreview.vue +163 -0
- package/packages/Radio/index.js +7 -0
- package/packages/Radio/src/main.vue +172 -0
- package/packages/Rate/index.js +7 -0
- package/packages/Rate/src/main.vue +89 -0
- package/packages/ReadonlyInput/index.js +7 -0
- package/packages/ReadonlyInput/src/main.vue +92 -0
- package/packages/RelevantFlow/index.js +7 -0
- package/packages/RelevantFlow/src/main.vue +547 -0
- package/packages/RelevantFlow/src/relevantFlow.js +28 -0
- package/packages/RoleSelector/index.js +7 -0
- package/packages/RoleSelector/src/main.vue +358 -0
- package/packages/RoleSelectorInput/index.js +7 -0
- package/packages/RoleSelectorInput/src/main.vue +84 -0
- package/packages/SaveButton/index.js +7 -0
- package/packages/SaveButton/src/main.vue +73 -0
- package/packages/Select/index.js +7 -0
- package/packages/Select/src/main.vue +330 -0
- package/packages/SelectTree/index.js +7 -0
- package/packages/SelectTree/src/SelectTree.vue +352 -0
- package/packages/Selector/index.js +7 -0
- package/packages/Selector/src/main.vue +617 -0
- package/packages/SidebarDialog/index.js +7 -0
- package/packages/SidebarDialog/src/main.vue +156 -0
- package/packages/Slider/index.js +7 -0
- package/packages/Slider/src/main.vue +84 -0
- package/packages/Step/index.js +7 -0
- package/packages/StepLayout/index.js +7 -0
- package/packages/Steps/index.js +7 -0
- package/packages/Steps/src/Step.vue +122 -0
- package/packages/Steps/src/StepLayout.vue +35 -0
- package/packages/Steps/src/Steps.vue +65 -0
- package/packages/Subtable/index.js +33 -0
- package/packages/Subtable/src/SubDialog.vue +1926 -0
- package/packages/Subtable/src/SubExportDialog.vue +115 -0
- package/packages/Subtable/src/SubImportDialog.vue +316 -0
- package/packages/Subtable/src/SubPagination.vue +112 -0
- package/packages/Subtable/src/SubtableBackfill.vue +83 -0
- package/packages/Subtable/src/dialog.js +42 -0
- package/packages/Switch/index.js +7 -0
- package/packages/Switch/src/main.vue +83 -0
- package/packages/Table/index.js +7 -0
- package/packages/Table/src/CustomColumn.vue +351 -0
- package/packages/Table/src/Table.vue +979 -0
- package/packages/TableColumn/index.js +7 -0
- package/packages/TableColumn/src/main.vue +177 -0
- package/packages/TableSearchField/index.js +7 -0
- package/packages/TableSearchField/src/main.vue +334 -0
- package/packages/TableSearchPanel/index.js +7 -0
- package/packages/TableSearchPanel/src/main.vue +149 -0
- package/packages/Tabs/index.js +7 -0
- package/packages/Tabs/src/Tabs.vue +140 -0
- package/packages/Tag/index.js +7 -0
- package/packages/Tag/src/main.vue +264 -0
- package/packages/TemplateBatchUpdate/index.js +7 -0
- package/packages/TemplateBatchUpdate/src/TemplateBatchUpdateDialog.vue +174 -0
- package/packages/TemplateForm/index.js +7 -0
- package/packages/TemplateForm/src/main.vue +645 -0
- package/packages/TemplateFormDialog/index.js +7 -0
- package/packages/TemplateFormDialog/src/main.vue +61 -0
- package/packages/TemplateImportResult/index.js +7 -0
- package/packages/TemplateImportResult/src/main.vue +158 -0
- package/packages/TemplatePreview/index.js +19 -0
- package/packages/TemplatePreview/src/TemplatePreview.vue +169 -0
- package/packages/TemplatePreview/src/TemplatePreviewFile.vue +171 -0
- package/packages/TemplatePreview/src/TemplatePreviewImage.vue +83 -0
- package/packages/TemplateTaskCirculate/index.js +7 -0
- package/packages/TemplateTaskCirculate/src/main.vue +238 -0
- package/packages/Text/index.js +7 -0
- package/packages/Text/src/main.vue +57 -0
- package/packages/TimePicker/index.js +7 -0
- package/packages/TimePicker/src/main.vue +139 -0
- package/packages/TimeSelect/index.js +7 -0
- package/packages/TimeSelect/src/main.vue +96 -0
- package/packages/Tree/index.js +7 -0
- package/packages/Tree/src/main.vue +439 -0
- package/packages/TreeDialog/index.js +7 -0
- package/packages/TreeDialog/src/main.vue +293 -0
- package/packages/TreeListDialog/index.js +7 -0
- package/packages/TreeListDialog/src/main.vue +219 -0
- package/packages/Typography/index.js +8 -0
- package/packages/Typography/src/create-header.js +72 -0
- package/packages/UserDialog/index.js +7 -0
- package/packages/UserDialog/src/main.vue +250 -0
- package/packages/UserSelector/index.js +7 -0
- package/packages/UserSelector/src/main.vue +746 -0
- package/packages/UserSelectorInput/index.js +7 -0
- package/packages/UserSelectorInput/src/main.vue +319 -0
- package/packages/picture/index.js +7 -0
- package/packages/picture/src/main.vue +530 -0
- package/packages/plugins/Echarts.js +30 -0
- package/packages/plugins/Map.js +29 -0
- package/packages/plugins/Preview.js +49 -0
- package/packages/plugins/Qrcode.js +7 -0
- package/packages/plugins/XLSX.js +7 -0
- package/packages/plugins/wangeditor.js +19 -0
- package/src/assets/icon_found_img.png +0 -0
- package/src/assets/table-no-data.png +0 -0
- package/src/directive/badge.js +53 -0
- package/src/directive/copy.js +47 -0
- package/src/directive/ellipsis.js +6 -0
- package/src/directive/expandClick.js +23 -0
- package/src/directive/express.js +86 -0
- package/src/directive/form.js +122 -0
- package/src/directive/format.js +24 -0
- package/src/directive/formulas.js +708 -0
- package/src/directive/index.js +42 -0
- package/src/directive/permissionLine.js +59 -0
- package/src/directive/permissionLineLable.js +56 -0
- package/src/directive/permit.js +23 -0
- package/src/directive/popconfirm.js +86 -0
- package/src/directive/relatedQuery.js +61 -0
- package/src/directive/resize.js +18 -0
- package/src/directive/subSort.js +18 -0
- package/src/directive/tableDrag.js +25 -0
- package/src/directive/tooltip.js +37 -0
- package/src/filter/computerSize.js +23 -0
- package/src/filter/dateFormat.js +10 -0
- package/src/filter/index.js +10 -0
- package/src/index.js +267 -0
- package/src/locale/format.js +44 -0
- package/src/locale/index.js +48 -0
- package/src/locale/lang/en.js +59 -0
- package/src/locale/lang/zh-CN.js +58 -0
- package/src/locale/lang/zh-TW.js +57 -0
- package/src/locale/validate/dict.js +223 -0
- package/src/math.js +270 -0
- package/src/mixins/emitter.js +33 -0
- package/src/mixins/form.js +25 -0
- package/src/mixins/formDataUpdate.js +32 -0
- package/src/mixins/ganged.js +126 -0
- package/src/mixins/inputName.js +30 -0
- package/src/mixins/linkage.js +403 -0
- package/src/mixins/locale.js +9 -0
- package/src/mixins/mobileMode.js +27 -0
- package/src/mixins/onlineHottable.js +105 -0
- package/src/mixins/onlineSubtable.js +468 -0
- package/src/mixins/permission.js +84 -0
- package/src/mixins/querySqlPreview.js +747 -0
- package/src/mixins/regionValidator.js +70 -0
- package/src/mixins/script.js +35 -0
- package/src/mixins/templatePreview.js +3673 -0
- package/src/service.js +336 -0
- package/src/services/CustomQuery.js +199 -0
- package/src/services/SubPagination.js +132 -0
- package/src/styles/index.scss +7 -0
- package/src/styles/selector.scss +127 -0
- package/src/styles/variables.scss +71 -0
- package/src/util/base64.js +21 -0
- package/src/util/brower.js +15 -0
- package/src/util/clone.js +61 -0
- package/src/util/path.js +4 -0
- package/src/util/request.js +14 -0
- package/src/utils.js +1205 -0
- package/src/validate.js +184 -0
package/src/utils.js
ADDED
|
@@ -0,0 +1,1205 @@
|
|
|
1
|
+
var utils = {
|
|
2
|
+
// 判断是否移动端设备
|
|
3
|
+
isMobile() {
|
|
4
|
+
const info = navigator.userAgent
|
|
5
|
+
const agents = [
|
|
6
|
+
'Android',
|
|
7
|
+
'iPhone',
|
|
8
|
+
'SymbianOS',
|
|
9
|
+
'Windows Phone',
|
|
10
|
+
'iPod',
|
|
11
|
+
'iPad',
|
|
12
|
+
]
|
|
13
|
+
for (let i = 0; i < agents.length; i++) {
|
|
14
|
+
if (info.indexOf(agents[i]) >= 0) return true
|
|
15
|
+
}
|
|
16
|
+
return false
|
|
17
|
+
},
|
|
18
|
+
isEmpty: (value) => {
|
|
19
|
+
if (value === null || value === undefined || value === '') {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
return false
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*是否无效值
|
|
27
|
+
* @param {*} value
|
|
28
|
+
*/
|
|
29
|
+
isVoid: (value) => {
|
|
30
|
+
return value === undefined || value === null || value === ''
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*去除对象中的无效值
|
|
36
|
+
* @param {*} object
|
|
37
|
+
* @return {*}
|
|
38
|
+
*/
|
|
39
|
+
validObject: (object) => {
|
|
40
|
+
if (!object) {
|
|
41
|
+
return {}
|
|
42
|
+
}
|
|
43
|
+
const result = { ...object }
|
|
44
|
+
Object.keys(result).forEach((key) => {
|
|
45
|
+
const value = result[key]
|
|
46
|
+
if (utils.isVoid(value)) {
|
|
47
|
+
delete result[key]
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
return result
|
|
51
|
+
},
|
|
52
|
+
// 获取随机的名称
|
|
53
|
+
getName: () => {
|
|
54
|
+
return Math.random()
|
|
55
|
+
.toString(36)
|
|
56
|
+
.substr(2, 10)
|
|
57
|
+
},
|
|
58
|
+
// 获取控件是否可编辑
|
|
59
|
+
getWriteable: (permission) => {
|
|
60
|
+
if (permission === 'n' || permission === 'r') {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
return true
|
|
64
|
+
},
|
|
65
|
+
// 合并验证规则(如果rules和appendRules均为字符串格式,合并后仍为字符串格式;如果其中一个为Object格式,合并后为Object格式。)
|
|
66
|
+
mergeValidate: (rules, appendRules) => {
|
|
67
|
+
if (
|
|
68
|
+
!appendRules ||
|
|
69
|
+
(appendRules.constructor !== Object && appendRules.constructor !== String)
|
|
70
|
+
) {
|
|
71
|
+
return rules
|
|
72
|
+
}
|
|
73
|
+
let rulesTypeIsString = true,
|
|
74
|
+
appendTypeIsString = appendRules.constructor === String,
|
|
75
|
+
finalTypeIsString = true
|
|
76
|
+
if (rules === undefined || rules === null) {
|
|
77
|
+
rulesTypeIsString = appendTypeIsString
|
|
78
|
+
rules = appendTypeIsString ? '' : {}
|
|
79
|
+
} else if (rules.constructor === Object || rules.constructor === String) {
|
|
80
|
+
rulesTypeIsString = rules.constructor === String
|
|
81
|
+
} else {
|
|
82
|
+
throw `rules的类型为${typeof rules},只能为Object类型或String类型。`
|
|
83
|
+
}
|
|
84
|
+
finalTypeIsString = rulesTypeIsString && appendTypeIsString
|
|
85
|
+
// 仍然以String格式
|
|
86
|
+
if (finalTypeIsString) {
|
|
87
|
+
const ruleAry = utils.stringSplit(rules, '|')
|
|
88
|
+
const appendAry = utils.stringSplit(appendRules, '|')
|
|
89
|
+
let ruleObj = {},
|
|
90
|
+
appendObj = {}
|
|
91
|
+
ruleAry.forEach((r) => {
|
|
92
|
+
const k = utils.stringSplit(r, ':')[0]
|
|
93
|
+
ruleObj[k] = r
|
|
94
|
+
})
|
|
95
|
+
appendAry.forEach((a) => {
|
|
96
|
+
const k = utils.stringSplit(a, ':')[0]
|
|
97
|
+
appendObj[k] = a
|
|
98
|
+
})
|
|
99
|
+
// 如果旧规则中存在与追加规则中的同名规则,则使用追加规则覆盖旧规则。
|
|
100
|
+
const mergeObj = Object.assign(ruleObj, appendObj)
|
|
101
|
+
return Object.values(mergeObj).join('|')
|
|
102
|
+
}
|
|
103
|
+
// 转换为Object格式
|
|
104
|
+
else {
|
|
105
|
+
let ruleObj = {},
|
|
106
|
+
appendObj = {}
|
|
107
|
+
if (rulesTypeIsString) {
|
|
108
|
+
ruleObj = utils.validateString2Object(rules)
|
|
109
|
+
} else {
|
|
110
|
+
ruleObj = { ...rules }
|
|
111
|
+
}
|
|
112
|
+
if (appendTypeIsString) {
|
|
113
|
+
appendObj = utils.validateString2Object(appendRules)
|
|
114
|
+
} else {
|
|
115
|
+
appendObj = { ...appendRules }
|
|
116
|
+
}
|
|
117
|
+
return Object.assign(ruleObj, appendObj)
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
// 减少校验规则
|
|
121
|
+
reduceValidate: (rules, reduceRules) => {
|
|
122
|
+
if (
|
|
123
|
+
!rules ||
|
|
124
|
+
!reduceRules ||
|
|
125
|
+
(reduceRules.constructor !== Object && reduceRules.constructor !== String)
|
|
126
|
+
) {
|
|
127
|
+
return rules
|
|
128
|
+
}
|
|
129
|
+
// 要减少的校验规则的名称集合
|
|
130
|
+
let reduceRuleNames = []
|
|
131
|
+
if (reduceRules.constructor === String) {
|
|
132
|
+
const reduceRuleObj = utils.validateString2Object(reduceRules)
|
|
133
|
+
reduceRuleNames = Object.keys(reduceRuleObj)
|
|
134
|
+
} else {
|
|
135
|
+
reduceRuleNames = Object.keys(reduceRules)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (rules.constructor === Object) {
|
|
139
|
+
Object.keys(rules).forEach((k) => {
|
|
140
|
+
if (reduceRuleNames.some((n) => n == k)) {
|
|
141
|
+
delete rules[k]
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
return rules
|
|
145
|
+
} else if (rules.constructor === String) {
|
|
146
|
+
const ruleAry = utils.stringSplit(rules, '|')
|
|
147
|
+
const nRuleAry = ruleAry.reduce((ary, r) => {
|
|
148
|
+
const name = utils.stringSplit(r, ':')[0]
|
|
149
|
+
if (reduceRuleNames.every((m) => m != name)) {
|
|
150
|
+
ary.push(r)
|
|
151
|
+
}
|
|
152
|
+
return ary
|
|
153
|
+
}, [])
|
|
154
|
+
return nRuleAry.join('|')
|
|
155
|
+
} else {
|
|
156
|
+
throw `rules的类型为${typeof rules},只能为Object类型或String类型。`
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
// 字符串格式的校验规则转为对象格式
|
|
160
|
+
validateString2Object: (rule) => {
|
|
161
|
+
if (!rule || rule.constructor !== String) {
|
|
162
|
+
return rule
|
|
163
|
+
}
|
|
164
|
+
let obj = {}
|
|
165
|
+
const ary = utils.stringSplit(rule, '|')
|
|
166
|
+
ary.forEach((m) => {
|
|
167
|
+
const regAndArgs = utils.stringSplit(m, ':')
|
|
168
|
+
if (regAndArgs.length == 1) {
|
|
169
|
+
obj[regAndArgs[0]] = true
|
|
170
|
+
} else if (regAndArgs.length > 1) {
|
|
171
|
+
const args = utils.stringSplit(regAndArgs[1], ',')
|
|
172
|
+
obj[regAndArgs[0]] = args
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
return obj
|
|
176
|
+
},
|
|
177
|
+
// 判断校验规则中是否至少包含指定规则中的一个
|
|
178
|
+
someRuleInValidate: (validate, rules) => {
|
|
179
|
+
if (
|
|
180
|
+
!validate ||
|
|
181
|
+
(validate.constructor !== Object && validate.constructor !== String) ||
|
|
182
|
+
!rules ||
|
|
183
|
+
rules.constructor !== Array ||
|
|
184
|
+
rules.length == 0
|
|
185
|
+
) {
|
|
186
|
+
return false
|
|
187
|
+
}
|
|
188
|
+
let objs = validate
|
|
189
|
+
if (validate.constructor === String) {
|
|
190
|
+
objs = utils.validateString2Object(validate)
|
|
191
|
+
}
|
|
192
|
+
return Object.keys(objs).some((item) => rules.indexOf(item) > -1)
|
|
193
|
+
},
|
|
194
|
+
// 字符串str按照sep分割为数组,并清理掉数组结果中的空白项。
|
|
195
|
+
stringSplit: (str, sep) => {
|
|
196
|
+
if (
|
|
197
|
+
!str ||
|
|
198
|
+
str.constructor !== String ||
|
|
199
|
+
!sep ||
|
|
200
|
+
sep.constructor !== String
|
|
201
|
+
) {
|
|
202
|
+
return []
|
|
203
|
+
}
|
|
204
|
+
let ary = str.split(sep)
|
|
205
|
+
ary = ary.map((p) => {
|
|
206
|
+
return p.trim()
|
|
207
|
+
})
|
|
208
|
+
ary = ary.trim()
|
|
209
|
+
return ary
|
|
210
|
+
},
|
|
211
|
+
// 获取控件是否添加必填校验
|
|
212
|
+
addRequiredOrNot: (permission, validate) => {
|
|
213
|
+
if (permission !== 'b') {
|
|
214
|
+
return validate
|
|
215
|
+
}
|
|
216
|
+
if (validate === undefined || validate === null) {
|
|
217
|
+
validate = ''
|
|
218
|
+
}
|
|
219
|
+
return utils.mergeValidate('required', validate)
|
|
220
|
+
},
|
|
221
|
+
// 格式化日期时间
|
|
222
|
+
formatDate: (value) => {
|
|
223
|
+
let date = null
|
|
224
|
+
if (!value) {
|
|
225
|
+
return date
|
|
226
|
+
}
|
|
227
|
+
if (value.constructor == Date && !isNaN(value.getTime())) {
|
|
228
|
+
date = value
|
|
229
|
+
} else if (value.constructor == String || value.constructor == Number) {
|
|
230
|
+
date = new Date(value)
|
|
231
|
+
} else {
|
|
232
|
+
throw '格式化日期时,传入的数据格式不正确。'
|
|
233
|
+
}
|
|
234
|
+
let y = date.getFullYear()
|
|
235
|
+
let MM = date.getMonth() + 1
|
|
236
|
+
MM = MM < 10 ? '0' + MM : MM
|
|
237
|
+
let d = date.getDate()
|
|
238
|
+
d = d < 10 ? '0' + d : d
|
|
239
|
+
let h = date.getHours()
|
|
240
|
+
h = h < 10 ? '0' + h : h
|
|
241
|
+
let m = date.getMinutes()
|
|
242
|
+
m = m < 10 ? '0' + m : m
|
|
243
|
+
let s = date.getSeconds()
|
|
244
|
+
s = s < 10 ? '0' + s : s
|
|
245
|
+
return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
|
|
246
|
+
},
|
|
247
|
+
// 格式化日期
|
|
248
|
+
formatDateYear: (value) => {
|
|
249
|
+
let date = new Date(value)
|
|
250
|
+
let y = date.getFullYear()
|
|
251
|
+
let MM = date.getMonth() + 1
|
|
252
|
+
MM = MM < 10 ? '0' + MM : MM
|
|
253
|
+
let d = date.getDate()
|
|
254
|
+
d = d < 10 ? '0' + d : d
|
|
255
|
+
return y + '-' + MM + '-' + d
|
|
256
|
+
},
|
|
257
|
+
// 日期1是否早于日期2
|
|
258
|
+
dateIsBefore: (dateOne, dateTwo, canEquals) => {
|
|
259
|
+
if (!dateOne || !dateTwo) {
|
|
260
|
+
return true
|
|
261
|
+
}
|
|
262
|
+
//兼容苹果浏览器写法 "- 符号替换成/"
|
|
263
|
+
dateOne = dateOne.replace(/-/g, '/')
|
|
264
|
+
dateTwo = dateTwo.replace(/-/g, '/')
|
|
265
|
+
var date1 =
|
|
266
|
+
new Date(dateOne).getTime() ||
|
|
267
|
+
new Date(new Date().format('yyyy-MM-dd') + ' ' + dateOne).getTime()
|
|
268
|
+
var date2 =
|
|
269
|
+
new Date(dateTwo).getTime() ||
|
|
270
|
+
new Date(new Date().format('yyyy-MM-dd') + ' ' + dateTwo).getTime()
|
|
271
|
+
if (!canEquals) {
|
|
272
|
+
//大于。v2>v1 。
|
|
273
|
+
if (date2 > date1) {
|
|
274
|
+
return true
|
|
275
|
+
} else {
|
|
276
|
+
return false
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
//大于等于。v2>=v1 。只要v1不大于v2即可
|
|
280
|
+
if (date1 > date2) {
|
|
281
|
+
return false
|
|
282
|
+
} else {
|
|
283
|
+
return true
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
// 日期计算,不传单位时,默认以'天'为单位计算
|
|
288
|
+
dateCalc: (startDate, endDate, op) => {
|
|
289
|
+
if (
|
|
290
|
+
!startDate ||
|
|
291
|
+
!endDate ||
|
|
292
|
+
startDate.length == 0 ||
|
|
293
|
+
endDate.length == 0
|
|
294
|
+
) {
|
|
295
|
+
return 0
|
|
296
|
+
}
|
|
297
|
+
if (!op || op.constructor != String) {
|
|
298
|
+
op = 'day'
|
|
299
|
+
}
|
|
300
|
+
const opAry = ['year', 'month', 'day', 'hour', 'minute', 'second']
|
|
301
|
+
if (opAry.indexOf(op) == -1) {
|
|
302
|
+
throw `计算日期的单位只能从${opAry}中选择`
|
|
303
|
+
}
|
|
304
|
+
let date1 = new Date(Date.parse(startDate.replace(/-/g, '/'))).getTime()
|
|
305
|
+
let date2 = new Date(Date.parse(endDate.replace(/-/g, '/'))).getTime()
|
|
306
|
+
if (!Number.isInteger(date1) || !Number.isInteger(date2)) {
|
|
307
|
+
const now = new Date()
|
|
308
|
+
let nowStr =
|
|
309
|
+
now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate()
|
|
310
|
+
if (!Number.isInteger(date1)) {
|
|
311
|
+
date1 = new Date(`${nowStr} ${startDate}`).getTime()
|
|
312
|
+
}
|
|
313
|
+
if (!Number.isInteger(date1)) {
|
|
314
|
+
date2 = new Date(`${nowStr} ${endDate}`).getTime()
|
|
315
|
+
}
|
|
316
|
+
if (!Number.isInteger(date1) || !Number.isInteger(date2)) {
|
|
317
|
+
return 0
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let res = 0
|
|
322
|
+
let days = date2 - date1
|
|
323
|
+
switch (op) {
|
|
324
|
+
case 'year':
|
|
325
|
+
res = parseInt(days / (1000 * 60 * 60 * 24 * 30 * 12))
|
|
326
|
+
break
|
|
327
|
+
case 'month':
|
|
328
|
+
res = parseInt(days / (1000 * 60 * 60 * 24 * 30))
|
|
329
|
+
break
|
|
330
|
+
case 'day':
|
|
331
|
+
res = parseInt(days / (1000 * 60 * 60 * 24))
|
|
332
|
+
break
|
|
333
|
+
case 'hour':
|
|
334
|
+
res = parseInt(days / (1000 * 60 * 60))
|
|
335
|
+
break
|
|
336
|
+
case 'minute':
|
|
337
|
+
res = parseInt(days / (1000 * 60))
|
|
338
|
+
break
|
|
339
|
+
case 'second':
|
|
340
|
+
res = parseInt(days / 1000)
|
|
341
|
+
}
|
|
342
|
+
return res
|
|
343
|
+
},
|
|
344
|
+
// 计算两个日期的间隔时间,分别返回{ days, hours, minutes, seconds }的时间差
|
|
345
|
+
dateDuration: (startDate, endDate) => {
|
|
346
|
+
const days = utils.dateCalc(startDate, endDate, 'day')
|
|
347
|
+
const hours = utils.dateCalc(startDate, endDate, 'hour')
|
|
348
|
+
const minutes = utils.dateCalc(startDate, endDate, 'minute')
|
|
349
|
+
const seconds = utils.dateCalc(startDate, endDate, 'second')
|
|
350
|
+
return { days, hours, minutes, seconds }
|
|
351
|
+
},
|
|
352
|
+
// 树形结构数组 转换成平铺数组
|
|
353
|
+
nest2tile: (arr, childrenKey, obtainChildren) => {
|
|
354
|
+
if (!childrenKey) {
|
|
355
|
+
childrenKey = 'children'
|
|
356
|
+
}
|
|
357
|
+
return [].concat(
|
|
358
|
+
...arr.map((item) => {
|
|
359
|
+
let _item = { ...item }
|
|
360
|
+
if (obtainChildren == undefined || obtainChildren == false) {
|
|
361
|
+
delete _item[childrenKey]
|
|
362
|
+
}
|
|
363
|
+
if (item[childrenKey] && item[childrenKey].length) {
|
|
364
|
+
return [].concat(
|
|
365
|
+
_item,
|
|
366
|
+
...utils.nest2tile(item[childrenKey], childrenKey, obtainChildren)
|
|
367
|
+
)
|
|
368
|
+
} else {
|
|
369
|
+
return [].concat(_item)
|
|
370
|
+
}
|
|
371
|
+
})
|
|
372
|
+
)
|
|
373
|
+
},
|
|
374
|
+
// 平铺结构转嵌套结构
|
|
375
|
+
tile2nest: (array, key, pKey, childrenKey) => {
|
|
376
|
+
if (!array || array.constructor !== Array) {
|
|
377
|
+
return array
|
|
378
|
+
}
|
|
379
|
+
// 复制一份,避免修改原始数组
|
|
380
|
+
let ary = [...array]
|
|
381
|
+
key = key || 'id'
|
|
382
|
+
pKey = pKey || 'parentId'
|
|
383
|
+
childrenKey = childrenKey || 'children'
|
|
384
|
+
// 定义一个待移除数组
|
|
385
|
+
let ary2remove = []
|
|
386
|
+
ary.map((item) => {
|
|
387
|
+
// isLeaf 字段 'Y' or 'N' 转换为 true or false
|
|
388
|
+
if (item.isLeaf == 'N') {
|
|
389
|
+
item.isLeaf = false
|
|
390
|
+
}
|
|
391
|
+
if (item.isLeaf == 'Y') {
|
|
392
|
+
item.isLeaf = true
|
|
393
|
+
}
|
|
394
|
+
if (item[key] !== item[pKey]) {
|
|
395
|
+
// 找父节点
|
|
396
|
+
let p = ary.filter((c) => c[key] === item[pKey])
|
|
397
|
+
if (p && p.length == 1) {
|
|
398
|
+
p[0][childrenKey] = p[0][childrenKey] || []
|
|
399
|
+
// 将子节点放到父节点中
|
|
400
|
+
p[0][childrenKey].push(item)
|
|
401
|
+
ary2remove.push(item[key])
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
})
|
|
405
|
+
// 遍历移除待删除对象
|
|
406
|
+
ary2remove.map((item) => {
|
|
407
|
+
ary = ary.filter((c) => c[key] !== item)
|
|
408
|
+
})
|
|
409
|
+
return ary
|
|
410
|
+
},
|
|
411
|
+
// 获取控件所在表单对应的实例对象
|
|
412
|
+
getOnlineFormInstance: (instance) => {
|
|
413
|
+
if (instance == instance.$root) {
|
|
414
|
+
return instance
|
|
415
|
+
}
|
|
416
|
+
if (!instance) {
|
|
417
|
+
throw 'VueComponent实例为空.'
|
|
418
|
+
}
|
|
419
|
+
if (instance.hasOwnProperty('watchMap')) {
|
|
420
|
+
return instance
|
|
421
|
+
} else if (instance.$parent) {
|
|
422
|
+
return utils.getOnlineFormInstance(instance.$parent)
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
// 获取在线表单的ClRuntimeTemplate实例
|
|
426
|
+
getRuntimeTemplateOnlineForm: (instance) => {
|
|
427
|
+
if (instance == instance.$root) {
|
|
428
|
+
return instance
|
|
429
|
+
}
|
|
430
|
+
if (!instance) {
|
|
431
|
+
throw 'VueComponent实例为空.'
|
|
432
|
+
}
|
|
433
|
+
if (instance.$options.componentName == 'ClRuntimeTemplate') {
|
|
434
|
+
return instance
|
|
435
|
+
} else if (instance.$parent) {
|
|
436
|
+
return utils.getRuntimeTemplateOnlineForm(instance.$parent)
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
// 获取子表每一行所在的作用域元素及索引
|
|
440
|
+
getSubScopeElAndIndex: (el) => {
|
|
441
|
+
let subScopeEl = utils.getParentElementByAttribute(el, 'data-subname')
|
|
442
|
+
if (!subScopeEl) {
|
|
443
|
+
subScopeEl = utils.getParentElementByClassNamePrefix(el, 'data-subname__')
|
|
444
|
+
}
|
|
445
|
+
if (!subScopeEl) {
|
|
446
|
+
return { subScopeEl: null, index: null, subname: null }
|
|
447
|
+
}
|
|
448
|
+
let index = subScopeEl.dataset['index']
|
|
449
|
+
if (index === undefined) {
|
|
450
|
+
const dataIndexClass = subScopeEl.className
|
|
451
|
+
.split(' ')
|
|
452
|
+
.find((c) => c.startsWith('data-index__'))
|
|
453
|
+
if (dataIndexClass) {
|
|
454
|
+
index = dataIndexClass.replace('data-index__', 0)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (index === undefined) {
|
|
458
|
+
throw '要计算的子表行未获取到index属性.'
|
|
459
|
+
}
|
|
460
|
+
index = Number.parseInt(index)
|
|
461
|
+
let subname = subScopeEl.dataset['subname']
|
|
462
|
+
if (!subname) {
|
|
463
|
+
const dataSubnameClass = subScopeEl.className
|
|
464
|
+
.split(' ')
|
|
465
|
+
.find((c) => c.startsWith('data-subname__'))
|
|
466
|
+
if (dataSubnameClass) {
|
|
467
|
+
subname = dataSubnameClass.replace('data-subname__', '')
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// 判断是否子表有分页
|
|
471
|
+
if (subname) {
|
|
472
|
+
let subPageMap = utils.getSubtablePageVue(el)
|
|
473
|
+
if (
|
|
474
|
+
subPageMap &&
|
|
475
|
+
subPageMap.internalCurrentPage > 1 &&
|
|
476
|
+
index <
|
|
477
|
+
(subPageMap.internalCurrentPage - 1) * subPageMap.internalPageSize
|
|
478
|
+
) {
|
|
479
|
+
index =
|
|
480
|
+
(subPageMap.internalCurrentPage - 1) * subPageMap.internalPageSize +
|
|
481
|
+
index
|
|
482
|
+
subScopeEl.dataset['index'] = index
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return { subScopeEl, index, subname }
|
|
486
|
+
},
|
|
487
|
+
getSubtablePageVue(el) {
|
|
488
|
+
while (el && el.parentElement.nodeName != 'TABLE') {
|
|
489
|
+
el = el.parentElement
|
|
490
|
+
}
|
|
491
|
+
if (
|
|
492
|
+
el &&
|
|
493
|
+
el.parentElement &&
|
|
494
|
+
el.parentElement.getElementsByClassName('el-pagination') &&
|
|
495
|
+
el.parentElement.getElementsByClassName('el-pagination')[0] &&
|
|
496
|
+
el.parentElement.getElementsByClassName('el-pagination')[0].__vue__._data
|
|
497
|
+
) {
|
|
498
|
+
return el.parentElement.getElementsByClassName('el-pagination')[0].__vue__
|
|
499
|
+
._data
|
|
500
|
+
}
|
|
501
|
+
return null
|
|
502
|
+
},
|
|
503
|
+
// 在子表指定行中通过v-model表达式获取input对应的vue实例
|
|
504
|
+
getSubInputScopeByModelExpression: (subScopeEl, expression) => {
|
|
505
|
+
const inputAry = subScopeEl.getElementsByClassName('inputs')
|
|
506
|
+
let result = null
|
|
507
|
+
for (var i = 0, c; (c = inputAry[i++]); ) {
|
|
508
|
+
let expressionName = c.__vue__.$vnode.data.model && c.__vue__.$vnode.data.model.expression ? c.__vue__.$vnode.data.model.expression : ''
|
|
509
|
+
// 兼容front端使用
|
|
510
|
+
if (
|
|
511
|
+
c.__vue__.$vnode &&
|
|
512
|
+
c.__vue__.$vnode.componentOptions &&
|
|
513
|
+
c.__vue__.$vnode.componentOptions.propsData &&
|
|
514
|
+
c.__vue__.$vnode.componentOptions.propsData.modelExpression
|
|
515
|
+
) {
|
|
516
|
+
expressionName =
|
|
517
|
+
c.__vue__.$vnode.componentOptions.propsData.modelExpression
|
|
518
|
+
}
|
|
519
|
+
if (
|
|
520
|
+
c &&
|
|
521
|
+
c.__vue__ &&
|
|
522
|
+
c.__vue__.$vnode.data.model &&
|
|
523
|
+
expressionName === expression
|
|
524
|
+
) {
|
|
525
|
+
result = c.__vue__
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return result
|
|
529
|
+
},
|
|
530
|
+
// 获取在线表单的json格式字符串的表单数据(validate参数决定是否需要对表单进行验证)
|
|
531
|
+
validateForm: (instance, scopeName) => {
|
|
532
|
+
return new Promise((resolve, reject) => {
|
|
533
|
+
instance.$root.$validator.validateAll(scopeName).then((result) => {
|
|
534
|
+
if (result) {
|
|
535
|
+
resolve(result)
|
|
536
|
+
} else {
|
|
537
|
+
reject(instance.$root.$validator.errors.items)
|
|
538
|
+
}
|
|
539
|
+
})
|
|
540
|
+
})
|
|
541
|
+
},
|
|
542
|
+
// 获取指定dom元素的父级中具有指定属性的dom元素
|
|
543
|
+
getParentElementByAttribute: (el, attribute) => {
|
|
544
|
+
if (el === null || el === undefined) {
|
|
545
|
+
return null
|
|
546
|
+
}
|
|
547
|
+
if (!el.hasAttribute || typeof el.hasAttribute != 'function') {
|
|
548
|
+
throw '传入的元素el不能为空且必须为HTMLHtmlElement类型.'
|
|
549
|
+
}
|
|
550
|
+
if (!attribute || attribute.constructor !== String) {
|
|
551
|
+
throw '传入的属性attribute不能为空且必须为String类型.'
|
|
552
|
+
}
|
|
553
|
+
if (el.hasAttribute(attribute)) {
|
|
554
|
+
return el
|
|
555
|
+
} else if (el.tagName === 'HTML') {
|
|
556
|
+
return null
|
|
557
|
+
} else {
|
|
558
|
+
return utils.getParentElementByAttribute(el.parentElement, attribute)
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
// 获取指定dom元素的父级中具有指定class前缀的dom元素
|
|
562
|
+
getParentElementByClassNamePrefix: (el, classNamePrefix) => {
|
|
563
|
+
if (el === null || el === undefined) {
|
|
564
|
+
return null
|
|
565
|
+
}
|
|
566
|
+
if (!el.hasAttribute || typeof el.hasAttribute != 'function') {
|
|
567
|
+
throw '传入的元素el不能为空且必须为HTMLHtmlElement类型.'
|
|
568
|
+
}
|
|
569
|
+
if (!classNamePrefix || classNamePrefix.constructor !== String) {
|
|
570
|
+
throw '传入的classNamePrefix不能为空且必须为String类型.'
|
|
571
|
+
}
|
|
572
|
+
const classNames = el.className.split(' ')
|
|
573
|
+
if (classNames && classNames.some((c) => c.startsWith(classNamePrefix))) {
|
|
574
|
+
return el
|
|
575
|
+
} else if (el.tagName === 'HTML') {
|
|
576
|
+
return null
|
|
577
|
+
} else {
|
|
578
|
+
return utils.getParentElementByClassNamePrefix(
|
|
579
|
+
el.parentElement,
|
|
580
|
+
classNamePrefix
|
|
581
|
+
)
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
// 从父级dom元素中获取指定属性的值
|
|
585
|
+
getSomeAttributeFromParentElement: (el, attribute) => {
|
|
586
|
+
let pEl = utils.getParentElementByAttribute(el, attribute)
|
|
587
|
+
if (pEl && pEl.getAttribute && pEl.getAttribute.constructor === Function) {
|
|
588
|
+
return pEl.getAttribute(attribute)
|
|
589
|
+
}
|
|
590
|
+
return null
|
|
591
|
+
},
|
|
592
|
+
// 将子表属性路径转换为完整的属性路径,例如:item.name => data.sub[0].name
|
|
593
|
+
getWholePathOfSub: function getWholePathOfSub(subPath, mainPath, index) {
|
|
594
|
+
if (!subPath || !mainPath || index === null || !Number.isInteger(index)) {
|
|
595
|
+
return null
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
var match = subPath.split('.')
|
|
599
|
+
|
|
600
|
+
if (match && match.length > 1) {
|
|
601
|
+
return ''
|
|
602
|
+
.concat(mainPath, '[')
|
|
603
|
+
.concat(index, '].')
|
|
604
|
+
.concat(match[match.length - 1])
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return null
|
|
608
|
+
},
|
|
609
|
+
// 通过路径取得对象中的属性
|
|
610
|
+
getValueByPath: (obj, path, subIndex) => {
|
|
611
|
+
if (!obj || !path || path.constructor != String) {
|
|
612
|
+
return null
|
|
613
|
+
}
|
|
614
|
+
if (!/^\w?.*[\w|\]]$/.test(path)) {
|
|
615
|
+
return null
|
|
616
|
+
}
|
|
617
|
+
let pathAry = path.split('.')
|
|
618
|
+
if (pathAry.length == 1) {
|
|
619
|
+
return obj[path]
|
|
620
|
+
} else if (pathAry.length > 1) {
|
|
621
|
+
let ret = obj
|
|
622
|
+
for (var i = 0; i < pathAry.length; i++) {
|
|
623
|
+
if (ret === null || ret === undefined) {
|
|
624
|
+
return null
|
|
625
|
+
}
|
|
626
|
+
const key = pathAry[i]
|
|
627
|
+
const match = /^(\w+)\[(\d+)\]$/.exec(key)
|
|
628
|
+
if (match) {
|
|
629
|
+
ret = ret[match[1]][match[2]]
|
|
630
|
+
} else if (ret && ret.constructor === Array) {
|
|
631
|
+
let index = 0
|
|
632
|
+
if (subIndex != null && subIndex != undefined) {
|
|
633
|
+
let preIndex = Number.parseInt(subIndex)
|
|
634
|
+
if (!isNaN(preIndex)) {
|
|
635
|
+
index = preIndex
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
ret = ret[index][key]
|
|
639
|
+
} else {
|
|
640
|
+
ret = ret[key]
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return ret
|
|
644
|
+
}
|
|
645
|
+
return null
|
|
646
|
+
},
|
|
647
|
+
// 通过路径设置对象中的属性
|
|
648
|
+
setValueByPath: (obj, path, value, subIndex) => {
|
|
649
|
+
if (!obj || !path || path.constructor != String) {
|
|
650
|
+
return
|
|
651
|
+
}
|
|
652
|
+
if (!/^\w?.*[\w|\]]$/.test(path)) {
|
|
653
|
+
return
|
|
654
|
+
}
|
|
655
|
+
let pathAry = path.split('.')
|
|
656
|
+
if (pathAry.length == 1) {
|
|
657
|
+
obj[path] = value
|
|
658
|
+
} else if (pathAry.length > 1) {
|
|
659
|
+
let ret = obj
|
|
660
|
+
for (var i = 0; i < pathAry.length; i++) {
|
|
661
|
+
const key = pathAry[i]
|
|
662
|
+
const match = /^(\w+)\[(\d+)\]$/.exec(key)
|
|
663
|
+
if (i == pathAry.length - 1) {
|
|
664
|
+
if (match) {
|
|
665
|
+
ret[match[1]][match[2]] = value
|
|
666
|
+
} else if (ret && ret.constructor === Array) {
|
|
667
|
+
let index = 0
|
|
668
|
+
if (subIndex != null && subIndex != undefined) {
|
|
669
|
+
let preIndex = Number.parseInt(subIndex)
|
|
670
|
+
if (!isNaN(preIndex)) {
|
|
671
|
+
index = preIndex
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
ret[index][key] = value
|
|
675
|
+
} else {
|
|
676
|
+
ret[key] = value
|
|
677
|
+
}
|
|
678
|
+
} else {
|
|
679
|
+
if (match) {
|
|
680
|
+
ret = ret[match[1]][match[2]]
|
|
681
|
+
} else {
|
|
682
|
+
ret = ret[key]
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
/**
|
|
689
|
+
* 将字符串转为json对象。
|
|
690
|
+
* @param jsonStr
|
|
691
|
+
* @param type 可不填写parseToJson
|
|
692
|
+
* @returns
|
|
693
|
+
*/
|
|
694
|
+
parseToJson: (jsonStr, type) => {
|
|
695
|
+
type = type || 1
|
|
696
|
+
if (!jsonStr || jsonStr === '') return null
|
|
697
|
+
try {
|
|
698
|
+
let obj
|
|
699
|
+
switch (type) {
|
|
700
|
+
case 1:
|
|
701
|
+
obj = JSON.parse(jsonStr)
|
|
702
|
+
break
|
|
703
|
+
case 2:
|
|
704
|
+
obj = eval(`(${jsonStr})`)
|
|
705
|
+
break
|
|
706
|
+
default:
|
|
707
|
+
throw '解析json对象错误'
|
|
708
|
+
}
|
|
709
|
+
return obj
|
|
710
|
+
} catch (e) {
|
|
711
|
+
return utils.parseToJson(jsonStr, type + 1)
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
/**
|
|
715
|
+
* 将数字转换成人名币大写。
|
|
716
|
+
*
|
|
717
|
+
* @param currencyDigits
|
|
718
|
+
* @returns
|
|
719
|
+
*/
|
|
720
|
+
convertCurrency: (currencyDigits) => {
|
|
721
|
+
var MAXIMUM_NUMBER = 99999999999.99
|
|
722
|
+
var CN_ZERO = '零'
|
|
723
|
+
var CN_ONE = '壹'
|
|
724
|
+
var CN_TWO = '贰'
|
|
725
|
+
var CN_THREE = '叁'
|
|
726
|
+
var CN_FOUR = '肆'
|
|
727
|
+
var CN_FIVE = '伍'
|
|
728
|
+
var CN_SIX = '陆'
|
|
729
|
+
var CN_SEVEN = '柒'
|
|
730
|
+
var CN_EIGHT = '捌'
|
|
731
|
+
var CN_NINE = '玖'
|
|
732
|
+
var CN_TEN = '拾'
|
|
733
|
+
var CN_HUNDRED = '佰'
|
|
734
|
+
var CN_THOUSAND = '仟'
|
|
735
|
+
var CN_TEN_THOUSAND = '万'
|
|
736
|
+
var CN_HUNDRED_MILLION = '亿'
|
|
737
|
+
var CN_SYMBOL = ''
|
|
738
|
+
var CN_DOLLAR = '元'
|
|
739
|
+
var CN_TEN_CENT = '角'
|
|
740
|
+
var CN_CENT = '分'
|
|
741
|
+
var CN_INTEGER = '整'
|
|
742
|
+
var integral
|
|
743
|
+
var decimal
|
|
744
|
+
var outputCharacters
|
|
745
|
+
var parts
|
|
746
|
+
var digits, radices, bigRadices, decimals
|
|
747
|
+
var zeroCount
|
|
748
|
+
var i, p, d
|
|
749
|
+
var quotient, modulus
|
|
750
|
+
currencyDigits = currencyDigits.toString()
|
|
751
|
+
if (currencyDigits == '') {
|
|
752
|
+
return ''
|
|
753
|
+
}
|
|
754
|
+
if (currencyDigits.match(/[^,.\d]/) != null) {
|
|
755
|
+
return ''
|
|
756
|
+
}
|
|
757
|
+
if (
|
|
758
|
+
currencyDigits.match(
|
|
759
|
+
/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/
|
|
760
|
+
) == null
|
|
761
|
+
) {
|
|
762
|
+
return ''
|
|
763
|
+
}
|
|
764
|
+
currencyDigits = currencyDigits.replace(/,/g, '')
|
|
765
|
+
currencyDigits = currencyDigits.replace(/^0+/, '')
|
|
766
|
+
|
|
767
|
+
if (Number(currencyDigits) > MAXIMUM_NUMBER) {
|
|
768
|
+
return ''
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
parts = currencyDigits.split('.')
|
|
772
|
+
if (parts.length > 1) {
|
|
773
|
+
integral = parts[0]
|
|
774
|
+
decimal = parts[1]
|
|
775
|
+
|
|
776
|
+
decimal = decimal.substr(0, 2)
|
|
777
|
+
} else {
|
|
778
|
+
integral = parts[0]
|
|
779
|
+
decimal = ''
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
digits = new Array(
|
|
783
|
+
CN_ZERO,
|
|
784
|
+
CN_ONE,
|
|
785
|
+
CN_TWO,
|
|
786
|
+
CN_THREE,
|
|
787
|
+
CN_FOUR,
|
|
788
|
+
CN_FIVE,
|
|
789
|
+
CN_SIX,
|
|
790
|
+
CN_SEVEN,
|
|
791
|
+
CN_EIGHT,
|
|
792
|
+
CN_NINE
|
|
793
|
+
)
|
|
794
|
+
radices = new Array('', CN_TEN, CN_HUNDRED, CN_THOUSAND)
|
|
795
|
+
bigRadices = new Array('', CN_TEN_THOUSAND, CN_HUNDRED_MILLION)
|
|
796
|
+
decimals = new Array(CN_TEN_CENT, CN_CENT)
|
|
797
|
+
|
|
798
|
+
outputCharacters = ''
|
|
799
|
+
|
|
800
|
+
if (Number(integral) > 0) {
|
|
801
|
+
zeroCount = 0
|
|
802
|
+
for (i = 0; i < integral.length; i++) {
|
|
803
|
+
p = integral.length - i - 1
|
|
804
|
+
d = integral.substr(i, 1)
|
|
805
|
+
quotient = p / 4
|
|
806
|
+
modulus = p % 4
|
|
807
|
+
if (d == '0') {
|
|
808
|
+
zeroCount++
|
|
809
|
+
} else {
|
|
810
|
+
if (zeroCount > 0) {
|
|
811
|
+
outputCharacters += digits[0]
|
|
812
|
+
}
|
|
813
|
+
zeroCount = 0
|
|
814
|
+
outputCharacters += digits[Number(d)] + radices[modulus]
|
|
815
|
+
}
|
|
816
|
+
if (modulus == 0 && zeroCount < 4) {
|
|
817
|
+
outputCharacters += bigRadices[quotient]
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
outputCharacters += CN_DOLLAR
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (decimal != '') {
|
|
824
|
+
for (i = 0; i < decimal.length; i++) {
|
|
825
|
+
d = decimal.substr(i, 1)
|
|
826
|
+
if (d != '0') {
|
|
827
|
+
outputCharacters += digits[Number(d)] + decimals[i]
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
if (outputCharacters == '') {
|
|
833
|
+
outputCharacters = CN_ZERO + CN_DOLLAR
|
|
834
|
+
}
|
|
835
|
+
if (decimal == '') {
|
|
836
|
+
outputCharacters += CN_INTEGER
|
|
837
|
+
}
|
|
838
|
+
outputCharacters = CN_SYMBOL + outputCharacters
|
|
839
|
+
return outputCharacters
|
|
840
|
+
},
|
|
841
|
+
/**
|
|
842
|
+
* 通过name获取页面url地址参数
|
|
843
|
+
* @param name
|
|
844
|
+
* @returns
|
|
845
|
+
*
|
|
846
|
+
*/
|
|
847
|
+
getUrlKey: (name) => {
|
|
848
|
+
return (
|
|
849
|
+
decodeURIComponent(
|
|
850
|
+
(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(
|
|
851
|
+
location.href
|
|
852
|
+
) || ['', ''])[1].replace(/\+/g, '%20')
|
|
853
|
+
) || null
|
|
854
|
+
)
|
|
855
|
+
},
|
|
856
|
+
// 返回调整顺序后的数组 part:数组中的一个或多个元素, direct:调整的方向 up:向上 down:向下
|
|
857
|
+
arrayMove: (ary, part, direct) => {
|
|
858
|
+
direct = direct || 'down'
|
|
859
|
+
if (!part || (part.constructor !== Object && part.constructor !== Array)) {
|
|
860
|
+
return ary
|
|
861
|
+
}
|
|
862
|
+
if (part.constructor === Object) {
|
|
863
|
+
part = [part]
|
|
864
|
+
}
|
|
865
|
+
if (direct == 'up') {
|
|
866
|
+
part.forEach((m) => {
|
|
867
|
+
let index = ary.indexOf(m, 1)
|
|
868
|
+
if (index > 0) {
|
|
869
|
+
let newAry = [...ary]
|
|
870
|
+
newAry[index - 1] = ary[index]
|
|
871
|
+
newAry[index] = ary[index - 1]
|
|
872
|
+
ary = newAry
|
|
873
|
+
}
|
|
874
|
+
})
|
|
875
|
+
} else if (direct == 'down') {
|
|
876
|
+
for (var i = part.length - 1, m; (m = part[i--]); ) {
|
|
877
|
+
let index = ary.indexOf(m, 0)
|
|
878
|
+
if (index > -1 && index < ary.length - 1) {
|
|
879
|
+
let newAry = [...ary]
|
|
880
|
+
newAry[index + 1] = ary[index]
|
|
881
|
+
newAry[index] = ary[index + 1]
|
|
882
|
+
ary = newAry
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return ary
|
|
887
|
+
},
|
|
888
|
+
// 通过配置中指定的key所对应的属性路径在当前表单中获取对应的值,支持通过data.main.name 或者是 item.name来分别获取主表数据及子表数据的情况
|
|
889
|
+
getValueByConfigKey: (inst, config, key) => {
|
|
890
|
+
if (!config.hasOwnProperty(key)) {
|
|
891
|
+
throw `config对象中未找到属性${key}`
|
|
892
|
+
}
|
|
893
|
+
const keyPath = config[key]
|
|
894
|
+
// 获取当前组件所在的表单
|
|
895
|
+
const formInst = utils.getOnlineFormInstance(inst.$parent)
|
|
896
|
+
// 获取当前组件是否在子表中的某一行
|
|
897
|
+
const { subScopeEl, index, subname } = utils.getSubScopeElAndIndex(inst.$el)
|
|
898
|
+
if (subScopeEl) {
|
|
899
|
+
//判断是否有孙表
|
|
900
|
+
let paths = subname
|
|
901
|
+
if (paths.split('.').length == 4 && paths.indexOf('[') == -1) {
|
|
902
|
+
//孙表回填路径
|
|
903
|
+
paths =
|
|
904
|
+
paths.split('.')[0] +
|
|
905
|
+
'.' +
|
|
906
|
+
paths.split('.')[1] +
|
|
907
|
+
'.' +
|
|
908
|
+
paths.split('.')[2] +
|
|
909
|
+
'[' +
|
|
910
|
+
index +
|
|
911
|
+
']' +
|
|
912
|
+
'.' +
|
|
913
|
+
paths.split('.')[3]
|
|
914
|
+
}
|
|
915
|
+
// 将item.name这样的路径替换为data.sub[0].name这样的全路径格式
|
|
916
|
+
let wholeKeyPath = utils.getWholePathOfSub(keyPath, paths, index)
|
|
917
|
+
return utils.getValueByPath(formInst, wholeKeyPath)
|
|
918
|
+
} else {
|
|
919
|
+
return utils.getValueByPath(formInst, keyPath)
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
// 通过配置中指定的key来设置值到对应的属性路径上,支持设置主表数据data.main.name 或设置子表数据item.name
|
|
923
|
+
setValueByConfigKey: (inst, config, key, value) => {
|
|
924
|
+
if (!config.hasOwnProperty(key)) {
|
|
925
|
+
return
|
|
926
|
+
}
|
|
927
|
+
const keyPath = config[key]
|
|
928
|
+
// 获取当前组件所在的表单
|
|
929
|
+
const formInst = utils.getOnlineFormInstance(inst.$parent)
|
|
930
|
+
// 获取当前组件是否在子表中的某一行
|
|
931
|
+
const { subScopeEl, index, subname } = utils.getSubScopeElAndIndex(inst.$el)
|
|
932
|
+
if (subScopeEl) {
|
|
933
|
+
//判断是否有孙表
|
|
934
|
+
let paths = subname
|
|
935
|
+
if (paths.split('.').length == 4 && paths.indexOf('[') == -1) {
|
|
936
|
+
//孙表回填路径
|
|
937
|
+
paths =
|
|
938
|
+
paths.split('.')[0] +
|
|
939
|
+
'.' +
|
|
940
|
+
paths.split('.')[1] +
|
|
941
|
+
'.' +
|
|
942
|
+
paths.split('.')[2] +
|
|
943
|
+
'[' +
|
|
944
|
+
index +
|
|
945
|
+
']' +
|
|
946
|
+
'.' +
|
|
947
|
+
paths.split('.')[3]
|
|
948
|
+
}
|
|
949
|
+
// 将item.name这样的路径替换为data.sub[0].name这样的全路径格式
|
|
950
|
+
let wholeKeyPath = utils.getWholePathOfSub(keyPath, paths, index)
|
|
951
|
+
utils.setValueByPath(formInst, wholeKeyPath, value)
|
|
952
|
+
} else {
|
|
953
|
+
utils.setValueByPath(formInst, keyPath, value)
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
// 判断两个对象是否相等(props为属性数组,有传入时,只比对传入的属性是否相等)
|
|
957
|
+
objectEquals: (obj1, obj2, props) => {
|
|
958
|
+
if (!props || props.constructor !== Array) {
|
|
959
|
+
props = []
|
|
960
|
+
}
|
|
961
|
+
if (!obj1 || !obj2) {
|
|
962
|
+
return obj1 === obj2
|
|
963
|
+
}
|
|
964
|
+
for (let propName in obj1) {
|
|
965
|
+
if (props.length > 0 && props.indexOf(propName) === -1) {
|
|
966
|
+
continue
|
|
967
|
+
}
|
|
968
|
+
if (obj1.hasOwnProperty(propName) != obj2.hasOwnProperty(propName)) {
|
|
969
|
+
return false
|
|
970
|
+
} else if (typeof obj1[propName] != typeof obj2[propName]) {
|
|
971
|
+
return false
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
for (let propName in obj2) {
|
|
975
|
+
if (props.length > 0 && props.indexOf(propName) === -1) {
|
|
976
|
+
continue
|
|
977
|
+
}
|
|
978
|
+
if (obj1.hasOwnProperty(propName) != obj2.hasOwnProperty(propName)) {
|
|
979
|
+
return false
|
|
980
|
+
} else if (typeof obj1[propName] != typeof obj2[propName]) {
|
|
981
|
+
return false
|
|
982
|
+
}
|
|
983
|
+
if (!obj1.hasOwnProperty(propName)) {
|
|
984
|
+
continue
|
|
985
|
+
}
|
|
986
|
+
if (obj1[propName] instanceof Array && obj2[propName] instanceof Array) {
|
|
987
|
+
if (!utils.arrayEquals(obj1[propName], obj2[propName])) {
|
|
988
|
+
return false
|
|
989
|
+
}
|
|
990
|
+
} else if (
|
|
991
|
+
obj1[propName] instanceof Object &&
|
|
992
|
+
obj2[propName] instanceof Object
|
|
993
|
+
) {
|
|
994
|
+
if (!utils.objectEquals(obj1[propName], obj2[propName])) {
|
|
995
|
+
return false
|
|
996
|
+
}
|
|
997
|
+
} else if (obj1[propName] != obj2[propName]) {
|
|
998
|
+
return false
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return true
|
|
1002
|
+
},
|
|
1003
|
+
// 判断两个数组是否相等,支持数组中元素为对象时的深度对比
|
|
1004
|
+
arrayEquals: (ary1, ary2) => {
|
|
1005
|
+
if (!ary1 || !ary2) {
|
|
1006
|
+
return ary1 === ary2
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
if (ary1.length != ary2.length) {
|
|
1010
|
+
return false
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
for (var i = 0, l = ary1.length; i < l; i++) {
|
|
1014
|
+
if (ary1[i] instanceof Array && ary2[i] instanceof Array) {
|
|
1015
|
+
if (!utils.arrayEquals(ary1[i], ary2[i])) {
|
|
1016
|
+
return false
|
|
1017
|
+
}
|
|
1018
|
+
} else if (ary1[i] instanceof Object && ary2[i] instanceof Object) {
|
|
1019
|
+
if (!utils.objectEquals(ary1[i], ary2[i])) {
|
|
1020
|
+
return false
|
|
1021
|
+
}
|
|
1022
|
+
} else if (ary1[i] != ary2[i]) {
|
|
1023
|
+
return false
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return true
|
|
1027
|
+
},
|
|
1028
|
+
// 以第一行文本的缩进空格数为基准,后续的每一行都去掉这个基准所对应的空格。
|
|
1029
|
+
trimEachLine: (text) => {
|
|
1030
|
+
if (!text || text.constructor != String || text.indexOf('\n') == -1) {
|
|
1031
|
+
return text
|
|
1032
|
+
}
|
|
1033
|
+
let ary = text.split('\n'),
|
|
1034
|
+
totem = 0
|
|
1035
|
+
return ary.reduce((prev, cur, index) => {
|
|
1036
|
+
if (index == 1) {
|
|
1037
|
+
const match = /^(\s+).*$/.exec(cur)
|
|
1038
|
+
match && match.length == 2 && (totem = match[1].length)
|
|
1039
|
+
}
|
|
1040
|
+
return prev + '\n' + cur.slice(totem, cur.length)
|
|
1041
|
+
})
|
|
1042
|
+
},
|
|
1043
|
+
// 获取字符串的哈希编码
|
|
1044
|
+
hashCode: (text) => {
|
|
1045
|
+
var hash = 0,
|
|
1046
|
+
char
|
|
1047
|
+
if (text.length == 0) return hash
|
|
1048
|
+
for (var i = 0; i < text.length; i++) {
|
|
1049
|
+
char = text.charCodeAt(i)
|
|
1050
|
+
hash = (hash << 5) - hash + char
|
|
1051
|
+
hash = hash & hash
|
|
1052
|
+
}
|
|
1053
|
+
return hash
|
|
1054
|
+
},
|
|
1055
|
+
// 使用ctx对象中的值替换掉exp中所有的${key}
|
|
1056
|
+
parseExp: (exp, ctx) => {
|
|
1057
|
+
if (!exp || exp.constructor != String) return exp
|
|
1058
|
+
ctx = ctx || {}
|
|
1059
|
+
var reg = /(\$\{(\w+)\})/,
|
|
1060
|
+
match = null,
|
|
1061
|
+
count = 0
|
|
1062
|
+
|
|
1063
|
+
while ((match = reg.exec(exp))) {
|
|
1064
|
+
count++
|
|
1065
|
+
// 避免死循环
|
|
1066
|
+
if (count > 999) {
|
|
1067
|
+
break
|
|
1068
|
+
}
|
|
1069
|
+
if (match != null) {
|
|
1070
|
+
exp = exp.replace(
|
|
1071
|
+
match[1],
|
|
1072
|
+
ctx.hasOwnProperty(match[2]) ? ctx[match[2]] : ''
|
|
1073
|
+
)
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return exp
|
|
1077
|
+
},
|
|
1078
|
+
/**
|
|
1079
|
+
* 数字格式转换成千分位
|
|
1080
|
+
*@param{Object}num
|
|
1081
|
+
*/
|
|
1082
|
+
thousandBit: (num) => {
|
|
1083
|
+
if ((num + '').trim() == '') {
|
|
1084
|
+
return ''
|
|
1085
|
+
}
|
|
1086
|
+
if (isNaN(num)) {
|
|
1087
|
+
return num
|
|
1088
|
+
}
|
|
1089
|
+
num = num + ''
|
|
1090
|
+
if (/^.*\..*$/.test(num)) {
|
|
1091
|
+
const pointIndex = num.lastIndexOf('.')
|
|
1092
|
+
const pointPart = num.substring(pointIndex + 1, num.length)
|
|
1093
|
+
let intPart = num.substring(0, pointIndex)
|
|
1094
|
+
intPart = intPart + ''
|
|
1095
|
+
const re = /(-?\d+)(\d{3})/
|
|
1096
|
+
while (re.test(intPart)) {
|
|
1097
|
+
intPart = intPart.replace(re, '$1,$2')
|
|
1098
|
+
}
|
|
1099
|
+
num = intPart + '.' + pointPart
|
|
1100
|
+
} else {
|
|
1101
|
+
num = num + ''
|
|
1102
|
+
const re = /(-?\d+)(\d{3})/
|
|
1103
|
+
while (re.test(num)) {
|
|
1104
|
+
num = num.replace(re, '$1,$2')
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return num
|
|
1108
|
+
},
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// 在数组上扩展一个删除指定项的方法
|
|
1112
|
+
Array.prototype.remove = function(item) {
|
|
1113
|
+
let index = this.findIndex((v) => v === item)
|
|
1114
|
+
if (index > -1) {
|
|
1115
|
+
this.splice(index, 1)
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// 在数组上扩展一个去重的方法
|
|
1120
|
+
Array.prototype.unique = function(arg) {
|
|
1121
|
+
const res = new Map()
|
|
1122
|
+
return this.filter((m) => {
|
|
1123
|
+
if (arg) {
|
|
1124
|
+
return !res.has(m[arg]) && res.set(m[arg], 1)
|
|
1125
|
+
} else {
|
|
1126
|
+
return !res.has(m) && res.set(m, 1)
|
|
1127
|
+
}
|
|
1128
|
+
})
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// 去除数组中的空字符串选项
|
|
1132
|
+
Array.prototype.trim = function() {
|
|
1133
|
+
return this.filter((m) => m !== '')
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// 按照数组中的指定key将数组进行分组
|
|
1137
|
+
Array.prototype.groupByKey = function(key) {
|
|
1138
|
+
let res = {}
|
|
1139
|
+
this.forEach((m) => {
|
|
1140
|
+
let group = res[m[key]]
|
|
1141
|
+
if (!group) {
|
|
1142
|
+
group = []
|
|
1143
|
+
res[m[key]] = group
|
|
1144
|
+
}
|
|
1145
|
+
group.push(m)
|
|
1146
|
+
})
|
|
1147
|
+
return res
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// 将数组对象中的某一个属性值单独抽取出来成为一个新的数组 [{id:'1',name:'苹果'},{id:'2',name:'香蕉'}].extractByKey("id") ==> ['1','2']
|
|
1151
|
+
Array.prototype.extractByKey = function(key) {
|
|
1152
|
+
let set = new Set()
|
|
1153
|
+
this.forEach((m) => {
|
|
1154
|
+
if (key && m[key]) {
|
|
1155
|
+
set.add(m[key])
|
|
1156
|
+
}
|
|
1157
|
+
})
|
|
1158
|
+
return Array.from(set)
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* 日期格式化。
|
|
1163
|
+
* 日期格式:
|
|
1164
|
+
* yyyy,yy 年份
|
|
1165
|
+
* MM 大写表示月份
|
|
1166
|
+
* dd 表示日期
|
|
1167
|
+
* hh 表示小时
|
|
1168
|
+
* mm 表示分钟
|
|
1169
|
+
* ss 表示秒
|
|
1170
|
+
* q 表示季度
|
|
1171
|
+
* 实例如下:
|
|
1172
|
+
* var now = new Date();
|
|
1173
|
+
* var nowStr = now.format("yyyy-MM-dd hh:mm:ss");
|
|
1174
|
+
*/
|
|
1175
|
+
Date.prototype.format = function(format) {
|
|
1176
|
+
var o = {
|
|
1177
|
+
'M+': this.getMonth() + 1, //month
|
|
1178
|
+
'd+': this.getDate(), //day
|
|
1179
|
+
'h+': this.getHours(), //hour
|
|
1180
|
+
'H+': this.getHours(), //hour
|
|
1181
|
+
'm+': this.getMinutes(), //minute
|
|
1182
|
+
's+': this.getSeconds(), //second
|
|
1183
|
+
'q+': Math.floor((this.getMonth() + 3) / 3), //quarter
|
|
1184
|
+
S: this.getMilliseconds(), //millisecond
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
if (/(y+)/.test(format)) {
|
|
1188
|
+
format = format.replace(
|
|
1189
|
+
RegExp.$1,
|
|
1190
|
+
(this.getFullYear() + '').substr(4 - RegExp.$1.length)
|
|
1191
|
+
)
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
for (var k in o) {
|
|
1195
|
+
if (new RegExp('(' + k + ')').test(format)) {
|
|
1196
|
+
format = format.replace(
|
|
1197
|
+
RegExp.$1,
|
|
1198
|
+
RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
|
|
1199
|
+
)
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return format
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
export default utils
|