mirror of https://gitee.com/godoos/godoos.git
6 changed files with 178 additions and 76 deletions
File diff suppressed because one or more lines are too long
@ -1,69 +1,171 @@ |
|||||
<!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>const getDataFromBackend = () => { |
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>let defNode = { |
||||
return new Promise((resolve, reject) => { |
mindMapData: { |
||||
setTimeout(() => { |
root: { |
||||
resolve({ |
data: { |
||||
mindMapData: { |
text: '根节点' |
||||
root: { |
}, |
||||
data: { |
children: [] |
||||
text: '根节点' |
}, |
||||
}, |
theme: { |
||||
children: [] |
template: 'avocado', |
||||
}, |
config: {} |
||||
theme: { |
}, |
||||
template: 'avocado', |
layout: 'logicalStructure', |
||||
config: {} |
config: {}, |
||||
}, |
view: null |
||||
layout: 'logicalStructure', |
}, |
||||
config: {}, |
lang: 'zh', |
||||
view: null |
localConfig: null |
||||
}, |
} |
||||
lang: 'zh', |
|
||||
localConfig: null |
function isBase64(str) { |
||||
}) |
if (str === '' || str.trim() === '') { |
||||
}, 200) |
return false |
||||
}) |
|
||||
} |
} |
||||
const setTakeOverAppMethods = data => { |
try { |
||||
window.takeOverAppMethods = {} |
return btoa(atob(str)) == str |
||||
// 获取思维导图数据的函数 |
} catch (err) { |
||||
window.takeOverAppMethods.getMindMapData = () => { |
return false |
||||
return data.mindMapData |
} |
||||
} |
} |
||||
// 保存思维导图数据的函数 |
function decodeBase64(base64String) { |
||||
window.takeOverAppMethods.saveMindMapData = data => { |
// 将Base64字符串分成每64个字符一组 |
||||
console.log(data) |
const padding = |
||||
} |
base64String.length % 4 === 0 ? 0 : 4 - (base64String.length % 4) |
||||
// 获取语言的函数 |
base64String += '='.repeat(padding) |
||||
window.takeOverAppMethods.getLanguage = () => { |
|
||||
return data.lang |
// 使用atob()函数解码Base64字符串 |
||||
} |
const binaryString = atob(base64String) |
||||
// 保存语言的函数 |
|
||||
window.takeOverAppMethods.saveLanguage = lang => { |
// 将二进制字符串转换为TypedArray |
||||
console.log(lang) |
const bytes = new Uint8Array(binaryString.length) |
||||
} |
for (let i = 0; i < binaryString.length; i++) { |
||||
// 获取本地配置的函数 |
bytes[i] = binaryString.charCodeAt(i) |
||||
window.takeOverAppMethods.getLocalConfig = () => { |
} |
||||
return data.localConfig |
|
||||
|
// 将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 |
||||
} |
} |
||||
// 保存本地配置的函数 |
} |
||||
window.takeOverAppMethods.saveLocalConfig = config => { |
|
||||
console.log(config) |
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) |
||||
|
}) |
||||
|
// 可以通过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 => { |
||||
|
window.takeOverAppMethods = {} |
||||
|
// 获取思维导图数据的函数 |
||||
|
window.takeOverAppMethods.getMindMapData = () => { |
||||
|
return data.mindMapData |
||||
|
} |
||||
|
// 保存思维导图数据的函数 |
||||
|
window.takeOverAppMethods.saveMindMapData = 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 = () => { |
||||
|
return data.lang |
||||
|
} |
||||
|
// 保存语言的函数 |
||||
|
window.takeOverAppMethods.saveLanguage = lang => { |
||||
|
//console.log(lang) |
||||
|
defNode.lang = lang |
||||
|
} |
||||
|
// 获取本地配置的函数 |
||||
|
window.takeOverAppMethods.getLocalConfig = () => { |
||||
|
return data.localConfig |
||||
|
} |
||||
|
// 保存本地配置的函数 |
||||
|
window.takeOverAppMethods.saveLocalConfig = config => { |
||||
|
//console.log(config) |
||||
|
//console.log("=======") |
||||
|
defNode.localConfig = config |
||||
} |
} |
||||
window.onload = async () => { |
} |
||||
if (!window.takeOverApp) return |
window.onload = async () => { |
||||
// 请求数据 |
if (!window.takeOverApp) return |
||||
const data = await getDataFromBackend() |
window.parent.postMessage({ type: 'initSuccess' }, '*') |
||||
// 设置全局的方法 |
window.addEventListener('message', eventHandler) |
||||
setTakeOverAppMethods(data) |
}</script><script src="js/chunk-vendors.js?ef62811a143384fba848"></script><script src="js/app.js?ef62811a143384fba848"></script></body></html> |
||||
// 思维导图实例创建完成事件 |
|
||||
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> |
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue