chore: 最重要的 file 增删改查添加成功
This commit is contained in:
91
apps/designer/.eslintrc-auto-import.json
Normal file
91
apps/designer/.eslintrc-auto-import.json
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"globals": {
|
||||
"Component": true,
|
||||
"ComponentPublicInstance": true,
|
||||
"ComputedRef": true,
|
||||
"DirectiveBinding": true,
|
||||
"EffectScope": true,
|
||||
"ExtractDefaultPropTypes": true,
|
||||
"ExtractPropTypes": true,
|
||||
"ExtractPublicPropTypes": true,
|
||||
"InjectionKey": true,
|
||||
"MaybeRef": true,
|
||||
"MaybeRefOrGetter": true,
|
||||
"PropType": true,
|
||||
"Ref": true,
|
||||
"VNode": true,
|
||||
"WritableComputedRef": true,
|
||||
"acceptHMRUpdate": true,
|
||||
"computed": true,
|
||||
"createApp": true,
|
||||
"createPinia": true,
|
||||
"customRef": true,
|
||||
"defineAsyncComponent": true,
|
||||
"defineComponent": true,
|
||||
"defineStore": true,
|
||||
"effectScope": true,
|
||||
"getActivePinia": true,
|
||||
"getCurrentInstance": true,
|
||||
"getCurrentScope": true,
|
||||
"h": true,
|
||||
"inject": true,
|
||||
"isProxy": true,
|
||||
"isReactive": true,
|
||||
"isReadonly": true,
|
||||
"isRef": true,
|
||||
"mapActions": true,
|
||||
"mapGetters": true,
|
||||
"mapState": true,
|
||||
"mapStores": true,
|
||||
"mapWritableState": true,
|
||||
"markRaw": true,
|
||||
"nextTick": true,
|
||||
"onActivated": true,
|
||||
"onBeforeMount": true,
|
||||
"onBeforeRouteLeave": true,
|
||||
"onBeforeRouteUpdate": true,
|
||||
"onBeforeUnmount": true,
|
||||
"onBeforeUpdate": true,
|
||||
"onDeactivated": true,
|
||||
"onErrorCaptured": true,
|
||||
"onMounted": true,
|
||||
"onRenderTracked": true,
|
||||
"onRenderTriggered": true,
|
||||
"onScopeDispose": true,
|
||||
"onServerPrefetch": true,
|
||||
"onUnmounted": true,
|
||||
"onUpdated": true,
|
||||
"onWatcherCleanup": true,
|
||||
"provide": true,
|
||||
"reactive": true,
|
||||
"readonly": true,
|
||||
"ref": true,
|
||||
"resolveComponent": true,
|
||||
"setActivePinia": true,
|
||||
"setMapStoreSuffix": true,
|
||||
"shallowReactive": true,
|
||||
"shallowReadonly": true,
|
||||
"shallowRef": true,
|
||||
"storeToRefs": true,
|
||||
"toRaw": true,
|
||||
"toRef": true,
|
||||
"toRefs": true,
|
||||
"toValue": true,
|
||||
"triggerRef": true,
|
||||
"unref": true,
|
||||
"useAttrs": true,
|
||||
"useCssModule": true,
|
||||
"useCssVars": true,
|
||||
"useId": true,
|
||||
"useLink": true,
|
||||
"useModel": true,
|
||||
"useRoute": true,
|
||||
"useRouter": true,
|
||||
"useSlots": true,
|
||||
"useTemplateRef": true,
|
||||
"watch": true,
|
||||
"watchEffect": true,
|
||||
"watchPostEffect": true,
|
||||
"watchSyncEffect": true
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@
|
||||
"axios": "^1.8.1",
|
||||
"element-plus": "^2.9.4",
|
||||
"licia-es": "^1.46.0",
|
||||
"pinia": "^3.0.1",
|
||||
"pinia-plugin-persistedstate": "^4.2.0",
|
||||
"unplugin-auto-import": "^19.1.1",
|
||||
"vue": "~3.5.13",
|
||||
"vue-router": "~4.5.0"
|
||||
},
|
||||
|
||||
88
apps/designer/src/auto-imports.d.ts
vendored
Normal file
88
apps/designer/src/auto-imports.d.ts
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
// @ts-nocheck
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
// Generated by unplugin-auto-import
|
||||
// biome-ignore lint: disable
|
||||
export {}
|
||||
declare global {
|
||||
const EffectScope: typeof import('vue')['EffectScope']
|
||||
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
|
||||
const computed: typeof import('vue')['computed']
|
||||
const createApp: typeof import('vue')['createApp']
|
||||
const createPinia: typeof import('pinia')['createPinia']
|
||||
const customRef: typeof import('vue')['customRef']
|
||||
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
||||
const defineComponent: typeof import('vue')['defineComponent']
|
||||
const defineStore: typeof import('pinia')['defineStore']
|
||||
const effectScope: typeof import('vue')['effectScope']
|
||||
const getActivePinia: typeof import('pinia')['getActivePinia']
|
||||
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||
const h: typeof import('vue')['h']
|
||||
const inject: typeof import('vue')['inject']
|
||||
const isProxy: typeof import('vue')['isProxy']
|
||||
const isReactive: typeof import('vue')['isReactive']
|
||||
const isReadonly: typeof import('vue')['isReadonly']
|
||||
const isRef: typeof import('vue')['isRef']
|
||||
const mapActions: typeof import('pinia')['mapActions']
|
||||
const mapGetters: typeof import('pinia')['mapGetters']
|
||||
const mapState: typeof import('pinia')['mapState']
|
||||
const mapStores: typeof import('pinia')['mapStores']
|
||||
const mapWritableState: typeof import('pinia')['mapWritableState']
|
||||
const markRaw: typeof import('vue')['markRaw']
|
||||
const nextTick: typeof import('vue')['nextTick']
|
||||
const onActivated: typeof import('vue')['onActivated']
|
||||
const onBeforeMount: typeof import('vue')['onBeforeMount']
|
||||
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
|
||||
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
|
||||
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
|
||||
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
|
||||
const onDeactivated: typeof import('vue')['onDeactivated']
|
||||
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
|
||||
const onMounted: typeof import('vue')['onMounted']
|
||||
const onRenderTracked: typeof import('vue')['onRenderTracked']
|
||||
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
|
||||
const onScopeDispose: typeof import('vue')['onScopeDispose']
|
||||
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
|
||||
const onUnmounted: typeof import('vue')['onUnmounted']
|
||||
const onUpdated: typeof import('vue')['onUpdated']
|
||||
const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
|
||||
const provide: typeof import('vue')['provide']
|
||||
const reactive: typeof import('vue')['reactive']
|
||||
const readonly: typeof import('vue')['readonly']
|
||||
const ref: typeof import('vue')['ref']
|
||||
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||
const setActivePinia: typeof import('pinia')['setActivePinia']
|
||||
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
|
||||
const shallowReactive: typeof import('vue')['shallowReactive']
|
||||
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
||||
const shallowRef: typeof import('vue')['shallowRef']
|
||||
const storeToRefs: typeof import('pinia')['storeToRefs']
|
||||
const toRaw: typeof import('vue')['toRaw']
|
||||
const toRef: typeof import('vue')['toRef']
|
||||
const toRefs: typeof import('vue')['toRefs']
|
||||
const toValue: typeof import('vue')['toValue']
|
||||
const triggerRef: typeof import('vue')['triggerRef']
|
||||
const unref: typeof import('vue')['unref']
|
||||
const useAttrs: typeof import('vue')['useAttrs']
|
||||
const useCssModule: typeof import('vue')['useCssModule']
|
||||
const useCssVars: typeof import('vue')['useCssVars']
|
||||
const useId: typeof import('vue')['useId']
|
||||
const useLink: typeof import('vue-router')['useLink']
|
||||
const useModel: typeof import('vue')['useModel']
|
||||
const useRoute: typeof import('vue-router')['useRoute']
|
||||
const useRouter: typeof import('vue-router')['useRouter']
|
||||
const useSlots: typeof import('vue')['useSlots']
|
||||
const useTemplateRef: typeof import('vue')['useTemplateRef']
|
||||
const watch: typeof import('vue')['watch']
|
||||
const watchEffect: typeof import('vue')['watchEffect']
|
||||
const watchPostEffect: typeof import('vue')['watchPostEffect']
|
||||
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
|
||||
}
|
||||
// for type re-export
|
||||
declare global {
|
||||
// @ts-ignore
|
||||
export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
|
||||
import('vue')
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type BlockSchema } from '@vtj/core';
|
||||
import instance from './instance';
|
||||
import { fi } from 'element-plus/es/locale/index.mjs';
|
||||
|
||||
export type LowCodeFileSchema = {
|
||||
project_id: number;
|
||||
@@ -7,6 +8,7 @@ export type LowCodeFileSchema = {
|
||||
active: boolean;
|
||||
dsl: BlockSchema;
|
||||
file_path?: string;
|
||||
file_id?: string;
|
||||
};
|
||||
|
||||
function transformFile(file: LowCodeFileSchema): LowCodeFileSchema {
|
||||
@@ -16,7 +18,8 @@ function transformFile(file: LowCodeFileSchema): LowCodeFileSchema {
|
||||
active: file.active,
|
||||
// @ts-ignore
|
||||
dsl: JSON.stringify(file.dsl),
|
||||
file_path: file.file_path
|
||||
file_path: file.file_path,
|
||||
file_id: file.file_id
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,10 +30,7 @@ export const getFileList = async () => {
|
||||
|
||||
export const getFile = async (id: string) => {
|
||||
const response = await instance.get(`/api/v1/files/${id}`);
|
||||
return {
|
||||
...response.data,
|
||||
dsl: JSON.parse(response.data.dsl)
|
||||
};
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const createFile = async (data: LowCodeFileSchema) => {
|
||||
@@ -39,7 +39,10 @@ export const createFile = async (data: LowCodeFileSchema) => {
|
||||
};
|
||||
|
||||
export const updateFile = async (id: string, data: LowCodeFileSchema) => {
|
||||
const response = await instance.put(`/api/v1/files/${id}`, data);
|
||||
const response = await instance.put(
|
||||
`/api/v1/files/${id}`,
|
||||
transformFile(data)
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
import { createApp } from 'vue';
|
||||
import { createPersistedState } from 'pinia-plugin-persistedstate';
|
||||
|
||||
import router from './router';
|
||||
import App from './App.vue';
|
||||
import './style/index.scss';
|
||||
import { pinia } from './store';
|
||||
|
||||
// 添加持久化插件
|
||||
pinia.use(
|
||||
createPersistedState({
|
||||
auto: true, // 自动持久化所有 store
|
||||
storage: localStorage
|
||||
})
|
||||
);
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.use(pinia);
|
||||
app.mount('#app');
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
createFile,
|
||||
updateFile as updateLowCodeFile,
|
||||
getFile as getLowCodeFile,
|
||||
deleteFile as deleteLowCodeFile,
|
||||
type LowCodeFileSchema
|
||||
} from '@/io';
|
||||
import { isNumeric } from 'licia-es';
|
||||
@@ -89,52 +90,34 @@ export class StorageService extends BaseService {
|
||||
}
|
||||
|
||||
public async saveFile(file: BlockSchema): Promise<boolean> {
|
||||
// console.log('file', file);
|
||||
// const ACTION = {
|
||||
// CREATE: 'create',
|
||||
// UPDATE: 'update'
|
||||
// };
|
||||
// const action = isNumeric(file.id) ? ACTION.UPDATE : ACTION.CREATE;
|
||||
// console.log('action', action);
|
||||
// console.log('saveFile', file);
|
||||
// if (action === ACTION.CREATE) {
|
||||
// const newFile: LowCodeFileSchema = {
|
||||
// project_id: 2,
|
||||
// publish: false,
|
||||
// active: true,
|
||||
// dsl: file
|
||||
// };
|
||||
// Reflect.deleteProperty(newFile, 'id');
|
||||
// const res = await createFile(newFile);
|
||||
// console.log('saveFile-res', res);
|
||||
// }
|
||||
console.log('saveFile', file);
|
||||
if (file.id) {
|
||||
const existFile = await getLowCodeFile(file.id);
|
||||
console.log('existFile', existFile);
|
||||
if (existFile) {
|
||||
if (existFile.file_id) {
|
||||
console.log('updateFile', file, existFile);
|
||||
await updateLowCodeFile(file.id, {
|
||||
...existFile,
|
||||
dsl: file
|
||||
});
|
||||
} else {
|
||||
console.log('createFile', file);
|
||||
await createFile({
|
||||
project_id: 2,
|
||||
publish: false,
|
||||
active: true,
|
||||
dsl: file
|
||||
dsl: file,
|
||||
file_id: file.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// storage.save(`file_${file.id}`, file);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
public async getFile(id: string): Promise<BlockSchema> {
|
||||
const dsl = storage.get(`file_${id}`);
|
||||
console.log('getFile', id, dsl);
|
||||
const lowCodeFile = await getLowCodeFile(id);
|
||||
console.log('lowCodeFile', lowCodeFile);
|
||||
console.log('getFile', lowCodeFile);
|
||||
if (lowCodeFile.dsl) {
|
||||
return Promise.resolve(lowCodeFile.dsl as BlockSchema);
|
||||
} else {
|
||||
@@ -142,10 +125,14 @@ export class StorageService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
public removeFile(id: string): Promise<boolean> {
|
||||
public async removeFile(id: string): Promise<boolean> {
|
||||
storage.remove(`file_${id}`);
|
||||
console.log('removeFile', id);
|
||||
return Promise.resolve(true);
|
||||
// return Promise.resolve(true);
|
||||
return deleteLowCodeFile(id).then((res) => {
|
||||
console.log('removeFile-res', res);
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
public saveHistory(history: HistorySchema): Promise<boolean> {
|
||||
|
||||
67
apps/designer/src/store/index.ts
Normal file
67
apps/designer/src/store/index.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { ref, computed } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { createPinia, defineStore } from 'pinia';
|
||||
|
||||
// 创建 pinia 实例
|
||||
export const pinia = createPinia();
|
||||
|
||||
// 用户模块 store
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
// 状态定义
|
||||
const token = ref<string>(localStorage.getItem('token') || '');
|
||||
const userProfile = ref<null>(null);
|
||||
|
||||
// getter 计算属性
|
||||
const isLoggedIn = computed(() => !!token.value);
|
||||
|
||||
// 同步 action
|
||||
const setToken = (newToken: string) => {
|
||||
token.value = newToken;
|
||||
localStorage.setItem('token', newToken);
|
||||
};
|
||||
|
||||
// 异步 action
|
||||
const fetchProfile = async () => {
|
||||
const { data } = await axios.get('/api/user/profile');
|
||||
userProfile.value = data;
|
||||
};
|
||||
|
||||
// 清理方法
|
||||
const logout = () => {
|
||||
token.value = '';
|
||||
userProfile.value = null;
|
||||
localStorage.removeItem('token');
|
||||
};
|
||||
|
||||
return {
|
||||
token,
|
||||
userProfile,
|
||||
isLoggedIn,
|
||||
setToken,
|
||||
fetchProfile,
|
||||
logout
|
||||
};
|
||||
});
|
||||
|
||||
// 应用配置 store
|
||||
export const useAppStore = defineStore('app', () => {
|
||||
const theme = ref<'light' | 'dark'>('light');
|
||||
const sidebarCollapsed = ref(false);
|
||||
|
||||
// 持久化配置
|
||||
const persist = {
|
||||
paths: ['theme', 'sidebarCollapsed'],
|
||||
storage: localStorage
|
||||
};
|
||||
|
||||
const toggleTheme = () => {
|
||||
theme.value = theme.value === 'light' ? 'dark' : 'light';
|
||||
};
|
||||
|
||||
return {
|
||||
theme,
|
||||
sidebarCollapsed,
|
||||
toggleTheme,
|
||||
persist
|
||||
};
|
||||
});
|
||||
@@ -4,10 +4,31 @@ import { createDevTools } from '@vtj/local';
|
||||
import http2Proxy from '@sy/vite-plugin-http2-proxy';
|
||||
import proxy from './proxy.config';
|
||||
import mkcert from 'vite-plugin-mkcert';
|
||||
import AutoImport from 'unplugin-auto-import/vite';
|
||||
|
||||
const config = createViteConfig({
|
||||
proxy,
|
||||
plugins: [createDevTools(), http2Proxy(), mkcert()]
|
||||
plugins: [
|
||||
createDevTools(),
|
||||
http2Proxy(),
|
||||
mkcert(),
|
||||
AutoImport({
|
||||
imports: [
|
||||
'vue',
|
||||
'pinia',
|
||||
'vue-router',
|
||||
{
|
||||
from: 'pinia',
|
||||
imports: ['storeToRefs', 'defineStore'],
|
||||
type: true
|
||||
}
|
||||
],
|
||||
dts: 'src/auto-imports.d.ts', // 生成类型声明文件
|
||||
eslintrc: {
|
||||
enabled: true // 生成 eslint 配置
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
export default defineConfig({
|
||||
|
||||
Reference in New Issue
Block a user