开发中封装的comfirmBox.js弹窗共用方法

代码主体

import Vue from 'vue';
import { escapeToHtml } from '@/util/htmlAndEscape';

function confirmBox({ info = '此操作将永久删除该信息, 是否继续?', title = '提示', bts = ['确定', '取消'], type = 'warning', okFun, noFun }) {
  Vue.prototype.$confirm(info, title, {
    confirmButtonText: bts[0],
    cancelButtonText: bts[1],
    type: type
  })
    .then(() => {
      okFun();
    })
    .catch(() => {
      noFun();
    });
}
function messageBox({ message = '', type = 'success' }) {
  Vue.prototype.$message({
    message: message,
    type: type
  });
}

/** 格式化初始化的日期 **/
function dateFormat(fmt, date) {
  let ret;
  const opt = {
    'Y+': date.getFullYear().toString(), // 年
    'm+': (date.getMonth() + 1).toString(), // 月
    'd+': date.getDate().toString(), // 日
    'H+': date.getHours().toString(), // 时
    'M+': date.getMinutes().toString(), // 分
    'S+': date.getSeconds().toString() // 秒
    // 有其他格式化字符需求可以继续添加,必须转化成字符串
  };
  for (const k in opt) {
    ret = new RegExp('(' + k + ')').exec(fmt);
    if (ret) {
      fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')));
    }
  }
  return fmt;
}

/** 格式化展示日期 **/
function timeFormat(time) {
  /* var d = new Date(time.substr(0, 19));// 加入substr(0, 19)处理兼容ios报错NAN
  var year = d.getFullYear(); // 年
  var month = d.getMonth() + 1; // 月
  var day = d.getDate(); // 日
  var hh = d.getHours(); // 时
  var mm = d.getMinutes(); // 分
  var ss = d.getSeconds(); // 秒

  var clock = year + '-';
  if (month < 10) { clock += '0'; }
  clock += month + '-';
  if (day < 10) { clock += '0'; }
  clock += day + ' ';
  if (hh < 10) { clock += '0'; }
  clock += hh + ':';
  if (mm < 10) clock += '0';
  clock += mm + ':';
  if (ss < 10) clock += '0';
  clock += ss;
  return (time);*/
  return time;
}

/** 去除富文本上的html标签 **/
function delHtmlTag(cc) {
  escapeToHtml(cc);
  return escapeToHtml(cc).replace(/<[^>]+>/g, '').replace(/&nbsp;/g, '');
}

export {
  confirmBox,
  messageBox,
  dateFormat,
  timeFormat,
  delHtmlTag
};

封装的htmlAndEscape.js


// 转义符转回HTML标签
function escapeToHtml(str) {
  const arrEntities = { 'lt': '<', 'gt': '>', "'": '"' };
  return str.replace(/&(lt|gt);/ig, function(all, t) { return arrEntities[t]; });
}
// HTML标签转换转义符
function htmlToEscape(myHtml) {
  return myHtml.replace(/[<>"]/g, function(c) { return { '<': '&lt;', '>': '&gt;', '"': "'" }[c]; });
}

export {
  escapeToHtml,
  htmlToEscape
};

官网链接:https://element.eleme.cn/#/zh-CN/component/message-box

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值