diff --git a/src/views/monitor-ops/log/data.ts b/src/views/monitor-ops/log/data.ts index a490f783..14e6f2f6 100644 --- a/src/views/monitor-ops/log/data.ts +++ b/src/views/monitor-ops/log/data.ts @@ -2,130 +2,126 @@ import { h } from 'vue' import { Tag } from 'ant-design-vue' import dayjs from 'dayjs' import type { BasicColumn, FormSchema } from '@/components/Table' -import { getAllProducts } from '@/api/product' -import type { Product } from '@/api/product/types' -import { useSystemEnumStoreWithOut } from '@/store/modules/systemEnum' +import { useSystemEnumStore } from '@/store/modules/systemEnum' +import { useSharedProducts } from '@/views/subscription/list/data' -let productsCache: Pick[] = [] -async function getCachedProducts() { - if (productsCache.length) - return productsCache +export function useColumns(): BasicColumn[] { + const { products } = useSharedProducts() + const { getSystemEnumLabel } = useSystemEnumStore() - try { - return productsCache = await getAllProducts() - } - catch { - return [] - } -} - -const { getSystemEnumLabel, getSystemEnums } = useSystemEnumStoreWithOut() - -export const columns: BasicColumn[] = [ - { - title: '所属产品', - dataIndex: 'productId', - customRender({ value }) { - return productsCache.find(item => item.id === value)?.productName + return [ + { + title: '所属产品', + dataIndex: 'productId', + customRender({ value }) { + return products.value.find(item => item.id === value)?.productName + }, }, - }, - { - title: '设备序列号', - dataIndex: 'deviceSn', - }, - { - title: 'TraceID', - dataIndex: 'traceId', - }, - { - title: '消息内容', - dataIndex: 'messageId', - width: 120, - }, - { - title: '业务类型', - dataIndex: 'bizType', - width: 150, - customRender({ value }) { - return h(Tag, () => getSystemEnumLabel('eDeviceLogBizType', value)) + { + title: '设备序列号', + dataIndex: 'deviceSn', }, - }, - { - title: '操作', - dataIndex: 'operation', - }, - { - title: '时间', - dataIndex: 'createTime', - }, - { - title: '状态', - dataIndex: 'code', - width: 120, - customRender({ value }) { - return h('b', { - style: { - color: value === 200 ? '#16a34a' : '#dc2626', - }, - }, value) + { + title: 'TraceID', + dataIndex: 'traceId', }, - }, -] - -export const searchFormSchema: FormSchema[] = [ - { - field: 'productId', - label: '所属产品', - component: 'ApiSelect', - componentProps: { - api: getCachedProducts, - valueField: 'id', - labelField: 'productName', - showSearch: true, + { + title: '消息内容', + dataIndex: 'messageId', + width: 120, }, - colProps: { - span: 6, + { + title: '业务类型', + dataIndex: 'bizType', + width: 150, + customRender({ value }) { + return h(Tag, () => getSystemEnumLabel('eDeviceLogBizType', value)) + }, }, - }, - { - field: 'deviceSn', - label: '设备序列号', - component: 'Input', - colProps: { - span: 6, + { + title: '操作', + dataIndex: 'operation', }, - }, - { - field: 'traceId', - label: 'TraceId', - component: 'Input', - colProps: { - span: 6, + { + title: '时间', + dataIndex: 'createTime', }, - }, - { - field: 'bizType', - label: '业务类型', - component: 'Select', - componentProps: { - options: getSystemEnums('eDeviceLogBizType'), + { + title: '状态', + dataIndex: 'code', + width: 120, + customRender({ value }) { + return h('b', { + style: { + color: value === 200 ? '#16a34a' : '#dc2626', + }, + }, value) + }, }, - colProps: { - span: 6, + ] +} + +export function useSearchFormSchema(): FormSchema[] { + const { products } = useSharedProducts() + const { getSystemEnums } = useSystemEnumStore() + + return [ + { + field: 'productId', + label: '所属产品', + component: 'Select', + componentProps: { + options: products as any, + showSearch: true, + fieldNames: { + label: 'productName', + value: 'id', + }, + }, + colProps: { + span: 6, + }, + }, + { + field: 'deviceSn', + label: '设备序列号', + component: 'Input', + colProps: { + span: 6, + }, }, - }, - { - field: 'time', - label: '日志时间', - component: 'RangePicker', - componentProps: { - showTime: true, - disabledDate(current) { - return current && current > dayjs().endOf('day') + { + field: 'traceId', + label: 'TraceId', + component: 'Input', + colProps: { + span: 6, }, }, - colProps: { - span: 6, + { + field: 'bizType', + label: '业务类型', + component: 'Select', + componentProps: { + options: getSystemEnums('eDeviceLogBizType'), + }, + colProps: { + span: 6, + }, }, - }, -] + { + field: 'time', + label: '日志时间', + component: 'RangePicker', + componentProps: { + showTime: true, + disabledDate(current) { + return current && current > dayjs().endOf('day') + }, + }, + colProps: { + span: 6, + }, + }, + ] +} diff --git a/src/views/monitor-ops/log/index.vue b/src/views/monitor-ops/log/index.vue index 4577b513..c1ec13cc 100644 --- a/src/views/monitor-ops/log/index.vue +++ b/src/views/monitor-ops/log/index.vue @@ -1,5 +1,5 @@