python通信,联调接口

This commit is contained in:
2025-04-07 18:26:39 +08:00
parent 489112d028
commit 758fdb49c2
8 changed files with 143 additions and 87 deletions

7
package-lock.json generated
View File

@@ -13,6 +13,7 @@
"echarts": "^5.6.0",
"element-plus": "^2.9.7",
"pinia": "^3.0.1",
"qwebchannel": "^6.2.0",
"vue": "^3.2.13",
"vue-router": "^4.0.3",
"vuex": "^4.0.0"
@@ -9271,6 +9272,12 @@
],
"license": "MIT"
},
"node_modules/qwebchannel": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/qwebchannel/-/qwebchannel-6.2.0.tgz",
"integrity": "sha512-DfJMFZutES2w/v2L3q6id+RoqG92PxnWIkW6dBQh1Be3mo6y2BEckvNfymXlIyCxks5dz0UbmzKZ2jT1qjOCzw==",
"license": "LGPL-3.0"
},
"node_modules/randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",

View File

@@ -12,6 +12,7 @@
"echarts": "^5.6.0",
"element-plus": "^2.9.7",
"pinia": "^3.0.1",
"qwebchannel": "^6.2.0",
"vue": "^3.2.13",
"vue-router": "^4.0.3",
"vuex": "^4.0.0"

View File

@@ -9,7 +9,7 @@
<title>
<%= webpackConfig.name %>
</title>
<!-- <script src="qrc:///qtwebchannel/qwebchannel.js"></script> -->
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
</head>
<body>

View File

@@ -11,6 +11,7 @@ const routes = [
{
path: '/nav',
name: 'nav',
redirect: '/workBenches', // 默认跳转
component: () => import(/* webpackChunkName: "hostsList" */ '../views/nav.vue'),
children: [
{

View File

@@ -12,18 +12,25 @@ export function usePythonBridge() {
};
// 调用 Python 方法
const callPython = (data) => {
if (bridge.value) {
bridge.value.stringFromJs(data);
}
const fetchDataConfig = (data) => {
return new Promise((resolve, reject) => {
if (!bridge.value) {
reject(new Error('返回出错,请检查是否已连接到 Python'));
return;
}
bridge.value.fetchDataConfig(data, function (result) {
resolve(result);
});
});
};
// 从 Python 获取数据
const getPythonData = () => {
const getPythonData = (data) => {
if (bridge.value) {
bridge.value.stringToJs(function (result) {
alert(result);
});
bridge.value.stringToJs(data, function (result) {
alert(result);
});
}
};
@@ -31,7 +38,7 @@ export function usePythonBridge() {
onMounted(initBridge);
return {
callPython,
fetchDataConfig,
getPythonData
};
}

View File

@@ -17,4 +17,11 @@ export function setUser(user) {
export function getUser() {
return JSON.parse(localStorage.getItem('user'));
}
export function setNumData(numData) {
localStorage.setItem('num', JSON.stringify(numData));
}
export function getNumData() {
return JSON.parse(localStorage.getItem('num'));
}

View File

@@ -12,65 +12,57 @@
<el-button style="margin-left: 50px;" type="primary" @click="serch">查询</el-button>
</div>
<div class="hostTable center-justify">
<el-table size="small" :data="tableData" stripe>
<el-table-column prop="hostId" label="主播id" width="200" />
<el-table-column prop="hostName" label="主播名字" min-width="200" />
<!-- <el-button type="primary" @click="getlist">查询列表</el-button>
<el-button type="primary" @click="getdictionary">查询字典</el-button> -->
</div>
<div class="hostTable center-justify">
<el-table :data="tableData" stripe>
<el-table-column prop="hostId" label="主播id" width="200" />
<el-table-column prop="hostName" label="主播名字" min-width="200" />
<el-table-column v-for="label in labelList" :key="label.paramCode" :prop="label.paramCode"
:label="label.paramCodeMeaning" width="120">
<template #default="scope">
<el-popover v-if="!(label.paramCode == 'hostcoins' || label.paramCode == 'ysthostcoins')" placement="bottom"
:width="600" trigger="hover">
<div style="height: 300px;">
<component :is="EChartsComponent" v-if="isPopoverVisible[label.paramCode]"
:title="label.paramCodeMeaning" :id="scope.row.hostId" :dataType="label.paramCode"></component>
<el-table-column v-for="label in labelList" :key="label.paramCode" :prop="label.paramCode"
:label="label.paramCodeMeaning" width="120">
<template #default="scope">
<el-popover v-if="!(label.paramCode == 'hostcoins' || label.paramCode == 'ysthostcoins')"
placement="bottom" :width="600" trigger="hover">
<div style="height: 300px;">
<component :is="EChartsComponent" v-if="isPopoverVisible[`${scope.row.hostId}-${label.paramCode}`]"
:title="label.paramCodeMeaning" :id="scope.row.hostId" :dataType="label.paramCode"></component>
</div>
<template #reference>
<span @mouseover="isPopoverVisible[`${scope.row.hostId}-${label.paramCode}`] = true"
@mouseout="isPopoverVisible[`${scope.row.hostId}-${label.paramCode}`] = false">
{{ scope.row[label.paramCode] }}
</span>
</template>
</el-popover>
<el-popover v-else placement="bottom" :width="500" trigger="hover">
<div style="height: 300px;">
<component :is="EChartsComponent" v-if="isPopoverVisible[`${scope.row.hostId}-${label.paramCode}`]"
:title="label.paramCodeMeaning" :id="scope.row.hostId" :dataType="label.paramCode"></component>
</div>
<template #reference>
<!-- 鼠标移入时开启 -->
<span @mouseover="isPopoverVisible[`${scope.row.hostId}-${label.paramCode}`] = true">
{{ scope.row[label.paramCode] }}
</span>
</template>
</el-popover>
</template>
</el-table-column>
<el-table-column label="操作">
<template #default="scope">
<div style="display: flex; align-items: center">
<el-button type="primary" @click="getTkhostdetail(scope.row.hostId)">查看</el-button>
</div>
<template #reference>
<span @mouseover="isPopoverVisible[label.paramCode] = true"> {{ scope.row[label.paramCode] }}</span>
</template>
</el-popover>
<el-popover v-else placement="bottom" :width="500" trigger="hover">
<div style="height: 300px;">
<component :is="EChartsComponent" v-if="isPopoverVisible[label.paramCode]"
:title="label.paramCodeMeaning" :id="scope.row.hostId" :dataType="label.paramCode"></component>
</div>
<template #reference>
<span @mouseover="isPopoverVisible[label.paramCode] = true"> {{ scope.row[label.paramCode] }}</span>
</template>
</el-popover>
</template>
</el-table-column>
<el-table-column label="操作">
<template #default="scope">
<div style="display: flex; align-items: center">
<el-button type="primary" @click="getTkhostdetail(scope.row.hostId)">查看</el-button>
</div>
</template>
</el-table-column>
</el-table>
</template>
</el-table-column>
</el-table>
</div>
<div class="center-justify" style="margin-top: 30px;">
<el-pagination :default-current-page="4" v-model:current-page="page" background layout="prev, pager, next"
:total="total" @change="serch" />
</div>
</div>
<div class="center-justify" style="margin-top: 30px;">
<el-pagination :default-current-page="4" v-model:current-page="page" background layout="prev, pager, next"
:total="total" @change="serch" />
</div>
</div>
</template>

View File

@@ -3,31 +3,31 @@
<el-card class="box-card">
<template #header>
<div class="card-header">
<span>工作台</span>
<span>工作台 </span>
</div>
</template>
<el-row :gutter="20">
<el-col :span="8">
<div class="input-group">
<label>设置金币数量</label>
<el-input type='number' v-model="range1.min" :min="0" :max="range1.max - 1" placeholder="最小值"
style="width: 100%">
<el-input type='number' v-model="pyData.gold.min" :min="0" :max="pyData.gold.max - 1"
placeholder="最小值" style="width: 100%">
<template #prepend>最小金币数</template>
</el-input>
<el-input type='number' v-model="range1.max" :min="range1.min + 1" :max="100" placeholder="最大值"
style="width: 100%; margin-top: 10px"> <template #prepend>最大金币数</template>
<el-input type='number' v-model="pyData.gold.max" :min="pyData.gold.min + 1" :max="100"
placeholder="最大值" style="width: 100%; margin-top: 10px"> <template #prepend>最大金币数</template>
</el-input>
</div>
</el-col>
<el-col :span="8">
<div class="input-group">
<label>设置粉丝数量</label>
<el-input type='number' v-model="range2.min" :min="0" :max="range2.max - 1" placeholder="最小值"
style="width: 100%">
<el-input type='number' v-model="pyData.fans.min" :min="0" :max="pyData.fans.max - 1"
placeholder="最小值" style="width: 100%">
<template #prepend>最小粉丝数</template>
</el-input>
<el-input type='number' v-model="range2.max" :min="range2.min + 1" :max="100" placeholder="最大值"
style="width: 100%; margin-top: 10px">
<el-input type='number' v-model="pyData.fans.max" :min="pyData.fans.min + 1" :max="100"
placeholder="最大值" style="width: 100%; margin-top: 10px">
<template #prepend>最大粉丝数</template>
</el-input>
</div>
@@ -35,19 +35,20 @@
<el-col :span="8">
<div class="input-group">
<label>后台查询频率</label>
<el-input type='number' v-model="range3.min" :min="0" :max="range3.max - 1" placeholder="次/小时"
style="width: 100%">
<el-input type='number' v-model="pyData.frequency.min" :min="0" :max="pyData.frequency.max - 1"
placeholder="次/小时" style="width: 100%">
<template #append>/小时</template>
</el-input>
<el-input type='number' v-model="range3.max" :min="range3.min + 1" :max="100"
placeholder="次/24小时" style="width: 100%; margin-top: 10px">
<el-input type='number' v-model="pyData.frequency.max" :min="pyData.frequency.min + 1"
:max="100" placeholder="次/24小时" style="width: 100%; margin-top: 10px">
<template #append>/24小时</template>
</el-input>
</div>
</el-col>
</el-row>
<div style="margin-top: 20px; text-align: center">
<el-button type="primary" @click="submit">开始获取数据</el-button>
<el-button v-show="pyData.isStart" type="primary" @click="submit">开始获取数据</el-button>
<el-button v-show="!pyData.isStart" type="danger" @click="unsubmit">停止获取</el-button>
<el-button @click="reset">重置数据</el-button>
</div>
</el-card>
@@ -55,21 +56,61 @@
</template>
<script setup>
import { ref } from 'vue';
import { ref, onMounted } from 'vue';
import { usePythonBridge } from '@/utils/pythonBridge'
import { setNumData, getNumData } from '@/utils/storage'
import { ElMessage } from 'element-plus'
const range1 = ref({ min: 0, max: 0 });
const range2 = ref({ min: 0, max: 0 });
const range3 = ref({ min: 0, max: 0 });
const { fetchDataConfig } = usePythonBridge();
let pyData = ref({
gold: { min: 0, max: 0 },
fans: { min: 0, max: 0 },
frequency: { min: 0, max: 0 },
isStart: true,
country: 'CN'
});
//提交数据到py
const submit = () => {
console.log('提交的区间值:', range1.value, range2.value, range3.value);
// console.log('提交的区间值:', pyData.value.gold, pyData.value.fans, pyData.value.frequency);
setNumData(pyData.value);
fetchDataConfig(JSON.stringify(pyData.value)).then((res) => {
ElMessage.sussec('提交成功')
pyData.value.isStart = false;
}).catch((err) => {
ElMessage.error('提交失败')
})
};
const reset = () => {
range1.value = { min: 0, max: 0 };
range2.value = { min: 0, max: 0 };
range3.value = { min: 0, max: 0 };
//停止
const unsubmit = () => {
fetchDataConfig(JSON.stringify(pyData.value)).then((res) => {
pyData.value.isStart = true;
alert('已停止' + res);
}).catch((err) => {
alert('停止失败', err);
})
};
//重置
const reset = () => {
pyData.value.gold = { min: 0, max: 0 };
pyData.value.fans = { min: 0, max: 0 };
pyData.value.frequency = { min: 0, max: 0 };
};
onMounted(() => {
console.log(getNumData())
if (getNumData()) {
pyData.value = getNumData();
}
})
</script>
<style scoped>