feat: 支持文档模板

This commit is contained in:
muwoo
2021-06-08 18:04:36 +08:00
parent 02d9c30bc9
commit 1d7c2f592c
8 changed files with 276 additions and 18 deletions

65
static/doc-tpl.html Normal file
View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script crossorigin="anonymous" src="https://lib.baomitu.com/vue/2.6.12/vue.min.js"></script>
<script src="https://lib.baomitu.com/vue-router/3.5.1/vue-router.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.doc-container {
width: 100%;
height: 100vh;
display: flex;
align-items: flex-start;
justify-content: flex-start;
border-top: 1px solid #ddd;
}
.doc-container .menu {
width: 200px;
height: 100%;
border-right: 1px solid #ddd;
overflow: auto;
background: #fff;
}
.doc-container .menu .item.active {
background: #DEE2E6;
}
.doc-container .menu .item {
padding: 5px 10px;
cursor: pointer;
}
.doc-container .menu .title {
font-size: 14px;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
width: 100%;
}
.doc-container .menu .desc {
font-size: 12px;
color: #999;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
width: 100%;
}
.frame {
flex: 1;
height: 100%;
border: none;
}
</style>
<body>
<div id="app">
<router-view />
</div>
</body>
<script src="./doc.js" type="module"></script>
<script src="./index.js" type="module"></script>
</html>

28
static/doc.js Normal file
View File

@@ -0,0 +1,28 @@
export default {
template: `
<div class="doc-container">
<div class="menu">
<div @click="active = index" :class="active === index ? 'active item' : 'item'" v-for="(item, index) in menu">
<div class="title">{{item.t}}</div>
<div class="desc">{{item.d}}</div>
</div>
</div>
<iframe class="frame" :src="path" />
</div>
`,
data() {
return {
query: this.$route.query,
menu: [],
active: 0,
}
},
mounted() {
this.menu = JSON.parse(this.query.args).indexes || [];
},
computed: {
path() {
return decodeURIComponent(this.query.rootPath) + (this.menu[this.active] || {}).p
}
}
}

41
static/index.js Normal file
View File

@@ -0,0 +1,41 @@
import doc from './doc.js';
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
console.log(vars);
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
const routes = [
{ path: '/doc', name: 'doc', component: doc },
]
const router = new VueRouter({
routes // (缩写) 相当于 routes: routes
})
const app = new Vue({
el: '#app',
data: {
config: window.exports,
code: '',
current: {}
},
mounted() {
this.code = getQueryVariable('code');
this.current = this.config[this.code];
this.$router.push({
name: this.current.mode,
query: {
args: JSON.stringify(this.current.args),
rootPath: getQueryVariable('targetFile').replace('index.html', '')
},
})
},
router,
})

View File

@@ -1,5 +1,21 @@
const path = require('path');
const filePath = location.href.replace('file://', '');
let filePath = '';
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
if (location.href.indexOf('targetFile') > -1) {
filePath = decodeURIComponent(getQueryVariable('targetFile'));
} else {
filePath = location.href.replace('file://', '');
}
const {ipcRenderer, nativeImage, clipboard, remote} = require('electron');
const currentWindow = remote.getCurrentWindow();
@@ -26,19 +42,20 @@ window.utools = window.rubick = {
onPluginEnter(cb) {
ipcRenderer.once('onPluginEnter', (e, message) => {
const feature = JSON.parse(message.detail)
cb(feature)
console.log(feature)
cb({...feature, type: 'text'})
})
},
onPluginReady(cb) {
ipcRenderer.once('onPluginReady', (e, message) => {
const feature = JSON.parse(message.detail)
cb(feature)
cb({...feature, type: 'text'})
})
},
onPluginOut(cb) {
ipcRenderer.once('onPluginOut', (e, message) => {
const feature = JSON.parse(message.detail)
cb(feature)
cb({...feature, type: 'text'})
})
},
@@ -69,8 +86,14 @@ window.utools = window.rubick = {
});
},
setSubInputValue(text) {
removeSubInput() {
ipcRenderer.sendToHost('removeSubInput');
},
setSubInputValue(text) {
ipcRenderer.sendToHost('setSubInputValue', {
text
});
},
getPath(name) {
@@ -139,5 +162,30 @@ window.utools = window.rubick = {
isDarkColors() {
return false;
},
getFeatures() {
ipcRenderer.sendToHost('getFeatures');
return new Promise(resolve => {
ipcRenderer.on(`msg-back-getFeatures`, (e, result) => {
resolve(result);
});
});
},
setFeature(feature) {
ipcRenderer.sendToHost('setFeature', {feature});
},
ubrowser: {
goto(md, title) {
ipcRenderer.send('msg-trigger', {
type: 'ubrowser.goto',
md, title,
});
return utools.ubrowser;
},
run() {
}
}
}
require(path.join(filePath, '../preload.js'));
window.exports && ipcRenderer.sendToHost('templateConfig', {config: window.exports});