import { arrIndex, clog } from 'js-fast-way' import config from '~src/config/index' import { useAppStore } from '~src/store' const store = useAppStore() //控制台打印 export const HcLog = (name, tips, data) => { const title = store.barMenuName ?? '' if (config.isLog === 'auto') { if (import.meta.env.DEV) { clog(title, name, tips, data) } } else if (config.isLog === true) { clog(title, name, tips, data) } } //取数组中的值 export const getRowsValue = (arr, key, key2, value) => { if (value) { const index = arrIndex(arr, key, value) return arr[index][key2] } else { return '' } } //获取ID,并转为数字 export const rowsToIdNumArr = (rows) => { const ids = rowsToId(rows) let keys = ids ? ids.split(',') : [] for (let i = 0; i < keys.length; i++) { keys[i] = Number(keys[i]) } return keys } //拼接ID export const rowsToId = (rows) => { return rowsToKey(rows, 'id') } //拼接字段 export const rowsToKey = (rows, key) => { return rows.map((obj) => { return obj[key] }).join(',') } //删除提醒 export const delMessage = (cbk) => { window?.$messageBox?.alert('请谨慎考虑后,确认是否需要删除?', '删除提醒', { showCancelButton: true, confirmButtonText: '确认删除', cancelButtonText: '取消', type: 'warning', callback: (action) => { if (action === 'confirm') { cbk() } }, }) } //日期格式化 export const dateFormat = (date, format) => { format = format || 'yyyy-MM-dd hh:mm:ss' if (date !== 'Invalid Date') { let o = { 'M+': date.getMonth() + 1, //month 'd+': date.getDate(), //day 'h+': date.getHours(), //hour 'm+': date.getMinutes(), //minute 's+': date.getSeconds(), //second 'q+': Math.floor((date.getMonth() + 3) / 3), //quarter 'S': date.getMilliseconds(), //millisecond } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) } } return format } return '' } //获取当前域名 export const getTopUrl = () => { return window.location.href.split('/#/')[0] } //设置系统名称 export const setAppName = (name) => { const title = window.document.title window.document.title = `${title} - ${name}` } //替换http为https export const setUrlHttps = (url) => { if (!url) return url return url.replace('http://', 'https://') }