更换组合式API写法

This commit is contained in:
不做码农 2022-06-13 12:31:18 +08:00
parent 4035eaee47
commit 6b505312d9
6 changed files with 525 additions and 561 deletions

View File

@ -1,101 +1,90 @@
<template> <template>
<div :class="className" :style="{height:height,width:width}" /> <div ref="chartRef" :class="className" :style="{ height: height, width: width }" />
</template> </template>
<script> <script setup>
import * as echarts from 'echarts'; import * as echarts from 'echarts'
// import resize from './mixins/resize' let chart = null
const { proxy } = getCurrentInstance()
const animationDuration = 6000 const animationDuration = 6000
const props = defineProps({
export default {
// mixins: [resize],
props: {
className: { className: {
type: String, type: String,
default: 'chart' default: 'chart',
}, },
width: { width: {
type: String, type: String,
default: '100%' default: '100%',
}, },
height: { height: {
type: String, type: String,
default: '300px' default: '300px',
}
}, },
data() { })
return { function initChart() {
chart: null chart = echarts.init(proxy.$refs.chartRef, 'macarons')
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el)
this.chart.setOption({ chart.setOption({
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { // axisPointer: {
type: 'shadow' // 线'line' | 'shadow' //
} type: 'shadow', // 线'line' | 'shadow'
},
}, },
grid: { grid: {
top: 10, top: 10,
left: '2%', left: '2%',
right: '2%', right: '2%',
bottom: '3%', bottom: '3%',
containLabel: true containLabel: true,
}, },
xAxis: [{ xAxis: [
{
type: 'category', type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: { axisTick: {
alignWithLabel: true alignWithLabel: true,
} },
}], },
yAxis: [{ ],
yAxis: [
{
type: 'value', type: 'value',
axisTick: { axisTick: {
show: false show: false,
} },
}], },
series: [{ ],
series: [
{
name: 'pageA', name: 'pageA',
type: 'bar', type: 'bar',
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [79, 52, 200, 334, 390, 330, 220], data: [79, 52, 200, 334, 390, 330, 220],
animationDuration animationDuration,
}, { },
{
name: 'pageB', name: 'pageB',
type: 'bar', type: 'bar',
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [80, 52, 200, 334, 390, 330, 220], data: [80, 52, 200, 334, 390, 330, 220],
animationDuration animationDuration,
}, { },
{
name: 'pageC', name: 'pageC',
type: 'bar', type: 'bar',
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [30, 52, 200, 334, 390, 330, 220], data: [30, 52, 200, 334, 390, 330, 220],
animationDuration animationDuration,
}] },
],
}) })
}
}
} }
onMounted(() => {
initChart()
})
</script> </script>

View File

@ -1,14 +1,12 @@
<template> <template>
<div :class="className" :style="{ height: height, width: width }" /> <div ref="chartRef" :class="className" :style="{ height: height, width: width }" />
</template> </template>
<script> <script setup>
import * as echarts from 'echarts' import * as echarts from 'echarts'
// import resize from './mixins/resize' const { proxy } = getCurrentInstance()
const chartRef = ref(null)
export default { const props = defineProps({
// mixins: [resize],
props: {
className: { className: {
type: String, type: String,
default: 'chart', default: 'chart',
@ -29,39 +27,18 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
})
let chart = null
watch(
() => props.chartData,
(val) => {
setOptions(val)
}, },
data() { { deep: true },
return { )
chart: null,
} function setOptions({ expectedData, actualData } = {}) {
}, chart.setOption({
watch: {
chartData: {
deep: true,
handler(val) {
this.setOptions(val)
},
},
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el)
this.setOptions(this.chartData)
},
setOptions({ expectedData, actualData } = {}) {
this.chart.setOption({
xAxis: { xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
boundaryGap: false, boundaryGap: false,
@ -127,7 +104,15 @@ export default {
}, },
], ],
}) })
}, }
}, function initChart() {
chart = echarts.init(proxy.$refs.chartRef, 'macarons')
setOptions(props.chartData)
}
onMounted(() => {
initChart()
})
window.onresize = function () {
chart.resize()
} }
</script> </script>

View File

@ -1,57 +1,38 @@
<template> <template>
<div :class="className" :style="{height:height,width:width}" /> <div ref="chartRef" :class="className" :style="{ height: height, width: width }" />
</template> </template>
<script> <script setup>
import * as echarts from 'echarts'; import * as echarts from 'echarts'
// import resize from './mixins/resize' const { proxy } = getCurrentInstance()
let chart = null
export default { const props = defineProps({
// mixins: [resize],
props: {
className: { className: {
type: String, type: String,
default: 'chart' default: 'chart',
}, },
width: { width: {
type: String, type: String,
default: '100%' default: '100%',
}, },
height: { height: {
type: String, type: String,
default: '300px' default: '300px',
}
}, },
data() { })
return {
chart: null
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el)
this.chart.setOption({ function initChart() {
chart = echarts.init(proxy.$refs.chartRef)
chart.setOption({
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)' formatter: '{a} <br/>{b} : {c} ({d}%)',
}, },
legend: { legend: {
left: 'center', left: 'center',
bottom: '10', bottom: '10',
data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts'] data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts'],
}, },
series: [ series: [
{ {
@ -65,14 +46,15 @@ export default {
{ value: 240, name: 'Technology' }, { value: 240, name: 'Technology' },
{ value: 149, name: 'Forex' }, { value: 149, name: 'Forex' },
{ value: 100, name: 'Gold' }, { value: 100, name: 'Gold' },
{ value: 59, name: 'Forecasts' } { value: 59, name: 'Forecasts' },
], ],
animationEasing: 'cubicInOut', animationEasing: 'cubicInOut',
animationDuration: 2600 animationDuration: 2600,
} },
] ],
}) })
}
}
} }
onMounted(() => {
initChart()
})
</script> </script>

View File

@ -4,7 +4,6 @@
<script> <script>
import * as echarts from 'echarts' import * as echarts from 'echarts'
// import resize from './mixins/resize'
const animationDuration = 3000 const animationDuration = 3000

View File

@ -8,12 +8,18 @@
<el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" /> <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="登录状态" clearable > <el-select v-model="queryParams.status" placeholder="登录状态" clearable>
<el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" /> <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="登录时间"> <el-form-item label="登录时间">
<el-date-picker v-model="dateRange" style="width: 240px" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker> <el-date-picker
v-model="dateRange"
style="width: 240px"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button> <el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
@ -23,7 +29,9 @@
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="danger" plain icon="delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['monitor:logininfor:remove']">删除</el-button> <el-button type="danger" plain icon="delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['monitor:logininfor:remove']"
>删除</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="danger" plain icon="delete" @click="handleClean" v-hasPermi="['monitor:logininfor:remove']">清空</el-button> <el-button type="danger" plain icon="delete" @click="handleClean" v-hasPermi="['monitor:logininfor:remove']">清空</el-button>
@ -43,7 +51,7 @@
<el-table-column label="浏览器" align="center" prop="browser" /> <el-table-column label="浏览器" align="center" prop="browser" />
<el-table-column label="操作系统" align="center" prop="os" /> <el-table-column label="操作系统" align="center" prop="os" />
<el-table-column label="操作状态" align="center" prop="status"> <el-table-column label="操作状态" align="center" prop="status">
<template #default="{row}"> <template #default="{ row }">
<dict-tag :options="statusOptions" :value="row.status"></dict-tag> <dict-tag :options="statusOptions" :value="row.status"></dict-tag>
</template> </template>
</el-table-column> </el-table-column>
@ -55,142 +63,124 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" /> <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</div> </div>
</template> </template>
<script> <script setup name="logininfor">
import { import { list as queryList, delLogininfor, cleanLogininfor, exportLogininfor } from '@/api/monitor/logininfor'
list,
delLogininfor,
cleanLogininfor,
exportLogininfor,
} from "@/api/monitor/logininfor";
export default { //
name: "logininfor", const loading = ref(true)
data() { //
return { const ids = ref([])
// //
loading: true, const multiple = ref(true)
// //
ids: [], const showSearch = ref(true)
// //
multiple: true, const total = ref(0)
// //
showSearch: true, const list = ref([])
// //
total: 0, const statusOptions = ref([])
// //
list: [], const dateRange = ref([])
// //
statusOptions: [], const queryParams = reactive({
//
dateRange: [],
//
queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
ipaddr: undefined, ipaddr: undefined,
userName: undefined, userName: undefined,
status: undefined, status: undefined,
}, })
};
}, const { proxy } = getCurrentInstance()
created() { /** 查询登录日志列表 */
this.getList(); function getList() {
this.getDicts("sys_common_status").then((response) => { loading.value = true
this.statusOptions = response.data; queryList(proxy.addDateRange(queryParams, dateRange.value)).then((response) => {
}); loading.value = false
},
methods: {
/** 查询登录日志列表 */
getList() {
this.loading = true;
list(this.addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.loading = false;
if (response.code == 200) { if (response.code == 200) {
this.list = response.data.result; list.value = response.data.result
this.total = response.data.totalNum; total.value = response.data.totalNum
} else { } else {
this.total = 0; total.value = 0
this.list = []; list.value = []
} }
} })
); }
}, //
// function statusFormat(row, column) {
statusFormat(row, column) { return proxy.selectDictLabel(statusOptions.value, row.status)
return this.selectDictLabel(this.statusOptions, row.status); }
}, getList()
/** 搜索按钮操作 */ proxy.getDicts('sys_common_status').then((response) => {
handleQuery() { statusOptions.value = response.data
this.queryParams.pageNum = 1; })
this.getList();
}, /** 搜索按钮操作 */
/** 重置按钮操作 */ function handleQuery() {
resetQuery() { queryParams.pageNum = 1
this.dateRange = []; getList()
this.resetForm("queryForm"); }
this.handleQuery(); /** 重置按钮操作 */
}, function resetQuery() {
// dateRange.value = []
handleSelectionChange(selection) { proxy.resetForm('queryForm')
this.ids = selection.map((item) => item.infoId); handleQuery()
this.multiple = !selection.length; }
}, //
/** 删除按钮操作 */ function handleSelectionChange(selection) {
handleDelete(row) { ids.value = selection.map((item) => item.infoId)
const infoIds = row.infoId || this.ids; multiple.value = !selection.length
this.$confirm( }
'是否确认删除访问编号为"' + infoIds + '"的数据项?', /** 删除按钮操作 */
"警告", function handleDelete(row) {
{ const infoIds = row.infoId || ids.value
confirmButtonText: "确定", proxy
cancelButtonText: "取消", .$confirm('是否确认删除访问编号为"' + infoIds + '"的数据项?', '警告', {
type: "warning", confirmButtonText: '确定',
} cancelButtonText: '取消',
) type: 'warning',
})
.then(function () { .then(function () {
return delLogininfor(infoIds); return delLogininfor(infoIds)
}) })
.then(() => { .then(() => {
this.getList(); getList()
this.$modal.msgSuccess("删除成功"); proxy.$modal.msgSuccess('删除成功')
}); })
}, }
/** 清空按钮操作 */ /** 清空按钮操作 */
handleClean() { function handleClean() {
this.$confirm("是否确认清空所有登录日志数据项?", "警告", { proxy
confirmButtonText: "确定", .$confirm('是否确认清空所有登录日志数据项?', '警告', {
cancelButtonText: "取消", confirmButtonText: '确定',
type: "warning", cancelButtonText: '取消',
type: 'warning',
}) })
.then(function () { .then(function () {
return cleanLogininfor(); return cleanLogininfor()
}) })
.then(() => { .then(() => {
this.getList(); getList()
this.$modal.msgSuccess("清空成功"); proxy.$modal.msgSuccess('清空成功')
}); })
}, }
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { function handleExport() {
const queryParams = this.queryParams; proxy
this.$confirm("是否确认导出所有操作日志数据项?", "警告", { .$confirm('是否确认导出所有操作日志数据项?', '警告', {
confirmButtonText: "确定", confirmButtonText: '确定',
cancelButtonText: "取消", cancelButtonText: '取消',
type: "warning", type: 'warning',
}) })
.then(function () { .then(function () {
return exportLogininfor(queryParams); return exportLogininfor(queryParams)
}) })
.then((response) => { .then((response) => {
this.download(response.data.path); proxy.download(response.data.path)
}); })
}, }
},
};
</script> </script>

View File

@ -90,7 +90,7 @@
<!-- 操作日志详细 --> <!-- 操作日志详细 -->
<el-dialog title="操作日志详细" v-model="open" width="700px" append-to-body> <el-dialog title="操作日志详细" v-model="open" width="700px" append-to-body>
<el-form ref="form" :model="form" label-width="100px"> <el-form ref="formRef" :model="form" label-width="100px">
<el-row> <el-row>
<el-col :lg="12"> <el-col :lg="12">
<el-form-item label="操作模块:">{{ form.title }} </el-form-item> <el-form-item label="操作模块:">{{ form.title }} </el-form-item>
@ -136,36 +136,33 @@
</div> </div>
</template> </template>
<script> <script setup name="operlog">
import { list, delOperlog, cleanOperlog, exportOperlog } from '@/api/monitor/operlog' import { list as listOperLog, delOperlog, cleanOperlog, exportOperlog } from '@/api/monitor/operlog'
export default { const { proxy } = getCurrentInstance()
name: 'operlog', //
data() { const loading = ref(true)
return { //
// const ids = ref([])
loading: true, //
// const multiple = ref(true)
ids: [], //
// const showSearch = ref(true)
multiple: true, //
// const total = ref(0)
showSearch: true, //
// const list = ref([])
total: 0, //
// const open = ref(false)
list: [], //
// const statusOptions = ref([])
open: false, // 0 1 2 3 eg:{ dictLabel: '', dictValue: '0'}
// const businessTypeOptions = ref([])
statusOptions: [], //
// 0 1 2 3 eg:{ dictLabel: '', dictValue: '0'} const dateRange = ref([])
businessTypeOptions: [],
// const state = reactive({
dateRange: [],
//
form: {}, form: {},
//
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 20, pageSize: 20,
@ -174,64 +171,85 @@ export default {
businessType: undefined, businessType: undefined,
status: undefined, status: undefined,
}, },
} })
}, const { form, queryParams } = toRefs(state)
created() { var dictParams = [
this.getList()
var dictParams = [
{ dictType: 'sys_oper_type', columnName: 'businessTypeOptions' }, { dictType: 'sys_oper_type', columnName: 'businessTypeOptions' },
{ dictType: 'sys_common_status', columnName: 'statusOptions' }, { dictType: 'sys_common_status', columnName: 'statusOptions' },
] ]
this.getDicts(dictParams).then((response) => { proxy.getDicts(dictParams).then((response) => {
response.data.forEach((element) => { response.data.forEach((element) => {
this[element.columnName] = element.list proxy[element.columnName] = element.list
}) })
}) })
}, /** 查询登录日志 */
methods: { function getList() {
/** 查询登录日志 */ loading.value = true
getList() { listOperLog(proxy.addDateRange(queryParams.value, dateRange.value)).then((response) => {
this.loading = true loading.value = false
list(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
this.loading = false
if (response.code == 200) { if (response.code == 200) {
this.list = response.data.result list.value = response.data.result
this.total = response.data.totalNum total.value = response.data.totalNum
} else { } else {
this.total = 0 total.value = 0
this.list = [] list.value = []
} }
}) })
}, }
// //
statusFormat(row, column) { function statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status) return proxy.selectDictLabel(statusOptions.value, row.status)
}, }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { function handleQuery() {
this.queryParams.pageNum = 1 queryParams.value.pageNum = 1
this.getList() getList()
}, }
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { function resetQuery() {
this.dateRange = [] dateRange.value = []
this.resetForm('queryForm') proxy.resetForm('queryForm')
this.handleQuery() handleQuery()
}, }
// //
handleSelectionChange(selection) { function handleSelectionChange(selection) {
this.ids = selection.map((item) => item.operId) ids.value = selection.map((item) => item.operId)
this.multiple = !selection.length multiple.value = !selection.length
}, }
/** 详细按钮操作 */ const formRef = ref()
handleView(row) { /** 重置操作表单 */
this.open = true function reset() {
this.form = row form.value = {
}, operId: undefined,
/** 删除按钮操作 */ title: undefined,
handleDelete(row) { businessType: undefined,
const operIds = row.operId || this.ids method: undefined,
this.$confirm('是否确认删除日志编号为"' + operIds + '"的数据项?', '警告', { requestMethod: undefined,
operatorType: undefined,
deptName: undefined,
operUrl: undefined,
operIp: undefined,
operLocation: undefined,
operParam: undefined,
jsonResult: undefined,
status: 0,
errorMsg: undefined,
operTime: undefined,
elapsed: 0,
}
proxy.resetForm('formRef')
}
/** 详细按钮操作 */
function handleView(row) {
reset()
open.value = true
form.value = row
}
/** 删除按钮操作 */
function handleDelete(row) {
const operIds = row.operId || ids.value
proxy
.$confirm('是否确认删除日志编号为"' + operIds + '"的数据项?', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning',
@ -240,13 +258,14 @@ export default {
return delOperlog(operIds) return delOperlog(operIds)
}) })
.then(() => { .then(() => {
this.getList() getList()
this.$modal.msgSuccess('删除成功') proxy.$modal.msgSuccess('删除成功')
}) })
}, }
/** 清空按钮操作 */ /** 清空按钮操作 */
handleClean() { function handleClean() {
this.$confirm('是否确认清空所有操作日志数据项?', '警告', { proxy
.$confirm('是否确认清空所有操作日志数据项?', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning',
@ -255,29 +274,29 @@ export default {
return cleanOperlog() return cleanOperlog()
}) })
.then(() => { .then(() => {
this.getList() getList()
this.$modal.msgSuccess('清空成功') proxy.$modal.msgSuccess('清空成功')
}) })
}, }
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { function handleExport() {
const queryParams = this.queryParams proxy
this.$confirm('是否确认导出所有操作日志?', '警告', { .$confirm('是否确认导出所有操作日志?', '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning',
}).then(() => { })
exportOperlog(queryParams).then((response) => { .then(() => {
exportOperlog(queryParams.value).then((response) => {
const { code, data } = response const { code, data } = response
if (code == 200) { if (code == 200) {
this.$modal.msgSuccess('导出成功') proxy.$modal.msgSuccess('导出成功')
this.download(data.path) proxy.download(data.path)
} else { } else {
this.$modal.msgError('导出失败') proxy.$modal.msgError('导出失败')
} }
}) })
}) })
},
},
} }
handleQuery()
</script> </script>