1.底部导航

v1.0.0
sws 2024-09-27 10:51:22 +08:00
parent 17a203b304
commit 63cc8253d4
2 changed files with 50 additions and 2 deletions

View File

@ -23,6 +23,51 @@ export const predefine_colors = ['#fff', '#ddd', '#ccc', '#999', '#666', '#333',
export function is_obj_empty(obj: object): boolean {
return Object.keys(obj).length === 0;
}
/**
*
*
*
*
* @param obj
* @param maxDepth 100
* @param currentDepth 0
* @returns
*/
export function convert_strings_to_numbers(obj: any, maxDepth: number = 100, currentDepth: number = 0): any {
// 递归深度限制
if (currentDepth >= maxDepth) {
return obj;
}
if (Array.isArray(obj)) {
// 处理数组
return obj.map((item) => convert_strings_to_numbers(item, maxDepth, currentDepth + 1));
} else if (is_obj(obj)) {
// 处理对象
return Object.keys(obj).reduce((acc: any, key: string) => {
const value = obj[key];
if (typeof value === 'string') {
// 处理字符串
const numValue = Number(value);
if (!isNaN(numValue) && value.trim() !== '') {
acc[key] = numValue;
} else {
acc[key] = value;
}
} else if (is_obj(value)) {
// 递归处理子对象
acc[key] = convert_strings_to_numbers(value, maxDepth, currentDepth + 1);
} else {
// 其他类型直接保留
acc[key] = value;
}
return acc;
}, {});
} else {
// 非对象类型直接返回
return obj;
}
}
/**
*
*

View File

@ -18,7 +18,7 @@
</template>
<script setup lang="ts">
import { get_math } from '@/utils';
import { get_math, convert_strings_to_numbers } from '@/utils';
import { Settings, AppMain } from './components/index';
import defaultSettings from './components/main/index';
import { cloneDeep } from 'lodash';
@ -40,7 +40,10 @@ const init = () => {
DiyAPI.getTabbar({ type: 'home' })
.then((res: any) => {
if (res.data) {
form.value = res.data;
let data = res.data;
data.style.common_style = convert_strings_to_numbers(data.style.common_style);
form.value = data;
console.log(form.value);
} else {
form.value = cloneDeep(temp_form.value);
}