Browse Source

add:实现gitee第三方登陆

master
秋田弘 6 months ago
parent
commit
8a60a6a71c
  1. 11
      frontend/components.d.ts
  2. 2
      frontend/package.json
  3. 31
      frontend/pnpm-lock.yaml
  4. 0
      frontend/public/image/login/sina.png
  5. 0
      frontend/public/image/login/wechat.png
  6. BIN
      frontend/src/assets/login/GitHub.png
  7. BIN
      frontend/src/assets/login/QQ.png
  8. BIN
      frontend/src/assets/login/gitee.png
  9. BIN
      frontend/src/assets/login/sina.png
  10. BIN
      frontend/src/assets/login/wechat.png
  11. 97
      frontend/src/components/desktop/LockDesktop.vue
  12. 154
      frontend/src/components/setting/SetLang.vue
  13. 517
      frontend/src/components/window/IframeFile.vue

11
frontend/components.d.ts

@ -67,18 +67,26 @@ declare module 'vue' {
ElCard: typeof import('element-plus/es')['ElCard']
ElCarousel: typeof import('element-plus/es')['ElCarousel']
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol']
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDrawer: typeof import('element-plus/es')['ElDrawer']
ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
ElEmpty: typeof import('element-plus/es')['ElEmpty']
ElFooter: typeof import('element-plus/es')['ElFooter']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElHeader: typeof import('element-plus/es')['ElHeader']
ElIcon: typeof import('element-plus/es')['ElIcon']
ElImage: typeof import('element-plus/es')['ElImage']
ElInput: typeof import('element-plus/es')['ElInput']
ElMain: typeof import('element-plus/es')['ElMain']
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElOption: typeof import('element-plus/es')['ElOption']
ElPageHeader: typeof import('element-plus/es')['ElPageHeader']
ElPagination: typeof import('element-plus/es')['ElPagination']
@ -97,6 +105,8 @@ declare module 'vue' {
ElTag: typeof import('element-plus/es')['ElTag']
ElText: typeof import('element-plus/es')['ElText']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElTransfer: typeof import('element-plus/es')['ElTransfer']
ElTree: typeof import('element-plus/es')['ElTree']
Error: typeof import('./src/components/taskbar/Error.vue')['default']
FileIcon: typeof import('./src/components/builtin/FileIcon.vue')['default']
FileIconImg: typeof import('./src/components/builtin/FileIconImg.vue')['default']
@ -106,7 +116,6 @@ declare module 'vue' {
FilePwd: typeof import('./src/components/oa/FilePwd.vue')['default']
FileTree: typeof import('./src/components/builtin/FileTree.vue')['default']
FileViewer: typeof import('./src/components/builtin/FileViewer.vue')['default']
GithubNext: typeof import('./src/components/desktop/GithubNext.vue')['default']
IframeFile: typeof import('./src/components/window/IframeFile.vue')['default']
ImageViewer: typeof import('./src/components/builtin/ImageViewer.vue')['default']
Install: typeof import('./src/components/install/Install.vue')['default']

2
frontend/package.json

@ -19,6 +19,7 @@
"jszip": "^3.10.1",
"lunar-typescript": "^1.7.6",
"moment": "^2.30.1",
"nanoid": "^5.0.9",
"pinia": "^2.1.7",
"pinia-plugin-persist": "^1.0.0",
"vite-plugin-svg-icons": "^2.0.1",
@ -31,6 +32,7 @@
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
"@types/nanoid": "^3.0.0",
"@types/node": "^20.14.10",
"@vitejs/plugin-vue": "^5.0.5",
"sass": "^1.77.8",

31
frontend/pnpm-lock.yaml

@ -33,11 +33,14 @@ importers:
specifier: ^3.10.1
version: 3.10.1
lunar-typescript:
specifier: ^1.7.5
version: 1.7.5
specifier: ^1.7.6
version: 1.7.6
moment:
specifier: ^2.30.1
version: 2.30.1
nanoid:
specifier: ^5.0.9
version: 5.0.9
pinia:
specifier: ^2.1.7
version: 2.2.4(typescript@5.6.3)(vue@3.5.12(typescript@5.6.3))
@ -69,6 +72,9 @@ importers:
'@types/file-saver':
specifier: ^2.0.7
version: 2.0.7
'@types/nanoid':
specifier: ^3.0.0
version: 3.0.0
'@types/node':
specifier: ^20.14.10
version: 20.16.13
@ -534,6 +540,10 @@ packages:
'@types/lodash@4.17.12':
resolution: {integrity: sha512-sviUmCE8AYdaF/KIHLDJBQgeYzPBI0vf/17NaYehBJfYD1j6/L95Slh07NlyK2iNyBNaEkb3En2jRt+a8y3xZQ==}
'@types/nanoid@3.0.0':
resolution: {integrity: sha512-UXitWSmXCwhDmAKe7D3hNQtQaHeHt5L8LO1CB8GF8jlYVzOv5cBWDNqiJ+oPEWrWei3i3dkZtHY/bUtd0R/uOQ==}
deprecated: This is a stub types definition. nanoid provides its own type definitions, so you do not need this installed.
'@types/node@20.16.13':
resolution: {integrity: sha512-GjQ7im10B0labo8ZGXDGROUl9k0BNyDgzfGpb4g/cl+4yYDWVKcozANF4FGr4/p0O/rAkQClM6Wiwkije++1Tg==}
@ -2040,8 +2050,8 @@ packages:
lottie-web@5.12.2:
resolution: {integrity: sha512-uvhvYPC8kGPjXT3MyKMrL3JitEAmDMp30lVkuq/590Mw9ok6pWcFCwXJveo0t5uqYw1UREQHofD+jVpdjBv8wg==}
lunar-typescript@1.7.5:
resolution: {integrity: sha512-AlOwYrxHRCR9Plba5TlZY0NVv6aFobmR1gxfiAE1KxjDzBXoDtT2KrsBYCVaErGokiL8qLMS1FNwGPiPRX2a4g==}
lunar-typescript@1.7.6:
resolution: {integrity: sha512-vrNRgzJ6UgK++P81jaOykV7YBCLemC8l/XDbsXE7MinojXolOKiIHm6sOZg5wdDMbJxCWP1ERAaqcBV9mhw2Bg==}
magic-string@0.30.12:
resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==}
@ -2145,6 +2155,11 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
nanoid@5.0.9:
resolution: {integrity: sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==}
engines: {node: ^18 || >=20}
hasBin: true
nanomatch@1.2.13:
resolution: {integrity: sha512-fpoe2T0RbHwBTBUOftAfBPaDEi06ufaUai0mE6Yn1kacc3SnTErfb/h+X94VXzI64rKFHYImXSvdwGGCmwOqCA==}
engines: {node: '>=0.10.0'}
@ -3356,6 +3371,10 @@ snapshots:
'@types/lodash@4.17.12': {}
'@types/nanoid@3.0.0':
dependencies:
nanoid: 5.0.9
'@types/node@20.16.13':
dependencies:
undici-types: 6.19.8
@ -5330,7 +5349,7 @@ snapshots:
lottie-web@5.12.2: {}
lunar-typescript@1.7.5: {}
lunar-typescript@1.7.6: {}
magic-string@0.30.12:
dependencies:
@ -5481,6 +5500,8 @@ snapshots:
nanoid@3.3.7: {}
nanoid@5.0.9: {}
nanomatch@1.2.13(supports-color@3.2.3):
dependencies:
arr-diff: 4.0.0

0
frontend/public/image/login/新浪微博.png → frontend/public/image/login/sina.png

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

0
frontend/public/image/login/微信.png → frontend/public/image/login/wechat.png

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
frontend/src/assets/login/GitHub.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
frontend/src/assets/login/QQ.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
frontend/src/assets/login/gitee.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
frontend/src/assets/login/sina.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
frontend/src/assets/login/wechat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

97
frontend/src/components/desktop/LockDesktop.vue

@ -48,54 +48,17 @@
</div>
<div class="third-party-login">
<img
v-for="platform in thirdPartyPlatforms"
:key="platform.name"
:src="platform.icon"
:alt="platform.name"
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/微信.png"
@click="onThirdPartyLogin('wechat')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/QQ.png"
@click="onThirdPartyLogin('qq')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/新浪微博.png"
@click="onThirdPartyLogin('sina')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/GitHub.png"
@click="onThirdPartyLogin('github')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/gitee.png"
@click="onThirdPartyLogin('gitee')"
@click="onThirdPartyLogin(platform.name)"
/>
</div>
<div
@ -199,6 +162,30 @@
const config = getSystemConfig();
const lockClassName = ref("screen-show");
const isRegisterMode = ref(false);
const thirdPartyPlatforms = [
{
name: "wechat",
icon: new URL("@/assets/login/wechat.png", import.meta.url).href,
},
{
name: "qq",
icon: new URL("@/assets/login/qq.png", import.meta.url).href,
},
{
name: "sina",
icon: new URL("@/assets/login/sina.png", import.meta.url).href,
},
{
name: "github",
icon: new URL("@/assets/login/github.png", import.meta.url).href,
},
{
name: "gitee",
icon: new URL("@/assets/login/gitee.png", import.meta.url).href,
},
];
function loginSuccess() {
lockClassName.value = "screen-hidean";
setTimeout(() => {
@ -219,6 +206,7 @@
}
});
// code
watch(
() => router.currentRoute.value.query.code,
() => {
@ -249,6 +237,8 @@
const returnedState = router.currentRoute.value.query
.state as string;
console.log(returnedState, "---", store.State);
if (returnedState !== store.State) {
notifyError("登录失败,请重试");
return;
@ -402,7 +392,7 @@
break;
case "gitee":
loginFunction = async function () {
return await authWithGithub();
return await authWithGitee();
};
break;
default:
@ -423,7 +413,6 @@
const authWithGithub = async (): Promise<boolean> => {
// stateCSRF,使
const state = Date.now() + Math.random().toString(36).substring(2, 15);
//
store.State = state;
const url = config.userInfo.url + "/github/authorize?state=" + state;
const res: any = await fetch(url, {
@ -452,6 +441,26 @@
const authWithSina = (): boolean | PromiseLike<boolean> => {
throw new Error("Function not implemented.");
};
const authWithGitee = async (): Promise<boolean> => {
// stateCSRF,使
const state = Date.now() + Math.random().toString(36).substring(2, 15);
store.State = state;
const url = config.userInfo.url + "/gitee/authorize?state=" + state;
const res: any = await fetch(url, {
method: "POST",
body: JSON.stringify({
state: state,
}),
});
if (!res.ok) {
return false;
}
const data = await res.json();
// Gitee
window.location.href = data.data.url;
return true;
};
</script>
<style scoped lang="scss">

154
frontend/src/components/setting/SetLang.vue

@ -1,88 +1,90 @@
<template>
<div class="container">
<div class="nav">
<ul>
<li
v-for="(item, index) in items"
:key="index"
@click="selectItem(index)"
:class="{ active: index === activeIndex }"
>
{{ item }}
</li>
</ul>
</div>
<div class="setting">
<div v-if="0 === activeIndex">
<div class="setting-item">
<h1 class="setting-title">{{ t("language") }}</h1>
</div>
<div class="setting-item">
<label></label>
<el-select v-model="modelvalue">
<el-option
v-for="(item, key) in langList"
:key="key"
:label="item.label"
:value="item.value"
/>
</el-select>
</div>
<div class="container">
<div class="nav">
<ul>
<li
v-for="(item, index) in items"
:key="index"
@click="selectItem(index)"
:class="{ active: index === activeIndex }"
>
{{ item }}
</li>
</ul>
</div>
<div class="setting">
<div v-if="0 === activeIndex">
<div class="setting-item">
<h1 class="setting-title">{{ t("language") }}</h1>
</div>
<div class="setting-item">
<label></label>
<el-select v-model="modelvalue">
<el-option
v-for="(item, key) in langList"
:key="key"
:label="item.label"
:value="item.value"
/>
</el-select>
</div>
<div class="setting-item">
<label></label>
<el-button @click="submit" type="primary">
{{ t("confirm") }}
</el-button>
</div>
</div>
</div>
</div>
<div class="setting-item">
<label></label>
<el-button
@click="submit"
type="primary"
>
{{ t("confirm") }}
</el-button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { ElMessageBox } from 'element-plus'
import { t, getLang, setLang } from "@/i18n";
import { useI18n } from 'vue-i18n';
const { locale } = useI18n()
const showDialog = ref(false);
const langList = [
{
label: "中文",
value: "zh-cn",
},
{
label: "English",
value: "en",
},
];
const items = [t("language")];
import { getLang, setLang, t } from "@/i18n";
import { ElMessageBox } from "element-plus";
import { ref } from "vue";
import { useI18n } from "vue-i18n";
const { locale } = useI18n();
// const showDialog = ref(false);
const langList = [
{
label: "中文",
value: "zh-cn",
},
{
label: "English",
value: "en",
},
];
const items = [t("language")];
const activeIndex = ref(0);
const currentLang = getLang();
const modelvalue = ref(currentLang);
const activeIndex = ref(0);
const currentLang = getLang();
const modelvalue = ref(currentLang);
const selectItem = (index: number) => {
activeIndex.value = index;
};
const selectItem = (index: number) => {
activeIndex.value = index;
};
async function submit() {
setLang(modelvalue.value);
locale.value = modelvalue.value;
ElMessageBox.alert(t("save.success"), t("language"), {
confirmButtonText: 'OK',
})
//showDialog.value = false
async function submit() {
setLang(modelvalue.value);
locale.value = modelvalue.value;
ElMessageBox.alert(t("save.success"), t("language"), {
confirmButtonText: "OK",
});
//showDialog.value = false
// Dialog.showMessageBox({
// message: t("save.success"),
// title: t("language"),
// type: "info",
// });
}
// Dialog.showMessageBox({
// message: t("save.success"),
// title: t("language"),
// type: "info",
// });
}
</script>
<style scoped>
@import "./setStyle.css";
@import "./setStyle.css";
</style>

517
frontend/src/components/window/IframeFile.vue

@ -1,269 +1,274 @@
<template>
<iframe class="setiframe" allow="fullscreen" ref="storeRef" :src="src"></iframe>
<iframe
class="setiframe"
allow="fullscreen"
ref="storeRef"
:src="src"
></iframe>
</template>
<script lang="ts" setup name="IframeFile">
//@ts-ignore
import { BrowserWindow, Dialog, Notify, System } from "@/system";
import { getSplit, getSystemConfig, setSystemKey } from "@/system/config";
import { base64ToBuffer, isBase64 } from "@/util/file";
import { isShareFile } from "@/util/sharePath.ts";
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue";
import { askAi } from "@/hook/useAi";
import { useChooseStore } from "@/stores/choose";
import { nanoid } from "nanoid";
import eventBus from "@/system/event/eventBus";
const SP = getSplit();
//@ts-ignore
import { askAi } from "@/hook/useAi";
import { useChooseStore } from "@/stores/choose";
import { BrowserWindow, Dialog, Notify, System } from "@/system";
import { getSplit, getSystemConfig, setSystemKey } from "@/system/config";
import eventBus from "@/system/event/eventBus";
import { base64ToBuffer, isBase64 } from "@/util/file";
import { isShareFile } from "@/util/sharePath.ts";
import { nanoid } from "nanoid";
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue";
const SP = getSplit();
const sys: any = inject<System>("system");
const win: any = inject<BrowserWindow>("browserWindow");
const props = defineProps({
src: {
type: String,
default: "",
},
eventType: {
type: String,
default: "",
},
ext: {
type: String,
default: "md",
},
});
const storeRef = ref<HTMLIFrameElement | null>(null);
let hasInit = false;
const sys: any = inject<System>("system");
const win: any = inject<BrowserWindow>("browserWindow");
const props = defineProps({
src: {
type: String,
default: "",
},
eventType: {
type: String,
default: "",
},
ext: {
type: String,
default: "md",
},
});
const storeRef = ref<HTMLIFrameElement | null>(null);
let hasInit = false;
const choose = useChooseStore();
const componentID = nanoid();
// console.log("ID", componentID);
const saveFile = async (e: any) => {
if (e.componentID !== componentID) return;
let data = JSON.parse(e.eventData.data);
let ext: any = props.ext;
if (ext instanceof Array) {
ext = ext[0];
}
if (data.ext) {
ext = data.ext;
}
let path:string
e.filePath !== ""
? (path = `${e.filePath}/${e.fileName}.${ext}`)
: (path = `${SP}C${SP}Users${SP}Desktop${SP}${e.fileName}.${ext}`);
// console.log('',path);
await writeFile(path, data, e.fileName);
};
eventBus.on("saveFile", saveFile);
const writeFile = async (path: string, data: any, title: string) => {
const isShare = ref(false);
const isWrite = ref(0);
if (isShareFile(path)) {
const file = await sys?.fs.getShareInfo(path);
isShare.value = true;
isWrite.value =
file.fs.sender === getSystemConfig().userInfo.id
? 1
: file.fs.is_write;
if (
!isWrite.value &&
file.fs.sender !== getSystemConfig().userInfo.id
) {
new Notify({
title: "提示",
content: "该文件没有编辑权限",
});
return;
}
} else if (await sys?.fs.exists(path)) {
let res = await Dialog.showMessageBox({
type: "info",
title: "提示",
message: "存在相同的文件名-" + title,
buttons: ["覆盖文件?", "取消"],
});
//console.log(res)
if (res.response > 0) {
return;
}
}
if (typeof data.content === "string") {
if (data.content.indexOf(";base64,") > -1) {
const parts = data.content.split(";base64,");
data.content = parts[1];
}
if (isBase64(data.content)) {
data.content = base64ToBuffer(data.content);
//console.log(data.content)
}
}
const choose = useChooseStore();
const componentID = nanoid();
// console.log("ID", componentID);
const saveFile = async (e: any) => {
if (e.componentID !== componentID) return;
let data = JSON.parse(e.eventData.data);
let ext: any = props.ext;
if (ext instanceof Array) {
ext = ext[0];
}
if (data.ext) {
ext = data.ext;
}
let path: string;
e.filePath !== ""
? (path = `${e.filePath}/${e.fileName}.${ext}`)
: (path = `${SP}C${SP}Users${SP}Desktop${SP}${e.fileName}.${ext}`);
// console.log('',path);
await writeFile(path, data, e.fileName);
};
eventBus.on("saveFile", saveFile);
const writeFile = async (path: string, data: any, title: string) => {
const isShare = ref(false);
const isWrite = ref(0);
if (isShareFile(path)) {
const file = await sys?.fs.getShareInfo(path);
isShare.value = true;
isWrite.value =
file.fs.sender === getSystemConfig().userInfo.id
? 1
: file.fs.is_write;
if (
!isWrite.value &&
file.fs.sender !== getSystemConfig().userInfo.id
) {
new Notify({
title: "提示",
content: "该文件没有编辑权限",
});
return;
}
} else if (await sys?.fs.exists(path)) {
let res = await Dialog.showMessageBox({
type: "info",
title: "提示",
message: "存在相同的文件名-" + title,
buttons: ["覆盖文件?", "取消"],
});
//console.log(res)
if (res.response > 0) {
return;
}
}
if (typeof data.content === "string") {
if (data.content.indexOf(";base64,") > -1) {
const parts = data.content.split(";base64,");
data.content = parts[1];
}
if (isBase64(data.content)) {
data.content = base64ToBuffer(data.content);
//console.log(data.content)
}
}
const res = isShare.value
? await sys?.fs.writeShareFile(path, data.content, isWrite.value)
: await sys?.fs.writeFile(path, data.content);
// console.log("", res, isShare);
new Notify({
title: "提示",
content: res.message,
// content: res.code === 0 ? "" : res.message,
});
sys.refershAppList();
};
const eventHandler = async (e: MessageEvent) => {
const eventData = e.data;
// console.log('', componentID == eventData.componentID);
if (eventData.type == props.eventType) {
// if (eventData.componentID !== componentID) return;
let data = JSON.parse(eventData.data);
let title = data.title;
let path;
let ext: any = props.ext;
if (ext instanceof Array) {
ext = ext[0];
}
if (data.ext) {
ext = data.ext;
}
if (title.indexOf("." + ext) > -1) {
title = title.replace("." + ext, "");
}
const res = isShare.value
? await sys?.fs.writeShareFile(path, data.content, isWrite.value)
: await sys?.fs.writeFile(path, data.content);
// console.log("", res, isShare);
new Notify({
title: "提示",
content: res.message,
// content: res.code === 0 ? "" : res.message,
});
sys.refershAppList();
};
const eventHandler = async (e: MessageEvent) => {
const eventData = e.data;
// console.log('', componentID == eventData.componentID);
if (eventData.type == props.eventType) {
// if (eventData.componentID !== componentID) return;
let data = JSON.parse(eventData.data);
let title = data.title;
let path;
let ext: any = props.ext;
if (ext instanceof Array) {
ext = ext[0];
}
if (data.ext) {
ext = data.ext;
}
if (title.indexOf("." + ext) > -1) {
title = title.replace("." + ext, "");
}
if (win.config && win.config.path) {
path = win.config.path;
if (win.config && win.config.path) {
path = win.config.path;
//1
let fileTitleArr = path.split(SP).pop().split(".");
let oldExt = fileTitleArr.pop();
let fileTitle = fileTitleArr.join(".");
if (fileTitle != title) {
path = path.replace(fileTitle, title);
}
if (oldExt != ext) {
path = path.replace("." + oldExt, "." + ext);
}
} else {
choose.saveFile("选择地址", "*", componentID, eventData);
return;
// path = `${SP}C${SP}Users${SP}Desktop${SP}${title}.${ext}`;
}
writeFile(path, data, title);
} else if (eventData.type == "initSuccess") {
if (hasInit) {
return;
}
hasInit = true;
let content = win?.config?.content;
let title = win.getTitle();
// console.log("win.config;", win?.config);
// console.log(title);
title = title.split(SP).pop();
//1
let fileTitleArr = path.split(SP).pop().split(".");
let oldExt = fileTitleArr.pop();
let fileTitle = fileTitleArr.join(".");
if (fileTitle != title) {
path = path.replace(fileTitle, title);
}
if (oldExt != ext) {
path = path.replace("." + oldExt, "." + ext);
}
} else {
choose.saveFile("选择地址", "*", componentID, eventData);
return;
// path = `${SP}C${SP}Users${SP}Desktop${SP}${title}.${ext}`;
}
writeFile(path, data, title);
} else if (eventData.type == "initSuccess") {
if (hasInit) {
return;
}
hasInit = true;
let content = win?.config?.content;
let title = win.getTitle();
// console.log("win.config;", win?.config);
// console.log(title);
title = title.split(SP).pop();
// if (!content && win?.config.path) {
// const header = {
// pwd: ''
// };
// const filePwd = getSystemConfig().fileInputPwd
// const pos = filePwd.findIndex((item: any) => item.path == win?.config.path)
// //console.log('', win?.config.path, pos, filePwd);
// const userType = getSystemConfig().userType
// if (pos !== -1) {
// header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
// }
// content = await sys?.fs.readFile(win?.config.path, header);
// }
content = toRaw(content);
if (content && content !== "") {
storeRef.value?.contentWindow?.postMessage(
{
type: "init",
data: { content, title },
componentID,
},
"*"
);
} else {
storeRef.value?.contentWindow?.postMessage(
{
type: "start",
title,
componentID,
},
"*"
);
}
} else if (eventData.type == "close") {
// console.log("");
win.close();
} else if (eventData.type == "saveMind") {
// console.log("");
const data = eventData.data;
const path = win?.config?.path;
//console.log(path,data)
const winMind = new BrowserWindow({
title: data.title,
url: "/mind/index.html",
frame: true,
config: {
ext: "mind",
path: path,
content: data.content,
},
icon: "gallery",
width: 700,
height: 500,
x: 100,
y: 100,
//center: true,
minimizable: false,
resizable: true,
});
winMind.show();
} else if (eventData.type == "aiCreater") {
console.log("传递内容: ", eventData);
let postData: any = {};
if (eventData.data) {
postData.content = eventData.data;
}
if (eventData.title) {
postData.title = eventData.title;
}
if (eventData.category) {
postData.category = eventData.category;
}
//console.log(postData,eventData.action)
// AI
const res: any = await askAi(postData, eventData.action);
storeRef.value?.contentWindow?.postMessage(
{
type: "aiReciver",
data: res,
action: eventData.action,
},
"*"
);
}
};
//
const delFileInputPwd = async () => {
let fileInputPwd = getSystemConfig().fileInputPwd;
const currentPath = win.config.path;
const temp = fileInputPwd.filter(
(item: any) => item.path !== currentPath
);
setSystemKey("fileInputPwd", temp);
};
onMounted(() => {
window.addEventListener("message", eventHandler);
});
// if (!content && win?.config.path) {
// const header = {
// pwd: ''
// };
// const filePwd = getSystemConfig().fileInputPwd
// const pos = filePwd.findIndex((item: any) => item.path == win?.config.path)
// //console.log('', win?.config.path, pos, filePwd);
// const userType = getSystemConfig().userType
// if (pos !== -1) {
// header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
// }
// content = await sys?.fs.readFile(win?.config.path, header);
// }
content = toRaw(content);
if (content && content !== "") {
storeRef.value?.contentWindow?.postMessage(
{
type: "init",
data: { content, title },
componentID,
},
"*"
);
} else {
storeRef.value?.contentWindow?.postMessage(
{
type: "start",
title,
componentID,
},
"*"
);
}
} else if (eventData.type == "close") {
// console.log("");
win.close();
} else if (eventData.type == "saveMind") {
// console.log("");
const data = eventData.data;
const path = win?.config?.path;
//console.log(path,data)
const winMind = new BrowserWindow({
title: data.title,
url: "/mind/index.html",
frame: true,
config: {
ext: "mind",
path: path,
content: data.content,
},
icon: "gallery",
width: 700,
height: 500,
x: 100,
y: 100,
//center: true,
minimizable: false,
resizable: true,
});
winMind.show();
} else if (eventData.type == "aiCreater") {
console.log("传递内容: ", eventData);
let postData: any = {};
if (eventData.data) {
postData.content = eventData.data;
}
if (eventData.title) {
postData.title = eventData.title;
}
if (eventData.category) {
postData.category = eventData.category;
}
//console.log(postData,eventData.action)
// AI
const res: any = await askAi(postData, eventData.action);
storeRef.value?.contentWindow?.postMessage(
{
type: "aiReciver",
data: res,
action: eventData.action,
},
"*"
);
}
};
//
const delFileInputPwd = async () => {
let fileInputPwd = getSystemConfig().fileInputPwd;
const currentPath = win.config.path;
const temp = fileInputPwd.filter(
(item: any) => item.path !== currentPath
);
setSystemKey("fileInputPwd", temp);
};
onMounted(() => {
window.addEventListener("message", eventHandler);
});
onUnmounted(async () => {
await delFileInputPwd();
window.removeEventListener("message", eventHandler);
});
onUnmounted(async () => {
await delFileInputPwd();
window.removeEventListener("message", eventHandler);
});
</script>
<style scoped>
.setiframe {
width: 100%;
height: 100%;
border: none;
}
.setiframe {
width: 100%;
height: 100%;
border: none;
}
</style>

Loading…
Cancel
Save