数据管理 接口完成
This commit is contained in:
@@ -5,9 +5,8 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import DictManager from "../DictManager";
|
import DictManager from "../DictManager";
|
||||||
import request from '../../api/request'; import { Country, State } from 'country-state-city';
|
import request from '../../api/request';
|
||||||
|
import { Country, State } from 'country-state-city';
|
||||||
|
|
||||||
|
|
||||||
// 接口导入
|
// 接口导入
|
||||||
import {
|
import {
|
||||||
@@ -15,18 +14,10 @@ import {
|
|||||||
addRobotTypeApi,
|
addRobotTypeApi,
|
||||||
updateRobotTypeApi,
|
updateRobotTypeApi,
|
||||||
deleteRobotTypeApi,
|
deleteRobotTypeApi,
|
||||||
getRobotProvinceListApi,
|
|
||||||
addRobotProvinceApi,
|
|
||||||
updateRobotProvinceApi,
|
|
||||||
deleteRobotProvinceApi,
|
|
||||||
getRobotModelPageApi,
|
getRobotModelPageApi,
|
||||||
addRobotModelApi,
|
addRobotModelApi,
|
||||||
updateRobotModelApi,
|
updateRobotModelApi,
|
||||||
deleteRobotModelApi,
|
deleteRobotModelApi,
|
||||||
getRobotCountryListApi,
|
|
||||||
addRobotCountryApi,
|
|
||||||
updateRobotCountryApi,
|
|
||||||
deleteRobotCountryApi,
|
|
||||||
getRobotConfigListApi,
|
getRobotConfigListApi,
|
||||||
addRobotConfigApi,
|
addRobotConfigApi,
|
||||||
updateRobotConfigApi,
|
updateRobotConfigApi,
|
||||||
@@ -34,89 +25,77 @@ import {
|
|||||||
} from '../../api/systemSetting';
|
} from '../../api/systemSetting';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
const { Option } = Select;
|
||||||
|
|
||||||
const SerialNumGenerate = () => {
|
const SerialNumGenerate = () => {
|
||||||
// 获取国家
|
// 表单实例
|
||||||
const countries1 = Country.getAllCountries();
|
|
||||||
// 根据国家获取省份
|
|
||||||
const states = State.getStatesOfCountry('CN');
|
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
// 国家/省份 数据(本地库获取)
|
||||||
|
const [allCountries, setAllCountries] = useState([]);
|
||||||
|
const [provinces, setProvinces] = useState([]);
|
||||||
|
|
||||||
|
// 二维码相关
|
||||||
const [qrUrl, setQrUrl] = useState('');
|
const [qrUrl, setQrUrl] = useState('');
|
||||||
const [serialNumber, setSerialNumber] = useState('');
|
const [serialNumber, setSerialNumber] = useState('');
|
||||||
const [qrJson, setQrJson] = useState('');
|
const [qrJson, setQrJson] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const qrRef = useRef(null);
|
const qrRef = useRef(null);
|
||||||
|
|
||||||
|
// 查询功能
|
||||||
const [queryCode, setQueryCode] = useState('');
|
const [queryCode, setQueryCode] = useState('');
|
||||||
const [queryLoading, setQueryLoading] = useState(false);
|
const [queryLoading, setQueryLoading] = useState(false);
|
||||||
|
|
||||||
|
// 数据管理弹窗
|
||||||
const [manageVisible, setManageVisible] = useState(false);
|
const [manageVisible, setManageVisible] = useState(false);
|
||||||
|
|
||||||
// 接口数据
|
// 接口数据(类型、型号、配置)
|
||||||
const [types, setTypes] = useState([]);
|
const [types, setTypes] = useState([]);
|
||||||
const [models, setModels] = useState([]);
|
const [models, setModels] = useState([]);
|
||||||
const [provinces, setProvinces] = useState([]);
|
|
||||||
const [countries, setCountries] = useState([]);
|
|
||||||
const [configs, setConfigs] = useState([]);
|
const [configs, setConfigs] = useState([]);
|
||||||
|
|
||||||
// 初始化加载
|
// 初始化:加载国家列表
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const countries = Country.getAllCountries();
|
||||||
|
setAllCountries(countries || []);
|
||||||
|
|
||||||
|
// 加载其他数据
|
||||||
loadTypeList();
|
loadTypeList();
|
||||||
loadModelList();
|
loadModelList();
|
||||||
loadProvinceList();
|
|
||||||
loadCountryList();
|
|
||||||
loadConfigList();
|
loadConfigList();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 国家改变 → 刷新省份
|
||||||
|
const handleCountryChange = (countryCode) => {
|
||||||
|
const states = State.getStatesOfCountry(countryCode);
|
||||||
|
setProvinces(states || []);
|
||||||
|
|
||||||
|
// 切换国家时自动清空省份
|
||||||
|
form.setFieldsValue({ province: undefined });
|
||||||
|
};
|
||||||
|
// ==================== 接口加载 ====================
|
||||||
// 加载机器人类型
|
// 加载机器人类型
|
||||||
const loadTypeList = async () => {
|
const loadTypeList = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getRobotTypeListApi({});
|
const res = await getRobotTypeListApi({});
|
||||||
if (res?.code == 200) {
|
if (res?.code === 200) setTypes(res.data || []);
|
||||||
setTypes(res.data || []);
|
} catch (e) { }
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载机器人型号
|
// 加载机器人型号
|
||||||
const loadModelList = async () => {
|
const loadModelList = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 });
|
const res = await getRobotModelPageApi({ pageNum: 1, pageSize: 100 });
|
||||||
if (res?.code == 200) {
|
if (res?.code === 200) setModels(res.data || []);
|
||||||
setModels(res?.data || []);
|
} catch (e) { }
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 加载省份
|
|
||||||
const loadProvinceList = async () => {
|
|
||||||
try {
|
|
||||||
const res = await getRobotProvinceListApi({});
|
|
||||||
setProvinces(res.rows || []);
|
|
||||||
} catch (e) {
|
|
||||||
message.error('加载省份失败');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 加载国家
|
|
||||||
const loadCountryList = async () => {
|
|
||||||
try {
|
|
||||||
const res = await getRobotCountryListApi({});
|
|
||||||
setCountries(res.rows || []);
|
|
||||||
} catch (e) {
|
|
||||||
message.error('加载国家失败');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 加载配置
|
// 加载配置
|
||||||
const loadConfigList = async () => {
|
const loadConfigList = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getRobotConfigListApi({});
|
const res = await getRobotConfigListApi({});
|
||||||
setConfigs(res.rows || []);
|
if (res?.code === 200) setConfigs(res.data || []);
|
||||||
} catch (e) {
|
} catch (e) { }
|
||||||
message.error('加载配置失败');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 生成序号
|
// 生成序号
|
||||||
@@ -148,7 +127,7 @@ const SerialNumGenerate = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 下载
|
// 下载二维码
|
||||||
const downloadQRCode = () => {
|
const downloadQRCode = () => {
|
||||||
if (!qrRef.current || !qrUrl) {
|
if (!qrRef.current || !qrUrl) {
|
||||||
message.warning('请先生成二维码');
|
message.warning('请先生成二维码');
|
||||||
@@ -160,7 +139,7 @@ const SerialNumGenerate = () => {
|
|||||||
link.click();
|
link.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 保存序列号
|
// 保存到数据库
|
||||||
const saveToDatabase = async () => {
|
const saveToDatabase = async () => {
|
||||||
if (!serialNumber) return message.warning('请先生成');
|
if (!serialNumber) return message.warning('请先生成');
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -187,7 +166,7 @@ const SerialNumGenerate = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 查询
|
// 查询序列号
|
||||||
const handleQueryQRCode = async () => {
|
const handleQueryQRCode = async () => {
|
||||||
if (!queryCode) return message.warning('请输入序列号');
|
if (!queryCode) return message.warning('请输入序列号');
|
||||||
setQueryLoading(true);
|
setQueryLoading(true);
|
||||||
@@ -195,7 +174,7 @@ const SerialNumGenerate = () => {
|
|||||||
const res = await request({
|
const res = await request({
|
||||||
url: '/iot/device/querySerial',
|
url: '/iot/device/querySerial',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: { sn: queryCode }
|
params: sn.queryCode
|
||||||
});
|
});
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
setSerialNumber(res.data.serialNumber);
|
setSerialNumber(res.data.serialNumber);
|
||||||
@@ -219,7 +198,8 @@ const SerialNumGenerate = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==================== 类型 ====================
|
// ==================== 数据处理方法 ====================
|
||||||
|
// 类型
|
||||||
const handleAddType = async (values) => {
|
const handleAddType = async (values) => {
|
||||||
return await addRobotTypeApi({
|
return await addRobotTypeApi({
|
||||||
storeValue: values.storeValue,
|
storeValue: values.storeValue,
|
||||||
@@ -236,65 +216,39 @@ const SerialNumGenerate = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==================== 型号 ====================
|
// 型号
|
||||||
const handleAddModel = async (values) => {
|
const handleAddModel = async (values) => {
|
||||||
return await addRobotModelApi({
|
return await addRobotModelApi({
|
||||||
modelName: values.modelName,
|
modelName: values.displayName,
|
||||||
storeValue: values.storeValue,
|
storeValue: values.storeValue,
|
||||||
displayName: ''
|
displayName: values.displayName
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const handleUpdateModel = async (values) => {
|
const handleUpdateModel = async (values) => {
|
||||||
return await updateRobotModelApi({
|
return await updateRobotModelApi({
|
||||||
id: values.id,
|
id: values.id,
|
||||||
modelName: values.modelName,
|
modelName: values.displayName,
|
||||||
displayName: values.displayName
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// ==================== 省份 ====================
|
|
||||||
const handleAddProvince = async (values) => {
|
|
||||||
return await addRobotProvinceApi({
|
|
||||||
storeValue: values.storeValue,
|
storeValue: values.storeValue,
|
||||||
displayName: values.displayName,
|
displayName: values.displayName
|
||||||
remark: values.remark || ''
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const handleUpdateProvince = async (values) => {
|
|
||||||
return await updateRobotProvinceApi({
|
|
||||||
id: values.id,
|
|
||||||
storeValue: values.storeValue,
|
|
||||||
displayName: values.displayName,
|
|
||||||
remark: values.remark || ''
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==================== 国家 ====================
|
// 配置
|
||||||
const handleAddCountry = async (values) => {
|
|
||||||
return await addRobotCountryApi({
|
|
||||||
countryName: values.countryName,
|
|
||||||
displayName: values.displayName
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const handleUpdateCountry = async (values) => {
|
|
||||||
return await updateRobotCountryApi({
|
|
||||||
id: values.id,
|
|
||||||
countryName: values.countryName,
|
|
||||||
displayName: values.displayName
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// ==================== 配置 ====================
|
|
||||||
const handleAddConfig = async (values) => {
|
const handleAddConfig = async (values) => {
|
||||||
return await addRobotConfigApi({
|
return await addRobotConfigApi({
|
||||||
configName: values.configName,
|
configName: values.displayName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
displayName: values.displayName
|
displayName: values.displayName
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const handleUpdateConfig = async (values) => {
|
const handleUpdateConfig = async (values) => {
|
||||||
return await updateRobotConfigApi({
|
return await updateRobotConfigApi({
|
||||||
id: values.id,
|
id: values.id,
|
||||||
configName: values.configName,
|
configName: values.displayName,
|
||||||
|
storeValue: values.storeValue,
|
||||||
displayName: values.displayName
|
displayName: values.displayName
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -308,43 +262,74 @@ const SerialNumGenerate = () => {
|
|||||||
>
|
>
|
||||||
<Row gutter={[32, 24]}>
|
<Row gutter={[32, 24]}>
|
||||||
<Col xs={24} md={14}>
|
<Col xs={24} md={14}>
|
||||||
<Form form={form} initialValues={{ type: 'mower' }} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
|
<Form form={form} labelCol={{ md: 5 }} wrapperCol={{ md: 19 }} size="large">
|
||||||
|
{/* 型号 */}
|
||||||
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
|
<Form.Item name="model" label="型号" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择型号">
|
<Select placeholder="选择型号" showSearch optionFilterProp="children" filterOption={(input, option) =>
|
||||||
|
option.children.toLowerCase().includes(input.toLowerCase())
|
||||||
|
}>
|
||||||
{models.map(m => (
|
{models.map(m => (
|
||||||
<Select.Option key={m.id} value={m.displayName}>{m.modelName}</Select.Option>
|
<Option key={m.id} value={m.displayName}>{m.modelName}</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
{/* 配置 */}
|
||||||
<Form.Item name="config" label="配置" rules={[{ required: true }]}>
|
<Form.Item name="config" label="配置" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择配置">
|
<Select placeholder="选择配置" showSearch optionFilterProp="children">
|
||||||
{configs.map(c => (
|
{configs.map(c => (
|
||||||
<Select.Option key={c.id} value={c.displayName}>{c.configName}</Select.Option>
|
<Option key={c.id} value={c.displayName}>{c.configName}</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
{/* 类型 */}
|
||||||
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
|
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择类型">
|
<Select placeholder="选择类型" showSearch optionFilterProp="children">
|
||||||
{types.map(t => (
|
{types.map(t => (
|
||||||
<Select.Option key={t.id} value={t.displayName}>{t.storeValue}</Select.Option>
|
<Option key={t.id} value={t.displayName}>{t.storeValue}</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
{/* 国家(级联) */}
|
||||||
|
{/* 国家(级联 + 可清空) */}
|
||||||
<Form.Item name="country" label="国家" rules={[{ required: true }]}>
|
<Form.Item name="country" label="国家" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择国家">
|
<Select
|
||||||
{countries.map(c => (
|
placeholder="选择国家"
|
||||||
<Select.Option key={c.id} value={c.displayName}>{c.countryName}</Select.Option>
|
showSearch
|
||||||
|
allowClear
|
||||||
|
optionFilterProp="children"
|
||||||
|
onChange={handleCountryChange}
|
||||||
|
filterOption={(input, option) =>
|
||||||
|
option.children.toLowerCase().includes(input.toLowerCase())
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{allCountries.map((c) => (
|
||||||
|
<Select.Option key={c.isoCode} value={c.isoCode}>
|
||||||
|
{c.name}
|
||||||
|
</Select.Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
{/* 省份(级联 + 可清空 + 中国显示中文) */}
|
||||||
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
|
<Form.Item name="province" label="省份" rules={[{ required: true }]}>
|
||||||
<Select placeholder="选择省份">
|
<Select
|
||||||
{provinces.map(p => (
|
placeholder="请先选择国家"
|
||||||
<Select.Option key={p.id} value={p.displayName}>{p.storeValue}</Select.Option>
|
showSearch
|
||||||
|
allowClear
|
||||||
|
disabled={provinces.length === 0}
|
||||||
|
optionFilterProp="children"
|
||||||
|
filterOption={(input, option) =>
|
||||||
|
option.children.toLowerCase().includes(input.toLowerCase())
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{provinces.map((p) => (
|
||||||
|
<Select.Option key={p.isoCode} value={p.name}>
|
||||||
|
{p.isoCode === 'CN' ? p.name : p.name}
|
||||||
|
{/* 中国省份默认就是中文,这里直接显示 name 即可 */}
|
||||||
|
</Select.Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -425,7 +410,7 @@ const SerialNumGenerate = () => {
|
|||||||
title="机器人型号"
|
title="机器人型号"
|
||||||
data={models}
|
data={models}
|
||||||
fields={[
|
fields={[
|
||||||
{ name: 'modelName', label: '型号名称', required: true },
|
{ name: 'displayName', label: '型号名称', required: true },
|
||||||
{ name: 'storeValue', label: '存储值', required: true },
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
]}
|
]}
|
||||||
onAdd={handleAddModel}
|
onAdd={handleAddModel}
|
||||||
@@ -434,42 +419,13 @@ const SerialNumGenerate = () => {
|
|||||||
refresh={loadModelList}
|
refresh={loadModelList}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 国家 */}
|
|
||||||
<DictManager
|
|
||||||
title="国家"
|
|
||||||
data={countries}
|
|
||||||
fields={[
|
|
||||||
{ name: 'countryName', label: '国家名称', required: true },
|
|
||||||
{ name: 'displayName', label: '存储值', required: true },
|
|
||||||
]}
|
|
||||||
onAdd={handleAddCountry}
|
|
||||||
onUpdate={handleUpdateCountry}
|
|
||||||
onDelete={deleteRobotCountryApi}
|
|
||||||
refresh={loadCountryList}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* 省份 */}
|
|
||||||
<DictManager
|
|
||||||
title="省份"
|
|
||||||
data={provinces}
|
|
||||||
fields={[
|
|
||||||
{ name: 'storeValue', label: '省份名称', required: true },
|
|
||||||
{ name: 'displayName', label: '存储值', required: true },
|
|
||||||
{ name: 'remark', label: '备注', required: false }
|
|
||||||
]}
|
|
||||||
onAdd={handleAddProvince}
|
|
||||||
onUpdate={handleUpdateProvince}
|
|
||||||
onDelete={deleteRobotProvinceApi}
|
|
||||||
refresh={loadProvinceList}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* 配置 */}
|
{/* 配置 */}
|
||||||
<DictManager
|
<DictManager
|
||||||
title="配置"
|
title="配置"
|
||||||
data={configs}
|
data={configs}
|
||||||
fields={[
|
fields={[
|
||||||
{ name: 'configName', label: '配置名称', required: true },
|
{ name: 'displayName', label: '配置名称', required: true },
|
||||||
{ name: 'displayName', label: '存储值', required: true },
|
{ name: 'storeValue', label: '存储值', required: true },
|
||||||
]}
|
]}
|
||||||
onAdd={handleAddConfig}
|
onAdd={handleAddConfig}
|
||||||
onUpdate={handleUpdateConfig}
|
onUpdate={handleUpdateConfig}
|
||||||
|
|||||||
Reference in New Issue
Block a user