表單校驗+自定義觸發(fā)

<template>
  <div class="h-full w-full p-2 overflow-hidden layout-side softwareDetailCss"
       style="background-color: #eef2fc">
    <div style="width: calc(100% - 0px);height: 100%;">
      <div class="layout-right-top" style="height: 40px;">
        <a-button type="primary" @click="back">返回</a-button>
        <a-button key="back" type="primary" @click="addLine">新增產(chǎn)品基線</a-button>
      </div>
      <div style="height: calc(100% - 40px);">
        <a-table bordered :columns="clomuns" :data-source="tableList" :rowKey="(record) => record.id"
        >
          <template #action="{ record }">
            <span>
              <a-tooltip placement="topRight">
                <template #title>編輯</template>
                <FormOutlined
                  class="mr-1 cursor-pointer-def primary-color"
                  style="font-size: 17px"
                />
              </a-tooltip>
              <a-tooltip placement="topRight">
                <template #title>刪除</template>
                <a-popconfirm
                  title="確定要刪除嗎献宫?"
                  @confirm="comfirm(record)"
                  @cancel="cancel"
                >
                  <DeleteOutlined
                    class="cursor-pointer-def primary-color"
                    style="font-size: 17px"
                  />
                </a-popconfirm>
              </a-tooltip>
               <a-tooltip placement="topRight">
                <template #title>下載</template>
                 <VerticalAlignBottomOutlined
                   class="mr-5 cursor-pointer-def danger-color"
                   style="font-size: 17px;margin-left: 5px;"
                 />
              </a-tooltip>
            </span>
          </template>
        </a-table>
      </div>
    </div>
    <!--彈窗-->
    <ak-dialog title="基線信息編輯" width="600px" animation="zoom" top="10vh" v-model="cusVisible" :closeModal="false"
               class="dialogPadding">
      <template #footer>
        <div class="w-full layout-right-center">
          <a-button key="back" @click="cusVisible = false">取消</a-button>
          <a-button type="primary" @click="handleOk">提交</a-button>
        </div>
      </template>
      <div style="width: 500px;">
        <a-form
          :model="userFormState"
          ref="userFormRef"
          :rules="rules"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
        >
          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-item label="基線名稱" name="lineName">
                <a-input v-model:value="userFormState.lineName"/>
              </a-form-item>
              <a-form-item label="內(nèi)容說明" name="content">
                <a-input v-model:value="userFormState.content"/>
              </a-form-item>
              <a-form-item label="用戶手冊" name="file1">
                <a-upload
                  v-model:file-list="fileList"
                  name="file"
                  :multiple="true"
                  :action="uploadFileUrl"
                  @change="handleChange"
                  :before-upload="beforeUpload"
                >
                  <a-button>
                    <upload-outlined></upload-outlined>
                    Click to Upload
                  </a-button>
                </a-upload>
              </a-form-item>
              <!--<a-form-item label="用戶頭像">-->
              <!--  <a-upload-->
              <!--    v-model:file-list="fileList"-->
              <!--    name="file"-->
              <!--    list-type="picture-card"-->
              <!--    class="avatar-uploader"-->
              <!--    :show-upload-list="false"-->
              <!--    :action="uploadFileUrl"-->
              <!--    :before-upload="beforeUpload"-->
              <!--    @change="handleChange"-->
              <!--    :disabled="state.onlyRead"-->
              <!--  >-->
              <!--    <nip-avatar v-if="userFormState.userImg" :url="userFormState.userImg" :size="94" :radius="false"-->
              <!--                :border="false"/>-->
              <!--    <div v-else>-->
              <!--      <loading-outlined v-if="loading"></loading-outlined>-->
              <!--      <plus-outlined v-else></plus-outlined>-->
              <!--      <div class="ant-upload-text">上傳</div>-->
              <!--    </div>-->
              <!--  </a-upload>-->
              <!--</a-form-item>-->
            </a-col>
          </a-row>
        </a-form>
      </div>
    </ak-dialog>
  </div>
</template>

<script>
  export default {
    name: "softwareDetail"
  }
</script>

<script setup>
  import {ref} from "vue";
  import {softwareDetailDel, softwareDetailGet} from "../../../../common/api/softwareDetail";
  import {message} from "ant-design-vue";
  import {
    DownOutlined,
    DeleteOutlined,
    FormOutlined,
    UploadOutlined,
    VerticalAlignBottomOutlined
  } from "@ant-design/icons-vue"

  const clomuns = [
    {
      title: '基線名稱',
      dataIndex: 'lineName',
      key: 'lineName',
      // width: '10%',
      ellipsis: true
    },
    {
      title: '創(chuàng)建時間',
      dataIndex: 'createTime',
      key: 'createTime',
      ellipsis: true
    },
    {
      title: '內(nèi)容說明',
      dataIndex: 'content',
      key: 'content',
      // width: '10%',
      ellipsis: true
    },
    {
      title: '用戶手冊',
      dataIndex: 'userBooks',
      key: 'userBooks',
      // width: '10%',
      ellipsis: true
    },
    {
      title: '源碼',
      dataIndex: 'code',
      key: 'code',
      // width: '10%',
      ellipsis: true
    },
    {
      title: '安裝文件',
      dataIndex: 'exeFile',
      key: 'exeFile',
      // width: '10%',
      ellipsis: true
    },
    {
      title: '操作',
      dataIndex: 'options',
      key: 'options',
      width: '10%',
      ellipsis: true,
      slots: {customRender: 'action'}
    }
  ]
  let tableList = ref([])

  const comfirm = (record) => {
    // softwareDetailDel(record).then(async (res) => {
    //   await softwareDetailGet({softwareId}).then(res => {
    //     tableList.value = res.data
    //   })
    //   message.success('已刪除成功')
    // })
  }
  //用戶點擊了確定取消按鈕
  const cancel = () => {
    message.warning('已取消刪除')
  }
  const back = () => {
    history.go(-1)
  }

  /**
   * 彈窗
   * */

  let cusVisible = ref(false)
  let addLine = () => {
    cusVisible.value = true
  }
  const userFormRef = ref()
  const handleOk = () => {
    userFormRef.value.validate().then(() => {
      console.log('通過驗證')
    }).catch((error) => {
      console.log("error", error);
    })
  };


  const userFormState = ref({
    lineName: '',
    content: '',
    userBooks: '',
    code: '',
    exeFile: ''
  })

  let uploadFileUrl = ref(window.uploadFileUrl)
  const fileList = ref([]);
  const handleChange = (info) => {
    if (info.file.status === 'uploading') {
      return;
    }
    if (info.file.status === 'done') {
      console.log(info.file.response.data.url)
      console.log(fileList)
    }
    if (info.file.status === 'error') {
      message.error('上傳錯誤');
    }
  };

  const beforeUpload = (file) => {
    // const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
    // if (!isJpgOrPng) {
    //   message.error('上傳文件格式錯誤,只支持jpg或者png圖片!');
    // }
    const isLt2M = file.size / 1024 / 1024 < 4;
    if (!isLt2M) {
      message.error('上傳文件超出4MB大小限制盯另!');
    }
    // return isJpgOrPng && isLt2M;
  };

  let labelCol = ref({span: 5})
  let wrapperCol = ref({span: 17})

  // 規(guī)則匯總
  const validatePhone = async (rule, value) => {
    if (value === '') {
      return Promise.reject('請輸入電話號碼');
    } else {
      const reg = /^1[3-9]\d{9}$/;
      if (!reg.test(value)) {
        return Promise.reject('手機號碼錯誤谢床,請檢查后重新輸入兄一!');
      }
      return Promise.resolve();
    }
  }
  const validateIdCard = async (rule, value) => {
    if (value === '') {
      return Promise.reject('請輸入身份證號碼');
    } else {
      const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (!reg.test(value)) {
        return Promise.reject('身份證號碼錯誤,請檢查后重新輸入识腿!');
      }
      return Promise.resolve();
    }
  }
  const validateEmail = async (rule, value) => {
    if (value === '') {
      return Promise.reject('請輸入內(nèi)部電子郵箱');
    } else {
      const reg = /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
      if (!reg.test(value)) {
        return Promise.reject('內(nèi)部電子郵箱格式錯誤出革,請檢查后重新輸入!');
      }
      return Promise.resolve();
    }
  }
  const validateFile = async (rule, value,callback) =>{
    // console.log(rule)
    // console.log(value)
    console.log(fileList.value)
    if(fileList.value.length === 0) {
      return Promise.reject('請選擇需要上傳的文件')
    }else {
      return Promise.resolve();
    }
  }
  const rules = {
    file1:[{required: true, validator: validateFile, trigger: 'change'}],
    lineName: [{required: true, trigger: 'change', message: "請輸入產(chǎn)品基線名稱",}],
    content: [{required: true, trigger: 'change', message: "請輸入內(nèi)容說明"}],
    userAccount: [{required: true, message: "請輸入用戶名", trigger: 'change'}, {min: 3, max: 30, message: "用戶名長度在3~30字之間"}],
    phone: [{required: true, validator: validatePhone, trigger: 'change'}],
    idCard: [{required: true, validator: validateIdCard, trigger: 'change'}],
    email: [{required: true, validator: validateEmail, trigger: 'change'}],
    bday: [{required: true, message: "請輸入出生日期", trigger: 'change', type: "object"}],
  };


</script>

<style scoped lang="less">

</style>


自定義觸發(fā)


544070096112e03473b3b892adfc0b9.png

9bf34b7b923e0cc4458ba9cfaf00810.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末渡讼,一起剝皮案震驚了整個濱河市骂束,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌成箫,老刑警劉巖展箱,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異蹬昌,居然都是意外死亡混驰,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來账胧,“玉大人竞慢,你說我怎么就攤上這事先紫≈文啵” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵遮精,是天一觀的道長居夹。 經(jīng)常有香客問我,道長本冲,這世上最難降的妖魔是什么准脂? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮檬洞,結(jié)果婚禮上狸膏,老公的妹妹穿的比我還像新娘。我一直安慰自己添怔,他們只是感情好湾戳,可當(dāng)我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著广料,像睡著了一般砾脑。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上艾杏,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天韧衣,我揣著相機與錄音,去河邊找鬼购桑。 笑死畅铭,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的勃蜘。 我是一名探鬼主播硕噩,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼元旬!你這毒婦竟也來了榴徐?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤匀归,失蹤者是張志新(化名)和其女友劉穎坑资,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體穆端,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡袱贮,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了体啰。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片攒巍。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡嗽仪,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出柒莉,到底是詐尸還是另有隱情闻坚,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布兢孝,位于F島的核電站窿凤,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏跨蟹。R本人自食惡果不足惜雳殊,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望窗轩。 院中可真熱鬧夯秃,春花似錦、人聲如沸痢艺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽腹备。三九已至衬潦,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間植酥,已是汗流浹背镀岛。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留友驮,地道東北人漂羊。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像卸留,于是被迫代替她去往敵國和親走越。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容