From d48d504b302b737e84cd3824cfbf599988bb199e Mon Sep 17 00:00:00 2001
From: xiongqian <2167232911@qq.com>
Date: Tue, 31 Jan 2023 17:25:51 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E4=BA=A7=E5=93=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/device/product.ts | 2 +-
src/views/device/Product/Save/index.vue | 258 +++++++++++++++---------
src/views/device/Product/index.vue | 25 ++-
3 files changed, 188 insertions(+), 97 deletions(-)
diff --git a/src/api/device/product.ts b/src/api/device/product.ts
index 6ae11030..9d29476b 100644
--- a/src/api/device/product.ts
+++ b/src/api/device/product.ts
@@ -108,7 +108,7 @@ export const deleteProduct = (id: string) => server.patch(`/device-product/${id}
* 检测产品Id唯一性
* @param id 产品ID
*/
- export const queryProductId = (id: string) => server.post(`/device-product/${id}/exists`)
+ export const queryProductId = (id: string) => server.get(`/device-product/${id}/exists`)
/**
* 保存产品
* @param data 产品信息
diff --git a/src/views/device/Product/Save/index.vue b/src/views/device/Product/Save/index.vue
index 5958a65c..d7605411 100644
--- a/src/views/device/Product/Save/index.vue
+++ b/src/views/device/Product/Save/index.vue
@@ -11,12 +11,21 @@
cancelText="取消"
v-bind="layout"
width="650px"
+ :confirmLoading="loading"
>
-
+
-
+
+
+
+
@@ -89,15 +98,16 @@
-
@@ -111,79 +121,69 @@
-
- {{ val }}
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
- {{
- item.value === 'device'
- ? '直连设备'
- : item.value ===
- 'childrenDevice'
- ? '网关子设备'
- : item.value === 'gateway'
- ? '网关设备'
- : ''
- }}
+
-
-
-
-
+
+
+
+
+
+
![]()
+
+
+
+
+ {{ item.label }}
+
+
+
+
+
+
+
+
+
+
+
+
(false);
const treeList = ref[]>([]);
-const visible = ref(false);
-const logoLoading = ref(false);
+const visible = ref(false);
+const logoLoading = ref(false);
+const formRef = ref();
+const disabled = ref(false);
const useForm = Form.useForm;
const _selectedRowKeys = ref([]);
const photoValue = ref('/images/device-product.png');
@@ -236,14 +245,17 @@ const deviceList = ref([
{
label: '直连设备',
value: 'device',
+ logo: getImage('/device-type-1.png'),
},
{
label: '网关子设备',
value: 'childrenDevice',
+ logo: getImage('/device-type-2.png'),
},
{
label: '网关设备',
value: 'gateway',
+ logo: getImage('/device/device-type-3.png'),
},
]);
@@ -254,7 +266,7 @@ const form = reactive({
classifiedName: '',
deviceType: '',
describe: '',
- photoUrl: '',
+ photoUrl: getImage('/device/instance/device-card.png'),
});
/**
* 校验id
@@ -265,12 +277,13 @@ const validateInput = async (_rule: Rule, value: string) => {
return Promise.reject('请输入英文或者数字或者-或者_');
} else {
const res = await queryProductId(value);
- if (res.status === 200) {
- if (res.result) {
- return Promise.reject('该ID已存在');
- }
+ if (res.status === 200 && res.result) {
+ return Promise.reject('ID重复');
+ } else {
+ return Promise.resolve();
}
}
+ } else {
return Promise.resolve();
}
};
@@ -278,25 +291,27 @@ const validateInput = async (_rule: Rule, value: string) => {
* 校验是否选择设备类型
*/
const validateDeviceType = async (_rule: Rule, value: string) => {
- if (photoValue.value.length === 0) {
- return Promise.resolve('请选择设备类型');
+ if (!value) {
+ return Promise.reject('请选择设备类型');
+ } else {
+ return Promise.resolve();
}
};
const rules = reactive({
- id: [
- { message: '请输入名称', validator: validateInput, trigger: 'change' },
- ],
+ id: [{ validator: validateInput, trigger: 'blur' }],
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
deviceType: [
{
required: true,
- message: '请选择设备类型',
- trigger: 'blur',
validator: validateDeviceType,
+ trigger: 'blur',
},
],
});
+const valueChange = (value: string, label: string) => {
+ form.classifiedName = label[0];
+};
/**
* 查询产品分类
*/
@@ -312,14 +327,33 @@ const queryProductTree = async () => {
watch(
() => props.isAdd,
() => {
- queryProductTree();
+ // queryProductTree();
},
{ immediate: true, deep: true },
);
/**
* 显示弹窗
*/
-const show = () => {
+const show = (data: any) => {
+ console.log(props.isAdd, '11111');
+ if (props.isAdd === 2) {
+ // form.name = data.name;
+ // form.classifiedId = data.classifiedId;
+ // form.classifiedName = data.classifiedName;
+ // form.photoUrl = data.photoUrl || photoValue.value;
+ // form.deviceType = data.deviceType.value;
+ // form.describe = form.describe;
+ // form.id = data.id;
+ // disabled.value = true;
+ } else {
+ // form.name = '';
+ // form.classifiedId = '';
+ // form.classifiedName = '';
+ // form.photoUrl = photoValue.value;
+ // form.deviceType = '';
+ // form.describe = '';
+ // form.id = '';
+ }
visible.value = true;
};
@@ -329,11 +363,18 @@ const show = () => {
const close = () => {
visible.value = false;
};
+const { resetFields, validate, validateInfos, clearValidate } = useForm(
+ form,
+ rules,
+);
/**
- * 卡片点击事件
+ * 提交表单数据
*/
-const handleClick = (dt: any) => {
- _selectedRowKeys.value = dt;
+const submitData = () => {
+ formRef.value
+ .validate()
+ .then(async () => {})
+ .catch((err: any) => {});
};
/**
* 文件上传之前
@@ -367,7 +408,7 @@ const handleChange = (info: any) => {
/**
* 初始化
*/
-queryProductTree();
+// queryProductTree();
defineExpose({
show: show,
});
@@ -375,7 +416,7 @@ defineExpose({
diff --git a/src/views/device/Product/index.vue b/src/views/device/Product/index.vue
index c5d6d505..e71205cd 100644
--- a/src/views/device/Product/index.vue
+++ b/src/views/device/Product/index.vue
@@ -107,7 +107,7 @@
-
+
@@ -140,6 +140,8 @@ import Save from './Save/index.vue';
/**
* 表格数据
*/
+const isAdd = ref(0);
+const title = ref('');
const statusMap = new Map();
statusMap.set(1, 'success');
statusMap.set(0, 'error');
@@ -187,6 +189,7 @@ const columns = [
];
const _selectedRowKeys = ref([]);
+const currentForm = ref({});
const onSelectChange = (keys: string[]) => {
_selectedRowKeys.value = [...keys];
@@ -205,11 +208,14 @@ const handleClick = (dt: any) => {
}
};
-const getActions = (data: Partial>): ActionsType[] => {
+const getActions = (
+ data: Partial>,
+ type: 'card' | 'table',
+): ActionsType[] => {
if (!data) {
return [];
}
- return [
+ const actions = [
{
key: 'view',
text: '查看',
@@ -217,6 +223,7 @@ const getActions = (data: Partial>): ActionsType[] => {
title: '查看',
},
icon: 'EyeOutlined',
+ onClick: () => {},
},
{
key: 'edit',
@@ -226,6 +233,13 @@ const getActions = (data: Partial>): ActionsType[] => {
},
icon: 'EditOutlined',
+ onClick: () => {
+ title.value = '编辑';
+ isAdd.value = 2;
+ nextTick(() => {
+ saveRef.value.show(data);
+ });
+ },
},
{
key: 'download',
@@ -283,10 +297,13 @@ const getActions = (data: Partial>): ActionsType[] => {
icon: 'DeleteOutlined',
},
];
+ return actions;
};
const add = () => {
- saveRef.value.show();
+ isAdd.value = 1;
+ title.value = '新增';
+ saveRef.value.show(currentForm.value);
};
// 筛选