1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- export const isValue = (val) => {
- if (val === null || val === undefined || (typeof val === 'string' && val.trim() === '') || (typeof val === 'object' && val?.length === 0)) {
- return false
- }
- return true
- }
- // 对象转驼峰命名
- export const objToCamel = (obj) => {
- for (let key in obj) {
- let newKey = key.replace(/_([a-z])/g, function($0, $1){ return $1.toUpperCase(); });
- if (newKey !== key) {
- obj[newKey] = obj[key];
- delete obj[key];
- }
- }
- }
- // 对象转下划线命名
- export const objToUnder = (obj) => {
- for (let key in obj) {
- let newKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
- if (newKey !== key) {
- obj[newKey] = obj[key];
- delete obj[key];
- }
- }
- }
- // 参数转驼峰命名
- export const paramToCamel = (param) => {
- return param.replace(/_([a-z])/g, function($0, $1){ return $1.toUpperCase(); });
- }
- // 参数转下划线命名
- export const paramToUnder = (param) => {
- return param.replace(/([A-Z])/g, '_$1').toLowerCase();
- }
- export const YMDHms = (date) => {
- const _date = new Date(date)
- 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}`;
- }
- export const YMD = (date, format = false) => {
- const _date = new Date(date)
- 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 format ? `${Y}年${M}月${D}日` : `${Y}-${M}-${D}`;
- }
- export const Hms = (date, format = false) => {
- const _date = new Date(date)
- 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 format ? `${H}时${m}分${s}秒` : `${H}:${m}:${s}`;
- }
|