From 52415dee0ba0491e141f0e2a3dbbd11f4cc0a61f Mon Sep 17 00:00:00 2001 From: pengxiaolong <15716207+pengxiaolong711@user.noreply.gitee.com> Date: Thu, 3 Jul 2025 19:14:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 8 +- package.json | 2 +- src/api/account.js | 2 +- src/main.js | 7 +- src/stores/notice.js | 27 +- src/utils/axios.js | 27 +- src/utils/pythonBridge.js | 44 ++- src/utils/storage.js | 74 +++-- src/views/HomeView.vue | 565 +++++++++++++++++----------------- src/views/hosts/hostsList.vue | 364 ++++++++++++---------- 10 files changed, 622 insertions(+), 498 deletions(-) diff --git a/package-lock.json b/package-lock.json index 07f6b89..f902511 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "core-js": "^3.8.3", "echarts": "^5.6.0", "element-plus": "^2.9.7", - "pinia": "^3.0.1", + "pinia": "^3.0.3", "qwebchannel": "^6.2.0", "vue": "^3.2.13", "vue-router": "^4.0.3", @@ -9709,9 +9709,9 @@ } }, "node_modules/pinia": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/pinia/-/pinia-3.0.1.tgz", - "integrity": "sha512-WXglsDzztOTH6IfcJ99ltYZin2mY8XZCXujkYWVIJlBjqsP6ST7zw+Aarh63E1cDVYeyUcPCxPHzJpEOmzB6Wg==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/pinia/-/pinia-3.0.3.tgz", + "integrity": "sha512-ttXO/InUULUXkMHpTdp9Fj4hLpD/2AoJdmAbAeW2yu1iy1k+pkFekQXw5VpC0/5p51IOR/jDaDRfRWRnMMsGOA==", "license": "MIT", "dependencies": { "@vue/devtools-api": "^7.7.2" diff --git a/package.json b/package.json index 9c2f5de..3ab880d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "core-js": "^3.8.3", "echarts": "^5.6.0", "element-plus": "^2.9.7", - "pinia": "^3.0.1", + "pinia": "^3.0.3", "qwebchannel": "^6.2.0", "vue": "^3.2.13", "vue-router": "^4.0.3", diff --git a/src/api/account.js b/src/api/account.js index ea46092..581bb56 100644 --- a/src/api/account.js +++ b/src/api/account.js @@ -1,5 +1,5 @@ import { getAxios, postAxios, downFile } from '@/utils/axios.js' - +import { ElMessage } from 'element-plus'; //租户获取登录id export function rentgetloginID(data) { return getAxios({ url: `/api/tenant/get-id-by-name?name=${data.name}`}) diff --git a/src/main.js b/src/main.js index 5fd80de..105993b 100644 --- a/src/main.js +++ b/src/main.js @@ -7,16 +7,13 @@ import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' import zhCn from 'element-plus/dist/locale/zh-cn.mjs'; // 引入中文语言包 -// createApp(App).use(store).use(router).mount('#app') - - const app = createApp(App); app.use(ElementPlus, { locale: zhCn, // 配置中文 }); + app.use(ElementPlus) // 注册 ElementPlus app.use(createPinia()); // 注册 Pinia app.use(store); // 注册 store app.use(router); // 注册 router -app.mount('#app'); - +app.mount('#app'); \ No newline at end of file diff --git a/src/stores/notice.js b/src/stores/notice.js index 94bf7b3..574f36a 100644 --- a/src/stores/notice.js +++ b/src/stores/notice.js @@ -9,4 +9,29 @@ export const noticeStore = defineStore('noticeNum', { this.data.num++; }, }, -}); \ No newline at end of file +}); +export const tokenStore = defineStore('token', { + state: () => { + return { token: '' } + }, + // 也可以这样定义 + // state: () => ({ count: 0 }) + actions: { + setToken(token){ + this.token = token + } + }, + }) + + export const UserStore = defineStore('User', { + state: () => { + return { user: {} } + }, + // 也可以这样定义 + // state: () => ({ count: 0 }) + actions: { + setUser(user){ + this.user = user + } + }, + }) \ No newline at end of file diff --git a/src/utils/axios.js b/src/utils/axios.js index ce34f94..ddccc1d 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -8,6 +8,12 @@ import router from '@/router' import { ElMessage } from 'element-plus'; import { usePythonBridge, } from '@/utils/pythonBridge' +import { ref } from 'vue'; +import { defineStore } from 'pinia' +import { tokenStore,UserStore } from '@/stores/notice' + + + const { stopScript } = usePythonBridge(); @@ -17,31 +23,34 @@ let baseURL = '' if (process.env.NODE_ENV === 'development') { // 生产环境 // baseURL = "https://api.tkpage.yolozs.com" - baseURL = "http://47.79.98.113:8101" + // baseURL = "http://47.79.98.113:8101" // baseURL = "http://192.168.0.103:8085/" + baseURL = "http://192.168.1.174:8101" } else { // 测试环境 // baseURL = "http://120.26.251.180:8085/" // 开发环境 // baseURL = "https://api.tkpage.yolozs.com" - baseURL = "http://47.79.98.113:8101" + // baseURL = "http://47.79.98.113:8101" + baseURL = "http://192.168.1.174:8101" // baseURL = "http://api.tkpage.vvtiktok.cn" } // 请求拦截器 axios.interceptors.request.use((config) => { + const tokenCache = tokenStore() console.log("config", config) const url = sliceUrl(config.url) console.log("url", url) - if (!(config.url == 'bigbrother-doLogin' || config.url == 'get-id-by-name')) { - config.headers['vvtoken'] = getToken(); - } - // 请求超时时间 - 毫秒 config.timeout = 60000 config.baseURL = baseURL // 自定义Content-type config.headers['Content-type'] = 'application/json' + if (!(config.url == 'bigbrother-doLogin' || config.url == 'get-id-by-name')) { + config.headers['vvtoken'] = tokenCache.token; + } + return config; }, (error) => { return Promise.reject(error) @@ -136,9 +145,11 @@ export const downFile = async (urlstr, data) => { } //请求前验证 function cheekalive() { + const userCache = UserStore() + const tokenCache = tokenStore() axios.post('api/account/cheekalive', { - userId: getUser().userId, - currcode: getToken(), + userId: userCache.user.id, + currcode: tokenCache.token, }, { headers: { diff --git a/src/utils/pythonBridge.js b/src/utils/pythonBridge.js index 9d3ab3c..f31b361 100644 --- a/src/utils/pythonBridge.js +++ b/src/utils/pythonBridge.js @@ -38,6 +38,43 @@ export function usePythonBridge() { // }); // }; + //删除前端储存数据 + const deleteStorageData = (data) => { + return new Promise((resolve, reject) => { + if (pyBridge.value) { + pyBridge.value.deleteAccountInfo(JSON.stringify(data),function (result) { + resolve(result); + }); + }else{ + console.log("pyBridge is null未连接上") + } + }); + }; + + //获取前端储存数据 + const getStorageData = (data) => { + return new Promise((resolve, reject) => { + if (pyBridge.value) { + pyBridge.value.readAccountInfo(JSON.stringify(data),function (result) { + resolve(result); + }); + }else{ + console.log("pyBridge is null未连接上") + } + }); + }; + //设置前端储存数据 + const setStorageData = (data) => { + return new Promise((resolve, reject) => { + if (pyBridge.value) { + pyBridge.value.storageAccountInfo(JSON.stringify(data),function (result) { + resolve(result); + }); + }else{ + console.log("pyBridge is null未连接上") + } + }); + }; // 查询获取大哥的数据 const controlTask = (data) => { @@ -58,7 +95,6 @@ export function usePythonBridge() { if (pyBridge.value) { pyBridge.value.getBrotherInfo(function (result) { resolve(JSON.parse(result)); - // ElMessage.success(result); }); }else{ console.log("pyBridge is null未连接上") @@ -92,7 +128,6 @@ export function usePythonBridge() { const givePyAnchorId = (id) => { console.log("id",id); if (pyBridge.value) { - ElMessage.success(id); pyBridge.value.givePyAnchorId(id, function (result) { }); } @@ -155,6 +190,9 @@ export function usePythonBridge() { controlTask, getBrotherInfo, getVersion, - givePyAnchorId + givePyAnchorId, + getStorageData, + setStorageData, + deleteStorageData, }; } \ No newline at end of file diff --git a/src/utils/storage.js b/src/utils/storage.js index cc1182a..f843818 100644 --- a/src/utils/storage.js +++ b/src/utils/storage.js @@ -1,54 +1,70 @@ -export function setToken(token) { - localStorage.setItem('token', token); + +import { usePythonBridge} from "@/utils/pythonBridge"; + +const { getStorageData, setStorageData,deleteStorageData} = usePythonBridge(); +import { ElMessage } from 'element-plus'; + +export async function setToken(token) { + const res = await setStorageData({key: 'token',data: token}).then(res => { + }); } -export function getToken() { - return localStorage.getItem('token'); +export async function getToken() { + const res = await getStorageData({ key: 'token' }); + return JSON.parse(res); } -export function removeToken() { - localStorage.removeItem('token'); +export async function removeToken() { + const res = deleteStorageData({key: 'token'}); } -export function setUser(user) { - - localStorage.setItem('user', JSON.stringify(user)); +export async function setUser(user) { + const res = await setStorageData({key: 'user',data: user}).then(res => { + }); } -export function getUser() { - return JSON.parse(localStorage.getItem('user')); +export async function getUser() { + const res = await getStorageData({ key: 'user' }); + return JSON.parse(res); } -export function setNumData(numData) { - localStorage.setItem('num', JSON.stringify(numData)); +export async function setNumData(numData) { + const res = await setStorageData({key: 'num',data: numData}) } -export function getNumData() { - return JSON.parse(localStorage.getItem('num')); + +export async function getNumData() { + const res = await getStorageData({ key: 'num' }); + return JSON.parse(res); } + // 导出一个函数,用于设置用户密码 -export function setUserPass(userdata) { - localStorage.setItem('userPass', JSON.stringify(userdata)); +export async function setUserPass(userdata) { + const res = await setStorageData({key: 'userPass',data:userdata}) } // 导出一个函数,用于获取用户密码 -export function getUserPass() { - return JSON.parse(localStorage.getItem('userPass')); +export async function getUserPass() { + const res = await getStorageData({ key: 'userPass' }); + return JSON.parse(res); } - // 用于设置tk账户密码 -export function setTkUser(userdata) { - localStorage.setItem('tkuser', JSON.stringify(userdata)); +export async function setTkUser(userdata) { + const res = await setStorageData({key: 'tkuser',data: userdata}) } // 用于获取tk账户密码 -export function getTkUser() { - return JSON.parse(localStorage.getItem('tkuser')); + +export async function getTkUser() { + const res = await getStorageData({ key: 'tkuser' }); + return JSON.parse(res); } // 用于列表筛选条件 -export function setSerch(data) { - localStorage.setItem('Serch', JSON.stringify(data)); +export async function setSerch(data) { + const res = await setStorageData({key: 'Serch',data: data}) } + // 用于获取列表筛选条件 -export function getSerch() { - return JSON.parse(localStorage.getItem('Serch')); -} \ No newline at end of file +export async function getSerch() { + const res = await getStorageData({ key: 'Serch' }); + return JSON.parse(res); +} diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index d6503e0..c9f2f04 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,356 +1,351 @@ \ No newline at end of file + diff --git a/src/views/hosts/hostsList.vue b/src/views/hosts/hostsList.vue index 90c3ea2..cdfea48 100644 --- a/src/views/hosts/hostsList.vue +++ b/src/views/hosts/hostsList.vue @@ -1,15 +1,14 @@ @@ -268,46 +299,45 @@ import { getCountryinfo, accountName, } from "@/api/account"; -import { usePythonBridge} from "@/utils/pythonBridge"; +import { usePythonBridge } from "@/utils/pythonBridge"; import { getUser, setSerch, getSerch } from "@/utils/storage"; import { ref, reactive, onMounted } from "vue"; import EChartsComponent from "@/components/EChartsComponent.vue"; import { ElMessage, ElMessageBox } from "element-plus"; import { color } from "echarts"; -import { getCountryName } from '@/utils/countryUtil' +import { getCountryName } from "@/utils/countryUtil"; //ip国家 -let countryData = ref(''); +let countryData = ref(""); //获取国家 const getIpInfo = async () => { - try { - const response = await fetch('https://ipapi.co/json/'); - if (!response.ok) { - throw new Error('请求失败'); - } - const data = await response.json(); - console.log('IP信息:', data.country); - - countryData.value = getCountryName(data.country); - } catch (error) { - console.error('请求出错:', error); - ElMessageBox.prompt('请输入将要获取国家的中文名', '获取国家失败', { - confirmButtonText: '确认', - cancelButtonText: '取消', - showClose: false, - closeOnClickModal: false, - showCancelButton: false, - }) - .then(({ value }) => { - countryData.value = value - }) - // .catch(() => { - // ElMessage({ - // type: 'info', - // message: 'Input canceled', - // }) - // }) + try { + const response = await fetch("https://ipapi.co/json/"); + if (!response.ok) { + throw new Error("请求失败"); } + const data = await response.json(); + console.log("IP信息:", data.country); + + countryData.value = getCountryName(data.country); + } catch (error) { + console.error("请求出错:", error); + ElMessageBox.prompt("请输入将要获取国家的中文名", "获取国家失败", { + confirmButtonText: "确认", + cancelButtonText: "取消", + showClose: false, + closeOnClickModal: false, + showCancelButton: false, + }).then(({ value }) => { + countryData.value = value; + }); + // .catch(() => { + // ElMessage({ + // type: 'info', + // message: 'Input canceled', + // }) + // }) + } }; //打开TikTok登录 function openTikTok() { @@ -315,7 +345,7 @@ function openTikTok() { } //重置 function Resetss() { - queryFormData.value = {} + queryFormData.value = {}; } //大哥climb const queryFormData = ref({ @@ -326,41 +356,47 @@ const queryFormData = ref({ isRunning: true, }); //时间 -const timerId = ref(null) +const timerId = ref(null); const getBrotherInfodata = ref({ total: 0, valid: 0, -}) +}); function BigBrotherstop() { queryFormData.value.tenantId = userInfo.value.tenantId; queryFormData.value.region = countryData.value; - controlTask(JSON.stringify(queryFormData.value)).then(res => { + controlTask(JSON.stringify(queryFormData.value)).then((res) => { queryFormData.value.isRunning = true; - clearInterval(timerId.value) - timerId.value = null - }) + clearInterval(timerId.value); + timerId.value = null; + }); } function getBigBrother() { queryFormData.value.tenantId = userInfo.value.tenantId; queryFormData.value.region = countryData.value; - controlTask(JSON.stringify(queryFormData.value)).then(res => { + controlTask(JSON.stringify(queryFormData.value)).then((res) => { queryFormData.value.isRunning = false; timerId.value = setInterval(() => { - getBrotherInfo().then(res => { + getBrotherInfo().then((res) => { getBrotherInfodata.value = res; - }) - }, 1000) - }) + }); + }, 1000); + }); } const loading = ref(false); //py方法 -const { givePyAnchorId, exportToExcel, loginTikTok , controlTask , getBrotherInfo } = usePythonBridge(); +const { + givePyAnchorId, + exportToExcel, + loginTikTok, + controlTask, + getBrotherInfo, +} = usePythonBridge(); let num = ref(0); //账号信息 -const userInfo = ref(getUser()); +const userInfo = ref({}); //主播列表DOM const multipleTableRef = ref(null); let labelList = ref([ @@ -430,18 +466,24 @@ let options = ref([]); let version = ref("0.0.0"); onMounted(() => { - getCountry(); //获取国家 - // getSerchStorage();//获取搜索条件 - getlist();//获取主播列表 - getIpInfo(); + setTimeout(() => { + getUserdata(); + }, 500); }); +async function getUserdata() { + const User = await getUser(); + userInfo.value = User; + getCountry(); //获取国家 + getlist(); //获取主播列表 + getIpInfo(); +} + function serch() { page.value = 1; getlist(); } - function exportList() { // if (searchForm.value.dataType == "InvitationType") { // searchForm.value.dataEnd = searchForm.value.dataStart; @@ -482,11 +524,11 @@ function handleSelectionChange(data) { //时间格式化 function formatDate(date) { const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0开始,需要+1 - const day = String(date.getDate()).padStart(2, '0'); - const hours = String(date.getHours()).padStart(2, '0'); - const minutes = String(date.getMinutes()).padStart(2, '0'); - const seconds = String(date.getSeconds()).padStart(2, '0'); + const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从 0开始,需要+1 + const day = String(date.getDate()).padStart(2, "0"); + const hours = String(date.getHours()).padStart(2, "0"); + const minutes = String(date.getMinutes()).padStart(2, "0"); + const seconds = String(date.getSeconds()).padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } @@ -501,8 +543,8 @@ const getlist = () => { sortName: sortData.value.sortName, //排序类型 current: page.value, pageSize: pageSize.value, - createTimeStart:createTimes.value[0], - createTimeEnd:createTimes.value[1], + createTimeStart: createTimes.value[0], + createTimeEnd: createTimes.value[1], ...searchForm.value, //筛选条件 }).then((res) => { loading.value = false; @@ -512,15 +554,15 @@ const getlist = () => { console.log(res.records); total.value = Number(res.total); tableData.value = res.records.map((item) => ({ - level: item.level,// 等级 - createTime:formatDate(new Date(item.createTime)),// 创建时间 - followerCount: item.followerCount,// 粉丝数 - followingCount: item.followingCount,// 关注数 - hostDisplayId: item.hostDisplayId,// 所在直播间主播id - hostcoins: item.hostcoins,// 打赏的金币 - region: item.region,// 地区 - totalGiftCoins: item.totalGiftCoins,// 打赏金币总和 - userIdStr: item.userIdStr,// 用户id + level: item.level, // 等级 + createTime: formatDate(new Date(item.createTime)), // 创建时间 + followerCount: item.followerCount, // 粉丝数 + followingCount: item.followingCount, // 关注数 + hostDisplayId: item.hostDisplayId, // 所在直播间主播id + hostcoins: item.hostcoins, // 打赏的金币 + region: item.region, // 地区 + totalGiftCoins: item.totalGiftCoins, // 打赏金币总和 + userIdStr: item.userIdStr, // 用户id displayId: item.displayId, })); } @@ -530,9 +572,9 @@ function handelClick() { filterdialogVisible.value = false; } function reset() { - searchForm.value = {} - sortData.value = { sortName: "createTime", sort: "desc" } - createTimes.value = [] + searchForm.value = {}; + sortData.value = { sortName: "createTime", sort: "desc" }; + createTimes.value = []; } function handleClose(done) { console.log("关闭"); @@ -577,7 +619,7 @@ function filterTag(value, row) { function getCountry() { getCountryinfo({}) .then((res) => { - console.log('````````国家`````````',res); + console.log("````````国家`````````", res); res.forEach((item) => { if (item.countryGroupName) { options.value.push({ @@ -586,7 +628,7 @@ function getCountry() { }); } }); - console.log('````````国家2`````````', options.value); + console.log("````````国家2`````````", options.value); }) .catch((err) => { console.log("getCountry", err); @@ -650,7 +692,7 @@ function closePopover(hostId, paramCode) { function openHTML(id) { console.log(id); - + givePyAnchorId(id); // upholdinfo({