@vtj/materials 0.13.16 → 0.13.18

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.
Files changed (127) hide show
  1. package/dist/assets/antdv/index.umd.js +2 -2
  2. package/dist/assets/charts/index.umd.js +2 -2
  3. package/dist/assets/element/index.umd.js +3 -3
  4. package/dist/assets/icons/index.umd.js +2 -2
  5. package/dist/assets/ui/index.umd.js +2 -2
  6. package/dist/assets/uni-h5/index.umd.js +2 -2
  7. package/dist/assets/uni-ui/index.umd.js +2 -2
  8. package/dist/assets/vant/index.umd.js +2 -2
  9. package/dist/deps/@vtj/charts/index.umd.js +2 -2
  10. package/dist/deps/@vtj/icons/index.umd.js +2 -2
  11. package/dist/deps/@vtj/ui/index.umd.js +4 -4
  12. package/dist/deps/@vtj/ui/style.css +1 -1
  13. package/dist/deps/@vtj/utils/index.umd.js +28 -33
  14. package/dist/deps/@vueuse/core/index.iife.min.js +1 -1
  15. package/dist/deps/element-plus/index.css +1 -1
  16. package/dist/deps/element-plus/index.full.min.js +14 -14
  17. package/dist/deps/element-plus/zh-cn.js +1 -1
  18. package/dist/deps/uni-app/index.umd.js +1 -1
  19. package/dist/deps/uni-h5/index.umd.js +8 -8
  20. package/dist/deps/uni-h5/style.css +1 -1
  21. package/dist/deps/uni-h5-vue/index.umd.js +1 -1
  22. package/dist/deps/uni-ui/index.umd.js +1 -1
  23. package/dist/deps/uni-ui/style.css +1 -1
  24. package/dist/deps/vue/vue.global.js +88 -53
  25. package/dist/deps/vue/vue.global.prod.js +9 -9
  26. package/package.json +12 -12
  27. package/src/antdv/image.ts +1 -1
  28. package/src/element/image.ts +1 -1
  29. package/src/element/virtualizedTable.ts +6 -6
  30. package/src/manifest.json +69 -0
  31. package/src/pages/index.vue +2 -0
  32. package/src/pages.json +19 -0
  33. package/src/uni-ui/index.ts +88 -58
  34. package/src/{uni-ui/lib/uni.scss → uni.scss} +4 -0
  35. package/src/version.ts +2 -2
  36. package/src/uni-ui/lib/uni-col/uni-col.vue +0 -324
  37. package/src/uni-ui/lib/uni-collapse/uni-collapse.vue +0 -153
  38. package/src/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue +0 -425
  39. package/src/uni-ui/lib/uni-data-picker/keypress.js +0 -45
  40. package/src/uni-ui/lib/uni-data-picker/uni-data-picker.vue +0 -604
  41. package/src/uni-ui/lib/uni-data-pickerview/uni-data-picker.js +0 -622
  42. package/src/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.css +0 -76
  43. package/src/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue +0 -335
  44. package/src/uni-ui/lib/uni-data-select/uni-data-select.vue +0 -590
  45. package/src/uni-ui/lib/uni-datetime-picker/calendar-item.vue +0 -188
  46. package/src/uni-ui/lib/uni-datetime-picker/calendar.vue +0 -985
  47. package/src/uni-ui/lib/uni-datetime-picker/i18n/en.json +0 -22
  48. package/src/uni-ui/lib/uni-datetime-picker/i18n/index.js +0 -8
  49. package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hans.json +0 -22
  50. package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hant.json +0 -22
  51. package/src/uni-ui/lib/uni-datetime-picker/time-picker.vue +0 -1032
  52. package/src/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +0 -1230
  53. package/src/uni-ui/lib/uni-datetime-picker/util.js +0 -448
  54. package/src/uni-ui/lib/uni-easyinput/common.js +0 -54
  55. package/src/uni-ui/lib/uni-easyinput/uni-easyinput.vue +0 -790
  56. package/src/uni-ui/lib/uni-fav/i18n/en.json +0 -4
  57. package/src/uni-ui/lib/uni-fav/i18n/index.js +0 -8
  58. package/src/uni-ui/lib/uni-fav/i18n/zh-Hans.json +0 -4
  59. package/src/uni-ui/lib/uni-fav/i18n/zh-Hant.json +0 -4
  60. package/src/uni-ui/lib/uni-fav/uni-fav.vue +0 -170
  61. package/src/uni-ui/lib/uni-file-picker/choose-and-upload-file.js +0 -280
  62. package/src/uni-ui/lib/uni-file-picker/uni-file-picker.vue +0 -668
  63. package/src/uni-ui/lib/uni-file-picker/upload-file.vue +0 -325
  64. package/src/uni-ui/lib/uni-file-picker/upload-image.vue +0 -292
  65. package/src/uni-ui/lib/uni-file-picker/utils.js +0 -110
  66. package/src/uni-ui/lib/uni-forms/uni-forms.vue +0 -416
  67. package/src/uni-ui/lib/uni-forms/utils.js +0 -293
  68. package/src/uni-ui/lib/uni-forms/validate.js +0 -486
  69. package/src/uni-ui/lib/uni-forms-item/uni-forms-item.vue +0 -630
  70. package/src/uni-ui/lib/uni-goods-nav/i18n/en.json +0 -6
  71. package/src/uni-ui/lib/uni-goods-nav/i18n/index.js +0 -8
  72. package/src/uni-ui/lib/uni-goods-nav/i18n/zh-Hans.json +0 -6
  73. package/src/uni-ui/lib/uni-goods-nav/i18n/zh-Hant.json +0 -6
  74. package/src/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue +0 -231
  75. package/src/uni-ui/lib/uni-grid/uni-grid.vue +0 -148
  76. package/src/uni-ui/lib/uni-icons/uni-icons.uvue +0 -91
  77. package/src/uni-ui/lib/uni-icons/uni-icons.vue +0 -114
  78. package/src/uni-ui/lib/uni-icons/uniicons.css +0 -664
  79. package/src/uni-ui/lib/uni-icons/uniicons.ttf +0 -0
  80. package/src/uni-ui/lib/uni-icons/uniicons_file.ts +0 -664
  81. package/src/uni-ui/lib/uni-icons/uniicons_file_vue.js +0 -649
  82. package/src/uni-ui/lib/uni-indexed-list/uni-indexed-list-item.vue +0 -168
  83. package/src/uni-ui/lib/uni-indexed-list/uni-indexed-list.vue +0 -404
  84. package/src/uni-ui/lib/uni-list/uni-list.vue +0 -123
  85. package/src/uni-ui/lib/uni-list/uni-refresh.vue +0 -65
  86. package/src/uni-ui/lib/uni-list/uni-refresh.wxs +0 -87
  87. package/src/uni-ui/lib/uni-load-more/i18n/en.json +0 -5
  88. package/src/uni-ui/lib/uni-load-more/i18n/index.js +0 -8
  89. package/src/uni-ui/lib/uni-load-more/i18n/zh-Hans.json +0 -5
  90. package/src/uni-ui/lib/uni-load-more/i18n/zh-Hant.json +0 -5
  91. package/src/uni-ui/lib/uni-load-more/uni-load-more.vue +0 -456
  92. package/src/uni-ui/lib/uni-notice-bar/uni-notice-bar.vue +0 -484
  93. package/src/uni-ui/lib/uni-popup/i18n/en.json +0 -7
  94. package/src/uni-ui/lib/uni-popup/i18n/index.js +0 -8
  95. package/src/uni-ui/lib/uni-popup/i18n/zh-Hans.json +0 -7
  96. package/src/uni-ui/lib/uni-popup/i18n/zh-Hant.json +0 -7
  97. package/src/uni-ui/lib/uni-popup/keypress.js +0 -45
  98. package/src/uni-ui/lib/uni-popup/popup.js +0 -26
  99. package/src/uni-ui/lib/uni-popup/uni-popup.uvue +0 -90
  100. package/src/uni-ui/lib/uni-popup/uni-popup.vue +0 -552
  101. package/src/uni-ui/lib/uni-popup-dialog/keypress.js +0 -45
  102. package/src/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue +0 -324
  103. package/src/uni-ui/lib/uni-popup-message/uni-popup-message.vue +0 -149
  104. package/src/uni-ui/lib/uni-rate/uni-rate.vue +0 -380
  105. package/src/uni-ui/lib/uni-row/uni-row.vue +0 -193
  106. package/src/uni-ui/lib/uni-search-bar/i18n/en.json +0 -4
  107. package/src/uni-ui/lib/uni-search-bar/i18n/index.js +0 -8
  108. package/src/uni-ui/lib/uni-search-bar/i18n/zh-Hans.json +0 -4
  109. package/src/uni-ui/lib/uni-search-bar/i18n/zh-Hant.json +0 -4
  110. package/src/uni-ui/lib/uni-search-bar/uni-search-bar.vue +0 -339
  111. package/src/uni-ui/lib/uni-swipe-action-item/bindingx.js +0 -311
  112. package/src/uni-ui/lib/uni-swipe-action-item/isPC.js +0 -12
  113. package/src/uni-ui/lib/uni-swipe-action-item/mpalipay.js +0 -195
  114. package/src/uni-ui/lib/uni-swipe-action-item/mpother.js +0 -260
  115. package/src/uni-ui/lib/uni-swipe-action-item/mpwxs.js +0 -84
  116. package/src/uni-ui/lib/uni-swipe-action-item/render.js +0 -270
  117. package/src/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +0 -493
  118. package/src/uni-ui/lib/uni-swipe-action-item/wx.wxs +0 -341
  119. package/src/uni-ui/lib/uni-table/uni-table.vue +0 -496
  120. package/src/uni-ui/lib/uni-td/uni-td.vue +0 -99
  121. package/src/uni-ui/lib/uni-th/filter-dropdown.vue +0 -559
  122. package/src/uni-ui/lib/uni-th/uni-th.vue +0 -322
  123. package/src/uni-ui/lib/uni-tr/table-checkbox.vue +0 -181
  124. package/src/uni-ui/lib/uni-tr/uni-tr.vue +0 -208
  125. package/src/uni-ui/lib/uni-transition/createAnimation.js +0 -131
  126. package/src/uni-ui/lib/uni-transition/uni-transition.vue +0 -310
  127. package/src/uni-ui/polyfill.ts +0 -41
@@ -1,416 +0,0 @@
1
- <template>
2
- <view class="uni-forms">
3
- <form>
4
- <slot></slot>
5
- </form>
6
- </view>
7
- </template>
8
-
9
- <script>
10
- import Validator from './validate.js';
11
- import {
12
- deepCopy,
13
- getValue,
14
- isRequiredField,
15
- setDataValue,
16
- getDataValue,
17
- realName,
18
- isRealName,
19
- rawData,
20
- isEqual
21
- } from './utils.js';
22
-
23
- // #ifndef VUE3
24
- // 后续会慢慢废弃这个方法
25
- // import Vue from 'vue';
26
- // Vue.prototype.binddata = function(name, value, formName) {
27
- // if (formName) {
28
- // this.$refs[formName].setValue(name, value);
29
- // } else {
30
- // let formVm;
31
- // for (let i in this.$refs) {
32
- // const vm = this.$refs[i];
33
- // if (vm && vm.$options && vm.$options.name === 'uniForms') {
34
- // formVm = vm;
35
- // break;
36
- // }
37
- // }
38
- // if (!formVm) return console.error('当前 uni-froms 组件缺少 ref 属性');
39
- // formVm.setValue(name, value);
40
- // }
41
- // };
42
- // #endif
43
- /**
44
- * Forms 表单
45
- * @description 由输入框、选择器、单选框、多选框等控件组成,用以收集、校验、提交数据
46
- * @tutorial https://ext.dcloud.net.cn/plugin?id=2773
47
- * @property {Object} rules 表单校验规则
48
- * @property {String} validateTrigger = [bind|submit|blur] 校验触发器方式 默认 submit
49
- * @value bind 发生变化时触发
50
- * @value submit 提交时触发
51
- * @value blur 失去焦点时触发
52
- * @property {String} labelPosition = [top|left] label 位置 默认 left
53
- * @value top 顶部显示 label
54
- * @value left 左侧显示 label
55
- * @property {String} labelWidth label 宽度,默认 70px
56
- * @property {String} labelAlign = [left|center|right] label 居中方式 默认 left
57
- * @value left label 左侧显示
58
- * @value center label 居中
59
- * @value right label 右侧对齐
60
- * @property {String} errShowType = [undertext|toast|modal] 校验错误信息提示方式
61
- * @value undertext 错误信息在底部显示
62
- * @value toast 错误信息toast显示
63
- * @value modal 错误信息modal显示
64
- * @event {Function} submit 提交时触发
65
- * @event {Function} validate 校验结果发生变化触发
66
- */
67
- export default {
68
- name: 'uniForms',
69
- emits: ['validate', 'submit'],
70
- options: {
71
- // #ifdef MP-TOUTIAO
72
- virtualHost: false,
73
- // #endif
74
- // #ifndef MP-TOUTIAO
75
- virtualHost: true
76
- // #endif
77
- },
78
- props: {
79
- // 即将弃用
80
- value: {
81
- type: Object,
82
- default() {
83
- return null;
84
- }
85
- },
86
- // vue3 替换 value 属性
87
- modelValue: {
88
- type: Object,
89
- default() {
90
- return null;
91
- }
92
- },
93
- // 1.4.0 开始将不支持 v-model ,且废弃 value 和 modelValue
94
- model: {
95
- type: Object,
96
- default() {
97
- return null;
98
- }
99
- },
100
- // 表单校验规则
101
- rules: {
102
- type: Object,
103
- default() {
104
- return {};
105
- }
106
- },
107
- //校验错误信息提示方式 默认 undertext 取值 [undertext|toast|modal]
108
- errShowType: {
109
- type: String,
110
- default: 'undertext'
111
- },
112
- // 校验触发器方式 默认 bind 取值 [bind|submit]
113
- validateTrigger: {
114
- type: String,
115
- default: 'submit'
116
- },
117
- // label 位置,默认 left 取值 top/left
118
- labelPosition: {
119
- type: String,
120
- default: 'left'
121
- },
122
- // label 宽度
123
- labelWidth: {
124
- type: [String, Number],
125
- default: ''
126
- },
127
- // label 居中方式,默认 left 取值 left/center/right
128
- labelAlign: {
129
- type: String,
130
- default: 'left'
131
- },
132
- border: {
133
- type: Boolean,
134
- default: false
135
- }
136
- },
137
- provide() {
138
- return {
139
- uniForm: this
140
- };
141
- },
142
- data() {
143
- return {
144
- // 表单本地值的记录,不应该与传如的值进行关联
145
- formData: {},
146
- formRules: {}
147
- };
148
- },
149
- computed: {
150
- // 计算数据源变化的
151
- localData() {
152
- const localVal = this.model || this.modelValue || this.value;
153
- if (localVal) {
154
- return deepCopy(localVal);
155
- }
156
- return {};
157
- }
158
- },
159
- watch: {
160
- // 监听数据变化 ,暂时不使用,需要单独赋值
161
- // localData: {},
162
- // 监听规则变化
163
- rules: {
164
- handler: function (val, oldVal) {
165
- this.setRules(val);
166
- },
167
- deep: true,
168
- immediate: true
169
- }
170
- },
171
- created() {
172
- // #ifdef VUE3
173
- let getbinddata =
174
- getApp().$vm.$.appContext.config.globalProperties.binddata;
175
- if (!getbinddata) {
176
- getApp().$vm.$.appContext.config.globalProperties.binddata = function (
177
- name,
178
- value,
179
- formName
180
- ) {
181
- if (formName) {
182
- this.$refs[formName].setValue(name, value);
183
- } else {
184
- let formVm;
185
- for (let i in this.$refs) {
186
- const vm = this.$refs[i];
187
- if (vm && vm.$options && vm.$options.name === 'uniForms') {
188
- formVm = vm;
189
- break;
190
- }
191
- }
192
- if (!formVm)
193
- return console.error('当前 uni-froms 组件缺少 ref 属性');
194
- if (formVm.model) formVm.model[name] = value;
195
- if (formVm.modelValue) formVm.modelValue[name] = value;
196
- if (formVm.value) formVm.value[name] = value;
197
- }
198
- };
199
- }
200
- // #endif
201
-
202
- // 子组件实例数组
203
- this.childrens = [];
204
- // TODO 兼容旧版 uni-data-picker ,新版本中无效,只是避免报错
205
- this.inputChildrens = [];
206
- this.setRules(this.rules);
207
- },
208
- methods: {
209
- /**
210
- * 外部调用方法
211
- * 设置规则 ,主要用于小程序自定义检验规则
212
- * @param {Array} rules 规则源数据
213
- */
214
- setRules(rules) {
215
- // TODO 有可能子组件合并规则的时机比这个要早,所以需要合并对象 ,而不是直接赋值,可能会被覆盖
216
- this.formRules = Object.assign({}, this.formRules, rules);
217
- // 初始化校验函数
218
- this.validator = new Validator(rules);
219
- },
220
-
221
- /**
222
- * 外部调用方法
223
- * 设置数据,用于设置表单数据,公开给用户使用 , 不支持在动态表单中使用
224
- * @param {Object} key
225
- * @param {Object} value
226
- */
227
- setValue(key, value) {
228
- let example = this.childrens.find((child) => child.name === key);
229
- if (!example) return null;
230
- this.formData[key] = getValue(
231
- key,
232
- value,
233
- (this.formRules[key] && this.formRules[key].rules) || []
234
- );
235
- return example.onFieldChange(this.formData[key]);
236
- },
237
-
238
- /**
239
- * 外部调用方法
240
- * 手动提交校验表单
241
- * 对整个表单进行校验的方法,参数为一个回调函数。
242
- * @param {Array} keepitem 保留不参与校验的字段
243
- * @param {type} callback 方法回调
244
- */
245
- validate(keepitem, callback) {
246
- return this.checkAll(this.formData, keepitem, callback);
247
- },
248
-
249
- /**
250
- * 外部调用方法
251
- * 部分表单校验
252
- * @param {Array|String} props 需要校验的字段
253
- * @param {Function} 回调函数
254
- */
255
- validateField(props = [], callback) {
256
- props = [].concat(props);
257
- let invalidFields = {};
258
- this.childrens.forEach((item) => {
259
- const name = realName(item.name);
260
- if (props.indexOf(name) !== -1) {
261
- invalidFields = Object.assign({}, invalidFields, {
262
- [name]: this.formData[name]
263
- });
264
- }
265
- });
266
- return this.checkAll(invalidFields, [], callback);
267
- },
268
-
269
- /**
270
- * 外部调用方法
271
- * 移除表单项的校验结果。传入待移除的表单项的 prop 属性或者 prop 组成的数组,如不传则移除整个表单的校验结果
272
- * @param {Array|String} props 需要移除校验的字段 ,不填为所有
273
- */
274
- clearValidate(props = []) {
275
- props = [].concat(props);
276
- this.childrens.forEach((item) => {
277
- if (props.length === 0) {
278
- item.errMsg = '';
279
- } else {
280
- const name = realName(item.name);
281
- if (props.indexOf(name) !== -1) {
282
- item.errMsg = '';
283
- }
284
- }
285
- });
286
- },
287
-
288
- /**
289
- * 外部调用方法 ,即将废弃
290
- * 手动提交校验表单
291
- * 对整个表单进行校验的方法,参数为一个回调函数。
292
- * @param {Array} keepitem 保留不参与校验的字段
293
- * @param {type} callback 方法回调
294
- */
295
- submit(keepitem, callback, type) {
296
- for (let i in this.dataValue) {
297
- const itemData = this.childrens.find((v) => v.name === i);
298
- if (itemData) {
299
- if (this.formData[i] === undefined) {
300
- this.formData[i] = this._getValue(i, this.dataValue[i]);
301
- }
302
- }
303
- }
304
-
305
- if (!type) {
306
- console.warn('submit 方法即将废弃,请使用validate方法代替!');
307
- }
308
-
309
- return this.checkAll(this.formData, keepitem, callback, 'submit');
310
- },
311
-
312
- // 校验所有
313
- async checkAll(invalidFields, keepitem, callback, type) {
314
- // 不存在校验规则 ,则停止校验流程
315
- if (!this.validator) return;
316
- let childrens = [];
317
- // 处理参与校验的item实例
318
- for (let i in invalidFields) {
319
- const item = this.childrens.find((v) => realName(v.name) === i);
320
- if (item) {
321
- childrens.push(item);
322
- }
323
- }
324
-
325
- // 如果validate第一个参数是funciont ,那就走回调
326
- if (!callback && typeof keepitem === 'function') {
327
- callback = keepitem;
328
- }
329
-
330
- let promise;
331
- // 如果不存在回调,那么使用 Promise 方式返回
332
- if (!callback && typeof callback !== 'function' && Promise) {
333
- promise = new Promise((resolve, reject) => {
334
- callback = function (valid, invalidFields) {
335
- !valid ? resolve(invalidFields) : reject(valid);
336
- };
337
- });
338
- }
339
-
340
- let results = [];
341
- // 避免引用错乱 ,建议拷贝对象处理
342
- let tempFormData = JSON.parse(JSON.stringify(invalidFields));
343
- // 所有子组件参与校验,使用 for 可以使用 awiat
344
- for (let i in childrens) {
345
- const child = childrens[i];
346
- let name = realName(child.name);
347
- const result = await child.onFieldChange(tempFormData[name]);
348
- if (result) {
349
- results.push(result);
350
- // toast ,modal 只需要执行第一次就可以
351
- if (this.errShowType === 'toast' || this.errShowType === 'modal')
352
- break;
353
- }
354
- }
355
-
356
- if (Array.isArray(results)) {
357
- if (results.length === 0) results = null;
358
- }
359
- if (Array.isArray(keepitem)) {
360
- keepitem.forEach((v) => {
361
- let vName = realName(v);
362
- let value = getDataValue(v, this.localData);
363
- if (value !== undefined) {
364
- tempFormData[vName] = value;
365
- }
366
- });
367
- }
368
-
369
- // TODO submit 即将废弃
370
- if (type === 'submit') {
371
- this.$emit('submit', {
372
- detail: {
373
- value: tempFormData,
374
- errors: results
375
- }
376
- });
377
- } else {
378
- this.$emit('validate', results);
379
- }
380
-
381
- // const resetFormData = rawData(tempFormData, this.localData, this.name)
382
- let resetFormData = {};
383
- resetFormData = rawData(tempFormData, this.name);
384
- callback &&
385
- typeof callback === 'function' &&
386
- callback(results, resetFormData);
387
-
388
- if (promise && callback) {
389
- return promise;
390
- } else {
391
- return null;
392
- }
393
- },
394
-
395
- /**
396
- * 返回validate事件
397
- * @param {Object} result
398
- */
399
- validateCheck(result) {
400
- this.$emit('validate', result);
401
- },
402
- _getValue: getValue,
403
- _isRequiredField: isRequiredField,
404
- _setDataValue: setDataValue,
405
- _getDataValue: getDataValue,
406
- _realName: realName,
407
- _isRealName: isRealName,
408
- _isEqual: isEqual
409
- }
410
- };
411
- </script>
412
-
413
- <style lang="scss">
414
- .uni-forms {
415
- }
416
- </style>
@@ -1,293 +0,0 @@
1
- /**
2
- * 简单处理对象拷贝
3
- * @param {Obejct} 被拷贝对象
4
- * @@return {Object} 拷贝对象
5
- */
6
- export const deepCopy = (val) => {
7
- return JSON.parse(JSON.stringify(val))
8
- }
9
- /**
10
- * 过滤数字类型
11
- * @param {String} format 数字类型
12
- * @@return {Boolean} 返回是否为数字类型
13
- */
14
- export const typeFilter = (format) => {
15
- return format === 'int' || format === 'double' || format === 'number' || format === 'timestamp';
16
- }
17
-
18
- /**
19
- * 把 value 转换成指定的类型,用于处理初始值,原因是初始值需要入库不能为 undefined
20
- * @param {String} key 字段名
21
- * @param {any} value 字段值
22
- * @param {Object} rules 表单校验规则
23
- */
24
- export const getValue = (key, value, rules) => {
25
- const isRuleNumType = rules.find(val => val.format && typeFilter(val.format));
26
- const isRuleBoolType = rules.find(val => (val.format && val.format === 'boolean') || val.format === 'bool');
27
- // 输入类型为 number
28
- if (!!isRuleNumType) {
29
- if (!value && value !== 0) {
30
- value = null
31
- } else {
32
- value = isNumber(Number(value)) ? Number(value) : value
33
- }
34
- }
35
-
36
- // 输入类型为 boolean
37
- if (!!isRuleBoolType) {
38
- value = isBoolean(value) ? value : false
39
- }
40
-
41
- return value;
42
- }
43
-
44
- /**
45
- * 获取表单数据
46
- * @param {String|Array} name 真实名称,需要使用 realName 获取
47
- * @param {Object} data 原始数据
48
- * @param {any} value 需要设置的值
49
- */
50
- export const setDataValue = (field, formdata, value) => {
51
- formdata[field] = value
52
- return value || ''
53
- }
54
-
55
- /**
56
- * 获取表单数据
57
- * @param {String|Array} field 真实名称,需要使用 realName 获取
58
- * @param {Object} data 原始数据
59
- */
60
- export const getDataValue = (field, data) => {
61
- return objGet(data, field)
62
- }
63
-
64
- /**
65
- * 获取表单类型
66
- * @param {String|Array} field 真实名称,需要使用 realName 获取
67
- */
68
- export const getDataValueType = (field, data) => {
69
- const value = getDataValue(field, data)
70
- return {
71
- type: type(value),
72
- value
73
- }
74
- }
75
-
76
- /**
77
- * 获取表单可用的真实name
78
- * @param {String|Array} name 表单name
79
- * @@return {String} 表单可用的真实name
80
- */
81
- export const realName = (name, data = {}) => {
82
- const base_name = _basePath(name)
83
- if (typeof base_name === 'object' && Array.isArray(base_name) && base_name.length > 1) {
84
- const realname = base_name.reduce((a, b) => a += `#${b}`, '_formdata_')
85
- return realname
86
- }
87
- return base_name[0] || name
88
- }
89
-
90
- /**
91
- * 判断是否表单可用的真实name
92
- * @param {String|Array} name 表单name
93
- * @@return {String} 表单可用的真实name
94
- */
95
- export const isRealName = (name) => {
96
- const reg = /^_formdata_#*/
97
- return reg.test(name)
98
- }
99
-
100
- /**
101
- * 获取表单数据的原始格式
102
- * @@return {Object|Array} object 需要解析的数据
103
- */
104
- export const rawData = (object = {}, name) => {
105
- let newData = JSON.parse(JSON.stringify(object))
106
- let formData = {}
107
- for(let i in newData){
108
- let path = name2arr(i)
109
- objSet(formData,path,newData[i])
110
- }
111
- return formData
112
- }
113
-
114
- /**
115
- * 真实name还原为 array
116
- * @param {*} name
117
- */
118
- export const name2arr = (name) => {
119
- let field = name.replace('_formdata_#', '')
120
- field = field.split('#').map(v => (isNumber(v) ? Number(v) : v))
121
- return field
122
- }
123
-
124
- /**
125
- * 对象中设置值
126
- * @param {Object|Array} object 源数据
127
- * @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
128
- * @param {String} value 需要设置的值
129
- */
130
- export const objSet = (object, path, value) => {
131
- if (typeof object !== 'object') return object;
132
- _basePath(path).reduce((o, k, i, _) => {
133
- if (i === _.length - 1) {
134
- // 若遍历结束直接赋值
135
- o[k] = value
136
- return null
137
- } else if (k in o) {
138
- // 若存在对应路径,则返回找到的对象,进行下一次遍历
139
- return o[k]
140
- } else {
141
- // 若不存在对应路径,则创建对应对象,若下一路径是数字,新对象赋值为空数组,否则赋值为空对象
142
- o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {}
143
- return o[k]
144
- }
145
- }, object)
146
- // 返回object
147
- return object;
148
- }
149
-
150
- // 处理 path, path有三种形式:'a[0].b.c'、'a.0.b.c' 和 ['a','0','b','c'],需要统一处理成数组,便于后续使用
151
- function _basePath(path) {
152
- // 若是数组,则直接返回
153
- if (Array.isArray(path)) return path
154
- // 若有 '[',']',则替换成将 '[' 替换成 '.',去掉 ']'
155
- return path.replace(/\[/g, '.').replace(/\]/g, '').split('.')
156
- }
157
-
158
- /**
159
- * 从对象中获取值
160
- * @param {Object|Array} object 源数据
161
- * @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
162
- * @param {String} defaultVal 如果无法从调用链中获取值的默认值
163
- */
164
- export const objGet = (object, path, defaultVal = 'undefined') => {
165
- // 先将path处理成统一格式
166
- let newPath = _basePath(path)
167
- // 递归处理,返回最后结果
168
- let val = newPath.reduce((o, k) => {
169
- return (o || {})[k]
170
- }, object);
171
- return !val || val !== undefined ? val : defaultVal
172
- }
173
-
174
-
175
- /**
176
- * 是否为 number 类型
177
- * @param {any} num 需要判断的值
178
- * @return {Boolean} 是否为 number
179
- */
180
- export const isNumber = (num) => {
181
- return !isNaN(Number(num))
182
- }
183
-
184
- /**
185
- * 是否为 boolean 类型
186
- * @param {any} bool 需要判断的值
187
- * @return {Boolean} 是否为 boolean
188
- */
189
- export const isBoolean = (bool) => {
190
- return (typeof bool === 'boolean')
191
- }
192
- /**
193
- * 是否有必填字段
194
- * @param {Object} rules 规则
195
- * @return {Boolean} 是否有必填字段
196
- */
197
- export const isRequiredField = (rules) => {
198
- let isNoField = false;
199
- for (let i = 0; i < rules.length; i++) {
200
- const ruleData = rules[i];
201
- if (ruleData.required) {
202
- isNoField = true;
203
- break;
204
- }
205
- }
206
- return isNoField;
207
- }
208
-
209
-
210
- /**
211
- * 获取数据类型
212
- * @param {Any} obj 需要获取数据类型的值
213
- */
214
- export const type = (obj) => {
215
- var class2type = {};
216
-
217
- // 生成class2type映射
218
- "Boolean Number String Function Array Date RegExp Object Error".split(" ").map(function(item, index) {
219
- class2type["[object " + item + "]"] = item.toLowerCase();
220
- })
221
- if (obj == null) {
222
- return obj + "";
223
- }
224
- return typeof obj === "object" || typeof obj === "function" ?
225
- class2type[Object.prototype.toString.call(obj)] || "object" :
226
- typeof obj;
227
- }
228
-
229
- /**
230
- * 判断两个值是否相等
231
- * @param {any} a 值
232
- * @param {any} b 值
233
- * @return {Boolean} 是否相等
234
- */
235
- export const isEqual = (a, b) => {
236
- //如果a和b本来就全等
237
- if (a === b) {
238
- //判断是否为0和-0
239
- return a !== 0 || 1 / a === 1 / b;
240
- }
241
- //判断是否为null和undefined
242
- if (a == null || b == null) {
243
- return a === b;
244
- }
245
- //接下来判断a和b的数据类型
246
- var classNameA = toString.call(a),
247
- classNameB = toString.call(b);
248
- //如果数据类型不相等,则返回false
249
- if (classNameA !== classNameB) {
250
- return false;
251
- }
252
- //如果数据类型相等,再根据不同数据类型分别判断
253
- switch (classNameA) {
254
- case '[object RegExp]':
255
- case '[object String]':
256
- //进行字符串转换比较
257
- return '' + a === '' + b;
258
- case '[object Number]':
259
- //进行数字转换比较,判断是否为NaN
260
- if (+a !== +a) {
261
- return +b !== +b;
262
- }
263
- //判断是否为0或-0
264
- return +a === 0 ? 1 / +a === 1 / b : +a === +b;
265
- case '[object Date]':
266
- case '[object Boolean]':
267
- return +a === +b;
268
- }
269
- //如果是对象类型
270
- if (classNameA == '[object Object]') {
271
- //获取a和b的属性长度
272
- var propsA = Object.getOwnPropertyNames(a),
273
- propsB = Object.getOwnPropertyNames(b);
274
- if (propsA.length != propsB.length) {
275
- return false;
276
- }
277
- for (var i = 0; i < propsA.length; i++) {
278
- var propName = propsA[i];
279
- //如果对应属性对应值不相等,则返回false
280
- if (a[propName] !== b[propName]) {
281
- return false;
282
- }
283
- }
284
- return true;
285
- }
286
- //如果是数组类型
287
- if (classNameA == '[object Array]') {
288
- if (a.toString() == b.toString()) {
289
- return true;
290
- }
291
- return false;
292
- }
293
- }