2021-12-01 17:51发布
在开发过程中,一个文件里要存放多个函数,那这些函数用不用按照功能一类的排一下序呢?一般都分为几类呢
// 金额三位加一个逗号100,322,33(从前往后)export const money = (value, num) => { num = num > 0 && num <= 20 ? num : 2; value = `${parseFloat((`${value}`).replace(/[^\d\.-]/g, '')).toFixed(num)}`; // 将金额转成比如 123.45的字符串 const valueArr = value.split('.')[0].split(''); // 将字符串的数变成数组 const valueFloat = value.split('.')[1]; // 取到 小数点后的值 let valueString = ''; // eslint-disable-next-line no-plusplus for (let i = 0; i < valueArr.length; i++) { valueString += valueArr[i] + ((i + 1) % 3 == 0 && (i + 1) != valueArr.length ? ',' : ''); // 循环 取数值并在每三位加个',' } const money = `${valueString.split('').join('')}.${valueFloat}`; // 拼接上小数位 return money;};// 金额三位加一个逗号,从后往前export const money=(nStr)=> { nStr += ''; const x = nStr.split('.'); let x1 = x[0]; const x2 = x.length > 1 ? '.' + x[1] : ''; const rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2;};// 9,999,999.00 // 传字符串// 时间戳转化成年月日,时分秒方法一export const time = (time = +new Date()) => { const date = new Date(time + 8 * 3600 * 1000); return date.toJSON().substr(0, 19).replace('T', ' ').replace(/-/g, '-');};// 时间戳转化成年月日export const time1 = (time) => { const date = new Date(parseInt(time)); // 时间戳为10位需乘1000,为13位则不用 const Y = date.getFullYear(); // 年 const M = (date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1); // 月 const D = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`;// 日 return `${Y}-${M}-${D}`; // yyyy-mm-dd};// 时间戳转化成年月日,时分秒方法二export const updateTime = (time) => { const date = new Date(parseInt(time)); // 时间戳为10位需乘1000,为13位则不用 const Y = date.getFullYear(); // 年 const M = (date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1); // 月 const D = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`;// 日 const h = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); // 时 const m = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); // 分 const s = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();// 秒 return `${Y}-${M}-${D} ${h}:${m}:${s}`; // yyyy-mm-dd hh:mm:ss};//深比较export const equals = function( x, y ) { if ( x === y ) return true; if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) return false; if ( x.constructor !== y.constructor ) return false; for ( var p in x ) { if ( typeof( x[ p ] ) === "function" ) { if ( x[ p ].toString() !== y[ p ].toString() ) return false }; if ( ! x.hasOwnProperty( p ) ) continue; if ( ! y.hasOwnProperty( p ) ) return false; if ( x[ p ] === y[ p ] ) continue; if ( typeof( x[ p ] ) !== "object" ) return false; if ( ! equals( x[ p ], y[ p ] ) ) return false; } for ( p in y ) { if ( y.hasOwnProperty( p ) && ! x.hasOwnProperty( p ) ) return false; } return true;}// 小数export const toNumber = (v) => { if (typeof v === 'number') { return v; } if (!v || !v.trim()) { return undefined; } let num = Number(v); if (!isNaN(num)) { num = parseInt(v, 10); } return isNaN(num) ? v : num;};// 保留两位export const toFix2 = (v) => { const num = toNumber(v); if (typeof num === 'number') { return num.toFixed(2); } return v;};// 带小数数字格式化 千分位,保留几位小数,四舍五入export const formatNumber = (v) => { v = Math.round(v / 1000); let num = v + ''; if (!num.includes('.')) { num += '.'; } return num.replace(/(\d)(?=(\d{3})+\.)/g, function ($0: string, $1: string) { return $1 + ','; }).replace(/\.$/, '');};// axios下载文件流函数export const blobFileDownload = (res) => { const contentType = res.headers['content-type']; const disposition = res.headers['content-disposition']; const fileName = decodeURI(disposition.substring(disposition.indexOf('filename=') + 9, disposition.length)); const blob = new Blob([res.data], { type: contentType }); const link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = fileName; link.click(); link.remove();};与之相关的请求import axios from 'axios';export const downloadDetail = data => axios('/a/downloadDetail', { // 下载 method: 'POST', data, responseType: 'blob',});export const downLoadTemplate = ({ // 模板下载 templateId,}) => { const url = `/a/downLoadTemplate?templateId=${templateId}`; return axios(url, { method: 'GET', responseType: 'blob', });};// 字符串超出长度显示...
指数函数、幂函数、对数函数、三角函数 初中部分的正反比例函数,二次函数也要很熟
最多设置5个标签!
回答: 2021-12-02 10:20
指数函数、幂函数、对数函数、三角函数 初中部分的正反比例函数,二次函数也要很熟
一周热门 更多>