feat: 完成代码生成模板(1.0)

This commit is contained in:
xlsea
2024-09-08 21:47:56 +08:00
parent 2e0b16d0b3
commit ff3ed20bba
13 changed files with 474 additions and 40 deletions

View File

@ -1,7 +1,9 @@
<script setup lang="ts">
import { createTextVNode, defineComponent } from 'vue';
import { createTextVNode, defineComponent, onMounted } from 'vue';
import { useDialog, useLoadingBar, useMessage, useNotification } from 'naive-ui';
import useContentLoading from '@/hooks/common/loading';
import { initWebSocket } from '@/utils/websocket';
import { initSSE } from '@/utils/sse';
defineOptions({
name: 'AppProvider'
@ -25,6 +27,12 @@ const ContextHolder = defineComponent({
return () => createTextVNode();
}
});
onMounted(() => {
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
initWebSocket(`${protocol + window.location.host + import.meta.env.VITE_APP_BASE_API}/resource/websocket`);
initSSE(`${import.meta.env.VITE_APP_BASE_API}/resource/sse`);
});
</script>
<template>

View File

@ -1,9 +1,11 @@
import { ref } from 'vue';
import { ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { fetchGetDictDataByType } from '@/service/api/system';
import { useDictStore } from '@/store/modules/dict';
export function useDict(dictType: string, immediate: boolean = true) {
const dictStore = useDictStore();
const { dictData: dictList } = storeToRefs(dictStore);
const data = ref<Api.System.DictData[]>([]);
const record = ref<Record<string, string>>({});
@ -43,6 +45,17 @@ export function useDict(dictType: string, immediate: boolean = true) {
getRecord();
getOptions();
});
} else {
watch(
() => dictList.value[dictType],
val => {
if (val && val.length) {
getRecord();
getOptions();
}
},
{ immediate: true }
);
}
return {

View File

@ -1,11 +1,9 @@
<script setup lang="ts">
import { computed, defineAsyncComponent, onMounted } from 'vue';
import { computed, defineAsyncComponent } from 'vue';
import { AdminLayout, LAYOUT_SCROLL_EL_ID } from '@sa/materials';
import type { LayoutMode } from '@sa/materials';
import { useAppStore } from '@/store/modules/app';
import { useThemeStore } from '@/store/modules/theme';
import { initWebSocket } from '@/utils/websocket';
import { initSSE } from '@/utils/sse';
import GlobalHeader from '../modules/global-header/index.vue';
import GlobalSider from '../modules/global-sider/index.vue';
import GlobalTab from '../modules/global-tab/index.vue';
@ -102,12 +100,6 @@ function getSiderCollapsedWidth() {
return w;
}
onMounted(() => {
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
initWebSocket(`${protocol + window.location.host + import.meta.env.VITE_APP_BASE_API}/resource/websocket`);
initSSE(`${import.meta.env.VITE_APP_BASE_API}/resource/sse`);
});
</script>
<template>

View File

@ -21,7 +21,12 @@ declare namespace Api {
}
/** common search params of table */
type CommonSearchParams = Pick<Common.PaginatingCommonParams, 'pageNum' | 'pageSize'>;
type CommonSearchParams<T = any> = Pick<Common.PaginatingCommonParams, 'pageNum' | 'pageSize'> &
CommonType.RecordNullable<{
orderByColumn: keyof T;
isAsc: 'asc' | 'desc';
params: { [key: string]: any };
}>;
/**
* 启用状态

View File

@ -10,8 +10,6 @@ declare namespace Api {
* backend api module: "system"
*/
namespace System {
type CommonSearchParams = Pick<Common.PaginatingCommonParams, 'pageNum' | 'pageSize'>;
/** role */
type Role = Common.CommonRecord<{
/** 数据范围1全部数据权限 2自定数据权限 3本部门数据权限 4本部门及以下数据权限 */
@ -40,7 +38,7 @@ declare namespace Api {
/** role search params */
type RoleSearchParams = CommonType.RecordNullable<
Pick<Role, 'roleName' | 'roleKey' | 'status'> & CommonSearchParams
Pick<Role, 'roleName' | 'roleKey' | 'status'> & Common.CommonSearchParams<Role>
>;
/** role list */
@ -93,7 +91,7 @@ declare namespace Api {
/** user search params */
type UserSearchParams = CommonType.RecordNullable<
Pick<User, 'userName' | 'sex' | 'nickName' | 'phonenumber' | 'email' | 'status'> & CommonSearchParams
Pick<User, 'userName' | 'sex' | 'nickName' | 'phonenumber' | 'email' | 'status'> & Common.CommonSearchParams<User>
>;
/** user list */

View File

@ -40,8 +40,8 @@ const visible = defineModel<boolean>('visible', {
default: false
});
const { options: showHideOptions, getOptions: getShowHideOptions } = useDict('sys_show_hide', false);
const { options: enableStatusOptions, getOptions: getNormalDisableOptions } = useDict('sys_normal_disable', false);
const { options: showHideOptions } = useDict('sys_show_hide', false);
const { options: enableStatusOptions } = useDict('sys_normal_disable');
const iconType = ref<Api.System.IconType>('1');
const { formRef, validate, restoreValidation } = useNaiveForm();
@ -217,9 +217,6 @@ watch(visible, () => {
if (visible.value) {
handleInitModel();
restoreValidation();
getShowHideOptions();
getShowHideOptions();
getNormalDisableOptions();
}
});

View File

@ -70,7 +70,9 @@ const genMap: Api.Tool.GenTablePreview = {
'vm/sql/sql.vm': 'sql',
'vm/soybean/api/soy.api.ts.vm': 'api.ts',
'vm/soybean/typings/soy.api.d.ts.vm': 'type.d.ts',
'vm/soybean/soy.index.vue.vm': 'index.vue'
'vm/soybean/soy.index.vue.vm': 'index.vue',
'vm/soybean/modules/soy.search.vue.vm': 'search.vue',
'vm/soybean/modules/soy.operate-drawer.vue.vm': 'operate-drawer.vue'
};
function getGenLanguage(name: string) {