更换组合式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 {
chart: null
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
}) })
}, function initChart() {
beforeDestroy() { chart = echarts.init(proxy.$refs.chartRef, 'macarons')
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,
}, },
},
data() {
return {
chart: null,
}
},
watch: {
chartData: {
deep: true,
handler(val) {
this.setOptions(val)
},
},
},
mounted() {
this.$nextTick(() => {
this.initChart()
}) })
let chart = null
watch(
() => props.chartData,
(val) => {
setOptions(val)
}, },
beforeDestroy() { { deep: true },
if (!this.chart) { )
return
} function setOptions({ expectedData, actualData } = {}) {
this.chart.dispose() chart.setOption({
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

@ -13,7 +13,13 @@
</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>
@ -59,138 +67,120 @@
</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",
data() {
return {
// //
loading: true, const loading = ref(true)
// //
ids: [], const ids = ref([])
// //
multiple: true, const multiple = ref(true)
// //
showSearch: true, const showSearch = ref(true)
// //
total: 0, const total = ref(0)
// //
list: [], const list = ref([])
// //
statusOptions: [], const statusOptions = ref([])
// //
dateRange: [], const dateRange = ref([])
// //
queryParams: { const queryParams = reactive({
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();
this.getDicts("sys_common_status").then((response) => {
this.statusOptions = response.data;
});
},
methods: {
/** 查询登录日志列表 */ /** 查询登录日志列表 */
getList() { function getList() {
this.loading = true; loading.value = true
list(this.addDateRange(this.queryParams, this.dateRange)).then( queryList(proxy.addDateRange(queryParams, dateRange.value)).then((response) => {
(response) => { loading.value = false
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() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.infoId);
this.multiple = !selection.length;
},
/** 删除按钮操作 */
handleDelete(row) {
const infoIds = row.infoId || this.ids;
this.$confirm(
'是否确认删除访问编号为"' + infoIds + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
} }
) getList()
proxy.getDicts('sys_common_status').then((response) => {
statusOptions.value = response.data
})
/** 搜索按钮操作 */
function handleQuery() {
queryParams.pageNum = 1
getList()
}
/** 重置按钮操作 */
function resetQuery() {
dateRange.value = []
proxy.resetForm('queryForm')
handleQuery()
}
//
function handleSelectionChange(selection) {
ids.value = selection.map((item) => item.infoId)
multiple.value = !selection.length
}
/** 删除按钮操作 */
function handleDelete(row) {
const infoIds = row.infoId || ids.value
proxy
.$confirm('是否确认删除访问编号为"' + infoIds + '"的数据项?', '警告', {
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() {
return {
// //
loading: true, const loading = ref(true)
// //
ids: [], const ids = ref([])
// //
multiple: true, const multiple = ref(true)
// //
showSearch: true, const showSearch = ref(true)
// //
total: 0, const total = ref(0)
// //
list: [], const list = ref([])
// //
open: false, const open = ref(false)
// //
statusOptions: [], const statusOptions = ref([])
// 0 1 2 3 eg:{ dictLabel: '', dictValue: '0'} // 0 1 2 3 eg:{ dictLabel: '', dictValue: '0'}
businessTypeOptions: [], const businessTypeOptions = ref([])
// //
dateRange: [], const dateRange = ref([])
//
const state = reactive({
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() {
this.getList()
var dictParams = [ 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: {
/** 查询登录日志 */ /** 查询登录日志 */
getList() { function getList() {
this.loading = true loading.value = true
list(this.addDateRange(this.queryParams, this.dateRange)).then((response) => { listOperLog(proxy.addDateRange(queryParams.value, dateRange.value)).then((response) => {
this.loading = false loading.value = 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()
/** 重置操作表单 */
function reset() {
form.value = {
operId: undefined,
title: undefined,
businessType: undefined,
method: undefined,
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')
}
/** 详细按钮操作 */ /** 详细按钮操作 */
handleView(row) { function handleView(row) {
this.open = true reset()
this.form = row open.value = true
}, form.value = row
}
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { function handleDelete(row) {
const operIds = row.operId || this.ids const operIds = row.operId || ids.value
this.$confirm('是否确认删除日志编号为"' + operIds + '"的数据项?', '警告', { 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>