You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
5.0 KiB
222 lines
5.0 KiB
4 years ago
|
import { Message } from 'element-ui'
|
||
|
|
||
|
const pad2 = str => ('0' + str).substr(-2)
|
||
|
|
||
|
function fMoney (s, n) {
|
||
|
n = n > 0 && n <= 20 ? n : 2
|
||
|
s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
|
||
|
let l = s.split('.')[0].split('').reverse()
|
||
|
let r = s.split('.')[1]
|
||
|
let t = ''
|
||
|
for(let i = 0; i < l.length; i ++ ) {
|
||
|
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? ',' : '')
|
||
|
}
|
||
|
return t.split('').reverse().join('') + '.' + r
|
||
|
}
|
||
|
|
||
|
function toDateTime (date, time) {
|
||
|
if (!date) return ''
|
||
|
date = date.toString()
|
||
|
time = time ? time.toString() : ''
|
||
|
let str = `${date.substr(0, 4)}-${date.substr(4, 2)}-${date.substr(6, 2)}`
|
||
|
if (date.length == 14) {
|
||
|
str += ` ${date.substr(8, 2)}:${date.substr(10, 2)}:${date.substr(12, 2)}`
|
||
|
} else if (date.length == 6) {
|
||
|
str = `${date.substr(0, 2)}:${date.substr(2, 2)}:${date.substr(4, 2)}`
|
||
|
} else if (time) {
|
||
|
str += ` ${time.substr(0, 2)}:${time.substr(2, 2)}:${time.substr(4, 2)}`
|
||
|
}
|
||
|
return str
|
||
|
}
|
||
|
|
||
|
|
||
|
function Percentage(num, total) {
|
||
|
if (num == 0 || total == 0){
|
||
|
return 0;
|
||
|
}
|
||
|
return (Math.round(num / total * 10000) / 100.00);// 小数点后两位百分比
|
||
|
}
|
||
|
|
||
|
function fMoney2 (m) {
|
||
|
return parseFloat(m).toFixed(2)
|
||
|
}
|
||
|
|
||
|
function systemStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '运行中',
|
||
|
'2': '故障中'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function systemTypeStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '工具',
|
||
|
'2': '实训',
|
||
|
'3': '网站'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function systemAttributionStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '外部产品',
|
||
|
'2': '内部系统'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function courseTypeStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '实训课程',
|
||
|
'2': '理论课程'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function hoursStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '32课时',
|
||
|
'2': '64课时'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function roleStatus (sts) {
|
||
|
const status = {
|
||
|
'1': '超级管理员',
|
||
|
'2': '管理员',
|
||
|
'3': '老师',
|
||
|
'4': '学生'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function orderTypeFn (sts) {
|
||
|
const status = {
|
||
|
'1': '正式',
|
||
|
'2': '试用'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function orderStatusFn (sts) {
|
||
|
const status = {
|
||
|
'1': '待发货',
|
||
|
'2': '已完成',
|
||
|
'3': '已取消'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
function orderNatureFn (sts) {
|
||
|
const status = {
|
||
|
'1': '初签',
|
||
|
'2': '续签'
|
||
|
}
|
||
|
return status[sts] || '未知状态'
|
||
|
}
|
||
|
|
||
|
// 获取出生日期
|
||
|
function getBirth(idCard) {
|
||
|
var birthday = "";
|
||
|
if(idCard != null && idCard != ""){
|
||
|
if(idCard.length == 15){
|
||
|
birthday = "19"+idCard.slice(6,12);
|
||
|
} else if(idCard.length == 18){
|
||
|
birthday = idCard.slice(6,14);
|
||
|
}
|
||
|
birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
|
||
|
//通过正则表达式来指定输出格式为:1990-01-01
|
||
|
}
|
||
|
return birthday;
|
||
|
}
|
||
|
|
||
|
// 获取性别
|
||
|
function getSex(idCard) {
|
||
|
var sexStr = '';
|
||
|
if (parseInt(idCard.slice(-2, -1)) % 2 == 1) {
|
||
|
sexStr = 'man';
|
||
|
}
|
||
|
else {
|
||
|
sexStr = 'woman';
|
||
|
}
|
||
|
return sexStr;
|
||
|
}
|
||
|
|
||
|
function removeByValue(arr, val) {
|
||
|
for(var i=0; i<arr.length; i++) {
|
||
|
if(arr[i] == val) {
|
||
|
arr.splice(i, 1);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
|
||
|
function formatDate(fmt,date) {
|
||
|
var date = date ? date : new Date()
|
||
|
var o = {
|
||
|
"M+" : date.getMonth()+1, //月份
|
||
|
"d+" : date.getDate(), //日
|
||
|
"h+" : date.getHours(), //小时
|
||
|
"m+" : date.getMinutes(), //分
|
||
|
"s+" : date.getSeconds(), //秒
|
||
|
"q+" : Math.floor((date.getMonth()+3)/3), //季度
|
||
|
"S" : date.getMilliseconds() //毫秒
|
||
|
};
|
||
|
if(/(y+)/.test(fmt)) {
|
||
|
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
|
||
|
}
|
||
|
for(var k in o) {
|
||
|
if(new RegExp("("+ k +")").test(fmt)){
|
||
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
|
||
|
}
|
||
|
}
|
||
|
return fmt;
|
||
|
}
|
||
|
|
||
|
// 是否IE
|
||
|
function isIE() {
|
||
|
if (!!window.ActiveXObject || "ActiveXObject" in window) return true
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// 成功提示
|
||
|
function successMsg(message) {
|
||
|
Message.success({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 1500})
|
||
|
}
|
||
|
|
||
|
// 警告提示
|
||
|
function warningMsg(message) {
|
||
|
Message.warning({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 1500})
|
||
|
}
|
||
|
|
||
|
// 错误提示
|
||
|
function errorMsg(message) {
|
||
|
Message.error({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration: 1500})
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
fMoney,
|
||
|
toDateTime,
|
||
|
Percentage,
|
||
|
fMoney2,
|
||
|
systemStatus,
|
||
|
systemTypeStatus,
|
||
|
systemAttributionStatus,
|
||
|
courseTypeStatus,
|
||
|
hoursStatus,
|
||
|
roleStatus,
|
||
|
orderTypeFn,
|
||
|
orderStatusFn,
|
||
|
orderNatureFn,
|
||
|
getBirth,
|
||
|
getSex,
|
||
|
removeByValue,
|
||
|
formatDate,
|
||
|
isIE,
|
||
|
successMsg,
|
||
|
warningMsg,
|
||
|
errorMsg
|
||
|
}
|