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