Skip to content

Commit

Permalink
feat: 使用自定义控件
Browse files Browse the repository at this point in the history
  • Loading branch information
wll8 committed Dec 10, 2024
1 parent 51462ef commit 3e4e1ce
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 77 deletions.
2 changes: 1 addition & 1 deletion store/demo/live-control-robot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@smallwei/avue": "^3.4.8",
"@smallwei/avue": "^3.6.0",
"alova": "^2.20.5",
"axios": "^0.21.1",
"disable-devtool": "^0.3.8",
Expand Down
12 changes: 6 additions & 6 deletions store/demo/live-control-robot/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion store/demo/live-control-robot/run.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ new Promise(async () => {
browserArguments: `--disable-web-security --allow-running-insecure-content`,
form: {
right: `1000`,
border: `thin`,
bottom: `600`,
},
page: `http://162.14.76.148:7800/live/#/`,
Expand Down
1 change: 0 additions & 1 deletion store/demo/live-control-robot/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ new Promise(async () => {
originRegExp: `.*`,
form: {
right: `1000`,
border: `thin`,
bottom: `600`,
},
socket: {
Expand Down
73 changes: 54 additions & 19 deletions store/demo/live-control-robot/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
<template>
<router-view />
<div :class="[`pageMain`, { min: isExpand }]">
<div>
<el-button v-if="isExpand" @click="toggle" circle :icon="DArrowRight"></el-button>
<el-button v-if="!isExpand" @click="toggle" circle :icon="DArrowLeft"></el-button>
</div>
<router-view />
</div>
</template>
<script>
export default {
name: `App`,
components: {},
created() {},
data() {
return {}
},
methods: {},
watch: {},
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { DArrowRight, DArrowLeft } from '@element-plus/icons-vue'
const isExpand = ref(false)
function toggle() {
isExpand.value = !isExpand.value
if (isExpand.value) {
globalThis.ws.call(
`run`,
[
`
global.G.winformSub.box.width = 60
global.G.winformSub.box.height = 60
`,
],
{
runType: `main`,
},
)
} else {
globalThis.ws.call(
`run`,
[
`
global.G.winformSub.box.width = 900
global.G.winformSub.box.height = 600
`,
],
{
runType: `main`,
},
)
}
}
</script>
<style lang="less">
Expand All @@ -19,12 +50,16 @@ body {
margin: 0;
padding: 0;
}
// .avue-crud__left {
// display: flex;
// flex-direction: row-reverse;
// .el-button + .el-button {
// margin-right: 12px;
// margin-left: 0;
// }
// }
.pageMain {
background-color: #fff;
border-radius: 10px;
border: 4px solid rgba(0, 0, 0, 0.1);
padding: 10px;
&.min {
width: 30px;
height: 30px;
overflow: hidden;
}
// background-color: #ccc;
}
</style>
8 changes: 7 additions & 1 deletion store/demo/live-control-robot/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { createPersistedState } from 'pinia-plugin-persistedstate'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import Avue from '@smallwei/avue'
import '@smallwei/avue/lib/index.css'

Expand All @@ -24,6 +26,10 @@ app.use(router)
app.use(ElementPlus)
app.use(Avue, { axios: http })

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}

const fn = async (sys) => {
console.log(`初始化完成`, sys)
globalThis.sys = sys
Expand All @@ -38,7 +44,7 @@ new Promise(async () => {
await fn(globalThis.sys)
} else {
await new Sys({
log: false,
log: true,
wsUrl: config.sysShimWs,
})
.then(fn)
Expand Down
4 changes: 4 additions & 0 deletions store/demo/live-control-robot/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const router = createRouter({
routes: [
{
path: `/`,
component: () => import(`@/views/page0/index.vue`),
},
{
path: `/page1`,
component: () => import(`@/views/page1/index.vue`),
},
{
Expand Down
110 changes: 110 additions & 0 deletions store/demo/live-control-robot/src/views/page0/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<div class="page">loading...</div>
</template>

<script setup>
const ws = globalThis.ws
new Promise(async () => {
console.log(111, window.sys.hwnd)
const [, winformInfo] = await ws.call(
`run`,
[
`
var winform = win._form.getForm(${window.sys.hwnd})
winform.show(false)
return {
left: winform.left,
top: winform.top,
right: winform.right,
bottom: winform.bottom,
}
`,
],
{
runType: `main`,
},
)
custom(winformInfo)
function custom(winformInfo) {
const boxUrl = location.origin + location.pathname + `#/page1`
const arg = {
title: document.title,
boxUrl,
toExit: true, // 关闭时是否退出主程序
}
console.log(`winformInfo`, winformInfo)
ws.call(
`run`,
[
`
var winformInfo = global.G.config.form
var arg = ...
var winformSub = win.form({
text: arg.title;
right: 1400;
bottom: 900;
})
global.G.winformSub = winformSub
global.G.winformSub.orphanWindow()
global.G.winformSub.add(
page={
cls="custom";
transparent=1;
z=2
};
box={
cls="custom";
left=50;
top=100;
right=900;
bottom=700;
ah=1;
aw=1;
transparent=1;
z=1
}
)
var wbBox = web.view( global.G.winformSub.box )
global.G.winformSub.wbBox = wbBox
// 挂载到 window.ext 上的对象
global.G.winformSub.wbBox.external = web.json.stringify({
token = global.G.token;
wsUrl = global.G.wsUrl;
hwnd = global.G.winformSub.hwnd;
})
// 页面每次刷新都会运行
var old = global.G.winformSub.wbBox.preloadScript
global.G.winformSub.wbBox.preloadScript = function(js) {
js = '\n\n' + js + '\n\n'
call(old, owner, js)
}
global.G.winformSub.wbBox.preloadScript(\`(() => {
window._ext = chrome.webview.hostObjects.external
delete window.aardio
})()\`)
global.G.winformSub.wbBox.preloadScript(string.load(global.G.appDataPath + "/res/browser/main.umd.min.js"))
global.G.winformSub.wbBox.go(arg.boxUrl)
global.G.winformSub.text = global.G.winformSub.wbBox.xcall("() => document.title")
global.G.winformSub.wbBox.defaultBackgroundColor = 0
global.G.winformSub.onClose = function() {
if(arg.toExit) global.G.killAll()
}
global.G.winformSub.show();
`,
arg,
],
{
runType: `main`,
},
)
}
})
</script>

<style scoped lang="less">
.page {
// background-color: #ccc;
}
</style>
16 changes: 7 additions & 9 deletions store/demo/live-control-robot/src/views/page1/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="page p20px">
<div class="page">
<h3 text-center>主配置</h3>
<avue-crud
:data="data"
Expand All @@ -21,14 +21,15 @@ import { useStore } from '@/stores/index.js'
import { storeToRefs } from 'pinia'
import { getUserToken } from '@/util.js'
import http from '@/http.js'
import { useRouter } from 'vue-router'
import { useRouter, useRoute } from 'vue-router'
const shim = globalThis.shim
const native = globalThis.shim.native
const ws = globalThis.shim.ws
const router = useRouter()
const route = useRoute()
const data = ref([])
console.log(`route`, route)
function getData() {
http.get(`/config`).then((res) => {
data.value = res
Expand All @@ -37,9 +38,10 @@ function getData() {
getData()
const option = ref({
menuWidth: 200,
column: [
{ label: `配置名称`, prop: `名称` },
{ label: `卡密`, prop: `卡密` },
{ label: `卡密`, prop: `卡密`, hide: true },
],
})
Expand Down Expand Up @@ -75,8 +77,4 @@ async function rowUpdate(row, index, done, loading) {
}
</script>

<style scoped lang="less">
.page {
// background-color: #ccc;
}
</style>
<style scoped lang="less"></style>
2 changes: 1 addition & 1 deletion store/demo/live-control-robot/src/views/page2/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="page p20px">
<div class="page">
<h3 text-center>平台选择</h3>
<avue-crud
:data="data"
Expand Down
Loading

0 comments on commit 3e4e1ce

Please sign in to comment.