feat: tools工具函数和自动生成路由

master
LCJ-MinYa 1 year ago
parent 8fb7a81b41
commit a75b3e674a

@ -1,5 +1,33 @@
const Layout = () => import('@/layout/index.vue'); const Layout = () => import('@/layout/index.vue');
// @/views/demo/**/*.vue
/**
* (使 ** )
* views/demo.vue
* /demo/jsx/components/index.vue
*/
// @/views/demo/*.vue 第一层目录
// @/views/demo/*/*.vue 第二层目录
/**
* => views/demo.vue()
* /views/demo/index.vue
*
* => views/demo.vue()
* /views/demo/jsx/index.vue
*
* /views/demo/jsx/components/index.vue
*/
const firstLevelComponents = import.meta.glob('@/views/demo/*.vue');
const secondLevelComponents = import.meta.glob('@/views/demo/*/*.vue');
const components = { ...firstLevelComponents, ...secondLevelComponents };
console.log(components);
const demoRoutes = Object.keys(components).map((path) => {
console.log(path);
const component = components[path];
});
export default { export default {
path: '/demo', path: '/demo',
name: 'Demo', name: 'Demo',
@ -13,7 +41,7 @@ export default {
children: [ children: [
{ {
path: '/demo/jsx', path: '/demo/jsx',
name: 'Jsx', name: 'DemoJsx',
component: () => import('@/views/demo/jsx/index.vue'), component: () => import('@/views/demo/jsx/index.vue'),
meta: { meta: {
title: '使用jsx', title: '使用jsx',

@ -0,0 +1,18 @@
/** url地址相关工具 */
export const url = {
/**
* url
* @param obj { x: 1, y: 2, z: 3 }
* @param ignoreFields ['z']
* @returns x=1&y=2
*/
objToUrlParma: (obj: Record<string, any>, ignoreFields: Array<string> = []): string => {
return (
'?' +
Object.keys(obj)
.filter((key) => ignoreFields.indexOf(key) === -1)
.map((key) => `${key}=${obj[key]}`)
.join('&')
);
},
};

@ -38,7 +38,7 @@ import styles from './jsx.module.scss';
* 4. jsx在template中怎么写才能渲染 * 4. jsx在template中怎么写才能渲染
*/ */
defineOptions({ defineOptions({
name: 'Jsx', name: 'DemoJsx',
}); });
const refs = ref({}); const refs = ref({});

@ -0,0 +1,15 @@
<template>
<el-card> 基础模版 </el-card>
</template>
<script setup lang="jsx">
import { ref } from 'vue';
defineOptions({
name: 'DemoTools',
});
const page = ref({});
</script>
<style lang="scss" scoped></style>

@ -0,0 +1,15 @@
<template>
<el-card> 基础模版 </el-card>
</template>
<script setup lang="jsx">
import { ref } from 'vue';
defineOptions({
name: 'DemoTools',
});
const page = ref({});
</script>
<style lang="scss" scoped></style>
Loading…
Cancel
Save