2024-02-29

公共方法用法

提示語

  1. actionMessage
    用途:固定通用的操作后提示語
    位置:src\utils\message.ts
    參數: type:取值 src\enums\messageEnum.ts 文件中 messageTypeEnum 取; 例如 messageTypeEnum.ADD_SUCCESS |messageTypeEnum.ADD_ERROR|messageTypeEnum.UPDATA_SUCCESS|messageTypeEnum.UPDATA_ERROR
    |messageTypeEnum.DEL_SUCCESS|messageTypeEnum.DEL_ERROR
  <a-button type="primary" style="margin-right: 20px" @click="testReminder"
        >測試操作提示語</a-button
      >
  function testReminder() {
    actionMessage(messageTypeEnum.ADD_SUCCESS);
  }
  1. customMessage
    用途:自定義提示語
    位置:src\utils\message.ts
    參數:label秦叛,resultColor,opt
    • label:提示語具體內容敬扛,

    • resultColor:結果顏色及圖標 單舉例SUCCESS | ERROR | WARNING src\enums\messageEnum.ts 文件中 CustomMessageEnum 取

    • opt 說明:若是在opt 中設置 content 會覆蓋 參數label蹬铺,opt 中設置icon 會覆蓋 參數resultColor渡处,兼容antdesign 關于自定義 的message

  <a-button type="primary" style="margin-right: 20px" @click="testCustomActionReminder"
        >自定義提示語</a-button
      >
  function testCustomActionReminder() {
    let opt = {
      contentStyle: 'contentStyle',
    };
    customMessage('自定義提示語', 'Error', opt);
  }
  <a-button type="primary" style="margin-right: 20px" @click="testCustomActionReminder"
        >自定義提示語</a-button
      >
  function testCustomActionReminder() {
    let opt = {
      content: '應用下架獲得批準',
      icon: h(CheckCircleOutlined, { style: 'color: blue' }),
      contentStyle: 'contentStyle',
    };
    customMessage('自定義提示語', 'Error', opt);
  }
  <a-button type="primary" style="margin-right: 20px" @click="testCustomActionReminder"
        >自定義提示語</a-button
      >

  function testCustomActionReminder() {
    let opt = {
      content: '審核通過',
       icon: h('img', { src: custommesicon }),   //src:對應的路徑值  無論是用封裝的還是antdesign封裝的 都需要引一下抹蚀,不然好像容易有bug   舉例 import custommesicon from '@/assets/icons/custommesicon.png';
      contentStyle: 'contentStyle',
    };
    // customMessage('自定義提示語', 'Error', opt);
  }
  1. placeholder 提示語和message 提示語 改的是vben框架源碼,不需要使用人員調用處理扰路。
    校驗中的message 提示語 調用源碼改動的 方式
formSchema = [
  {
    field: 'SaleDeliverBillId',
    label: '委外出庫單號',
    component: 'Input',
    rules: [
      { required: true, trigger: ['change', 'blur'] },//注意這里的寫法帖渠,不寫`message`字段, 會自動用統(tǒng)一的谒亦。
      { max: 20, message: '輸入字符不能超過20', trigger: ['change', 'blur'] },
    ],
  }]

二次確認提示彈窗

  1. confirmModal
    用途:二次確認彈窗,提示語是固定幾個類型
    位置:src\utils\ConfirmModal.ts
    參數 messageType空郊,displayName, callback: () => callbackResult,
  • messageType 從src/utils/messageType中messagePrefix.ts取 例如'ADD' | 'UPDATA'| 'DEL' | 'AUDITING' | 'LISTING' | 'OPEN | 'CLOSE' | 'LOADDING' | 'AUTH' | 'RECOVERY'份招,
  • displayName 對誰進行二次確認。即提示語中樣式用加粗紅色樣式那部分參數 狞甚;
  • callback 點確定后的回調處理锁摔,必須有返回值result類型布爾
  <a-button type="primary" style="margin-right: 20px" @click="onDel "
        >刪除</a-button
      >
 const onDel = (record) => {
    confirmModal('DEL', '昵稱', () => {
         // 業(yè)務代碼
          return {
              result: true,
          };
      });
  };
  1. customConfirmModal
    用途:二次確認彈窗,提示語是固定幾個類型
    位置:src\utils\ConfirmModal.ts
    參數:messageType入愧,displayName, fun。
  • messageType 從src/utils/messageType中messagePrefix.ts取 例如'ADD' | 'UPDATA'| 'DEL' | 'AUDITING' | 'LISTING' | 'OPEN | 'CLOSE' | 'LOADDING' | 'AUTH' | 'RECOVERY'嗤谚,
  • displayName 對誰進行二次確認棺蛛。即提示語中樣式用加粗紅色樣式那部分參數 ;
  • fun 點確定后的回調處理無特殊要求根據具體需求自定義
  <a-button type="primary" style="margin-right: 20px" @click="onDel "
        >刪除</a-button
      >
 const onDel = (record) => {
    customConfirmModal('RECOVERY', '自定義測試', () => {
         // 業(yè)務代碼   
      });
  };

封裝分頁

使用方法巩步,按照VBEN 自定義的 分頁做即可旁赊,需要注意的是,若是遇到添加后 再掉分頁需要這樣寫

<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate">添加</a-button>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup>
  import { ref, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '@/components/Table';

  // 表格
  const searchInfo = ref();
  const [registerTable, { reload}] = useTable({ 
    handleSearchInfoFn(info) {
      searchInfo.value = info;
      return info;
    },
   //......

  async function onSuccess() {

   if (title.value === '添加') {
      let paramobj = { ...searchInfo.value, resetFirstPage: true };
      reload(paramobj);
    } else {
      reload();
    }
  }
</script>

防抖和節(jié)流

引用方法: import { useThrottleFn, useDebounceFn } from '@vueuse/core'
參數都是有兩個參數椅野,第一個是回調函數终畅,第二個是毫秒數。

   <a-button type="primary" style="margin-right: 20px" @click="onTestThrottleFn"
      >測試節(jié)流函數</a-button
    >
    <a-button type="primary" @click="onTestDebounceFn">測試防抖函數</a-button>

  import { useThrottleFn, useDebounceFn } from '@vueuse/core';
   function fun (){
     console.log('測試222');
   }
  const onTestThrottleFn = useThrottleFn(fun , 2000);
  const onTestDebounceFn = useDebounceFn(fun , 3000);

時間轉換

  1. convertDateToLocalOrUTC
    用途: utc時間 竟闪、本地時間相互轉換
    位置:src\utils\dateUtil.ts
    參數: date离福,format,type
  • date:需要被轉換的時間
  • format:需要的時間格式
  • type:默認local 目標類型local即將utc時間轉換為本地時間
  import { convertDateToLocalOrUTC  } from '@/utils/dateUtil';
  console.log(convertDateToLocalOrUTC('2024-01-09T10:00:00'), '假設后臺反的是utc,轉為本地時間');
  console.log(
    convertDateToLocalOrUTC('2024-01-09 10:00:00', 'utc'),
    '假設后臺反的是本地,轉為utc間',
  );
  console.log(
    convertDateToLocalOrUTC('2024-01-09 10:00:00z', ''),
    '2假設后臺反的是utc,轉為本地時間',
  );
  console.log(
    convertDateToLocalOrUTC('2024-01-09 10:00:00z', 'utc'),
    '假設后臺時間以z結尾=========',
  );
  1. timeStart
    用途: 時間轉換為 一天|周|月|年 的開始炼蛤,
    位置:src\utils\dateUtil.ts
    參數: date妖爷,format,type
  • day 可取 |'day'|'week'| 'month' | 'year' |理朋,默認'day'
  • date 可選絮识。 供參考這幾種類型 string | Date | Dayjs | null | undefined
console.log( timeStart('day', '2024-2-29') )
  1. timeEnd
    用途: 時間轉換為 一天|周|月|年 的結束,
    位置:src\utils\dateUtil.ts
    參數: date嗽上,format次舌,type
  • day 可取 |'day'|'week'| 'month' | 'year'
  • date 可選。 供參考這幾種類型 string | Date | Dayjs | null | undefined
console.log( timeEnd('day', '2024-2-29') )

自定義校驗

  1. emailValidate
    用途: 自定義郵箱校驗兽愤,
    位置:src\utils\customVerification.ts
    參數:value 輸入的值
 const schemas: FormSchema[] = [
    {
      field: 'field1',
      component: 'Input',
      label: '郵箱',
      rules: [
        {
          required: true,
          validator: (rule, value) => emailValidate(value),
          trigger: 'blur',
        },
      ],
    },
  ];

  1. phoneVerification
    用途: 手機號校驗(只適用于手機號)彼念,
    位置:src\utils\customVerification.ts
    參數:value 輸入的值
 const schemas: FormSchema[] = [
    {
      field: 'phone',
      component: 'Input',
      label: '手機號',
      rules: [
        {
          required: true,
          validator: (rule, value) => phoneVerification(value),
          trigger: 'blur',
        },
      ],
    },
  ];
  1. fixedLineVerification
    用途: 固定電話校驗(只適用于固定電話)挪圾,
    位置:src\utils\customVerification.ts
    參數:value 輸入的值
 const schemas: FormSchema[] = [
    {
      field: 'fixedLine',
      component: 'Input',
      label: '固定電話',
      rules: [
        {
          required: true,
          validator: (rule, value) => fixedLineVerification(value),
          trigger: 'blur',
        },
      ],
    },
  ];
  1. phoneValidate
    用途: 手機/固話校驗,
    位置:src\utils\customVerification.ts
    參數:value 輸入的值
 const schemas: FormSchema[] = [
    {
      field: 'tel',
      component: 'Input',
      label: '手機/固定電話',
      rules: [
        {
          required: true,
          validator: (rule, value) => phoneValidate(value),
          trigger: 'blur',
        },
      ],
    },
  ];
  1. checkRepeat
    用途: 查重校驗国拇,
    位置:src\utils\customVerification.ts
    參數:value,api, param , label , id
  • value 輸入的值
  • api 查重接口
  • param 查重接口需要傳的參數
  • label 標簽名
  • id 當為文字(例如某名稱查重)查重時洛史,id不用傳;當為修改時當前修改值的id
 const schemas: FormSchema[] = [
    {
      field: 'code',
      component: 'Input',
      label: '查重',
      rules: [
         {
          validator: (rule, value) => checkRepeat(value, isAccountExist, 'DisplayName', '名稱', ),
          trigger: 'blur',
        },
      ],
    },
  ];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末酱吝,一起剝皮案震驚了整個濱河市也殖,隨后出現的幾起案子,更是在濱河造成了極大的恐慌务热,老刑警劉巖忆嗜,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異崎岂,居然都是意外死亡捆毫,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進店門冲甘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來绩卤,“玉大人,你說我怎么就攤上這事江醇”舯铮” “怎么了?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵陶夜,是天一觀的道長凛驮。 經常有香客問我,道長条辟,這世上最難降的妖魔是什么黔夭? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮羽嫡,結果婚禮上本姥,老公的妹妹穿的比我還像新娘。我一直安慰自己杭棵,他們只是感情好扣草,可當我...
    茶點故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著颜屠,像睡著了一般辰妙。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上甫窟,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天密浑,我揣著相機與錄音,去河邊找鬼粗井。 笑死尔破,一個胖子當著我的面吹牛街图,可吹牛的內容都是我干的。 我是一名探鬼主播懒构,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼餐济,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了胆剧?” 一聲冷哼從身側響起絮姆,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎秩霍,沒想到半個月后篙悯,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡铃绒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年鸽照,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片颠悬。...
    茶點故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡矮燎,死狀恐怖,靈堂內的尸體忽然破棺而出赔癌,到底是詐尸還是另有隱情诞外,我是刑警寧澤,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布届榄,位于F島的核電站浅乔,受9級特大地震影響倔喂,放射性物質發(fā)生泄漏铝条。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一席噩、第九天 我趴在偏房一處隱蔽的房頂上張望班缰。 院中可真熱鬧,春花似錦悼枢、人聲如沸埠忘。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽莹妒。三九已至,卻和暖如春绰上,著一層夾襖步出監(jiān)牢的瞬間旨怠,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工蜈块, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留鉴腻,地道東北人迷扇。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像爽哎,于是被迫代替她去往敵國和親蜓席。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內容

  • 星期四课锌,雨 (個人日記——吾日三省吾身厨内。用文字記錄生活,記錄想法产镐,記錄成長隘庄。文責自負,原創(chuàng)首發(fā)癣亚。) 《解開一切問題...
    馬力不足閱讀 60評論 0 2
  • 純粹奉愛真理明鑒 2024.1.25佳格牟黑妮迪迪講課.主題_“什么是純粹的奉愛服務?什么是虛假的宗教?”來自巴克...
    觀自在_8260閱讀 125評論 0 1
  • 在大家的印象中丑掺,河南人愛吃面食是不爭的事實。早上白面饃饃述雾,中午面條街州,晚上又是白面饅頭。大米在自家里的日常飲食中幾乎...
    農家女在田園閱讀 34評論 0 0
  • 20240201七點十分星期四《小學語文課程標準與教材研究》5.3.2.2 昨天晚上和牙醫(yī)張醫(yī)生一起在巴莊吃飯玻孟,連...
    每天堅持閱讀 55評論 0 1
  • 最近在寫文唆缴,其實寫結論反倒是最簡單的(這里的簡單不是說傳統(tǒng)意義上的簡單,只是不麻煩黍翎,動腦子查查其他論文面徽,實在不行扔...
    Athena404閱讀 259評論 0 2