惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 飘扬De黑夜

SqlServer 批量修改某个字段类型 U8数据库表汇总 FastReport 使用JSON作为数据源,手工赋值和导出PDF Vue.js 2 使用 extends 扩展 element-ui 组件 FastReport-Barcode/QRCode 控件总是存在白色空白区域 双网卡同时访问内外网 vs项目启动后总是提示ID为XXX的进程当前未运行 Vue2全局管理格式化器和Filter uniapp 以npm模式安装插件的项目,如何让自定义组件支持easycom方式自动导入 Http请求中 Content-Type 常用格式说明 WPF入门基础之双向数据绑定 WPF入门之设置样式 ElementUI-如何给 el-dropdown 的 command 事件传递多个参数 TortoiseGit使用 管理系统中台示例参照 淘宝源安装npm visual studio 2022 自定义组件和自定义控件和用户控件的区别 SqlServer GoupBy 分组后对于非分组的某个字符串进行拼接 SQL Server 实现类似CountIF的函数
elementui关于表单校验validator
飘扬De黑夜 · 2025-06-04 · via 博客园 - 飘扬De黑夜

表单字段自由组合校验规则,避免重复书写相同规则,参照代码如下:

<template>
  <!-- 表单对话框 -->
  <ft-dialog v-el-drag-dialog :title="formTitle" width="800px" :visible.sync="dialogVisible" @confirm="handleSubmit">
    <el-form ref="dataFormAddUpdate" :model="formEntity" :rules="validateRules" label-position="left"
      label-width="100px" label-suffix=":">
      <el-form-item label="模板编码" prop="TemplateCode" :rules="validateRules.NotEmpty">
        <el-input v-model="formEntity.TemplateCode" autocomplete="off" :disabled="codeDisable" />
      </el-form-item>
      <el-form-item label="模板描述" prop="TemplateDesc" :rules="[validateRules.NotEmpty,validateRules.Min0Max5]">
        <el-input v-model="formEntity.TemplateDesc" autocomplete="off" />
      </el-form-item>
      <el-form-item label="模板文件" prop="TemplateFile" :rules="validateRules.NotEmpty">
        <el-input v-model="formEntity.TemplateFile" autocomplete="off" />
      </el-form-item>
      <el-form-item label="备注" prop="Remark">
        <el-input v-model="formEntity.Remark" :autosize="{ minRows: 3, maxRows: 5 }" type="textarea" />
      </el-form-item>
    </el-form>
  </ft-dialog>
</template>

<script>
import { add, update } from '@/api/Sys/Sys_PrintTemplate'
export default {
  name: 'Sys.Sys_PrintTemplate.addUpdate',
  data() {
    return {
      dialogVisible: false,
      formEntity: {
        RowUid: '',
        RoleCode: '',
        UserDesc: '',
        Remark: ''
      },
      validateRules: {
        NotEmpty: { required: true, message: '必须输入!', trigger: 'blur' },
        Min0Max5: { min: 0, max: 5, message: '长度在 0 到 5 个字符', trigger: 'blur' }
      }
    }
  },
  computed: {
    mode: function () {
      const entityKey = this.formEntity.RowUid
      return entityKey === undefined || entityKey === null || entityKey === '' ? 'Add' : 'Update'
    },
    codeDisable: function () {
      return this.mode === 'Update'
    },
    formTitle: function () {
      return this.mode === 'Add' ? '添加' : '编辑'
    }
  },
  methods: {
    show: function (entity) {
      // 注意本处写法,更新显示dialogVisible =true,然后nextTick中调用resetFields

      this.dialogVisible = true
      // console.log(this.formEntity,this.$options.data(), 'formEntity')
      if (undefined !== entity && entity !== null) {
        // console.log(entity,entity===null,'entity')
        this.formEntity = Object.assign({}, entity)
      } else {
        this.formEntity = this.$options.data().formEntity
      }
      // this.$nextTick(() => {
      //   // 注意visibile属性为true设置后才可以获取到$refs
      //   this.$refs.dataFormAddUpdate.resetFields()
      //   if (undefined !== entity && entity !== null) {
      //     const entityCopy = Object.assign({}, entity)
      //     this.formEntity = entityCopy
      //   }
      // })
    },
    hide: function () {
      this.dialogVisible = false
    },
    handleSubmit() {
      const action = this.mode === 'Add' ? add(this.formEntity) : update(this.formEntity)
      this.doSubmit(action)
    },
    doSubmit(submitAction) {
      this.$refs.dataFormAddUpdate
        .validate()
        .then(() => {
          console.log(submitAction, typeof submitAction, 'dddddddddf')
          submitAction.then(result => {
            this.dialogVisible = false
            console.log(this.dialogVisible, 'hide')
            this.$emit('confirm')
          })
        })
        .catch(error => {
          console.log('failed', error)
          this.$emit('cancel', error)
        })
    }
  }
}
</script>

<style scoped></style>

posted on 2025-06-04 14:06  飘扬De黑夜  阅读(75)  评论()    收藏  举报