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`字段, 会自动用统一的。
      { 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', '昵称', () => {
         // 业务代码
          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', '自定义测试', () => {
         // 业务代码   
      });
  };

封装分页

使用方法,按照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>

防抖和节流

引用方法: import { useThrottleFn, useDebounceFn } from '@vueuse/core'
参数都是有两个参数,第一个是回调函数,第二个是毫秒数。

   <a-button type="primary" style="margin-right: 20px" @click="onTestThrottleFn"
      >测试节流函数</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',
        },
      ],
    },
  ];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 星期四,雨 (个人日记——吾日三省吾身。用文字记录生活,记录想法,记录成长。文责自负,原创首发。) 《解开一切问题...
    马力不足阅读 74评论 0 2
  • 纯粹奉爱真理明鉴 2024.1.25佳格牟黑妮迪迪讲课.主题_“什么是纯粹的奉爱服务?什么是虚假的宗教?”来自巴克...
    观自在_8260阅读 214评论 0 1
  • 在大家的印象中,河南人爱吃面食是不争的事实。早上白面馍馍,中午面条,晚上又是白面馒头。大米在自家里的日常饮食中几乎...
    农家女在田园阅读 45评论 0 0
  • 20240201七点十分星期四《小学语文课程标准与教材研究》5.3.2.2 昨天晚上和牙医张医生一起在巴庄吃饭,连...
    每天坚持阅读 87评论 0 1
  • 最近在写文,其实写结论反倒是最简单的(这里的简单不是说传统意义上的简单,只是不麻烦,动脑子查查其他论文,实在不行扔...
    Athena404阅读 311评论 0 2