Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 3.6 KiB |
@ -1,88 +1,90 @@ |
|||||
<template> |
<template> |
||||
<div class="container"> |
<div class="container"> |
||||
<div class="nav"> |
<div class="nav"> |
||||
<ul> |
<ul> |
||||
<li |
<li |
||||
v-for="(item, index) in items" |
v-for="(item, index) in items" |
||||
:key="index" |
:key="index" |
||||
@click="selectItem(index)" |
@click="selectItem(index)" |
||||
:class="{ active: index === activeIndex }" |
:class="{ active: index === activeIndex }" |
||||
> |
> |
||||
{{ item }} |
{{ item }} |
||||
</li> |
</li> |
||||
</ul> |
</ul> |
||||
</div> |
</div> |
||||
<div class="setting"> |
<div class="setting"> |
||||
<div v-if="0 === activeIndex"> |
<div v-if="0 === activeIndex"> |
||||
<div class="setting-item"> |
<div class="setting-item"> |
||||
<h1 class="setting-title">{{ t("language") }}</h1> |
<h1 class="setting-title">{{ t("language") }}</h1> |
||||
</div> |
</div> |
||||
<div class="setting-item"> |
<div class="setting-item"> |
||||
<label></label> |
<label></label> |
||||
<el-select v-model="modelvalue"> |
<el-select v-model="modelvalue"> |
||||
<el-option |
<el-option |
||||
v-for="(item, key) in langList" |
v-for="(item, key) in langList" |
||||
:key="key" |
:key="key" |
||||
:label="item.label" |
:label="item.label" |
||||
:value="item.value" |
:value="item.value" |
||||
/> |
/> |
||||
</el-select> |
</el-select> |
||||
</div> |
</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> |
</template> |
||||
|
|
||||
<script lang="ts" setup> |
<script lang="ts" setup> |
||||
import { ref } from "vue"; |
import { getLang, setLang, t } from "@/i18n"; |
||||
import { ElMessageBox } from 'element-plus' |
import { ElMessageBox } from "element-plus"; |
||||
import { t, getLang, setLang } from "@/i18n"; |
import { ref } from "vue"; |
||||
import { useI18n } from 'vue-i18n'; |
import { useI18n } from "vue-i18n"; |
||||
const { locale } = useI18n() |
const { locale } = useI18n(); |
||||
const showDialog = ref(false); |
// const showDialog = ref(false); |
||||
const langList = [ |
const langList = [ |
||||
{ |
{ |
||||
label: "中文", |
label: "中文", |
||||
value: "zh-cn", |
value: "zh-cn", |
||||
}, |
}, |
||||
{ |
{ |
||||
label: "English", |
label: "English", |
||||
value: "en", |
value: "en", |
||||
}, |
}, |
||||
]; |
]; |
||||
const items = [t("language")]; |
const items = [t("language")]; |
||||
|
|
||||
const activeIndex = ref(0); |
const activeIndex = ref(0); |
||||
const currentLang = getLang(); |
const currentLang = getLang(); |
||||
const modelvalue = ref(currentLang); |
const modelvalue = ref(currentLang); |
||||
|
|
||||
const selectItem = (index: number) => { |
const selectItem = (index: number) => { |
||||
activeIndex.value = index; |
activeIndex.value = index; |
||||
}; |
}; |
||||
|
|
||||
async function submit() { |
async function submit() { |
||||
setLang(modelvalue.value); |
setLang(modelvalue.value); |
||||
locale.value = modelvalue.value; |
locale.value = modelvalue.value; |
||||
ElMessageBox.alert(t("save.success"), t("language"), { |
ElMessageBox.alert(t("save.success"), t("language"), { |
||||
confirmButtonText: 'OK', |
confirmButtonText: "OK", |
||||
}) |
}); |
||||
//showDialog.value = false |
//showDialog.value = false |
||||
|
|
||||
// Dialog.showMessageBox({ |
// Dialog.showMessageBox({ |
||||
// message: t("save.success"), |
// message: t("save.success"), |
||||
// title: t("language"), |
// title: t("language"), |
||||
// type: "info", |
// type: "info", |
||||
// }); |
// }); |
||||
} |
} |
||||
</script> |
</script> |
||||
<style scoped> |
<style scoped> |
||||
@import "./setStyle.css"; |
@import "./setStyle.css"; |
||||
</style> |
</style> |
||||
|
@ -1,269 +1,274 @@ |
|||||
<template> |
<template> |
||||
<iframe class="setiframe" allow="fullscreen" ref="storeRef" :src="src"></iframe> |
<iframe |
||||
|
class="setiframe" |
||||
|
allow="fullscreen" |
||||
|
ref="storeRef" |
||||
|
:src="src" |
||||
|
></iframe> |
||||
</template> |
</template> |
||||
<script lang="ts" setup name="IframeFile"> |
<script lang="ts" setup name="IframeFile"> |
||||
//@ts-ignore |
//@ts-ignore |
||||
import { BrowserWindow, Dialog, Notify, System } from "@/system"; |
import { askAi } from "@/hook/useAi"; |
||||
import { getSplit, getSystemConfig, setSystemKey } from "@/system/config"; |
import { useChooseStore } from "@/stores/choose"; |
||||
import { base64ToBuffer, isBase64 } from "@/util/file"; |
import { BrowserWindow, Dialog, Notify, System } from "@/system"; |
||||
import { isShareFile } from "@/util/sharePath.ts"; |
import { getSplit, getSystemConfig, setSystemKey } from "@/system/config"; |
||||
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue"; |
import eventBus from "@/system/event/eventBus"; |
||||
import { askAi } from "@/hook/useAi"; |
import { base64ToBuffer, isBase64 } from "@/util/file"; |
||||
import { useChooseStore } from "@/stores/choose"; |
import { isShareFile } from "@/util/sharePath.ts"; |
||||
import { nanoid } from "nanoid"; |
import { nanoid } from "nanoid"; |
||||
import eventBus from "@/system/event/eventBus"; |
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue"; |
||||
const SP = getSplit(); |
const SP = getSplit(); |
||||
|
|
||||
const sys: any = inject<System>("system"); |
const sys: any = inject<System>("system"); |
||||
const win: any = inject<BrowserWindow>("browserWindow"); |
const win: any = inject<BrowserWindow>("browserWindow"); |
||||
const props = defineProps({ |
const props = defineProps({ |
||||
src: { |
src: { |
||||
type: String, |
type: String, |
||||
default: "", |
default: "", |
||||
}, |
}, |
||||
eventType: { |
eventType: { |
||||
type: String, |
type: String, |
||||
default: "", |
default: "", |
||||
}, |
}, |
||||
ext: { |
ext: { |
||||
type: String, |
type: String, |
||||
default: "md", |
default: "md", |
||||
}, |
}, |
||||
}); |
}); |
||||
const storeRef = ref<HTMLIFrameElement | null>(null); |
const storeRef = ref<HTMLIFrameElement | null>(null); |
||||
let hasInit = false; |
let hasInit = false; |
||||
|
|
||||
const choose = useChooseStore(); |
const choose = useChooseStore(); |
||||
const componentID = nanoid(); |
const componentID = nanoid(); |
||||
// console.log("唯一ID:", componentID); |
// console.log("唯一ID:", componentID); |
||||
const saveFile = async (e: any) => { |
const saveFile = async (e: any) => { |
||||
if (e.componentID !== componentID) return; |
if (e.componentID !== componentID) return; |
||||
let data = JSON.parse(e.eventData.data); |
let data = JSON.parse(e.eventData.data); |
||||
let ext: any = props.ext; |
let ext: any = props.ext; |
||||
if (ext instanceof Array) { |
if (ext instanceof Array) { |
||||
ext = ext[0]; |
ext = ext[0]; |
||||
} |
} |
||||
if (data.ext) { |
if (data.ext) { |
||||
ext = data.ext; |
ext = data.ext; |
||||
} |
} |
||||
let path:string |
let path: string; |
||||
e.filePath !== "" |
e.filePath !== "" |
||||
? (path = `${e.filePath}/${e.fileName}.${ext}`) |
? (path = `${e.filePath}/${e.fileName}.${ext}`) |
||||
: (path = `${SP}C${SP}Users${SP}Desktop${SP}${e.fileName}.${ext}`); |
: (path = `${SP}C${SP}Users${SP}Desktop${SP}${e.fileName}.${ext}`); |
||||
// console.log('路径:',path); |
// console.log('路径:',path); |
||||
await writeFile(path, data, e.fileName); |
await writeFile(path, data, e.fileName); |
||||
}; |
}; |
||||
eventBus.on("saveFile", saveFile); |
eventBus.on("saveFile", saveFile); |
||||
const writeFile = async (path: string, data: any, title: string) => { |
const writeFile = async (path: string, data: any, title: string) => { |
||||
const isShare = ref(false); |
const isShare = ref(false); |
||||
const isWrite = ref(0); |
const isWrite = ref(0); |
||||
if (isShareFile(path)) { |
if (isShareFile(path)) { |
||||
const file = await sys?.fs.getShareInfo(path); |
const file = await sys?.fs.getShareInfo(path); |
||||
isShare.value = true; |
isShare.value = true; |
||||
isWrite.value = |
isWrite.value = |
||||
file.fs.sender === getSystemConfig().userInfo.id |
file.fs.sender === getSystemConfig().userInfo.id |
||||
? 1 |
? 1 |
||||
: file.fs.is_write; |
: file.fs.is_write; |
||||
if ( |
if ( |
||||
!isWrite.value && |
!isWrite.value && |
||||
file.fs.sender !== getSystemConfig().userInfo.id |
file.fs.sender !== getSystemConfig().userInfo.id |
||||
) { |
) { |
||||
new Notify({ |
new Notify({ |
||||
title: "提示", |
title: "提示", |
||||
content: "该文件没有编辑权限", |
content: "该文件没有编辑权限", |
||||
}); |
}); |
||||
return; |
return; |
||||
} |
} |
||||
} else if (await sys?.fs.exists(path)) { |
} else if (await sys?.fs.exists(path)) { |
||||
let res = await Dialog.showMessageBox({ |
let res = await Dialog.showMessageBox({ |
||||
type: "info", |
type: "info", |
||||
title: "提示", |
title: "提示", |
||||
message: "存在相同的文件名-" + title, |
message: "存在相同的文件名-" + title, |
||||
buttons: ["覆盖文件?", "取消"], |
buttons: ["覆盖文件?", "取消"], |
||||
}); |
}); |
||||
//console.log(res) |
//console.log(res) |
||||
if (res.response > 0) { |
if (res.response > 0) { |
||||
return; |
return; |
||||
} |
} |
||||
} |
} |
||||
if (typeof data.content === "string") { |
if (typeof data.content === "string") { |
||||
if (data.content.indexOf(";base64,") > -1) { |
if (data.content.indexOf(";base64,") > -1) { |
||||
const parts = data.content.split(";base64,"); |
const parts = data.content.split(";base64,"); |
||||
data.content = parts[1]; |
data.content = parts[1]; |
||||
} |
} |
||||
if (isBase64(data.content)) { |
if (isBase64(data.content)) { |
||||
data.content = base64ToBuffer(data.content); |
data.content = base64ToBuffer(data.content); |
||||
//console.log(data.content) |
//console.log(data.content) |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
const res = isShare.value |
const res = isShare.value |
||||
? await sys?.fs.writeShareFile(path, data.content, isWrite.value) |
? await sys?.fs.writeShareFile(path, data.content, isWrite.value) |
||||
: await sys?.fs.writeFile(path, data.content); |
: await sys?.fs.writeFile(path, data.content); |
||||
// console.log("编写文件:", res, isShare); |
// console.log("编写文件:", res, isShare); |
||||
new Notify({ |
new Notify({ |
||||
title: "提示", |
title: "提示", |
||||
content: res.message, |
content: res.message, |
||||
// content: res.code === 0 ? "文件已保存" : res.message, |
// content: res.code === 0 ? "文件已保存" : res.message, |
||||
}); |
}); |
||||
sys.refershAppList(); |
sys.refershAppList(); |
||||
}; |
}; |
||||
const eventHandler = async (e: MessageEvent) => { |
const eventHandler = async (e: MessageEvent) => { |
||||
const eventData = e.data; |
const eventData = e.data; |
||||
// console.log('是否同一个:', componentID == eventData.componentID); |
// console.log('是否同一个:', componentID == eventData.componentID); |
||||
if (eventData.type == props.eventType) { |
if (eventData.type == props.eventType) { |
||||
// if (eventData.componentID !== componentID) return; |
// if (eventData.componentID !== componentID) return; |
||||
let data = JSON.parse(eventData.data); |
let data = JSON.parse(eventData.data); |
||||
let title = data.title; |
let title = data.title; |
||||
let path; |
let path; |
||||
let ext: any = props.ext; |
let ext: any = props.ext; |
||||
if (ext instanceof Array) { |
if (ext instanceof Array) { |
||||
ext = ext[0]; |
ext = ext[0]; |
||||
} |
} |
||||
if (data.ext) { |
if (data.ext) { |
||||
ext = data.ext; |
ext = data.ext; |
||||
} |
} |
||||
if (title.indexOf("." + ext) > -1) { |
if (title.indexOf("." + ext) > -1) { |
||||
title = title.replace("." + ext, ""); |
title = title.replace("." + ext, ""); |
||||
} |
} |
||||
|
|
||||
if (win.config && win.config.path) { |
if (win.config && win.config.path) { |
||||
path = win.config.path; |
path = win.config.path; |
||||
|
|
||||
//去除重复文件名后的(1) |
//去除重复文件名后的(1) |
||||
let fileTitleArr = path.split(SP).pop().split("."); |
let fileTitleArr = path.split(SP).pop().split("."); |
||||
let oldExt = fileTitleArr.pop(); |
let oldExt = fileTitleArr.pop(); |
||||
let fileTitle = fileTitleArr.join("."); |
let fileTitle = fileTitleArr.join("."); |
||||
if (fileTitle != title) { |
if (fileTitle != title) { |
||||
path = path.replace(fileTitle, title); |
path = path.replace(fileTitle, title); |
||||
} |
} |
||||
if (oldExt != ext) { |
if (oldExt != ext) { |
||||
path = path.replace("." + oldExt, "." + ext); |
path = path.replace("." + oldExt, "." + ext); |
||||
} |
} |
||||
} else { |
} else { |
||||
choose.saveFile("选择地址", "*", componentID, eventData); |
choose.saveFile("选择地址", "*", componentID, eventData); |
||||
return; |
return; |
||||
// path = `${SP}C${SP}Users${SP}Desktop${SP}${title}.${ext}`; |
// path = `${SP}C${SP}Users${SP}Desktop${SP}${title}.${ext}`; |
||||
} |
} |
||||
writeFile(path, data, title); |
writeFile(path, data, title); |
||||
} else if (eventData.type == "initSuccess") { |
} else if (eventData.type == "initSuccess") { |
||||
if (hasInit) { |
if (hasInit) { |
||||
return; |
return; |
||||
} |
} |
||||
hasInit = true; |
hasInit = true; |
||||
let content = win?.config?.content; |
let content = win?.config?.content; |
||||
let title = win.getTitle(); |
let title = win.getTitle(); |
||||
// console.log("win.config;", win?.config); |
// console.log("win.config;", win?.config); |
||||
// console.log(title); |
// console.log(title); |
||||
title = title.split(SP).pop(); |
title = title.split(SP).pop(); |
||||
|
|
||||
// if (!content && win?.config.path) { |
// if (!content && win?.config.path) { |
||||
// const header = { |
// const header = { |
||||
// pwd: '' |
// pwd: '' |
||||
// }; |
// }; |
||||
// const filePwd = getSystemConfig().fileInputPwd |
// const filePwd = getSystemConfig().fileInputPwd |
||||
// const pos = filePwd.findIndex((item: any) => item.path == win?.config.path) |
// const pos = filePwd.findIndex((item: any) => item.path == win?.config.path) |
||||
// //console.log('路径:', win?.config.path, pos, filePwd); |
// //console.log('路径:', win?.config.path, pos, filePwd); |
||||
// const userType = getSystemConfig().userType |
// const userType = getSystemConfig().userType |
||||
// if (pos !== -1) { |
// if (pos !== -1) { |
||||
// header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd |
// header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd |
||||
// } |
// } |
||||
// content = await sys?.fs.readFile(win?.config.path, header); |
// content = await sys?.fs.readFile(win?.config.path, header); |
||||
// } |
// } |
||||
content = toRaw(content); |
content = toRaw(content); |
||||
if (content && content !== "") { |
if (content && content !== "") { |
||||
storeRef.value?.contentWindow?.postMessage( |
storeRef.value?.contentWindow?.postMessage( |
||||
{ |
{ |
||||
type: "init", |
type: "init", |
||||
data: { content, title }, |
data: { content, title }, |
||||
componentID, |
componentID, |
||||
}, |
}, |
||||
"*" |
"*" |
||||
); |
); |
||||
} else { |
} else { |
||||
storeRef.value?.contentWindow?.postMessage( |
storeRef.value?.contentWindow?.postMessage( |
||||
{ |
{ |
||||
type: "start", |
type: "start", |
||||
title, |
title, |
||||
componentID, |
componentID, |
||||
}, |
}, |
||||
"*" |
"*" |
||||
); |
); |
||||
} |
} |
||||
} else if (eventData.type == "close") { |
} else if (eventData.type == "close") { |
||||
// console.log("关闭"); |
// console.log("关闭"); |
||||
win.close(); |
win.close(); |
||||
} else if (eventData.type == "saveMind") { |
} else if (eventData.type == "saveMind") { |
||||
// console.log("保存"); |
// console.log("保存"); |
||||
const data = eventData.data; |
const data = eventData.data; |
||||
const path = win?.config?.path; |
const path = win?.config?.path; |
||||
//console.log(path,data) |
//console.log(path,data) |
||||
const winMind = new BrowserWindow({ |
const winMind = new BrowserWindow({ |
||||
title: data.title, |
title: data.title, |
||||
url: "/mind/index.html", |
url: "/mind/index.html", |
||||
frame: true, |
frame: true, |
||||
config: { |
config: { |
||||
ext: "mind", |
ext: "mind", |
||||
path: path, |
path: path, |
||||
content: data.content, |
content: data.content, |
||||
}, |
}, |
||||
icon: "gallery", |
icon: "gallery", |
||||
width: 700, |
width: 700, |
||||
height: 500, |
height: 500, |
||||
x: 100, |
x: 100, |
||||
y: 100, |
y: 100, |
||||
//center: true, |
//center: true, |
||||
minimizable: false, |
minimizable: false, |
||||
resizable: true, |
resizable: true, |
||||
}); |
}); |
||||
winMind.show(); |
winMind.show(); |
||||
} else if (eventData.type == "aiCreater") { |
} else if (eventData.type == "aiCreater") { |
||||
console.log("传递内容: ", eventData); |
console.log("传递内容: ", eventData); |
||||
let postData: any = {}; |
let postData: any = {}; |
||||
if (eventData.data) { |
if (eventData.data) { |
||||
postData.content = eventData.data; |
postData.content = eventData.data; |
||||
} |
} |
||||
if (eventData.title) { |
if (eventData.title) { |
||||
postData.title = eventData.title; |
postData.title = eventData.title; |
||||
} |
} |
||||
if (eventData.category) { |
if (eventData.category) { |
||||
postData.category = eventData.category; |
postData.category = eventData.category; |
||||
} |
} |
||||
//console.log(postData,eventData.action) |
//console.log(postData,eventData.action) |
||||
// 模拟AI返回数据 |
// 模拟AI返回数据 |
||||
const res: any = await askAi(postData, eventData.action); |
const res: any = await askAi(postData, eventData.action); |
||||
storeRef.value?.contentWindow?.postMessage( |
storeRef.value?.contentWindow?.postMessage( |
||||
{ |
{ |
||||
type: "aiReciver", |
type: "aiReciver", |
||||
data: res, |
data: res, |
||||
action: eventData.action, |
action: eventData.action, |
||||
}, |
}, |
||||
"*" |
"*" |
||||
); |
); |
||||
} |
} |
||||
}; |
}; |
||||
//删除本地暂存的文件密码 |
//删除本地暂存的文件密码 |
||||
const delFileInputPwd = async () => { |
const delFileInputPwd = async () => { |
||||
let fileInputPwd = getSystemConfig().fileInputPwd; |
let fileInputPwd = getSystemConfig().fileInputPwd; |
||||
const currentPath = win.config.path; |
const currentPath = win.config.path; |
||||
const temp = fileInputPwd.filter( |
const temp = fileInputPwd.filter( |
||||
(item: any) => item.path !== currentPath |
(item: any) => item.path !== currentPath |
||||
); |
); |
||||
setSystemKey("fileInputPwd", temp); |
setSystemKey("fileInputPwd", temp); |
||||
}; |
}; |
||||
onMounted(() => { |
onMounted(() => { |
||||
window.addEventListener("message", eventHandler); |
window.addEventListener("message", eventHandler); |
||||
}); |
}); |
||||
|
|
||||
onUnmounted(async () => { |
onUnmounted(async () => { |
||||
await delFileInputPwd(); |
await delFileInputPwd(); |
||||
window.removeEventListener("message", eventHandler); |
window.removeEventListener("message", eventHandler); |
||||
}); |
}); |
||||
</script> |
</script> |
||||
<style scoped> |
<style scoped> |
||||
.setiframe { |
.setiframe { |
||||
width: 100%; |
width: 100%; |
||||
height: 100%; |
height: 100%; |
||||
border: none; |
border: none; |
||||
} |
} |
||||
</style> |
</style> |
||||
|