feat(iot):优化 ota 的代码风格(v5)
parent
b9a7eddb72
commit
09c19526bb
|
|
@ -1,12 +1,17 @@
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { DescriptionItemSchema } from '#/components/description';
|
import type { DescriptionItemSchema } from '#/components/description';
|
||||||
|
import type { IotProductApi } from '#/api/iot/product/product';
|
||||||
|
|
||||||
import { formatDateTime } from '@vben/utils';
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
import { getSimpleProductList } from '#/api/iot/product/product';
|
import { getSimpleProductList } from '#/api/iot/product/product';
|
||||||
import { getRangePickerDefaultProps } from '#/utils';
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
/** 关联数据 */
|
||||||
|
let productList: IotProductApi.Product[] = [];
|
||||||
|
getSimpleProductList().then((data) => (productList = data));
|
||||||
|
|
||||||
/** 固件详情的描述字段 */
|
/** 固件详情的描述字段 */
|
||||||
export function useDetailSchema(): DescriptionItemSchema[] {
|
export function useDetailSchema(): DescriptionItemSchema[] {
|
||||||
return [
|
return [
|
||||||
|
|
@ -124,9 +129,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns(
|
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
getProductName?: (productId: number) => string | undefined,
|
|
||||||
): VxeTableGridOptions['columns'] {
|
|
||||||
return [
|
return [
|
||||||
{ type: 'checkbox', width: 40 },
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
|
|
@ -149,13 +152,12 @@ export function useGridColumns(
|
||||||
title: '固件描述',
|
title: '固件描述',
|
||||||
minWidth: 200,
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
// TODO DONE @AI:后端 firmware 没返回 productName,formatter 调 getProductName resolver;resolver + productList 反应式状态由 index.vue 注入(对齐 infra/codegen 模式)
|
|
||||||
{
|
{
|
||||||
field: 'productId',
|
field: 'productId',
|
||||||
title: '所属产品',
|
title: '所属产品',
|
||||||
minWidth: 150,
|
minWidth: 150,
|
||||||
formatter: ({ cellValue }) =>
|
formatter: ({ cellValue }) =>
|
||||||
getProductName?.(cellValue) || (cellValue ? '加载中...' : '-'),
|
productList.find((p) => p.id === cellValue)?.name || '-',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'fileUrl',
|
field: 'fileUrl',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||||
|
|
||||||
import { Card } from 'ant-design-vue';
|
import { Card } from 'ant-design-vue';
|
||||||
|
|
@ -8,7 +8,6 @@ import { useDescription } from '#/components/description';
|
||||||
import { useDetailSchema } from '../../data';
|
import { useDetailSchema } from '../../data';
|
||||||
|
|
||||||
/** IoT OTA 固件基本信息 */
|
/** IoT OTA 固件基本信息 */
|
||||||
// TODO DONE @AI:不需要;script setup 默认用文件名生成 __name(这里是 info),devtools 能识别;跟之前 upgrade-statistics / list 处理一致
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
firmware: IoTOtaFirmwareApi.Firmware;
|
firmware: IoTOtaFirmwareApi.Firmware;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||||
import type { IotProductApi } from '#/api/iot/product/product';
|
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
|
@ -13,26 +11,13 @@ import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
|
import { deleteOtaFirmware, getOtaFirmwarePage } from '#/api/iot/ota/firmware';
|
||||||
import { getSimpleProductList } from '#/api/iot/product/product';
|
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import OtaFirmwareForm from './modules/form.vue';
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
import OtaFirmwareForm from './modules/form.vue';
|
||||||
|
|
||||||
const { push } = useRouter();
|
const { push } = useRouter();
|
||||||
|
|
||||||
const productList = ref<IotProductApi.Product[]>([]);
|
|
||||||
|
|
||||||
/** 根据产品编号查找名称 */
|
|
||||||
// TODO @AI:需要类似别的模块,拿到 data.ts 里么?
|
|
||||||
function getProductName(productId: number | undefined) {
|
|
||||||
if (!productId) {
|
|
||||||
return '-';
|
|
||||||
}
|
|
||||||
const product = productList.value.find((p) => p.id === productId);
|
|
||||||
return product ? product.name : '加载中...';
|
|
||||||
}
|
|
||||||
|
|
||||||
const [FormModal, formModalApi] = useVbenModal({
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
connectedComponent: OtaFirmwareForm,
|
connectedComponent: OtaFirmwareForm,
|
||||||
destroyOnClose: true,
|
destroyOnClose: true,
|
||||||
|
|
@ -80,7 +65,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(getProductName),
|
columns: useGridColumns(),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
|
|
@ -104,11 +89,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<IoTOtaFirmwareApi.Firmware>,
|
} as VxeTableGridOptions<IoTOtaFirmwareApi.Firmware>,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 初始化加载产品列表 */
|
|
||||||
onMounted(async () => {
|
|
||||||
productList.value = (await getSimpleProductList()) || [];
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
import type { IoTOtaFirmwareApi } from '#/api/iot/ota/firmware';
|
||||||
|
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
@ -17,9 +17,7 @@ import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits(['success']);
|
||||||
success: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const formData = ref<IoTOtaFirmwareApi.Firmware>();
|
const formData = ref<IoTOtaFirmwareApi.Firmware>();
|
||||||
|
|
||||||
|
|
@ -30,13 +28,15 @@ const getTitle = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
schema: useFormSchema(),
|
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
},
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
},
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
@ -19,6 +19,8 @@ const [Form, formApi] = useVbenForm({
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
},
|
},
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
labelWidth: 80,
|
||||||
},
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
||||||
|
|
||||||
import { Card } from 'ant-design-vue';
|
import { Card } from 'ant-design-vue';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
import type { IoTOtaTaskApi } from '#/api/iot/ota/task';
|
||||||
|
|
||||||
|
|
@ -121,6 +121,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
label: '新增',
|
label: '新增',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
icon: ACTION_ICON.ADD,
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['iot:ota-task:create'],
|
||||||
onClick: handleCreate,
|
onClick: handleCreate,
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
|
|
@ -134,6 +135,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
label: '详情',
|
label: '详情',
|
||||||
type: 'link',
|
type: 'link',
|
||||||
icon: ACTION_ICON.VIEW,
|
icon: ACTION_ICON.VIEW,
|
||||||
|
auth: ['iot:ota-task:query'],
|
||||||
onClick: handleDetail.bind(null, row),
|
onClick: handleDetail.bind(null, row),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -141,6 +143,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
type: 'link',
|
type: 'link',
|
||||||
danger: true,
|
danger: true,
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['iot:ota-task:cancel'],
|
||||||
ifShow: row.status === IoTOtaTaskStatusEnum.IN_PROGRESS.value,
|
ifShow: row.status === IoTOtaTaskStatusEnum.IN_PROGRESS.value,
|
||||||
popConfirm: {
|
popConfirm: {
|
||||||
title: '确认要取消该升级任务吗?',
|
title: '确认要取消该升级任务吗?',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script lang="ts" setup>
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { IoTOtaTaskRecordApi } from '#/api/iot/ota/task/record';
|
import type { IoTOtaTaskRecordApi } from '#/api/iot/ota/task/record';
|
||||||
|
|
||||||
|
|
@ -19,9 +19,7 @@ const props = defineProps<{
|
||||||
taskId: number | undefined;
|
taskId: number | undefined;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits(['cancelled']);
|
||||||
cancelled: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const activeTab = ref('');
|
const activeTab = ref('');
|
||||||
|
|
||||||
|
|
@ -119,6 +117,7 @@ defineExpose({ refresh: () => gridApi.query() });
|
||||||
type: 'link',
|
type: 'link',
|
||||||
danger: true,
|
danger: true,
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['iot:ota-task-record:cancel'],
|
||||||
ifShow: [
|
ifShow: [
|
||||||
IoTOtaTaskRecordStatusEnum.PENDING.value,
|
IoTOtaTaskRecordStatusEnum.PENDING.value,
|
||||||
IoTOtaTaskRecordStatusEnum.PUSHED.value,
|
IoTOtaTaskRecordStatusEnum.PUSHED.value,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue