fix(device): 在线状态改为非阻塞补齐,恢复表单文本自动去空格
列表先渲染,批量在线状态返回后再更新;新增/编辑提交前 trim 文本字段,SN 与昵称拒绝纯空白。
This commit is contained in:
1 parent
e85456f0a5
commit
daca252cb9
3 files changed
+33
-19
No files matched your search
@@ -2,6 +2,24 @@ import DeviceAPI from "@/api/device";
|
|||||||
import type { DeviceForm } from "@/api/device/types";
|
import type { DeviceForm } from "@/api/device/types";
|
||||||
import type { CrudFormConfig } from "@/components/Crud/types";
|
import type { CrudFormConfig } from "@/components/Crud/types";
|
||||||
|
|
||||||
|
/** 表单不再自动 trim,提交前去掉文本字段首尾空格 */
|
||||||
|
function trimText(data: DeviceForm): DeviceForm {
|
||||||
|
const payload = { ...data };
|
||||||
|
for (const key of [
|
||||||
|
"serialno",
|
||||||
|
"snModel",
|
||||||
|
"snName",
|
||||||
|
"snMobile",
|
||||||
|
"snImei",
|
||||||
|
"deviceType",
|
||||||
|
"source",
|
||||||
|
] as const) {
|
||||||
|
const value = payload[key];
|
||||||
|
if (typeof value === "string") payload[key] = value.trim();
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
const addFormConfig: CrudFormConfig<DeviceForm> = {
|
const addFormConfig: CrudFormConfig<DeviceForm> = {
|
||||||
component: "dialog",
|
component: "dialog",
|
||||||
dialog: {
|
dialog: {
|
||||||
@@ -12,12 +30,12 @@ const addFormConfig: CrudFormConfig<DeviceForm> = {
|
|||||||
form: {
|
form: {
|
||||||
labelWidth: 100,
|
labelWidth: 100,
|
||||||
},
|
},
|
||||||
submitForm: (data) => DeviceAPI.create(data),
|
submitForm: (data) => DeviceAPI.create(trimText(data)),
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
label: "设备SN",
|
label: "设备SN",
|
||||||
prop: "serialno",
|
prop: "serialno",
|
||||||
rules: [{ required: true, message: "设备SN不能为空", trigger: "blur" }],
|
rules: [{ required: true, whitespace: true, message: "设备SN不能为空", trigger: "blur" }],
|
||||||
type: "input",
|
type: "input",
|
||||||
attrs: {
|
attrs: {
|
||||||
placeholder: "请输入设备序列号",
|
placeholder: "请输入设备序列号",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import DeviceAPI from "@/api/device";
|
import DeviceAPI from "@/api/device";
|
||||||
import type { DeviceItem, DeviceQueryParams } from "@/api/device/types";
|
import type { DeviceItem, DeviceQueryParams } from "@/api/device/types";
|
||||||
import type { CrudTableConfig } from "@/components/Crud/types";
|
import type { CrudTableConfig } from "@/components/Crud/types";
|
||||||
import { onlineStatus, syncOnlineStatus } from "./online";
|
import { syncOnlineStatus, updateOnlineStatus } from "./online";
|
||||||
|
|
||||||
/** 列表接口不保证带在线状态,加载后批量补齐 */
|
/** 列表接口不保证带在线状态,加载后批量补齐 */
|
||||||
async function fetchDevices(params: DeviceQueryParams) {
|
async function fetchDevices(params: DeviceQueryParams) {
|
||||||
@@ -9,12 +9,9 @@ async function fetchDevices(params: DeviceQueryParams) {
|
|||||||
syncOnlineStatus(page.list);
|
syncOnlineStatus(page.list);
|
||||||
const sns = page.list.map((item) => item.serialno).filter((sn): sn is string => !!sn);
|
const sns = page.list.map((item) => item.serialno).filter((sn): sn is string => !!sn);
|
||||||
if (sns.length) {
|
if (sns.length) {
|
||||||
await DeviceAPI.getOnlineStatusBatch(sns)
|
// 在线状态后补,不阻塞列表首屏
|
||||||
.then((onlineMap) => {
|
void DeviceAPI.getOnlineStatusBatch(sns)
|
||||||
Object.values(onlineMap ?? {}).forEach((info) => {
|
.then((onlineMap) => Object.values(onlineMap ?? {}).forEach(updateOnlineStatus))
|
||||||
if (info?.serialno) onlineStatus[info.serialno] = info.online ?? 0;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@@ -15,15 +15,14 @@ const editFormConfig: CrudFormConfig<DeviceForm> = {
|
|||||||
labelWidth: 100,
|
labelWidth: 100,
|
||||||
},
|
},
|
||||||
// 编辑只回传可修改字段(仅设备昵称与状态)
|
// 编辑只回传可修改字段(仅设备昵称与状态)
|
||||||
submitForm: (data) =>
|
submitForm: (data) => {
|
||||||
DeviceAPI.update(
|
const payload = {
|
||||||
data.id as string,
|
id: data.id,
|
||||||
{
|
snName: data.snName?.trim(),
|
||||||
id: data.id,
|
status: data.status,
|
||||||
snName: data.snName,
|
} as DeviceForm;
|
||||||
status: data.status,
|
return DeviceAPI.update(payload.id as string, payload);
|
||||||
} as DeviceForm,
|
},
|
||||||
),
|
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
label: "设备SN",
|
label: "设备SN",
|
||||||
@@ -38,7 +37,7 @@ const editFormConfig: CrudFormConfig<DeviceForm> = {
|
|||||||
{
|
{
|
||||||
label: "设备昵称",
|
label: "设备昵称",
|
||||||
prop: "snName",
|
prop: "snName",
|
||||||
rules: [{ required: true, message: "设备昵称不能为空", trigger: "blur" }],
|
rules: [{ required: true, whitespace: true, message: "设备昵称不能为空", trigger: "blur" }],
|
||||||
type: "input",
|
type: "input",
|
||||||
attrs: {
|
attrs: {
|
||||||
placeholder: "请输入设备昵称",
|
placeholder: "请输入设备昵称",
|
||||||
|
|||||||
Reference in new issue
Block a user