解决微信小程序首页空白问题。
This commit is contained in:
@@ -1,352 +0,0 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const _sfc_main = {
|
||||
name: "uniFormsItem",
|
||||
options: {
|
||||
virtualHost: true
|
||||
},
|
||||
provide() {
|
||||
return {
|
||||
uniFormItem: this
|
||||
};
|
||||
},
|
||||
inject: {
|
||||
form: {
|
||||
from: "uniForm",
|
||||
default: null
|
||||
}
|
||||
},
|
||||
props: {
|
||||
// 表单校验规则
|
||||
rules: {
|
||||
type: Array,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
// 表单域的属性名,在使用校验规则时必填
|
||||
name: {
|
||||
type: [String, Array],
|
||||
default: ""
|
||||
},
|
||||
required: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
// label的宽度
|
||||
labelWidth: {
|
||||
type: [String, Number],
|
||||
default: ""
|
||||
},
|
||||
// label 居中方式,默认 left 取值 left/center/right
|
||||
labelAlign: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
// 强制显示错误信息
|
||||
errorMessage: {
|
||||
type: [String, Boolean],
|
||||
default: ""
|
||||
},
|
||||
// 1.4.0 弃用,统一使用 form 的校验时机
|
||||
// validateTrigger: {
|
||||
// type: String,
|
||||
// default: ''
|
||||
// },
|
||||
// 1.4.0 弃用,统一使用 form 的label 位置
|
||||
// labelPosition: {
|
||||
// type: String,
|
||||
// default: ''
|
||||
// },
|
||||
// 1.4.0 以下属性已经废弃,请使用 #label 插槽代替
|
||||
leftIcon: String,
|
||||
iconColor: {
|
||||
type: String,
|
||||
default: "#606266"
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
errMsg: "",
|
||||
userRules: null,
|
||||
localLabelAlign: "left",
|
||||
localLabelWidth: "70px",
|
||||
localLabelPos: "left",
|
||||
border: false,
|
||||
isFirstBorder: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 处理错误信息
|
||||
msg() {
|
||||
return this.errorMessage || this.errMsg;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 规则发生变化通知子组件更新
|
||||
"form.formRules"(val) {
|
||||
this.init();
|
||||
},
|
||||
"form.labelWidth"(val) {
|
||||
this.localLabelWidth = this._labelWidthUnit(val);
|
||||
},
|
||||
"form.labelPosition"(val) {
|
||||
this.localLabelPos = this._labelPosition();
|
||||
},
|
||||
"form.labelAlign"(val) {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.init(true);
|
||||
if (this.name && this.form) {
|
||||
this.$watch(
|
||||
() => {
|
||||
const val = this.form._getDataValue(this.name, this.form.localData);
|
||||
return val;
|
||||
},
|
||||
(value, oldVal) => {
|
||||
const isEqual = this.form._isEqual(value, oldVal);
|
||||
if (!isEqual) {
|
||||
const val = this.itemSetValue(value);
|
||||
this.onFieldChange(val, false);
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
unmounted() {
|
||||
this.__isUnmounted = true;
|
||||
this.unInit();
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 设置规则 ,主要用于小程序自定义检验规则
|
||||
* @param {Array} rules 规则源数据
|
||||
*/
|
||||
setRules(rules = null) {
|
||||
this.userRules = rules;
|
||||
this.init(false);
|
||||
},
|
||||
// 兼容老版本表单组件
|
||||
setValue() {
|
||||
},
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 校验数据
|
||||
* @param {any} value 需要校验的数据
|
||||
* @param {boolean} 是否立即校验
|
||||
* @return {Array|null} 校验内容
|
||||
*/
|
||||
async onFieldChange(value, formtrigger = true) {
|
||||
const {
|
||||
formData,
|
||||
localData,
|
||||
errShowType,
|
||||
validateCheck,
|
||||
validateTrigger,
|
||||
_isRequiredField,
|
||||
_realName
|
||||
} = this.form;
|
||||
const name = _realName(this.name);
|
||||
if (!value) {
|
||||
value = this.form.formData[name];
|
||||
}
|
||||
const ruleLen = this.itemRules.rules && this.itemRules.rules.length;
|
||||
if (!this.validator || !ruleLen || ruleLen === 0)
|
||||
return;
|
||||
const isRequiredField = _isRequiredField(this.itemRules.rules || []);
|
||||
let result = null;
|
||||
if (validateTrigger === "bind" || formtrigger) {
|
||||
result = await this.validator.validateUpdate(
|
||||
{
|
||||
[name]: value
|
||||
},
|
||||
formData
|
||||
);
|
||||
if (!isRequiredField && (value === void 0 || value === "")) {
|
||||
result = null;
|
||||
}
|
||||
if (result && result.errorMessage) {
|
||||
if (errShowType === "undertext") {
|
||||
this.errMsg = !result ? "" : result.errorMessage;
|
||||
}
|
||||
if (errShowType === "toast") {
|
||||
common_vendor.index.showToast({
|
||||
title: result.errorMessage || "校验错误",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
if (errShowType === "modal") {
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: result.errorMessage || "校验错误"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.errMsg = "";
|
||||
}
|
||||
validateCheck(result ? result : null);
|
||||
} else {
|
||||
this.errMsg = "";
|
||||
}
|
||||
return result ? result : null;
|
||||
},
|
||||
/**
|
||||
* 初始组件数据
|
||||
*/
|
||||
init(type = false) {
|
||||
const {
|
||||
validator,
|
||||
formRules,
|
||||
childrens,
|
||||
formData,
|
||||
localData,
|
||||
_realName,
|
||||
labelWidth,
|
||||
_getDataValue,
|
||||
_setDataValue
|
||||
} = this.form || {};
|
||||
this.localLabelAlign = this._justifyContent();
|
||||
this.localLabelWidth = this._labelWidthUnit(labelWidth);
|
||||
this.localLabelPos = this._labelPosition();
|
||||
this.form && type && childrens.push(this);
|
||||
if (!validator || !formRules)
|
||||
return;
|
||||
if (!this.form.isFirstBorder) {
|
||||
this.form.isFirstBorder = true;
|
||||
this.isFirstBorder = true;
|
||||
}
|
||||
if (this.group) {
|
||||
if (!this.group.isFirstBorder) {
|
||||
this.group.isFirstBorder = true;
|
||||
this.isFirstBorder = true;
|
||||
}
|
||||
}
|
||||
this.border = this.form.border;
|
||||
const name = _realName(this.name);
|
||||
const itemRule = this.userRules || this.rules;
|
||||
if (typeof formRules === "object" && itemRule) {
|
||||
formRules[name] = {
|
||||
rules: itemRule
|
||||
};
|
||||
validator.updateSchema(formRules);
|
||||
}
|
||||
const itemRules = formRules[name] || {};
|
||||
this.itemRules = itemRules;
|
||||
this.validator = validator;
|
||||
this.itemSetValue(_getDataValue(this.name, localData));
|
||||
},
|
||||
unInit() {
|
||||
if (this.form) {
|
||||
const {
|
||||
childrens,
|
||||
formData,
|
||||
_realName
|
||||
} = this.form;
|
||||
childrens.forEach((item, index) => {
|
||||
if (item === this) {
|
||||
this.form.childrens.splice(index, 1);
|
||||
delete formData[_realName(item.name)];
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
// 设置item 的值
|
||||
itemSetValue(value) {
|
||||
const name = this.form._realName(this.name);
|
||||
const rules = this.itemRules.rules || [];
|
||||
const val = this.form._getValue(name, value, rules);
|
||||
this.form._setDataValue(name, this.form.formData, val);
|
||||
return val;
|
||||
},
|
||||
/**
|
||||
* 移除该表单项的校验结果
|
||||
*/
|
||||
clearValidate() {
|
||||
this.errMsg = "";
|
||||
},
|
||||
// 是否显示星号
|
||||
_isRequired() {
|
||||
return this.required;
|
||||
},
|
||||
// 处理对齐方式
|
||||
_justifyContent() {
|
||||
if (this.form) {
|
||||
const {
|
||||
labelAlign
|
||||
} = this.form;
|
||||
let labelAli = this.labelAlign ? this.labelAlign : labelAlign;
|
||||
if (labelAli === "left")
|
||||
return "flex-start";
|
||||
if (labelAli === "center")
|
||||
return "center";
|
||||
if (labelAli === "right")
|
||||
return "flex-end";
|
||||
}
|
||||
return "flex-start";
|
||||
},
|
||||
// 处理 label宽度单位 ,继承父元素的值
|
||||
_labelWidthUnit(labelWidth) {
|
||||
return this.num2px(this.labelWidth ? this.labelWidth : labelWidth || (this.label ? 70 : "auto"));
|
||||
},
|
||||
// 处理 label 位置
|
||||
_labelPosition() {
|
||||
if (this.form)
|
||||
return this.form.labelPosition || "left";
|
||||
return "left";
|
||||
},
|
||||
/**
|
||||
* 触发时机
|
||||
* @param {Object} rule 当前规则内时机
|
||||
* @param {Object} itemRlue 当前组件时机
|
||||
* @param {Object} parentRule 父组件时机
|
||||
*/
|
||||
isTrigger(rule, itemRlue, parentRule) {
|
||||
if (rule === "submit" || !rule) {
|
||||
if (rule === void 0) {
|
||||
if (itemRlue !== "bind") {
|
||||
if (!itemRlue) {
|
||||
return parentRule === "" ? "bind" : "submit";
|
||||
}
|
||||
return "submit";
|
||||
}
|
||||
return "bind";
|
||||
}
|
||||
return "submit";
|
||||
}
|
||||
return "bind";
|
||||
},
|
||||
num2px(num) {
|
||||
if (typeof num === "number") {
|
||||
return `${num}px`;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return common_vendor.e({
|
||||
a: $props.required
|
||||
}, $props.required ? {} : {}, {
|
||||
b: common_vendor.t($props.label),
|
||||
c: !$props.label && !$props.required ? 1 : "",
|
||||
d: $data.localLabelWidth,
|
||||
e: $data.localLabelAlign,
|
||||
f: common_vendor.t($options.msg),
|
||||
g: $options.msg ? 1 : "",
|
||||
h: common_vendor.n("is-direction-" + $data.localLabelPos),
|
||||
i: common_vendor.n($data.border ? "uni-forms-item--border" : ""),
|
||||
j: common_vendor.n($data.border && $data.isFirstBorder ? "is-first-border" : "")
|
||||
});
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js.map
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="{{['uni-forms-item', h, i, j]}}"><block wx:if="{{$slots.label}}"><slot name="label"></slot></block><block wx:else><view class="{{['uni-forms-item__label', c && 'no-label']}}" style="{{'width:' + d + ';' + ('justify-content:' + e)}}"><text wx:if="{{a}}" class="is-required">*</text><text>{{b}}</text></view></block><view class="uni-forms-item__content"><slot></slot><view class="{{['uni-forms-item__error', g && 'msg--active']}}"><text>{{f}}</text></view></view></view>
|
||||
@@ -1,114 +0,0 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.uni-forms-item {
|
||||
position: relative;
|
||||
display: flex;
|
||||
margin-bottom: 22px;
|
||||
flex-direction: row;
|
||||
}
|
||||
.uni-forms-item__label {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
text-align: left;
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
height: 36px;
|
||||
padding: 0 12px 0 0;
|
||||
vertical-align: middle;
|
||||
flex-shrink: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.uni-forms-item__label.no-label {
|
||||
padding: 0;
|
||||
}
|
||||
.uni-forms-item__content {
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
flex: 1;
|
||||
box-sizing: border-box;
|
||||
flex-direction: row;
|
||||
}
|
||||
.uni-forms-item .uni-forms-item__nuve-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
.uni-forms-item__error {
|
||||
color: #f56c6c;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
padding-top: 4px;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
transition: transform 0.3s;
|
||||
transform: translateY(-100%);
|
||||
opacity: 0;
|
||||
}
|
||||
.uni-forms-item__error .error-text {
|
||||
color: #f56c6c;
|
||||
font-size: 12px;
|
||||
}
|
||||
.uni-forms-item__error.msg--active {
|
||||
opacity: 1;
|
||||
transform: translateY(0%);
|
||||
}
|
||||
.uni-forms-item.is-direction-left {
|
||||
flex-direction: row;
|
||||
}
|
||||
.uni-forms-item.is-direction-top {
|
||||
flex-direction: column;
|
||||
}
|
||||
.uni-forms-item.is-direction-top .uni-forms-item__label {
|
||||
padding: 0 0 8px;
|
||||
line-height: 1.5715;
|
||||
text-align: left;
|
||||
white-space: initial;
|
||||
}
|
||||
.uni-forms-item .is-required {
|
||||
color: #dd524d;
|
||||
font-weight: bold;
|
||||
}
|
||||
.uni-forms-item--border {
|
||||
margin-bottom: 0;
|
||||
padding: 10px 0;
|
||||
border-top: 1px #eee solid;
|
||||
}
|
||||
.uni-forms-item--border .uni-forms-item__content {
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.uni-forms-item--border .uni-forms-item__content .uni-forms-item__error {
|
||||
position: relative;
|
||||
top: 5px;
|
||||
left: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
.is-first-border {
|
||||
border: none;
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const uni_modules_uniForms_components_uniForms_validate = require("./validate.js");
|
||||
const uni_modules_uniForms_components_uniForms_utils = require("./utils.js");
|
||||
const _sfc_main = {
|
||||
name: "uniForms",
|
||||
emits: ["validate", "submit"],
|
||||
options: {
|
||||
virtualHost: true
|
||||
},
|
||||
props: {
|
||||
// 即将弃用
|
||||
value: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
// vue3 替换 value 属性
|
||||
modelValue: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
// 1.4.0 开始将不支持 v-model ,且废弃 value 和 modelValue
|
||||
model: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
// 表单校验规则
|
||||
rules: {
|
||||
type: Object,
|
||||
default() {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
//校验错误信息提示方式 默认 undertext 取值 [undertext|toast|modal]
|
||||
errShowType: {
|
||||
type: String,
|
||||
default: "undertext"
|
||||
},
|
||||
// 校验触发器方式 默认 bind 取值 [bind|submit]
|
||||
validateTrigger: {
|
||||
type: String,
|
||||
default: "submit"
|
||||
},
|
||||
// label 位置,默认 left 取值 top/left
|
||||
labelPosition: {
|
||||
type: String,
|
||||
default: "left"
|
||||
},
|
||||
// label 宽度
|
||||
labelWidth: {
|
||||
type: [String, Number],
|
||||
default: ""
|
||||
},
|
||||
// label 居中方式,默认 left 取值 left/center/right
|
||||
labelAlign: {
|
||||
type: String,
|
||||
default: "left"
|
||||
},
|
||||
border: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
provide() {
|
||||
return {
|
||||
uniForm: this
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 表单本地值的记录,不应该与传如的值进行关联
|
||||
formData: {},
|
||||
formRules: {}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 计算数据源变化的
|
||||
localData() {
|
||||
const localVal = this.model || this.modelValue || this.value;
|
||||
if (localVal) {
|
||||
return uni_modules_uniForms_components_uniForms_utils.deepCopy(localVal);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 监听数据变化 ,暂时不使用,需要单独赋值
|
||||
// localData: {},
|
||||
// 监听规则变化
|
||||
rules: {
|
||||
handler: function(val, oldVal) {
|
||||
this.setRules(val);
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
created() {
|
||||
let getbinddata = getApp().$vm.$.appContext.config.globalProperties.binddata;
|
||||
if (!getbinddata) {
|
||||
getApp().$vm.$.appContext.config.globalProperties.binddata = function(name, value, formName) {
|
||||
if (formName) {
|
||||
this.$refs[formName].setValue(name, value);
|
||||
} else {
|
||||
let formVm;
|
||||
for (let i in this.$refs) {
|
||||
const vm = this.$refs[i];
|
||||
if (vm && vm.$options && vm.$options.name === "uniForms") {
|
||||
formVm = vm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!formVm)
|
||||
return common_vendor.index.__f__("error", "at uni_modules/uni-forms/components/uni-forms/uni-forms.vue:187", "当前 uni-froms 组件缺少 ref 属性");
|
||||
if (formVm.model)
|
||||
formVm.model[name] = value;
|
||||
if (formVm.modelValue)
|
||||
formVm.modelValue[name] = value;
|
||||
if (formVm.value)
|
||||
formVm.value[name] = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
this.childrens = [];
|
||||
this.inputChildrens = [];
|
||||
this.setRules(this.rules);
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 设置规则 ,主要用于小程序自定义检验规则
|
||||
* @param {Array} rules 规则源数据
|
||||
*/
|
||||
setRules(rules) {
|
||||
this.formRules = Object.assign({}, this.formRules, rules);
|
||||
this.validator = new uni_modules_uniForms_components_uniForms_validate.SchemaValidator(rules);
|
||||
},
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 设置数据,用于设置表单数据,公开给用户使用 , 不支持在动态表单中使用
|
||||
* @param {Object} key
|
||||
* @param {Object} value
|
||||
*/
|
||||
setValue(key, value) {
|
||||
let example = this.childrens.find((child) => child.name === key);
|
||||
if (!example)
|
||||
return null;
|
||||
this.formData[key] = uni_modules_uniForms_components_uniForms_utils.getValue(key, value, this.formRules[key] && this.formRules[key].rules || []);
|
||||
return example.onFieldChange(this.formData[key]);
|
||||
},
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 手动提交校验表单
|
||||
* 对整个表单进行校验的方法,参数为一个回调函数。
|
||||
* @param {Array} keepitem 保留不参与校验的字段
|
||||
* @param {type} callback 方法回调
|
||||
*/
|
||||
validate(keepitem, callback) {
|
||||
return this.checkAll(this.formData, keepitem, callback);
|
||||
},
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 部分表单校验
|
||||
* @param {Array|String} props 需要校验的字段
|
||||
* @param {Function} 回调函数
|
||||
*/
|
||||
validateField(props = [], callback) {
|
||||
props = [].concat(props);
|
||||
let invalidFields = {};
|
||||
this.childrens.forEach((item) => {
|
||||
const name = uni_modules_uniForms_components_uniForms_utils.realName(item.name);
|
||||
if (props.indexOf(name) !== -1) {
|
||||
invalidFields = Object.assign({}, invalidFields, {
|
||||
[name]: this.formData[name]
|
||||
});
|
||||
}
|
||||
});
|
||||
return this.checkAll(invalidFields, [], callback);
|
||||
},
|
||||
/**
|
||||
* 外部调用方法
|
||||
* 移除表单项的校验结果。传入待移除的表单项的 prop 属性或者 prop 组成的数组,如不传则移除整个表单的校验结果
|
||||
* @param {Array|String} props 需要移除校验的字段 ,不填为所有
|
||||
*/
|
||||
clearValidate(props = []) {
|
||||
props = [].concat(props);
|
||||
this.childrens.forEach((item) => {
|
||||
if (props.length === 0) {
|
||||
item.errMsg = "";
|
||||
} else {
|
||||
const name = uni_modules_uniForms_components_uniForms_utils.realName(item.name);
|
||||
if (props.indexOf(name) !== -1) {
|
||||
item.errMsg = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 外部调用方法 ,即将废弃
|
||||
* 手动提交校验表单
|
||||
* 对整个表单进行校验的方法,参数为一个回调函数。
|
||||
* @param {Array} keepitem 保留不参与校验的字段
|
||||
* @param {type} callback 方法回调
|
||||
*/
|
||||
submit(keepitem, callback, type) {
|
||||
for (let i in this.dataValue) {
|
||||
const itemData = this.childrens.find((v) => v.name === i);
|
||||
if (itemData) {
|
||||
if (this.formData[i] === void 0) {
|
||||
this.formData[i] = this._getValue(i, this.dataValue[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!type) {
|
||||
common_vendor.index.__f__("warn", "at uni_modules/uni-forms/components/uni-forms/uni-forms.vue:296", "submit 方法即将废弃,请使用validate方法代替!");
|
||||
}
|
||||
return this.checkAll(this.formData, keepitem, callback, "submit");
|
||||
},
|
||||
// 校验所有
|
||||
async checkAll(invalidFields, keepitem, callback, type) {
|
||||
if (!this.validator)
|
||||
return;
|
||||
let childrens = [];
|
||||
for (let i in invalidFields) {
|
||||
const item = this.childrens.find((v) => uni_modules_uniForms_components_uniForms_utils.realName(v.name) === i);
|
||||
if (item) {
|
||||
childrens.push(item);
|
||||
}
|
||||
}
|
||||
if (!callback && typeof keepitem === "function") {
|
||||
callback = keepitem;
|
||||
}
|
||||
let promise;
|
||||
if (!callback && typeof callback !== "function" && Promise) {
|
||||
promise = new Promise((resolve, reject) => {
|
||||
callback = function(valid, invalidFields2) {
|
||||
!valid ? resolve(invalidFields2) : reject(valid);
|
||||
};
|
||||
});
|
||||
}
|
||||
let results = [];
|
||||
let tempFormData = JSON.parse(JSON.stringify(invalidFields));
|
||||
for (let i in childrens) {
|
||||
const child = childrens[i];
|
||||
let name = uni_modules_uniForms_components_uniForms_utils.realName(child.name);
|
||||
const result = await child.onFieldChange(tempFormData[name]);
|
||||
if (result) {
|
||||
results.push(result);
|
||||
if (this.errShowType === "toast" || this.errShowType === "modal")
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(results)) {
|
||||
if (results.length === 0)
|
||||
results = null;
|
||||
}
|
||||
if (Array.isArray(keepitem)) {
|
||||
keepitem.forEach((v) => {
|
||||
let vName = uni_modules_uniForms_components_uniForms_utils.realName(v);
|
||||
let value = uni_modules_uniForms_components_uniForms_utils.getDataValue(v, this.localData);
|
||||
if (value !== void 0) {
|
||||
tempFormData[vName] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (type === "submit") {
|
||||
this.$emit("submit", {
|
||||
detail: {
|
||||
value: tempFormData,
|
||||
errors: results
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.$emit("validate", results);
|
||||
}
|
||||
let resetFormData = {};
|
||||
resetFormData = uni_modules_uniForms_components_uniForms_utils.rawData(tempFormData, this.name);
|
||||
callback && typeof callback === "function" && callback(results, resetFormData);
|
||||
if (promise && callback) {
|
||||
return promise;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 返回validate事件
|
||||
* @param {Object} result
|
||||
*/
|
||||
validateCheck(result) {
|
||||
this.$emit("validate", result);
|
||||
},
|
||||
_getValue: uni_modules_uniForms_components_uniForms_utils.getValue,
|
||||
_isRequiredField: uni_modules_uniForms_components_uniForms_utils.isRequiredField,
|
||||
_setDataValue: uni_modules_uniForms_components_uniForms_utils.setDataValue,
|
||||
_getDataValue: uni_modules_uniForms_components_uniForms_utils.getDataValue,
|
||||
_realName: uni_modules_uniForms_components_uniForms_utils.realName,
|
||||
_isRealName: uni_modules_uniForms_components_uniForms_utils.isRealName,
|
||||
_isEqual: uni_modules_uniForms_components_uniForms_utils.isEqual
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-forms/components/uni-forms/uni-forms.js.map
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="uni-forms"><form><slot></slot></form></view>
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
@@ -1,154 +0,0 @@
|
||||
"use strict";
|
||||
const deepCopy = (val) => {
|
||||
return JSON.parse(JSON.stringify(val));
|
||||
};
|
||||
const typeFilter = (format) => {
|
||||
return format === "int" || format === "double" || format === "number" || format === "timestamp";
|
||||
};
|
||||
const getValue = (key, value, rules) => {
|
||||
const isRuleNumType = rules.find((val) => val.format && typeFilter(val.format));
|
||||
const isRuleBoolType = rules.find((val) => val.format && val.format === "boolean" || val.format === "bool");
|
||||
if (!!isRuleNumType) {
|
||||
if (!value && value !== 0) {
|
||||
value = null;
|
||||
} else {
|
||||
value = isNumber(Number(value)) ? Number(value) : value;
|
||||
}
|
||||
}
|
||||
if (!!isRuleBoolType) {
|
||||
value = isBoolean(value) ? value : false;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
const setDataValue = (field, formdata, value) => {
|
||||
formdata[field] = value;
|
||||
return value || "";
|
||||
};
|
||||
const getDataValue = (field, data) => {
|
||||
return objGet(data, field);
|
||||
};
|
||||
const realName = (name, data = {}) => {
|
||||
const base_name = _basePath(name);
|
||||
if (typeof base_name === "object" && Array.isArray(base_name) && base_name.length > 1) {
|
||||
const realname = base_name.reduce((a, b) => a += `#${b}`, "_formdata_");
|
||||
return realname;
|
||||
}
|
||||
return base_name[0] || name;
|
||||
};
|
||||
const isRealName = (name) => {
|
||||
const reg = /^_formdata_#*/;
|
||||
return reg.test(name);
|
||||
};
|
||||
const rawData = (object = {}, name) => {
|
||||
let newData = JSON.parse(JSON.stringify(object));
|
||||
let formData = {};
|
||||
for (let i in newData) {
|
||||
let path = name2arr(i);
|
||||
objSet(formData, path, newData[i]);
|
||||
}
|
||||
return formData;
|
||||
};
|
||||
const name2arr = (name) => {
|
||||
let field = name.replace("_formdata_#", "");
|
||||
field = field.split("#").map((v) => isNumber(v) ? Number(v) : v);
|
||||
return field;
|
||||
};
|
||||
const objSet = (object, path, value) => {
|
||||
if (typeof object !== "object")
|
||||
return object;
|
||||
_basePath(path).reduce((o, k, i, _) => {
|
||||
if (i === _.length - 1) {
|
||||
o[k] = value;
|
||||
return null;
|
||||
} else if (k in o) {
|
||||
return o[k];
|
||||
} else {
|
||||
o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {};
|
||||
return o[k];
|
||||
}
|
||||
}, object);
|
||||
return object;
|
||||
};
|
||||
function _basePath(path) {
|
||||
if (Array.isArray(path))
|
||||
return path;
|
||||
return path.replace(/\[/g, ".").replace(/\]/g, "").split(".");
|
||||
}
|
||||
const objGet = (object, path, defaultVal = "undefined") => {
|
||||
let newPath = _basePath(path);
|
||||
let val = newPath.reduce((o, k) => {
|
||||
return (o || {})[k];
|
||||
}, object);
|
||||
return !val || val !== void 0 ? val : defaultVal;
|
||||
};
|
||||
const isNumber = (num) => {
|
||||
return !isNaN(Number(num));
|
||||
};
|
||||
const isBoolean = (bool) => {
|
||||
return typeof bool === "boolean";
|
||||
};
|
||||
const isRequiredField = (rules) => {
|
||||
let isNoField = false;
|
||||
for (let i = 0; i < rules.length; i++) {
|
||||
const ruleData = rules[i];
|
||||
if (ruleData.required) {
|
||||
isNoField = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isNoField;
|
||||
};
|
||||
const isEqual = (a, b) => {
|
||||
if (a === b) {
|
||||
return a !== 0 || 1 / a === 1 / b;
|
||||
}
|
||||
if (a == null || b == null) {
|
||||
return a === b;
|
||||
}
|
||||
var classNameA = toString.call(a), classNameB = toString.call(b);
|
||||
if (classNameA !== classNameB) {
|
||||
return false;
|
||||
}
|
||||
switch (classNameA) {
|
||||
case "[object RegExp]":
|
||||
case "[object String]":
|
||||
return "" + a === "" + b;
|
||||
case "[object Number]":
|
||||
if (+a !== +a) {
|
||||
return +b !== +b;
|
||||
}
|
||||
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
||||
case "[object Date]":
|
||||
case "[object Boolean]":
|
||||
return +a === +b;
|
||||
}
|
||||
if (classNameA == "[object Object]") {
|
||||
var propsA = Object.getOwnPropertyNames(a), propsB = Object.getOwnPropertyNames(b);
|
||||
if (propsA.length != propsB.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < propsA.length; i++) {
|
||||
var propName = propsA[i];
|
||||
if (a[propName] !== b[propName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (classNameA == "[object Array]") {
|
||||
if (a.toString() == b.toString()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
exports.deepCopy = deepCopy;
|
||||
exports.getDataValue = getDataValue;
|
||||
exports.getValue = getValue;
|
||||
exports.isEqual = isEqual;
|
||||
exports.isRealName = isRealName;
|
||||
exports.isRequiredField = isRequiredField;
|
||||
exports.rawData = rawData;
|
||||
exports.realName = realName;
|
||||
exports.setDataValue = setDataValue;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-forms/components/uni-forms/utils.js.map
|
||||
@@ -1,423 +0,0 @@
|
||||
"use strict";
|
||||
var pattern = {
|
||||
email: /^\S+?@\S+?\.\S+?$/,
|
||||
idcard: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
||||
url: new RegExp(
|
||||
"^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$",
|
||||
"i"
|
||||
)
|
||||
};
|
||||
const FORMAT_MAPPING = {
|
||||
"int": "integer",
|
||||
"bool": "boolean",
|
||||
"double": "number",
|
||||
"long": "number",
|
||||
"password": "string"
|
||||
// "fileurls": 'array'
|
||||
};
|
||||
function formatMessage(args, resources = "") {
|
||||
var defaultMessage = ["label"];
|
||||
defaultMessage.forEach((item) => {
|
||||
if (args[item] === void 0) {
|
||||
args[item] = "";
|
||||
}
|
||||
});
|
||||
let str = resources;
|
||||
for (let key in args) {
|
||||
let reg = new RegExp("{" + key + "}");
|
||||
str = str.replace(reg, args[key]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function isEmptyValue(value, type) {
|
||||
if (value === void 0 || value === null) {
|
||||
return true;
|
||||
}
|
||||
if (typeof value === "string" && !value) {
|
||||
return true;
|
||||
}
|
||||
if (Array.isArray(value) && !value.length) {
|
||||
return true;
|
||||
}
|
||||
if (type === "object" && !Object.keys(value).length) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const types = {
|
||||
integer(value) {
|
||||
return types.number(value) && parseInt(value, 10) === value;
|
||||
},
|
||||
string(value) {
|
||||
return typeof value === "string";
|
||||
},
|
||||
number(value) {
|
||||
if (isNaN(value)) {
|
||||
return false;
|
||||
}
|
||||
return typeof value === "number";
|
||||
},
|
||||
"boolean": function(value) {
|
||||
return typeof value === "boolean";
|
||||
},
|
||||
"float": function(value) {
|
||||
return types.number(value) && !types.integer(value);
|
||||
},
|
||||
array(value) {
|
||||
return Array.isArray(value);
|
||||
},
|
||||
object(value) {
|
||||
return typeof value === "object" && !types.array(value);
|
||||
},
|
||||
date(value) {
|
||||
return value instanceof Date;
|
||||
},
|
||||
timestamp(value) {
|
||||
if (!this.integer(value) || Math.abs(value).toString().length > 16) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
file(value) {
|
||||
return typeof value.url === "string";
|
||||
},
|
||||
email(value) {
|
||||
return typeof value === "string" && !!value.match(pattern.email) && value.length < 255;
|
||||
},
|
||||
url(value) {
|
||||
return typeof value === "string" && !!value.match(pattern.url);
|
||||
},
|
||||
pattern(reg, value) {
|
||||
try {
|
||||
return new RegExp(reg).test(value);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
method(value) {
|
||||
return typeof value === "function";
|
||||
},
|
||||
idcard(value) {
|
||||
return typeof value === "string" && !!value.match(pattern.idcard);
|
||||
},
|
||||
"url-https"(value) {
|
||||
return this.url(value) && value.startsWith("https://");
|
||||
},
|
||||
"url-scheme"(value) {
|
||||
return value.startsWith("://");
|
||||
},
|
||||
"url-web"(value) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class RuleValidator {
|
||||
constructor(message) {
|
||||
this._message = message;
|
||||
}
|
||||
async validateRule(fieldKey, fieldValue, value, data, allData) {
|
||||
var result = null;
|
||||
let rules = fieldValue.rules;
|
||||
let hasRequired = rules.findIndex((item) => {
|
||||
return item.required;
|
||||
});
|
||||
if (hasRequired < 0) {
|
||||
if (value === null || value === void 0) {
|
||||
return result;
|
||||
}
|
||||
if (typeof value === "string" && !value.length) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
var message = this._message;
|
||||
if (rules === void 0) {
|
||||
return message["default"];
|
||||
}
|
||||
for (var i = 0; i < rules.length; i++) {
|
||||
let rule = rules[i];
|
||||
let vt = this._getValidateType(rule);
|
||||
Object.assign(rule, {
|
||||
label: fieldValue.label || `["${fieldKey}"]`
|
||||
});
|
||||
if (RuleValidatorHelper[vt]) {
|
||||
result = RuleValidatorHelper[vt](rule, value, message);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rule.validateExpr) {
|
||||
let now = Date.now();
|
||||
let resultExpr = rule.validateExpr(value, allData, now);
|
||||
if (resultExpr === false) {
|
||||
result = this._getMessage(rule, rule.errorMessage || this._message["default"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rule.validateFunction) {
|
||||
result = await this.validateFunction(rule, value, data, allData, vt);
|
||||
if (result !== null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result !== null) {
|
||||
result = message.TAG + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async validateFunction(rule, value, data, allData, vt) {
|
||||
let result = null;
|
||||
try {
|
||||
let callbackMessage = null;
|
||||
const res = await rule.validateFunction(rule, value, allData || data, (message) => {
|
||||
callbackMessage = message;
|
||||
});
|
||||
if (callbackMessage || typeof res === "string" && res || res === false) {
|
||||
result = this._getMessage(rule, callbackMessage || res, vt);
|
||||
}
|
||||
} catch (e) {
|
||||
result = this._getMessage(rule, e.message, vt);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
_getMessage(rule, message, vt) {
|
||||
return formatMessage(rule, message || rule.errorMessage || this._message[vt] || message["default"]);
|
||||
}
|
||||
_getValidateType(rule) {
|
||||
var result = "";
|
||||
if (rule.required) {
|
||||
result = "required";
|
||||
} else if (rule.format) {
|
||||
result = "format";
|
||||
} else if (rule.arrayType) {
|
||||
result = "arrayTypeFormat";
|
||||
} else if (rule.range) {
|
||||
result = "range";
|
||||
} else if (rule.maximum !== void 0 || rule.minimum !== void 0) {
|
||||
result = "rangeNumber";
|
||||
} else if (rule.maxLength !== void 0 || rule.minLength !== void 0) {
|
||||
result = "rangeLength";
|
||||
} else if (rule.pattern) {
|
||||
result = "pattern";
|
||||
} else if (rule.validateFunction) {
|
||||
result = "validateFunction";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
const RuleValidatorHelper = {
|
||||
required(rule, value, message) {
|
||||
if (rule.required && isEmptyValue(value, rule.format || typeof value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.required);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
range(rule, value, message) {
|
||||
const {
|
||||
range,
|
||||
errorMessage
|
||||
} = rule;
|
||||
let list = new Array(range.length);
|
||||
for (let i = 0; i < range.length; i++) {
|
||||
const item = range[i];
|
||||
if (types.object(item) && item.value !== void 0) {
|
||||
list[i] = item.value;
|
||||
} else {
|
||||
list[i] = item;
|
||||
}
|
||||
}
|
||||
let result = false;
|
||||
if (Array.isArray(value)) {
|
||||
result = new Set(value.concat(list)).size === list.length;
|
||||
} else {
|
||||
if (list.indexOf(value) > -1) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
return formatMessage(rule, errorMessage || message["enum"]);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
rangeNumber(rule, value, message) {
|
||||
if (!types.number(value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||
}
|
||||
let {
|
||||
minimum,
|
||||
maximum,
|
||||
exclusiveMinimum,
|
||||
exclusiveMaximum
|
||||
} = rule;
|
||||
let min = exclusiveMinimum ? value <= minimum : value < minimum;
|
||||
let max = exclusiveMaximum ? value >= maximum : value > maximum;
|
||||
if (minimum !== void 0 && min) {
|
||||
return formatMessage(rule, rule.errorMessage || message["number"][exclusiveMinimum ? "exclusiveMinimum" : "minimum"]);
|
||||
} else if (maximum !== void 0 && max) {
|
||||
return formatMessage(rule, rule.errorMessage || message["number"][exclusiveMaximum ? "exclusiveMaximum" : "maximum"]);
|
||||
} else if (minimum !== void 0 && maximum !== void 0 && (min || max)) {
|
||||
return formatMessage(rule, rule.errorMessage || message["number"].range);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
rangeLength(rule, value, message) {
|
||||
if (!types.string(value) && !types.array(value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||
}
|
||||
let min = rule.minLength;
|
||||
let max = rule.maxLength;
|
||||
let val = value.length;
|
||||
if (min !== void 0 && val < min) {
|
||||
return formatMessage(rule, rule.errorMessage || message["length"].minLength);
|
||||
} else if (max !== void 0 && val > max) {
|
||||
return formatMessage(rule, rule.errorMessage || message["length"].maxLength);
|
||||
} else if (min !== void 0 && max !== void 0 && (val < min || val > max)) {
|
||||
return formatMessage(rule, rule.errorMessage || message["length"].range);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
pattern(rule, value, message) {
|
||||
if (!types["pattern"](rule.pattern, value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
format(rule, value, message) {
|
||||
var customTypes = Object.keys(types);
|
||||
var format = FORMAT_MAPPING[rule.format] ? FORMAT_MAPPING[rule.format] : rule.format || rule.arrayType;
|
||||
if (customTypes.indexOf(format) > -1) {
|
||||
if (!types[format](value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.typeError);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
arrayTypeFormat(rule, value, message) {
|
||||
if (!Array.isArray(value)) {
|
||||
return formatMessage(rule, rule.errorMessage || message.typeError);
|
||||
}
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const element = value[i];
|
||||
let formatResult = this.format(rule, element, message);
|
||||
if (formatResult !== null) {
|
||||
return formatResult;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
class SchemaValidator extends RuleValidator {
|
||||
constructor(schema, options) {
|
||||
super(SchemaValidator.message);
|
||||
this._schema = schema;
|
||||
this._options = options || null;
|
||||
}
|
||||
updateSchema(schema) {
|
||||
this._schema = schema;
|
||||
}
|
||||
async validate(data, allData) {
|
||||
let result = this._checkFieldInSchema(data);
|
||||
if (!result) {
|
||||
result = await this.invokeValidate(data, false, allData);
|
||||
}
|
||||
return result.length ? result[0] : null;
|
||||
}
|
||||
async validateAll(data, allData) {
|
||||
let result = this._checkFieldInSchema(data);
|
||||
if (!result) {
|
||||
result = await this.invokeValidate(data, true, allData);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async validateUpdate(data, allData) {
|
||||
let result = this._checkFieldInSchema(data);
|
||||
if (!result) {
|
||||
result = await this.invokeValidateUpdate(data, false, allData);
|
||||
}
|
||||
return result.length ? result[0] : null;
|
||||
}
|
||||
async invokeValidate(data, all, allData) {
|
||||
let result = [];
|
||||
let schema = this._schema;
|
||||
for (let key in schema) {
|
||||
let value = schema[key];
|
||||
let errorMessage = await this.validateRule(key, value, data[key], data, allData);
|
||||
if (errorMessage != null) {
|
||||
result.push({
|
||||
key,
|
||||
errorMessage
|
||||
});
|
||||
if (!all)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async invokeValidateUpdate(data, all, allData) {
|
||||
let result = [];
|
||||
for (let key in data) {
|
||||
let errorMessage = await this.validateRule(key, this._schema[key], data[key], data, allData);
|
||||
if (errorMessage != null) {
|
||||
result.push({
|
||||
key,
|
||||
errorMessage
|
||||
});
|
||||
if (!all)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
_checkFieldInSchema(data) {
|
||||
var keys = Object.keys(data);
|
||||
var keys2 = Object.keys(this._schema);
|
||||
if (new Set(keys.concat(keys2)).size === keys2.length) {
|
||||
return "";
|
||||
}
|
||||
var noExistFields = keys.filter((key) => {
|
||||
return keys2.indexOf(key) < 0;
|
||||
});
|
||||
var errorMessage = formatMessage({
|
||||
field: JSON.stringify(noExistFields)
|
||||
}, SchemaValidator.message.TAG + SchemaValidator.message["defaultInvalid"]);
|
||||
return [{
|
||||
key: "invalid",
|
||||
errorMessage
|
||||
}];
|
||||
}
|
||||
}
|
||||
function Message() {
|
||||
return {
|
||||
TAG: "",
|
||||
default: "验证错误",
|
||||
defaultInvalid: "提交的字段{field}在数据库中并不存在",
|
||||
validateFunction: "验证无效",
|
||||
required: "{label}必填",
|
||||
"enum": "{label}超出范围",
|
||||
timestamp: "{label}格式无效",
|
||||
whitespace: "{label}不能为空",
|
||||
typeError: "{label}类型无效",
|
||||
date: {
|
||||
format: "{label}日期{value}格式无效",
|
||||
parse: "{label}日期无法解析,{value}无效",
|
||||
invalid: "{label}日期{value}无效"
|
||||
},
|
||||
length: {
|
||||
minLength: "{label}长度不能少于{minLength}",
|
||||
maxLength: "{label}长度不能超过{maxLength}",
|
||||
range: "{label}必须介于{minLength}和{maxLength}之间"
|
||||
},
|
||||
number: {
|
||||
minimum: "{label}不能小于{minimum}",
|
||||
maximum: "{label}不能大于{maximum}",
|
||||
exclusiveMinimum: "{label}不能小于等于{minimum}",
|
||||
exclusiveMaximum: "{label}不能大于等于{maximum}",
|
||||
range: "{label}必须介于{minimum}and{maximum}之间"
|
||||
},
|
||||
pattern: {
|
||||
mismatch: "{label}格式不匹配"
|
||||
}
|
||||
};
|
||||
}
|
||||
SchemaValidator.message = new Message();
|
||||
exports.SchemaValidator = SchemaValidator;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-forms/components/uni-forms/validate.js.map
|
||||
Reference in New Issue
Block a user