查询列表功能

This commit is contained in:
2025-04-03 16:41:54 +08:00
parent cd884686ce
commit 32cbc6404a
15 changed files with 951 additions and 226 deletions

View File

@@ -1,152 +1,219 @@
<template>
<div>
<button @click="callPython">设置数据"123" Python</button>
<button @click="getPythonData"> Python 获取数据</button>
<button @click="clickChildButton">从tk模拟点击按钮 </button>
<input type="text" id="input" v-model="inputValue"></input>
<div id="output">{{ output }}</div>
<h1>嵌入tk页面</h1>
<iframe id="myIframe" src="https://live-backstage.tiktok.com/portal/overview" width="100%" height="600px"
frameborder="0" ref="myIframe"></iframe>
</div>
<div class="main">
<!-- <button @click="callPython">设置数据"123" Python</button>
<button @click="getPythonData"> Python 获取数据</button> -->
<!-- <input type="text" id="input" v-model="inputValue"></input>
<div id="output">{{ output }}</div> -->
<div class="container">
<div class="left">
</div>
<div class="right">
<!-- 设置 -->
<div class="center-align">
<div></div>
<div class="setup">
<div class="setup-item center-justify">
<div></div>
<span>
网络设置
</span>
</div>
<div class="setup-item center-justify">
<div></div>
<span>
简体中文
</span>
</div>
</div>
</div>
<!-- logo -->
<div class="logo">
<div style="height: 80px; width: 300px; background-color: aqua;">
</div>
</div>
<!-- From -->
<div class="from">
<div class="from-title">
<div>账号登陆</div>
</div>
<div class="from-input">
<el-form label-position="left" label-width="100px" :model="formData">
<div class="from-input-item">
<div class="from-input-item-title center-justify">
账号
</div>
<el-input style="height: 50px;" v-model="formData.userId" placeholder="请输入登录账号"
clearable />
</div>
<div class="from-input-item">
<div class="from-input-item-title center-justify">
密码
</div>
<el-input style="height: 50px;" v-model="formData.password" type="password"
placeholder="请输入登录密码" show-password />
</div>
<div class="from-input-item">
<el-button style="width: 100%; height: 40px;" type="primary"
@click="onSubmit">登录</el-button>
</div>
</el-form>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { login } from '@/api/account';
import { getToken, setToken, setUser } from '@/utils/storage'
const myIframe = ref(null);
let inputValue = ref('999');
// 确保 DOM 渲染完成后再访问 iframe
onMounted(() => {
if (myIframe.value) {
// console.log('Iframe mounted:', myIframe.value);
onIframeLoad();
}
});
const router = useRouter();
const onIframeLoad = () => {
if (myIframe.value) {
const iframeDoc = myIframe.value.contentDocument;
// import { usePythonBridge } from '@/utils/pythonBridge';
// const button = iframeDoc.querySelector('button[data-id="add-host-btn"]')[0];
// if (button) {
// button.click(); // 触发点击事件
// }
// let inputValue = ref('999');
// const output = ref('');
// const { callPython, getPythonData } = usePythonBridge();
const formData = ref({
userId: '',
password: '',
})
const onSubmit = () => {
console.log('submit!')
login({
userId: formData.value.userId,
password: formData.value.password,
}).then(res => {
console.log(res)
setToken(res.currcode)
setUser(res)
router.push('/hostsList');
})
console.log('Iframe loaded:', iframeDoc);
if (iframeDoc) {
// console.log('Iframe loaded:', iframeDoc);
}
// 注入脚本
const script = iframeDoc.createElement('script');
// console.log('script:', script);
script.textContent = `
(function() {
// 拦截 XMLHttpRequest
const originalOpen = XMLHttpRequest.prototype.open;
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
this._method = method; // 保存请求方法
this._url = url; // 保存请求的URL
return originalOpen.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function(body) {
if (this._url && this._url.includes('batch_check_anchor')) {
this.addEventListener('load', function() {
console.log('[XHR] 拦截到 batch_check_anchor 请求:');
console.log('URL:', this._url);
console.log('方法:', this._method);
console.log('请求体:', body);
console.log('响应:', this.responseText);
console.log('------------------------');
});
}
return originalSend.apply(this, arguments);
};
// 拦截 fetch
const originalFetch = window.fetch;
window.fetch = async function(...args) {
const [input, init] = args;
const url = typeof input === 'string' ? input : input.url;
if (url && url.includes('batch_check_anchor')) {
console.log('[Fetch] 拦截到 batch_check_anchor 请求:');
console.log('URL:', url);
console.log('方法:', (init && init.method) || 'GET');
console.log('请求体:', (init && init.body) || null);
const response = await originalFetch.apply(this, args);
const clonedResponse = response.clone();
try {
const data = await clonedResponse.json();
console.log('响应:', data);
} catch (e) {
const text = await clonedResponse.text();
console.log('响应:', text);
}
console.log('------------------------');
return response;
}
return originalFetch.apply(this, args);
};
console.log('batch_check_anchor 拦截器已成功注入');
console.log("123123123123132",document.querySelectorAll('button[data-id="view-more"]'))
})();
`;
iframeDoc.body.appendChild(script);
} else {
console.error('无法访问 iframe 的 contentDocument');
}
console.log(123)
} else {
console.error('无法获取 iframe 引用');
}
};
const output = ref('');
const bridge = ref(null);
onMounted(() => {
new QWebChannel(qt.webChannelTransport, function (channel) {
bridge.value = channel.objects.bridge;
});
});
const callPython = () => {
if (bridge.value) {
bridge.value.stringFromJs("123")
}
};
const getPythonData = () => {
if (bridge.value) {
bridge.value.stringToJs(function (result) {
alert(result); // 这里才会显示返回值
});
}
};
const clickChildButton = () => {
const iframeDoc = myIframe.value.contentDocument;
console.log(iframeDoc)
// 查找子页面中的按钮(假设按钮 id 为 child-button
};
</script>
<style lang="less">
.main {
height: 100vh;
width: 100vw;
// background-color: #ffffff;
.container {
display: flex;
.left {
width: 40%;
height: 100vh;
background-color: #1db97d;
padding: 20px 40px;
}
.right {
width: 60%;
height: 100vh;
background-color: #ffffff;
padding: 20px 40px 20px 50px;
.setup {
display: flex;
.setup-item {
padding: 10px 6px;
display: flex;
div {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: red;
margin-right: 5px;
}
}
}
.logo {
padding: 20px 0;
}
.from {
.from-title {
display: flex;
padding: 10px 0 0 0;
div {
font-size: 20px;
font-weight: 600;
border-bottom: 4px solid #1db97d;
}
}
.from-input {
width: 100%;
padding: 15px 0;
.from-input-item {
display: flex;
padding: 20px 0;
.from-input-item-title {
width: 80px;
height: 50px;
}
}
}
}
}
}
}
.center-line {
display: flex;
flex-direction: column;
align-items: center;
// justify-content: center;
}
.center-justify {
display: flex;
justify-content: space-around;
align-items: center;
}
.center-align {
display: flex;
justify-content: space-between;
}
.center-flex {
display: flex;
justify-content: center;
align-items: center;
}
</style>