proxymysql/resource/view/index.tmpl

375 lines
12 KiB
Cheetah
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
{{/* <script src="/resource/js/default-passive-events-index.umd.js"></script>*/}}
<link rel="stylesheet" href="/resource/css/element-index.css"/>
<!-- Import component library -->
<script src="/resource/js/vue.global.js"></script>
<script src="/resource/js/element-index.full.js"></script>
<script src="/resource/js/element-zh-cn.js"></script>
<link rel="stylesheet" href="/resource/css/vxe-style.css">
<script src="/resource/js/xe-utils.js"></script>
<script src="/resource/js/vxe-table.js"></script>
<style>
#app {
width: 90%;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="app">
<div class="header">
<el-form :inline="true" :model="form" class="demo-form-inline">
<el-form-item label="时间范围" style="width: 350px">
<el-date-picker
v-model="form.date"
type="daterange"
start-placeholder="Start date"
end-placeholder="End date"
format="YYYY-MM-DD"
date-format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
:clearable="false"
/>
</el-form-item>
<el-form-item label="管理员">
<el-select v-model="form.admin_name" placeholder="选择" clearable>
<el-option v-for="item in selectInfo.adminNameList" :label="item.AdminName"
:value="item.AdminName"/>
</el-select>
</el-form-item>
<el-form-item label="sql信息" style="width: 500px">
<el-input v-model="form.query_info" placeholder="sql信息" clearable/>
</el-form-item>
</el-form>
<div>
<el-button type="primary" @click="listSqlQueryLog">查询</el-button>
</div>
</div>
<div>
<div style="margin-top: 15px; height: 750px">
<vxe-table
height="100%"
stripe
:data="tableData"
:column-config="{resizable: true}"
>
<vxe-column width="80" field="Id" title="ID" show-overflow></vxe-column>
<vxe-column width="200" field="QueryTime" title="调用时间" show-overflow></vxe-column>
<vxe-column width="130" field="Ip" title="IP" show-overflow></vxe-column>
<vxe-column width="100" field="AdminName" title="账号" show-overflow></vxe-column>
<vxe-column width="100" field="AdminRealName" title="姓名" show-overflow></vxe-column>
<vxe-column width="100" field="Project" title="项目" show-overflow></vxe-column>
<vxe-column width="200" field="RequestPath" title="接口地址" show-overflow></vxe-column>
<vxe-column width="200" field="MenuName" title="接口名称" show-overflow></vxe-column>
<vxe-column field="CallInfo" title="调用路径" show-overflow></vxe-column>
<vxe-column width="200" field="Query" title="SQL" show-overflow>
<template #default="{ row }">
<span style="cursor: pointer" @click="copText(row.Query)">${ row.Query }$</span>
</template>
</vxe-column>
<vxe-column width="100" field="" title="操作">
<template #default="{ row }">
<el-button size="small" type="success" @click="showQuerySql(row)">查看</el-button>
</template>
</vxe-column>
</vxe-table>
</div>
<div style="margin-top: 15px; width: 100%; display: flex; justify-content: center">
<el-pagination
background
:total="pageInfo.totalCount"
v-model:current-page="pageInfo.currentPage"
v-model:page-size="pageInfo.pageSize"
layout="prev, slot, next, sizes"
@size-change="listSqlQueryLog(true)"
@current-change="listSqlQueryLog(false)"
:page-sizes="[200, 600, 1000]"
>
<template #default>
<ul class="el-pager">
<li class="is-active number">${ pageInfo.currentPage }$</li>
</ul>
</template>
</el-pagination>
</div>
</div>
<el-dialog
v-model="dialogVisible"
title="Title"
width="30%"
>
<div>
<el-input
v-model="dialogRow.Query"
rows="20"
type="textarea"
placeholder="Please input"
/>
</div>
<template #footer>
<el-button type="primary" @click="dialogRow = {}; dialogVisible = false">确定</el-button>
</template>
</el-dialog>
</div>
<script>
function getDate(diff) {
let date = new Date(); // 当前日期和时间
date.setDate(date.getDate() + diff)
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始需要加1并确保是两位数
const day = date.getDate().toString().padStart(2, '0'); // 确保是两位数的日期
return `${year}-${month}-${day}`;
}
const {createApp, ref, reactive, toRefs, toRef} = Vue
console.log(getDate(5))
const vm = createApp({
delimiters: ['${', '}$'],
setup() {
const data = reactive({
mailMessage: "",
form: {
game_id: "",
query_info: "",
date: [getDate(-15), getDate(0)],
admin_name: "",
},
tableData: [],
pageInfo: {
currentPage: 1,
pageSize: 200,
},
dialogVisible: false,
dialogRow: {},
selectInfo: {
adminNameList: []
}
})
setTimeout(() => {
listSqlQueryLog()
selectInfo()
})
const resetPageInfo = () => {
data.pageInfo.currentPage = 1
}
const selectInfo = () => {
let loading = ElementPlus.ElLoading.service({
fullscreen: true,
lock: true
})
fetch("/SelectInfo", {
method: 'POST', // 或 'POST'、'PUT' 等
})
.then(response => {
// 检查请求是否成功(状态码为 200 到 299
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// 将响应解析为 JSON
return response.json();
})
.then(res => {
// 处理返回的 JSON 数据
if (res.Code != 0) {
console.log(res);
ElementPlus.ElMessage.error(res.Message)
return
}
data.selectInfo.adminNameList = res.Data.AdminNameList
})
.catch(error => {
// 处理错误
console.error('Fetch error:', error);
alert(error)
}).finally(
() => {
loading.close()
})
}
const copText = (text) => {
var textToCopy = text;
var textArea = document.createElement("textarea");
textArea.value = textToCopy;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
console.log('Text copied to clipboard');
ElementPlus.ElMessage.success("复制成功")
} catch (err) {
console.error('Unable to copy text', err);
}
document.body.removeChild(textArea);
// navigator.clipboard.writeText(text)
// .then(function () {
// ElementPlus.ElMessage.success("复制成功")
// })
// .catch(function (err) {
// console.error('复制失败', err);
// ElementPlus.ElMessage.error("复制失败")
// });
}
const showQuerySql = (row) => {
console.log(row)
data.dialogRow = JSON.parse(JSON.stringify(row))
data.dialogVisible = true
}
const listSqlQueryLog = (reset) => {
if (reset === true) {
resetPageInfo()
}
let loading = ElementPlus.ElLoading.service({
fullscreen: true,
lock: true
})
// console.log(data.form)
// return
let req = {
start_date: "",
end_date: "",
// game_id: (/^\d+$/).test(data.form.game_id) ? Number(data.form.game_id) : -1,
query_info: data.form.query_info,
page: data.pageInfo.currentPage,
limit: data.pageInfo.pageSize,
admin_name: data.form.admin_name,
}
if (data.form.date) {
req.start_date = data.form.date[0]
req.end_date = data.form.date[1]
}
const requestOptions = {
method: 'POST', // 或 'POST'、'PUT' 等
headers: {
'Content-Type': 'application/json', // 指定请求类型为 JSON
// 可以添加其他请求头,比如认证信息等
},
// 如果是 POST 或 PUT 请求,可以在 body 中添加请求数据
body: JSON.stringify(req)
};
// 使用 fetch 发起请求
fetch("/ListSqlQueryLog", requestOptions)
.then(response => {
// 检查请求是否成功(状态码为 200 到 299
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// 将响应解析为 JSON
return response.json();
})
.then(res => {
// 处理返回的 JSON 数据
if (res.Code != 0) {
console.log(res);
alert(res.Message)
return
}
data.tableData = res.Data.List
data.pageInfo.totalCount = res.Data.TotalCount
})
.catch(error => {
// 处理错误
console.error('Fetch error:', error);
alert(error)
}).finally(
() => {
loading.close()
}
);
}
return {
...toRefs(data),
listSqlQueryLog, showQuerySql, copText
}
}
})
vm.use(ElementPlus, {locale: ElementPlusLocaleZhCn})
vm.use(VXETable)
vm.mount("#app")
</script>
</body>
</html>