diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index cee8c010..001d94e0 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -18,6 +18,5 @@ declare global { const IEpPicture: typeof import('~icons/ep/picture')['default'] const IEpPostcard: typeof import('~icons/ep/postcard')['default'] const IEpSetting: typeof import('~icons/ep/setting')['default'] - const IEpSwitch: typeof import('~icons/ep/switch')['default'] const IEpUpload: typeof import('~icons/ep/upload')['default'] } diff --git a/src/common/api/branch.ts b/src/common/api/branch.ts index e1b48839..ddc79d42 100644 --- a/src/common/api/branch.ts +++ b/src/common/api/branch.ts @@ -2,6 +2,7 @@ import { UserConfigInfoModel } from '@/common/model' import request from '@/utils/request' import axios from '@/utils/request/axios' import { GH_PAGES } from '@/common/constant' +import i18n from '@/plugins/vue/i18n' /** * 获取分支信息 @@ -58,18 +59,13 @@ export const getBranchInfoList = ( * 将当前分支 checkout 到 gh-pages 分支 * 部署到 GitHub Pages,完成图片资源托管,获取访问能力 * @param userConfigInfo - * @param $t * @param cb */ -export const checkoutGhPagesBranch = async ( - userConfigInfo: UserConfigInfoModel, - $t: any, - cb?: any -) => { +export const checkoutGhPagesBranch = async (userConfigInfo: UserConfigInfoModel, cb?: any) => { const { owner, selectedRepo: repo, selectedBranch } = userConfigInfo const initLoading = ElLoading.service({ - text: $t('settings.image_hosting_deploy.deploying') + text: i18n.global.t('settings.image_hosting_deploy.deploying') }) const cbHandler = (evt: boolean = false) => { diff --git a/src/common/constant/init.ts b/src/common/constant/init.ts index 32ff9570..ea374592 100644 --- a/src/common/constant/init.ts +++ b/src/common/constant/init.ts @@ -9,3 +9,7 @@ export const PICX_DEL_IMG_DESC = 'Delete image via PicX (https://github.com/XPoe export const PICX_INIT_SETTINGS_MSG = 'Init settings via PicX (https://github.com/XPoet/picx)' export const PICX_UPDATE_SETTINGS_MSG = 'Update settings via PicX (https://github.com/XPoet/picx)' export const PICX_INIT_REPO_MSG = 'Init repo via PicX (https://github.com/XPoet/picx)' + +export const PICX_INIT_DEPLOY_MSG = 'Init deploy status via PicX (https://github.com/XPoet/picx)' +export const PICX_UPDATE_DEPLOY_MSG = + 'Update deploy status via PicX (https://github.com/XPoet/picx)' diff --git a/src/common/model/user-settings.ts b/src/common/model/user-settings.ts index 01cc33c9..e04785f0 100644 --- a/src/common/model/user-settings.ts +++ b/src/common/model/user-settings.ts @@ -1,5 +1,5 @@ import { CompressEncoderEnum, ImageLinkFormatModel, ImageLinkRuleModel } from '@/common/model' -import { DeployServerEnum } from '@/components/image-hosting-deploy/image-hosting-deploy.model' +import { DeployServerEnum } from '@/components/deploy-bar/deploy-bar.model' export enum ElementPlusSizeEnum { // eslint-disable-next-line no-unused-vars diff --git a/src/components.d.ts b/src/components.d.ts index 8fe16647..a2952cbe 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -15,6 +15,7 @@ declare module '@vue/runtime-core' { CompressConfigBox: typeof import('./components/compress-config-box/compress-config-box.vue')['default'] CompressTool: typeof import('./components/tools/compress-tool/compress-tool.vue')['default'] CopyImageLink: typeof import('./components/copy-image-link/copy-image-link.vue')['default'] + DeployBar: typeof import('./components/deploy-bar/deploy-bar.vue')['default'] ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb'] ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem'] ElButton: typeof import('element-plus/es')['ElButton'] @@ -71,7 +72,7 @@ declare module '@vue/runtime-core' { IEpUploadFilled: typeof import('~icons/ep/upload-filled')['default'] IEpUserFilled: typeof import('~icons/ep/user-filled')['default'] ImageCard: typeof import('./components/image-card/image-card.vue')['default'] - ImageHostingDeploy: typeof import('./components/image-hosting-deploy/image-hosting-deploy.vue')['default'] + ImageHostingDeploy: typeof import('./components/deploy-bar/image-hosting-deploy.vue')['default'] ImageLinkRuleConfig: typeof import('./components/image-link-rule-config/image-link-rule-config.vue')['default'] ImageSelector: typeof import('./components/image-selector/image-selector.vue')['default'] ImgProcessStateCard: typeof import('./components/tools/img-process-state-card/img-process-state-card.vue')['default'] diff --git a/src/components/cloud-settings-bar/cloud-settings-bar.vue b/src/components/cloud-settings-bar/cloud-settings-bar.vue index 8b88f5e7..d9c5ee99 100644 --- a/src/components/cloud-settings-bar/cloud-settings-bar.vue +++ b/src/components/cloud-settings-bar/cloud-settings-bar.vue @@ -98,15 +98,17 @@ const onOK = () => { watch( () => userSettings, (settings) => { - // 本地设置发生变化时,判断和云端设置是否相等 - if (deepObjectEqual(settings, cloudSettings.value!)) { - // 相等情况 - selectedAction.value = CloudSettingsActions.equal - saveDisabled.value = true - } else { - // 不相等情况 - selectedAction.value = CloudSettingsActions.update - saveDisabled.value = false + if (cloudSettings.value) { + // 本地设置发生变化时,判断和云端设置是否相等 + if (deepObjectEqual(settings, cloudSettings.value)) { + // 相等情况 + selectedAction.value = CloudSettingsActions.equal + saveDisabled.value = true + } else { + // 不相等情况 + selectedAction.value = CloudSettingsActions.update + saveDisabled.value = false + } } }, { diff --git a/src/components/image-hosting-deploy/image-hosting-deploy.model.ts b/src/components/deploy-bar/deploy-bar.model.ts similarity index 100% rename from src/components/image-hosting-deploy/image-hosting-deploy.model.ts rename to src/components/deploy-bar/deploy-bar.model.ts diff --git a/src/components/image-hosting-deploy/image-hosting-deploy.styl b/src/components/deploy-bar/deploy-bar.styl similarity index 100% rename from src/components/image-hosting-deploy/image-hosting-deploy.styl rename to src/components/deploy-bar/deploy-bar.styl diff --git a/src/components/image-hosting-deploy/image-hosting-deploy.util.ts b/src/components/deploy-bar/deploy-bar.util.ts similarity index 72% rename from src/components/image-hosting-deploy/image-hosting-deploy.util.ts rename to src/components/deploy-bar/deploy-bar.util.ts index a8790b01..83356140 100644 --- a/src/components/image-hosting-deploy/image-hosting-deploy.util.ts +++ b/src/components/deploy-bar/deploy-bar.util.ts @@ -1,4 +1,4 @@ -import { DeployServerEnum } from '@/components/image-hosting-deploy/image-hosting-deploy.model' +import { DeployServerEnum } from '@/components/deploy-bar/deploy-bar.model' export const getDeployServerName = (server: DeployServerEnum) => { switch (server) { diff --git a/src/components/image-hosting-deploy/image-hosting-deploy.vue b/src/components/deploy-bar/deploy-bar.vue similarity index 74% rename from src/components/image-hosting-deploy/image-hosting-deploy.vue rename to src/components/deploy-bar/deploy-bar.vue index b7315f0a..add4171b 100644 --- a/src/components/image-hosting-deploy/image-hosting-deploy.vue +++ b/src/components/deploy-bar/deploy-bar.vue @@ -35,12 +35,7 @@ $t('settings.image_hosting_deploy.deploy_to', { server: getDeployServerName(di.type) }) " > - + {{ $t('settings.image_hosting_deploy.one_click_deploy') }} @@ -50,15 +45,15 @@ diff --git a/src/stores/modules/user-settings/index.ts b/src/stores/modules/user-settings/index.ts index b65c6539..c4d301a5 100644 --- a/src/stores/modules/user-settings/index.ts +++ b/src/stores/modules/user-settings/index.ts @@ -16,7 +16,7 @@ import UserSettingsStateTypes, { ImgLinkRuleActionsEnum } from '@/stores/modules/user-settings/types' import { LS_PICX_SETTINGS } from '@/common/constant' -import { DeployServerEnum } from '@/components/image-hosting-deploy/image-hosting-deploy.model' +import { DeployServerEnum } from '@/components/deploy-bar/deploy-bar.model' import { imgLinkRuleVerification } from '@/stores/modules/user-settings/utils' const initSettings: UserSettingsModel = { diff --git a/src/views/github-authorize/github-authorize.styl b/src/views/github-authorize/github-authorize.styl deleted file mode 100644 index e69de29b..00000000 diff --git a/src/views/github-authorize/github-authorize.vue b/src/views/github-authorize/github-authorize.vue deleted file mode 100644 index 8a7216cf..00000000 --- a/src/views/github-authorize/github-authorize.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/src/views/main-container/main-container.util.ts b/src/views/main-container/main-container.util.ts new file mode 100644 index 00000000..207c9e50 --- /dev/null +++ b/src/views/main-container/main-container.util.ts @@ -0,0 +1,69 @@ +import { computed } from 'vue' +import request from '@/utils/request' +import { PICX_INIT_DEPLOY_MSG, PICX_UPDATE_DEPLOY_MSG } from '@/common/constant' +import { store } from '@/stores' + +const userSettings = computed(() => store.getters.getUserSettings).value +const userConfigInfo = computed(() => store.getters.getUserConfigInfo).value + +const filename = '.deploy' + +/** + * 获取云端仓库存储的部署状态信息 + */ +export const getCloudDeployInfo = async () => { + const { owner, selectedRepo: repo, selectedBranch: branch } = userConfigInfo + const res = await request({ + url: `/repos/${owner}/${repo}/contents/${filename}`, + method: 'GET', + noShowErrorMsg: true, + cache: { + maxAge: 0 + }, + params: { + branch, + timestamp: Date.now() + } + }) + + return Promise.resolve(res) +} + +/** + * 保存部署状态信息到云端仓库 + */ +export const saveCloudDeployInfo = async () => { + const { owner, selectedRepo: repo, selectedBranch: branch } = userConfigInfo + + const res = await getCloudDeployInfo() + + const data: any = { + message: res ? PICX_UPDATE_DEPLOY_MSG : PICX_INIT_DEPLOY_MSG, + content: window.btoa(JSON.stringify(userSettings.deploy)) + } + + if (res) { + data.sha = res.sha + } else { + data.branch = branch + } + + const res2 = await request({ + url: `/repos/${owner}/${repo}/contents/${filename}`, + method: 'PUT', + data, + noShowErrorMsg: true + }) + + return Promise.resolve(res2) +} + +/** + * 设置云端仓库的部署状态到本地 + * @param content + */ +export const setCloudDeployInfo = (content: string) => { + store.dispatch('SET_USER_SETTINGS', { + deploy: JSON.parse(window.atob(content)) + }) +} diff --git a/src/views/main-container/main-container.vue b/src/views/main-container/main-container.vue index 4577e83e..afd4abee 100644 --- a/src/views/main-container/main-container.vue +++ b/src/views/main-container/main-container.vue @@ -19,14 +19,35 @@