|
|
@@ -17,6 +17,8 @@ import { useDebouncedRefHistory } from '@vueuse/core'
|
|
|
import { useRecentProject } from './recentProject'
|
|
|
import { v4 } from 'uuid'
|
|
|
import dayjs from 'dayjs'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
export interface IProject {
|
|
|
version: string
|
|
|
@@ -48,6 +50,7 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
})
|
|
|
|
|
|
const recentProjectStore = useRecentProject()
|
|
|
+ const { t } = useI18n()
|
|
|
|
|
|
// 项目路径
|
|
|
const projectPath = ref<string>()
|
|
|
@@ -68,6 +71,8 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
*/
|
|
|
const createApp = async (meta: AppMeta) => {
|
|
|
meta = klona(meta)
|
|
|
+ meta.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ meta.modifyTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
// 1、应用元信息
|
|
|
project.value = {
|
|
|
version: '1.0.0',
|
|
|
@@ -139,8 +144,8 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
id: v4(),
|
|
|
projectName: meta.name,
|
|
|
projectPath: `${meta.path}\\${meta.name}`,
|
|
|
- createTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- modifyTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ createTime: meta.createTime,
|
|
|
+ modifyTime: meta.modifyTime
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -148,13 +153,44 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
* 加载项目
|
|
|
* @param newProject 项目字符串
|
|
|
*/
|
|
|
- const loadProject = (newProject: IProject) => {
|
|
|
+ const loadProject = (newProject: IProject, path: string) => {
|
|
|
project.value = newProject
|
|
|
+ // 修改项目路径
|
|
|
+ if (project.value.meta.path !== path) {
|
|
|
+ project.value.meta.path = path
|
|
|
+ }
|
|
|
// 初始化处理
|
|
|
clear()
|
|
|
- projectPath.value = `${newProject.meta.path}/${newProject.meta.name}`
|
|
|
+ projectPath.value = path
|
|
|
activePageId.value = newProject.screens[0].pages?.[0]?.id
|
|
|
imageCompressFormat.value = newProject.meta.imageCompress
|
|
|
+ recentProjectStore.addProject({
|
|
|
+ id: v4(),
|
|
|
+ projectName: newProject.meta.name,
|
|
|
+ projectPath: path,
|
|
|
+ createTime: newProject.meta.createTime,
|
|
|
+ modifyTime: newProject.meta.modifyTime
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存当前项目
|
|
|
+ const saveProject = async () => {
|
|
|
+ if (!projectPath.value) {
|
|
|
+ ElMessage.error(t('projectNotExist'))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 1、保存项目
|
|
|
+ await window.electron.ipcRenderer.invoke(
|
|
|
+ 'write-file',
|
|
|
+ `${projectPath.value}\\project.ui`,
|
|
|
+ JSON.stringify(project.value)
|
|
|
+ )
|
|
|
+ // 2、更新修改时间
|
|
|
+ recentProjectStore.updateProject({
|
|
|
+ ...recentProjectStore.currentRecord!,
|
|
|
+ modifyTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ })
|
|
|
+ ElMessage.success(t('saveSuccess'))
|
|
|
}
|
|
|
|
|
|
// 删除页面
|
|
|
@@ -174,6 +210,45 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ // 打开本地项目
|
|
|
+ const openLocalProject = async () => {
|
|
|
+ const paths = await window.electron.ipcRenderer.invoke('get-file', {
|
|
|
+ title: t('chooseProject'),
|
|
|
+ buttonLabel: t('open'),
|
|
|
+ properties: ['openFile'],
|
|
|
+ filters: [
|
|
|
+ {
|
|
|
+ name: 'Project',
|
|
|
+ extensions: ['ui']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ const path = paths?.[0]
|
|
|
+ if (!path) return
|
|
|
+ // 存在 打开项目
|
|
|
+ let msg
|
|
|
+ try {
|
|
|
+ msg = ElMessage.info({
|
|
|
+ message: t('openingProject'),
|
|
|
+ duration: 0,
|
|
|
+ plain: true
|
|
|
+ })
|
|
|
+ const result = await window.electron.ipcRenderer.invoke('read-file', path, 'utf-8')
|
|
|
+ if (result) {
|
|
|
+ loadProject(JSON.parse(result), path.slice(0, path.lastIndexOf('\\') + 1))
|
|
|
+ ElMessage.success({
|
|
|
+ message: t('openProjectSuccess'),
|
|
|
+ plain: true
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 读取失败 删除项目
|
|
|
+ ElMessage.error(t('readProjectError'))
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ msg?.close()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
createApp,
|
|
|
project,
|
|
|
@@ -184,6 +259,8 @@ export const useProjectStore = defineStore('project', () => {
|
|
|
projectPath,
|
|
|
imageCompressFormat,
|
|
|
loadProject,
|
|
|
+ openLocalProject,
|
|
|
+ saveProject,
|
|
|
|
|
|
// 历史记录
|
|
|
history,
|