modify: webview插件入口

This commit is contained in:
2025-09-06 23:04:06 +08:00
parent e9f0c8ef5f
commit 3631b383d6
19 changed files with 996 additions and 498 deletions
+23
View File
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+24
View File
@@ -0,0 +1,24 @@
# entrance
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}
File diff suppressed because it is too large Load Diff
+44
View File
@@ -0,0 +1,44 @@
{
"name": "entrance",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.8.3",
"qwebchannel": "^6.2.0",
"vue": "^3.2.13"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@@ -0,0 +1,17 @@
<!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,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
+574
View File
@@ -0,0 +1,574 @@
<template>
<div id="app">
<div class="container">
<h1>插件门户</h1>
<nav class="navbar">
<button @click="showUploadForm" :class="{ active: currentView === 'upload' }">上传插件</button>
<button @click="listPlugins" :class="{ active: currentView === 'list' }">插件列表</button>
<button @click="showSettings" :class="{ active: currentView === 'settings' }">设置</button>
</nav>
<div class="content">
<!-- 上传插件表单 -->
<div v-if="currentView === 'upload'" class="upload-section">
<h2>上传新插件</h2>
<form @submit.prevent="uploadPlugin">
<div class="form-group">
<label for="pluginName">插件名称:</label>
<input type="text" id="pluginName" v-model="pluginForm.name" required>
</div>
<div class="form-group">
<label for="pluginFile">选择插件文件 (ZIP格式):</label>
<input type="file" id="pluginFile" @change="handleFileUpload" accept=".zip" required>
</div>
<div class="form-group">
<label for="pluginDescription">插件描述:</label>
<textarea id="pluginDescription" v-model="pluginForm.description"></textarea>
</div>
<button type="submit" :disabled="uploading">
{{ uploading ? '上传中...' : '上传插件' }}
</button>
</form>
<div v-if="uploadMessage" class="message" :class="uploadMessage.type">
{{ uploadMessage.text }}
</div>
</div>
<!-- 插件列表 -->
<div v-if="currentView === 'list'" class="plugins-section">
<h2>可用插件</h2>
<div v-if="loading" class="loading">加载中...</div>
<div v-else-if="plugins.length === 0" class="no-plugins">
暂无插件,请先上传插件。
</div>
<div v-else class="plugins-grid">
<div
v-for="plugin in plugins"
:key="plugin.id"
class="plugin-card"
@click="launchPlugin(plugin)"
>
<h3>{{ plugin.name }}</h3>
<p>{{ plugin.description || '无描述' }}</p>
<div class="plugin-meta">
<span class="version">版本: {{ plugin.version || '1.0.0' }}</span>
<span class="date">{{ plugin.uploadDate }}</span>
</div>
</div>
</div>
</div>
<!-- 设置界面 -->
<div v-if="currentView === 'settings'" class="settings-section">
<h2>系统设置</h2>
<div class="form-group">
<label for="theme">主题:</label>
<select id="theme" v-model="settings.theme">
<option value="light">明亮</option>
<option value="dark">暗黑</option>
</select>
</div>
<div class="form-group">
<label>
<input
type="checkbox"
v-model="settings.autoUpdate"
> 自动检查更新
</label>
</div>
<button @click="saveSettings">保存设置</button>
</div>
</div>
</div>
</div>
</template>
<script>
import { ref, onMounted } from 'vue';
import { QWebChannel } from 'qwebchannel';
export default {
name: 'App',
setup() {
const currentView = ref('upload');
const pluginForm = ref({
name: '',
description: ''
});
const selectedFile = ref(null);
const uploading = ref(false);
const uploadMessage = ref(null);
const plugins = ref([]);
const loading = ref(false);
const settings = ref({
theme: 'light',
autoUpdate: true
});
let py = null;
// 初始化QWebChannel
onMounted(() => {
if (window.qt && window.qt.webChannelTransport) {
new QWebChannel(window.qt.webChannelTransport, function (channel) {
py = channel.objects.py;
// 通知Python端前端已经准备就绪
setTimeout(() => {
if (py && py.on_frontend_ready) {
py.on_frontend_ready();
}
}, 100);
});
}
});
const handleFileUpload = (event) => {
selectedFile.value = event.target.files[0];
};
const uploadPlugin = async () => {
if (!pluginForm.value.name || !selectedFile.value) {
showMessage('请填写插件名称并选择文件', 'error');
return;
}
uploading.value = true;
try {
if (py && py.upload_plugin) {
// 读取文件内容并转换为base64
const reader = new FileReader();
reader.onload = function(e) {
const fileContent = e.target.result.split(',')[1]; // 去掉data:application/zip;base64,前缀
// 调用Python端的上传函数,传递文件名、描述和文件内容
py.upload_plugin(
pluginForm.value.name,
pluginForm.value.description,
fileContent,
(result) => {
try {
// 检查result是否为空或无效
if (!result) {
showMessage('上传失败: 服务器返回空结果', 'error');
uploading.value = false;
return;
}
// 解析从Python返回的JSON字符串
const parsedResult = JSON.parse(result);
if (parsedResult.success) {
showMessage('插件上传成功', 'success');
pluginForm.value = { name: '', description: '' };
// 重置文件输入
document.getElementById('pluginFile').value = '';
selectedFile.value = null;
} else {
console.error(parsedResult);
showMessage(`上传失败: ${parsedResult.error}`, 'error');
}
} catch (parseError) {
console.error('解析Python返回结果失败:', parseError);
console.error('原始返回结果:', result);
showMessage(`上传失败: 返回结果解析错误`, 'error');
}
uploading.value = false;
}
);
};
reader.onerror = function() {
showMessage('文件读取失败', 'error');
uploading.value = false;
};
reader.readAsDataURL(selectedFile.value);
} else {
// 模拟上传成功
showMessage('插件上传成功', 'success');
pluginForm.value = { name: '', description: '' };
// 重置文件输入
document.getElementById('pluginFile').value = '';
selectedFile.value = null;
uploading.value = false;
}
} catch (error) {
showMessage(`上传失败: ${error.message}`, 'error');
uploading.value = false;
}
};
const showMessage = (text, type) => {
uploadMessage.value = { text, type };
setTimeout(() => {
uploadMessage.value = null;
}, 3000);
};
const showUploadForm = () => {
currentView.value = 'upload';
};
const listPlugins = () => {
currentView.value = 'list';
loadPlugins();
};
const showSettings = () => {
currentView.value = 'settings';
};
const loadPlugins = async () => {
loading.value = true;
try {
if (py && py.list_plugins) {
py.list_plugins((result) => {
try {
// 检查result是否为空或无效
if (!result) {
showMessage('加载插件列表失败: 服务器返回空结果', 'error');
loading.value = false;
return;
}
// 解析从Python返回的JSON字符串
const parsedResult = JSON.parse(result);
if (parsedResult.success) {
plugins.value = parsedResult.plugins;
} else {
showMessage(`加载插件列表失败: ${parsedResult.error}`, 'error');
}
} catch (parseError) {
console.error('解析Python返回结果失败:', parseError);
console.error('原始返回结果:', result);
showMessage(`加载插件列表失败: 返回结果解析错误`, 'error');
}
loading.value = false;
});
} else {
// 模拟插件数据
plugins.value = [
{ id: 1, name: '示例插件1', description: '这是一个示例插件', version: '1.0.0', uploadDate: '2023-01-01' },
{ id: 2, name: '示例插件2', description: '另一个示例插件', version: '2.1.0', uploadDate: '2023-02-15' }
];
loading.value = false;
}
} catch (error) {
showMessage(`加载插件列表失败: ${error.message}`, 'error');
loading.value = false;
}
};
const launchPlugin = (plugin) => {
if (py && py.launch_plugin) {
py.launch_plugin(plugin.id, (result) => {
try {
// 检查result是否为空或无效
if (!result) {
showMessage('启动插件失败: 服务器返回空结果', 'error');
return;
}
// 解析从Python返回的JSON字符串
const parsedResult = JSON.parse(result);
if (parsedResult.success) {
console.log(parsedResult.url)
} else {
showMessage(`启动插件失败: ${parsedResult.error}`, 'error');
}
} catch (parseError) {
console.error('解析Python返回结果失败:', parseError);
console.error('原始返回结果:', result);
showMessage(`启动插件失败: 返回结果解析错误`, 'error');
}
});
} else {
// 模拟启动插件
console.log(`启动插件: ${plugin.name}`);
}
};
const saveSettings = () => {
if (py && py.save_settings) {
// 将settings对象转换为JSON字符串再传递给Python
const settingsJson = JSON.stringify(settings.value);
py.save_settings(settingsJson, (result) => {
try {
// 检查result是否为空或无效
if (!result) {
showMessage('保存设置失败: 服务器返回空结果', 'error');
return;
}
// 解析从Python返回的JSON字符串
const parsedResult = JSON.parse(result);
if (parsedResult.success) {
showMessage('设置已保存', 'success');
} else {
showMessage(`保存设置失败: ${parsedResult.error}`, 'error');
}
} catch (parseError) {
console.error('解析Python返回结果失败:', parseError);
console.error('原始返回结果:', result);
showMessage(`保存设置失败: 返回结果解析错误`, 'error');
}
});
} else {
showMessage('设置已保存', 'success');
}
};
return {
currentView,
pluginForm,
uploading,
uploadMessage,
plugins,
loading,
settings,
handleFileUpload,
uploadPlugin,
showUploadForm,
listPlugins,
showSettings,
launchPlugin,
saveSettings
};
}
};
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 20px;
padding: 20px;
}
/* 自定义滚动条样式 */
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #a8a8a8;
}
::-webkit-scrollbar-corner {
background: #f1f1f1;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.navbar {
display: flex;
justify-content: center;
gap: 10px;
margin-bottom: 30px;
flex-wrap: wrap;
}
.navbar button {
padding: 10px 20px;
background-color: #f0f0f0;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: all 0.3s;
}
.navbar button:hover {
background-color: #e0e0e0;
}
.navbar button.active {
background-color: #42b983;
color: white;
}
.content {
min-height: 400px;
}
.form-group {
margin-bottom: 20px;
text-align: left;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input,
.form-group textarea,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
box-sizing: border-box;
}
.form-group textarea {
min-height: 100px;
resize: vertical;
}
button {
padding: 12px 24px;
background-color: #42b983;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
button:hover:not(:disabled) {
background-color: #359c6d;
}
button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.message {
padding: 15px;
border-radius: 5px;
margin-top: 20px;
}
.message.success {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.message.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.loading, .no-plugins {
text-align: center;
padding: 40px;
color: #666;
}
.plugins-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
}
.plugin-card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
cursor: pointer;
transition: all 0.3s;
text-align: left;
}
.plugin-card:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
.plugin-card h3 {
margin-top: 0;
color: #333;
}
.plugin-card p {
color: #666;
margin-bottom: 15px;
}
.plugin-meta {
display: flex;
justify-content: space-between;
font-size: 14px;
color: #999;
}
.plugin-window {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.8);
z-index: 1000;
}
.plugin-window-header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #42b983;
color: white;
padding: 10px 20px;
}
.plugin-window-header button {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
}
.plugin-window-content {
height: calc(100% - 50px);
background-color: white;
}
@media (max-width: 768px) {
.plugins-grid {
grid-template-columns: 1fr;
}
.navbar {
flex-direction: column;
align-items: center;
}
.navbar button {
width: 100%;
margin-bottom: 10px;
}
}
</style>
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@@ -0,0 +1,58 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
</ul>
<h3>Essential Links</h3>
<ul>
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
+4
View File
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
+5
View File
@@ -0,0 +1,5 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
publicPath: './'
})