feat: 接口对接

feat-im-0607-xwk
向文可 3 years ago
parent 56a45fb9bf
commit ffe1bb7690

@ -15,7 +15,7 @@ const actions = {
loadOnline: async ({ commit }, data) => { loadOnline: async ({ commit }, data) => {
let res = await api.online(data); let res = await api.online(data);
commit('setOnline', res || 0); commit('setOnline', res || 0);
if (!res) { if (!res && res !== 0) {
ElMessage.error('查询失败'); ElMessage.error('查询失败');
} }
return res; return res;

@ -2,7 +2,12 @@
<div class="home-container"> <div class="home-container">
<el-form> <el-form>
<el-form-item label="所属系统"> <el-form-item label="所属系统">
<el-select v-model="systemId" :config="{ label: 'name', value: 'id' }" :opts="opts.system" /> <el-select
v-model="systemId"
:clearable="false"
:config="{ label: 'name', value: 'id' }"
:opts="opts.system"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-card header="在线人数">{{ online }}</el-card> <el-card header="在线人数">{{ online }}</el-card>
@ -33,6 +38,8 @@
</template> </template>
<script setup> <script setup>
import dayjs from 'dayjs';
import * as echarts from 'echarts';
const store = useStore(); const store = useStore();
const loading = ref(false); const loading = ref(false);
const opts = computed(() => store.state.chatStore.opts); const opts = computed(() => store.state.chatStore.opts);
@ -60,9 +67,64 @@
}; };
watch(systemId, handleLoadOnline); watch(systemId, handleLoadOnline);
const date1 = ref(null); const handleChart = (selector, name, data) => {
const chart = echarts.init(document.querySelector(selector));
const option = {
gradientColor: ['#1DE7FF', '#249AFF', '#6F41FA', '#6F41FA'],
visualMap: [
{
show: false,
type: 'continuous',
dimension: 0,
min: 0,
max: data.length - 1,
},
],
tooltip: {
trigger: 'axis',
},
grid: {
left: '0',
right: '0',
top: '5%',
bottom: '0',
containLabel: true,
},
xAxis: [
{
data: data.map((item) => item.label),
},
],
yAxis: [{}],
series: [
{
type: 'line',
name,
showSymbol: false,
smooth: true,
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(29, 231, 255, 0.3)',
},
{
offset: 1,
color: 'rgba(29, 231, 255, 0)',
},
]),
},
data: data.map((item) => item.value),
},
],
};
chart.setOption(option);
};
const date1 = ref(dayjs(new Date()).format('YYYY-MM-DD'));
const handleLoadSingle = async () => { const handleLoadSingle = async () => {
loading.value = true; loading.value = true;
store.commit('chatHome/setSingle', []);
if (unref(systemId)) { if (unref(systemId)) {
if (unref(date1)) { if (unref(date1)) {
await store.dispatch('chatHome/loadSingle', { await store.dispatch('chatHome/loadSingle', {
@ -70,17 +132,37 @@
start: new Date(unref(date1) + ' 00:00:00').getTime(), start: new Date(unref(date1) + ' 00:00:00').getTime(),
end: new Date(unref(date1) + ' 23:59:59').getTime(), end: new Date(unref(date1) + ' 23:59:59').getTime(),
}); });
} else {
store.commit('setSingle', []);
} }
} }
loading.value = false; loading.value = false;
}; };
watch(date1, handleLoadSingle); watch(date1, handleLoadSingle, { immediate: true });
watch(systemId, handleLoadSingle);
watch(
() => store.state.chatHome.single,
(value) => {
handleChart(
'.chart-1',
'消息量',
value.map((item) => {
return {
label: item.hours,
value: item.messageCount,
};
})
);
}
);
const date2 = ref([]); const date2 = ref([
new Date(
dayjs(new Date(Date.now() - ((new Date().getDay() || 7) - 1) * 86400000)).format('YYYY-MM-DD') + ' 00:00:00'
).getTime(),
new Date(dayjs(new Date()).format('YYYY-MM-DD') + ' 23:59:59').getTime(),
]);
const handleLoadRange = async () => { const handleLoadRange = async () => {
loading.value = true; loading.value = true;
store.commit('chatHome/setRange', []);
if (unref(systemId)) { if (unref(systemId)) {
if (unref(date2)?.length) { if (unref(date2)?.length) {
await store.dispatch('chatHome/loadRange', { await store.dispatch('chatHome/loadRange', {
@ -88,13 +170,29 @@
start: unref(date2)[0], start: unref(date2)[0],
end: unref(date2)[1], end: unref(date2)[1],
}); });
} else {
store.commit('setSingle', []);
} }
} }
loading.value = false; loading.value = false;
}; };
watch(date2, handleLoadRange); watch(date2, handleLoadRange, {
immediate: true,
});
watch(systemId, handleLoadRange);
watch(
() => store.state.chatHome.range,
(value) => {
handleChart(
'.chart-2',
'消息量',
value.map((item) => {
return {
label: item.days,
value: item.messageCount,
};
})
);
}
);
onActivated(() => { onActivated(() => {
handleLoadOnline(); handleLoadOnline();
@ -116,10 +214,14 @@
& + .el-card { & + .el-card {
margin-top: 30px; margin-top: 30px;
} }
&:nth-of-type(1) {
:deep(.el-card__body) {
font-size: 32px;
}
}
.chart { .chart {
width: 100%; width: 100%;
height: 300px; height: 300px;
background: #eee;
} }
} }
} }

Loading…
Cancel
Save