123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import Vrules from "./Vregular.js";
- var verification={};
- verification.install=function(Vue){
- Vue.prototype.$vervify =function(option){
-
-
-
- var otherDefault={
- reqEmptyVal:false,
-
- }
- var otherPra=Object.assign({},otherDefault,option.otherPra)
- var result=0;
- var flag=true;
- for(var m=0;m<option.formDate.length;m++){
- var regular=option.formDate[m].rules.verify.split("|");
- for(var i=0;i<regular.length;i++){
- if(Vrules[regular[i]]){
- var _default=Object.assign({},Vrules[regular[i]],option.formDate[m].rules)
- if(regular[i]=="req"){
-
- if(otherPra.reqEmptyVal){
- var emptyMessage="请输入"+option.formDate[m].label;
- if(option.formDate[m].type=="radio"){
- emptyMessage="请选择"+option.formDate[m].label;
- }else if(option.formDate[m].type=="image"){
- emptyMessage="请上传"+option.formDate[m].label;
- }
-
- if(_default.value.length==0){
- uni.showToast({
- title:emptyMessage,
- duration: 2000,
- icon:"none"
- });
- flag=false;
- }else{
- regularVer()
- }
- }else{
- regularVer()
- }
- }else if(regular[i]=="same"){
- if(m>0){
- if(option.formDate[m-1].rules.value!=_default.value){
- uni.showToast({
- title: _default.errMess,
- duration: 2000,
- icon:"none"
- });
- flag=false;
- }
- }else{
- uni.showToast({
- title: "表单配置不正确,请检查被确认输入框的位置",
- duration: 2000,
- icon:"none"
- });
- flag=false;
- }
-
- }else{
- if(_default.value.length>0){
- regularVer()
- }
- }
- function regularVer(){
- if(!_default.pattern.test( _default.value)){
- uni.showToast({
- title: _default.errMess,
- duration: 2000,
- icon:"none"
- });
- flag=false;
- }else{
- flag=true;
- }
- }
- if(!flag){
- return flag
- }
- }
- }
- }
- return flag;
- },
-
- Vue.prototype.$submitForm =function(option){
- var submitData={};
- for(var i=0;i<option.length;i++){
- submitData[option[i].rules.name]=option[i].rules.value;
- }
- return submitData;
- }
- }
- export default verification
|