@ -1,10 +1,7 @@
<!DOCTYPE html> < html lang = "" > < head > < meta charset = "utf-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" > < meta name = "viewport" content = "width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1" > < link rel = "icon" href = "./logo.ico" > < title > 思维导图< / title > < script > / / 自 定 义 静 态 资 源 的 路 径
<!DOCTYPE html> < html lang = "" > < head > < meta charset = "utf-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" > < meta name = "viewport" content = "width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1" > < link rel = "icon" href = "./logo.ico" > < title > 思维导图< / title > < script > / / 自 定 义 静 态 资 源 的 路 径
window.externalPublicPath = './'
window.externalPublicPath = './'
// 接管应用
// 接管应用
window.takeOverApp = true< / script > < link href = "css/chunk-vendors.css?a40af00e8d1349d73634" rel = "stylesheet" > < link href = "css/app.css?a40af00e8d1349d73634" rel = "stylesheet" > < / head > < body > < noscript > < strong > We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.< / strong > < / noscript > < div id = "app" > < / div > < script > c o n s t g e t D a t a F r o m B a c k e n d = ( ) = > {
window.takeOverApp = true< / script > < link href = "css/chunk-vendors.css?ef62811a143384fba848" rel = "stylesheet" > < link href = "css/app.css?ef62811a143384fba848" rel = "stylesheet" > < / head > < body > < noscript > < strong > We're sorry but thoughts doesn't work properly without JavaScript enabled. Please enable it to continue.< / strong > < / noscript > < div id = "app" > < / div > < script > l e t d e f N o d e = {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
mindMapData: {
mindMapData: {
root: {
root: {
data: {
data: {
@ -22,9 +19,112 @@
},
},
lang: 'zh',
lang: 'zh',
localConfig: null
localConfig: null
}
function isBase64(str) {
if (str === '' || str.trim() === '') {
return false
}
try {
return btoa(atob(str)) == str
} catch (err) {
return false
}
}
function decodeBase64(base64String) {
// 将Base64字符串分成每64个字符一组
const padding =
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4)
base64String += '='.repeat(padding)
// 使用atob()函数解码Base64字符串
const binaryString = atob(base64String)
// 将二进制字符串转换为TypedArray
const bytes = new Uint8Array(binaryString.length)
for (let i = 0; i < binaryString.length ; i + + ) {
bytes[i] = binaryString.charCodeAt(i)
}
// 将TypedArray转换为字符串
return new TextDecoder('utf-8').decode(bytes)
}
function findInnermostTextNode(node) {
if (node.nodeType === Node.TEXT_NODE) {
return node
}
for (var child of node.childNodes) {
var innerTextNode = findInnermostTextNode(child)
if (innerTextNode) {
return innerTextNode
}
}
return null
}
function getTitle(data) {
//console.log(data)
const htmlStr = data.mindMapData.root.data.text
//console.log(htmlStr)
var div = document.createElement('div')
div.innerHTML = htmlStr
var innerTextNode = findInnermostTextNode(div)
if (innerTextNode) {
return innerTextNode.textContent
} else {
return '未命名思维导图'
}
}
function setData(data) {
// const data = await getDataFromBackend()
// // 设置全局的方法
setTakeOverAppMethods(data)
// 思维导图实例创建完成事件
window.$bus.$on('app_inited', mindMap => {
//console.log(mindMap)
})
})
}, 200)
// 可以通过window.$bus.$on()来监听应用的一些事件
})
// 实例化页面
window.initApp()
}
function eventHandler(e) {
const eventData = e.data
if (eventData.type === 'start') {
//console.log(eventData)
const initTitle =
eventData.title.substring(0, eventData.title.lastIndexOf('.')) ||
'根节点'
defNode.mindMapData.root.data.text = initTitle
setData(defNode)
return
}
if (eventData.type === 'init') {
const data = eventData.data
if (data.content) {
if (typeof data.content === 'string' & & isBase64(data.content)) {
data.content = decodeBase64(data.content)
//console.log(data.content)
setData(JSON.parse(data.content))
} else {
setData(data.content)
}
} else {
//console.log(evTitle)
}
return
}
//setData(defNode)
}
window.SaveOsData = function () {
const save = {
data: JSON.stringify({ content: defNode, title: getTitle(defNode) }),
type: 'exportMind'
}
console.log(save)
window.parent.postMessage(save, '*')
}
}
const setTakeOverAppMethods = data => {
const setTakeOverAppMethods = data => {
window.takeOverAppMethods = {}
window.takeOverAppMethods = {}
@ -34,7 +134,15 @@
}
}
// 保存思维导图数据的函数
// 保存思维导图数据的函数
window.takeOverAppMethods.saveMindMapData = data => {
window.takeOverAppMethods.saveMindMapData = data => {
console.log(data)
//console.log("========")
defNode.mindMapData = data
//console.log(JSON.stringify(defNode))
// const save = {
// data: JSON.stringify({ content, title }),
// type: 'exportMind'
// }
// console.log(save)
// window.parent.postMessage(save, '*')
}
}
// 获取语言的函数
// 获取语言的函数
window.takeOverAppMethods.getLanguage = () => {
window.takeOverAppMethods.getLanguage = () => {
@ -42,7 +150,8 @@
}
}
// 保存语言的函数
// 保存语言的函数
window.takeOverAppMethods.saveLanguage = lang => {
window.takeOverAppMethods.saveLanguage = lang => {
console.log(lang)
//console.log(lang)
defNode.lang = lang
}
}
// 获取本地配置的函数
// 获取本地配置的函数
window.takeOverAppMethods.getLocalConfig = () => {
window.takeOverAppMethods.getLocalConfig = () => {
@ -50,20 +159,13 @@
}
}
// 保存本地配置的函数
// 保存本地配置的函数
window.takeOverAppMethods.saveLocalConfig = config => {
window.takeOverAppMethods.saveLocalConfig = config => {
console.log(config)
//console.log(config)
//console.log("=======")
defNode.localConfig = config
}
}
}
}
window.onload = async () => {
window.onload = async () => {
if (!window.takeOverApp) return
if (!window.takeOverApp) return
// 请求数据
window.parent.postMessage({ type: 'initSuccess' }, '*')
const data = await getDataFromBackend()
window.addEventListener('message', eventHandler)
// 设置全局的方法
}< / script > < script src = "js/chunk-vendors.js?ef62811a143384fba848" > < / script > < script src = "js/app.js?ef62811a143384fba848" > < / script > < / body > < / html >
setTakeOverAppMethods(data)
// 思维导图实例创建完成事件
window.$bus.$on('app_inited', mindMap => {
console.log(mindMap)
})
// 可以通过window.$bus.$on()来监听应用的一些事件
// 实例化页面
window.initApp()
}< / script > < script src = "js/chunk-vendors.js?a40af00e8d1349d73634" > < / script > < script src = "js/app.js?a40af00e8d1349d73634" > < / script > < / body > < / html >