mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-10-01 08:12:03 +00:00
* feat(mcp): 新增gva_review工具并优化字典和代码生成逻辑 * fix: 调整mcp整体逻辑 * chore: 更新.gitignore,添加对本地配置文件的忽略 * feat(logo): 新增Logo组件并在多个页面中替换原有logo实现 * fix: 修复菜单 Logo 部分删除文本后显示异常的问题 * fix:添加字典列表搜索,支持中英文搜索.添加字典详情搜索 * style: 优化部分视觉样式 * feat: 增强错误预览组件的暗黑模式支持 * feat: 优化请求错误消息获取逻辑,增加状态文本优先级 * feat: 添加前端登录验证码静态验证逻辑 * feat: 添加开发环境启动脚本 * feat: 更新 SvgIcon 组件,支持本地图标和 Iconify 图标、移除未使用的 unocss 依赖 * fix:字典支持 tree 结构 * feat: 优化动态路由注册方式 * feat: 添加配置控制标签页keep-alive功能 * feat: 添加全局错误处理机制,捕获 Vue 和 JS 错误 * refactor: 移除API和菜单创建结果中的权限分配提醒,优化输出信息 * feat: 更新 reset.scss,优化全局样式重置,增强兼容性和可读性 * refactor(字典详情): 优化字典详情查询逻辑,移除预加载改为按需加载 * refactor(路由管理): 优化路由添加逻辑,增强路径处理和顶级路由注册 * refactor(系统配置): 将auto-migrate修改为disable-auto-migrate,保证用户升级的兼容性 * feat(utils): 优化字典数据递归查找功能并替换select为tree-select * fix(deps): 修复在字段类型为file生成搜索条件无法运行的bug * fix: 修复header的tools中icon不展示的问题 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: Azir-11 <2075125282@qq.com> Co-authored-by: bypanghu <bypanghu@163.com> Co-authored-by: feitianbubu <feitianbubu@qq.com> Co-authored-by: 青菜白玉汤 <79054161+Azir-11@users.noreply.github.com> Co-authored-by: krank <emosick@qq.com>
186 lines
4.8 KiB
JavaScript
186 lines
4.8 KiB
JavaScript
import { formatTimeToStr } from '@/utils/date'
|
|
import { getDict } from '@/utils/dictionary'
|
|
import { ref } from 'vue'
|
|
|
|
export const formatBoolean = (bool) => {
|
|
if (bool !== null) {
|
|
return bool ? '是' : '否'
|
|
} else {
|
|
return ''
|
|
}
|
|
}
|
|
export const formatDate = (time) => {
|
|
if (time !== null && time !== '') {
|
|
var date = new Date(time)
|
|
return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
|
|
} else {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
export const filterDict = (value, options) => {
|
|
// 递归查找函数
|
|
const findInOptions = (opts, targetValue) => {
|
|
if (!opts || !Array.isArray(opts)) return null
|
|
|
|
for (const item of opts) {
|
|
if (item.value === targetValue) {
|
|
return item
|
|
}
|
|
|
|
if (item.children && Array.isArray(item.children)) {
|
|
const found = findInOptions(item.children, targetValue)
|
|
if (found) return found
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
const rowLabel = findInOptions(options, value)
|
|
return rowLabel && rowLabel.label
|
|
}
|
|
|
|
export const filterDataSource = (dataSource, value) => {
|
|
// 递归查找函数
|
|
const findInDataSource = (data, targetValue) => {
|
|
if (!data || !Array.isArray(data)) return null
|
|
|
|
for (const item of data) {
|
|
// 检查当前项是否匹配
|
|
if (item.value === targetValue) {
|
|
return item
|
|
}
|
|
|
|
// 如果有children属性,递归查找
|
|
if (item.children && Array.isArray(item.children)) {
|
|
const found = findInDataSource(item.children, targetValue)
|
|
if (found) return found
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
return value.map((item) => {
|
|
const rowLabel = findInDataSource(dataSource, item)
|
|
return rowLabel?.label
|
|
})
|
|
}
|
|
|
|
const rowLabel = findInDataSource(dataSource, value)
|
|
return rowLabel?.label
|
|
}
|
|
|
|
export const getDictFunc = async (type) => {
|
|
const dicts = await getDict(type)
|
|
return dicts
|
|
}
|
|
|
|
const path =
|
|
import.meta.env.VITE_BASE_PATH + ':' + import.meta.env.VITE_SERVER_PORT + '/'
|
|
export const ReturnArrImg = (arr) => {
|
|
const imgArr = []
|
|
if (arr instanceof Array) {
|
|
// 如果是数组类型
|
|
for (const arrKey in arr) {
|
|
if (arr[arrKey].slice(0, 4) !== 'http') {
|
|
imgArr.push(path + arr[arrKey])
|
|
} else {
|
|
imgArr.push(arr[arrKey])
|
|
}
|
|
}
|
|
} else {
|
|
// 如果不是数组类型
|
|
if (arr?.slice(0, 4) !== 'http') {
|
|
imgArr.push(path + arr)
|
|
} else {
|
|
imgArr.push(arr)
|
|
}
|
|
}
|
|
return imgArr
|
|
}
|
|
|
|
export const returnArrImg = ReturnArrImg
|
|
|
|
export const onDownloadFile = (url) => {
|
|
window.open(path + url)
|
|
}
|
|
const colorToHex = (u) => {
|
|
let e = u.replace('#', '').match(/../g)
|
|
for (let t = 0; t < 3; t++) e[t] = parseInt(e[t], 16)
|
|
return e
|
|
}
|
|
|
|
const hexToColor = (u, e, t) => {
|
|
let a = [u.toString(16), e.toString(16), t.toString(16)]
|
|
for (let n = 0; n < 3; n++) a[n].length === 1 && (a[n] = `0${a[n]}`)
|
|
return `#${a.join('')}`
|
|
}
|
|
const generateAllColors = (u, e) => {
|
|
let t = colorToHex(u)
|
|
const target = [10, 10, 30]
|
|
for (let a = 0; a < 3; a++) t[a] = Math.floor(t[a] * (1 - e) + target[a] * e)
|
|
return hexToColor(t[0], t[1], t[2])
|
|
}
|
|
|
|
const generateAllLightColors = (u, e) => {
|
|
let t = colorToHex(u)
|
|
const target = [240, 248, 255] // RGB for blue white color
|
|
for (let a = 0; a < 3; a++) t[a] = Math.floor(t[a] * (1 - e) + target[a] * e)
|
|
return hexToColor(t[0], t[1], t[2])
|
|
}
|
|
|
|
function addOpacityToColor(u, opacity) {
|
|
let t = colorToHex(u)
|
|
return `rgba(${t[0]}, ${t[1]}, ${t[2]}, ${opacity})`
|
|
}
|
|
|
|
export const setBodyPrimaryColor = (primaryColor, darkMode) => {
|
|
let fmtColorFunc = generateAllColors
|
|
if (darkMode === 'light') {
|
|
fmtColorFunc = generateAllLightColors
|
|
}
|
|
|
|
document.documentElement.style.setProperty('--el-color-primary', primaryColor)
|
|
document.documentElement.style.setProperty(
|
|
'--el-color-primary-bg',
|
|
addOpacityToColor(primaryColor, 0.4)
|
|
)
|
|
for (let times = 1; times <= 2; times++) {
|
|
document.documentElement.style.setProperty(
|
|
`--el-color-primary-dark-${times}`,
|
|
fmtColorFunc(primaryColor, times / 10)
|
|
)
|
|
}
|
|
for (let times = 1; times <= 10; times++) {
|
|
document.documentElement.style.setProperty(
|
|
`--el-color-primary-light-${times}`,
|
|
fmtColorFunc(primaryColor, times / 10)
|
|
)
|
|
}
|
|
document.documentElement.style.setProperty(
|
|
`--el-menu-hover-bg-color`,
|
|
addOpacityToColor(primaryColor, 0.2)
|
|
)
|
|
}
|
|
|
|
const baseUrl = ref(import.meta.env.VITE_BASE_API)
|
|
|
|
export const getBaseUrl = () => {
|
|
return baseUrl.value === '/' ? '' : baseUrl.value
|
|
}
|
|
|
|
export const CreateUUID = () => {
|
|
let d = new Date().getTime()
|
|
if (window.performance && typeof window.performance.now === 'function') {
|
|
d += performance.now()
|
|
}
|
|
return '00000000-0000-0000-0000-000000000000'.replace(/0/g, (c) => {
|
|
const r = (d + Math.random() * 16) % 16 | 0 // d是随机种子
|
|
d = Math.floor(d / 16)
|
|
return (c === '0' ? r : (r & 0x3) | 0x8).toString(16)
|
|
})
|
|
}
|