From 9749722649b564009b68f6cd38ef9f68b70d4342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?1024=E5=B0=8F=E7=A5=9E?= <15670339118@163.com> Date: Thu, 19 Dec 2024 17:59:41 +0800 Subject: [PATCH] update --- src-tauri/capabilities/default.json | 2 + src/pages/edit.vue | 13 ++++- src/pages/home.vue | 89 ++++++++++++++++------------- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index d8656197..2c574a39 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -5,6 +5,8 @@ "windows": ["main"], "permissions": [ "core:default", + "core:app:allow-set-app-theme", + "core:app:allow-name", "opener:default", "http:allow-fetch", "http:allow-fetch-cancel", diff --git a/src/pages/edit.vue b/src/pages/edit.vue index efddb573..66d18b8f 100644 --- a/src/pages/edit.vue +++ b/src/pages/edit.vue @@ -130,6 +130,7 @@ > {{ t('save') }} {{ t('preview') }} - {{ t('publish') }} + + {{ t('publish') }} + @@ -360,7 +363,7 @@ const formSize = ref('default') const appFormRef = ref() const appForm: any = reactive(store.currentProject) const platformName = platform() - +const token = localStorage.getItem('token') const iconFileName = ref('') const selJs = ref(null) const jsFileContents = ref('') @@ -1382,7 +1385,13 @@ const initJsFileContents = async () => { }) } +// init project +const initProject = async () => { + console.log('initProject') +} + onMounted(async () => { + console.log('token', token) getLatestRelease() initJsFileContents() buildTime = 0 diff --git a/src/pages/home.vue b/src/pages/home.vue index 81db1afb..d58ba84d 100644 --- a/src/pages/home.vue +++ b/src/pages/home.vue @@ -175,6 +175,7 @@ import { usePakeStore } from '@/store' import { pakeUrlMap, openUrl, initProject } from '@/utils/common' import pakePlusIcon from '@/assets/images/pakeplus.png' import { useI18n } from 'vue-i18n' +import { setTheme } from '@tauri-apps/api/app' import { invoke, convertFileSrc } from '@tauri-apps/api/core' import { getVersion } from '@tauri-apps/api/app' @@ -189,15 +190,17 @@ const branchDialog = ref(false) const branchName = ref('') const testLoading = ref(false) -const chageTheme = (theme: string) => { +const chageTheme = async (theme: string) => { if (theme === 'light') { document.documentElement.setAttribute('theme', 'light') document.querySelector('html')?.classList.remove('dark') document.querySelector('html')?.classList.add('light') + // await setTheme('light') } else { document.documentElement.setAttribute('theme', 'dark') document.querySelector('html')?.classList.remove('light') document.querySelector('html')?.classList.add('dark') + // await setTheme('dark') } localStorage.setItem('theme', theme) } @@ -225,17 +228,14 @@ const getImgUrl = (filePath: string) => { // new barnch config const showBranchDialog = () => { - // TODO if token exist, then creat branch, else next page + // if token exist, then creat branch, else next page getCommitSha() // checkout has github token - if (localStorage.getItem('token')) { - // need creat new branch, first input project name - branchDialog.value = true - } else { - tokenDialog.value = true + if (token.value === '') { ElMessage.error(t('configToken')) - return } + // need creat new branch, first input project name + branchDialog.value = true } const changeLang = (lang: string) => { @@ -339,44 +339,55 @@ const creatLoading = ref(false) // creat project branch const creatBranch = async () => { creatLoading.value = true - await uploadBuildYml() + token.value && (await uploadBuildYml()) // checkout branch name is english if (branchName.value && /^[A-Za-z0-9]+$/.test(branchName.value)) { console.log('branchName.value', branchName.value) - const res: any = await githubApi.createBranch( - store.userInfo.login, - 'PakePlus', - { - ref: `refs/heads/${branchName.value}`, - sha: store.commit.sha, + // if token exist, then creat branch, else next page + if (token.value) { + const res: any = await githubApi.createBranch( + store.userInfo.login, + 'PakePlus', + { + ref: `refs/heads/${branchName.value}`, + sha: store.commit.sha, + } + ) + console.log('createBranch', res) + // 201 is ok + if (res.status === 201) { + const branchInfo: Project = { + ...res.data, + ...initProject, + name: branchName.value, + } + console.log('branch Info success', branchInfo) + store.setCurrentProject(branchInfo) + creatLoading.value = false + router.push('/edit') + // update new branch build.yml file + // updateBuildYml(branchName.value) + } else if (res.status === 422) { + console.log('project existed') + creatLoading.value = false + ElMessage.success(t('projectExist')) + // router.push('/publish') + } else if (res.status === 401) { + ElMessage.error(t('tokenError')) + creatLoading.value = false + } else { + creatLoading.value = false + console.log('branchInfo error', res) + ElMessage.error( + `${t('creatProjectError')}: ${res.data.message}` + ) } - ) - console.log('createBranch', res) - // 201 is ok - if (res.status === 201) { - const branchInfo: Project = { - ...res.data, + } else { + store.setCurrentProject({ ...initProject, name: branchName.value, - } - console.log('branch Info success', branchInfo) - store.setCurrentProject(branchInfo) - creatLoading.value = false + }) router.push('/edit') - // update new branch build.yml file - // updateBuildYml(branchName.value) - } else if (res.status === 422) { - console.log('project existed') - creatLoading.value = false - ElMessage.success(t('projectExist')) - // router.push('/publish') - } else if (res.status === 401) { - ElMessage.error(t('tokenError')) - creatLoading.value = false - } else { - creatLoading.value = false - console.log('branchInfo error', res) - ElMessage.error(`${t('creatProjectError')}: ${res.data.message}`) } } else { ElMessage.error(t('englishName'))