Commit 010a1519 authored by 陈浩玮's avatar 陈浩玮

Merge branch 'feature/chw' into 'master'

设备管理

See merge request product/kim3-web-vue/starter-web-vue!34
parents 46a55538 42c2ae7c
import { request, METHOD, formatObj } from '@/utils'; import { request, METHOD, formatObj } from '@/utils';
import Lang from '@/utils/langUtils';
export * from './menu'; export * from './menu';
export * from './system'; export * from './system';
export * from './task'; export * from './task';
...@@ -19,3 +20,16 @@ export const getStaticParam = async staticKey => { ...@@ -19,3 +20,16 @@ export const getStaticParam = async staticKey => {
}); });
return newData; return newData;
}; };
export const getStaticDataApi = async data => {
const res = await request('/api/v1/parameters/business/list', METHOD.GET, {
...data,
paramLocale: Lang.get(),
});
const newData = await formatObj(res || [], {
value: 'paramValue',
label: 'paramName',
key: 'paramId',
});
return newData;
};
...@@ -23,7 +23,21 @@ function movementAttributesApi(data) { ...@@ -23,7 +23,21 @@ function movementAttributesApi(data) {
} }
function getEquipmentsTreeApi(data) { function getEquipmentsTreeApi(data) {
return getReq(`/oceanus/api/v1/equipments/catalogs/${data.catalogId}`, data); return getReq(`/oceanus/api/v1/equipments/catalogs/${data.catalogId}`);
}
function addEquipmentsTreeApi(data) {
return postReq(`/oceanus/api/v1/equipments/catalogs`, data);
}
function updateEquipmentsTreeApi(data) {
return putReq(`/oceanus/api/v1/equipments/catalogs`, data);
}
function delEquipmentsTreeApi(data) {
return delReq(`/oceanus/api/v1/equipments/catalogs`, {}, { data });
}
function getEquipmentsInfoApi(data) {
return getReq(`/oceanus/api/v1/equipments/${data.catalogValue}`);
} }
export default { export default {
...@@ -35,4 +49,8 @@ export default { ...@@ -35,4 +49,8 @@ export default {
updateAttributes: updateAttributesApi, updateAttributes: updateAttributesApi,
movementAttributes: movementAttributesApi, movementAttributes: movementAttributesApi,
getEquipmentsTree: getEquipmentsTreeApi, getEquipmentsTree: getEquipmentsTreeApi,
addEquipmentsTree: addEquipmentsTreeApi,
updateEquipmentsTree: updateEquipmentsTreeApi,
delEquipmentsTree: delEquipmentsTreeApi,
getEquipmentsInfo: getEquipmentsInfoApi,
}; };
...@@ -19,9 +19,14 @@ ...@@ -19,9 +19,14 @@
</a-col> </a-col>
<a-col :span="24" class="tw-text-right"> <a-col :span="24" class="tw-text-right">
<a-button-group> <a-button-group>
<a-dropdown> <a-dropdown :disabled="selectedKeys.length === 0">
<a-menu slot="overlay"> <a-menu slot="overlay">
<a-menu-item key="1" @click="addOrg">新增组织 </a-menu-item> <a-menu-item
key="1"
@click="addOrg"
:disabled="selectedObj.catalogType === 'EQUIPMENT'"
>新增组织
</a-menu-item>
<a-menu-item key="2" @click="addEqu">新增设备 </a-menu-item> <a-menu-item key="2" @click="addEqu">新增设备 </a-menu-item>
</a-menu> </a-menu>
<a-button type="primary" ghost>新增 <a-icon type="down" /></a-button> <a-button type="primary" ghost>新增 <a-icon type="down" /></a-button>
...@@ -30,10 +35,18 @@ ...@@ -30,10 +35,18 @@
type="primary" type="primary"
ghost ghost
@click="edit" @click="edit"
:disabled="selectedObj.catalogType !== 'ORGANIZATION'" :disabled="
selectedKeys.length === 0 || selectedObj.catalogType === 'ORGANIZATION'
"
>编辑</a-button >编辑</a-button
> >
<a-button type="primary" ghost @click="del">删除</a-button> <a-button
type="primary"
ghost
@click="del"
:disabled="selectedKeys.length === 0 || selectedObj.catalogType === 'ROOTNODE'"
>删除</a-button
>
</a-button-group> </a-button-group>
</a-col> </a-col>
</a-row> </a-row>
...@@ -42,6 +55,7 @@ ...@@ -42,6 +55,7 @@
<a-row :gutter="[16, 16]"> <a-row :gutter="[16, 16]">
<a-col :span="24"> <a-col :span="24">
<a-tree <a-tree
ref="Tree"
:treeData="treeData" :treeData="treeData"
:replaceFields="replaceFields" :replaceFields="replaceFields"
:selectedKeys="selectedKeys" :selectedKeys="selectedKeys"
...@@ -50,21 +64,23 @@ ...@@ -50,21 +64,23 @@
/> />
</a-col> </a-col>
</a-row> </a-row>
<TreeDrawer ref="TreeDrawer" :refresh="init" /> <TreeDrawer ref="TreeDrawer" :refresh="treeDrawerRefresh" />
<TreeModal ref="TreeModal" :parentNodeId="selectedKeys[0]" :afterSubmit="afterSubmit" />
</my-card> </my-card>
</div> </div>
</template> </template>
<script> <script>
import moment from 'moment';
import Api from '@/api/oceanus'; import Api from '@/api/oceanus';
import { formatObj } from '@/utils'; import { formatObj, isObjEmpty } from '@/utils';
import TreeDrawer from './TreeDrawer.vue'; import TreeDrawer from './TreeDrawer.vue';
import TreeModal from './TreeModal.vue';
export default { export default {
components: { TreeDrawer }, components: { TreeDrawer, TreeModal },
data() { data() {
return { return {
catalogId: -1,
searchValue: undefined, searchValue: undefined,
dataSource: [], dataSource: [],
replaceFields: { title: 'catalogName', key: 'catalogId', children: 'children' }, replaceFields: { title: 'catalogName', key: 'catalogId', children: 'children' },
...@@ -72,6 +88,7 @@ export default { ...@@ -72,6 +88,7 @@ export default {
selectedKeys: [], selectedKeys: [],
selectedObj: {}, selectedObj: {},
allData: [], allData: [],
treeNode: undefined,
}; };
}, },
model: { model: {
...@@ -79,35 +96,32 @@ export default { ...@@ -79,35 +96,32 @@ export default {
event: 'change', event: 'change',
}, },
mounted() { mounted() {
this.init(this.catalogId); this.init();
}, },
methods: { methods: {
async init(id) { async init() {
const data = await Api.getEquipmentsTree({ catalogId: id }); this.treeData = [];
this.treeData = data; const parentNode = {
this.selectedKeys = [data[0]?.catalogId]; catalogId: -1,
this.selectedObj = data[0]; catalogName: '根节点',
this.$emit('change', data[0]); catalogType: 'ROOTNODE',
this.allData = [...this.allData, ...data]; isLeaf: false,
};
this.treeData = [parentNode];
this.allData = [...this.allData, parentNode];
this.treeNode = undefined;
this.selectedKeys = [];
this.selectedObj = {};
}, },
onLoadData(treeNode) { onLoadData(treeNode) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (treeNode.dataRef.children) {
resolve();
return;
}
Api.getEquipmentsTree({ catalogId: treeNode.dataRef.catalogId }).then((resp) => { Api.getEquipmentsTree({ catalogId: treeNode.dataRef.catalogId }).then((resp) => {
if (resp.length === 0) { if (resp.length === 0) {
treeNode.dataRef.isLeaf = true; treeNode.dataRef.isLeaf = false;
} else { } else {
this.allData = [...this.allData, ...resp]; this.allData = [...this.allData, ...resp];
const newData = resp.map((i) => { treeNode.dataRef.children = resp;
return {
...i,
isLeaf: i.catalogType !== 'ORGANIZATION',
};
});
treeNode.dataRef.children = newData;
} }
this.treeData = [...this.treeData]; this.treeData = [...this.treeData];
resolve(); resolve();
...@@ -126,14 +140,28 @@ export default { ...@@ -126,14 +140,28 @@ export default {
this.searchValue = val; this.searchValue = val;
this.$emit('change', data); this.$emit('change', data);
}, },
onSelect(selectedKeys, { node }) { async onSelect(selectedKeys, { node }) {
console.log(node.dataRef);
this.treeNode = node;
this.selectedKeys = selectedKeys;
let data = {};
if (selectedKeys.length !== 0) { if (selectedKeys.length !== 0) {
this.selectedKeys = selectedKeys; const curData = node.dataRef;
const cueData = node.$props.dataRef; this.selectedObj = curData;
this.selectedObj = cueData;
this.searchValue = undefined; this.searchValue = undefined;
this.$emit('change', cueData); if (curData.catalogType === 'EQUIPMENT') {
data = await Api.getEquipmentsInfo(curData);
this.selectedObj = {
...data,
catalogId: curData.catalogId,
catalogType: curData.catalogType,
};
data = this.selectedObj;
}
} else {
this.selectedObj = {};
} }
this.$emit('change', data);
}, },
async view(data = {}, type = 0) { async view(data = {}, type = 0) {
this.$refs['TreeDrawer']?.open(); this.$refs['TreeDrawer']?.open();
...@@ -142,26 +170,57 @@ export default { ...@@ -142,26 +170,57 @@ export default {
}); });
}, },
addEqu() { addEqu() {
const { categoryId } = this.selectedObj; const { catalogId } = this.selectedObj;
this.view({ parentCategoryId: categoryId }, 0); this.view({ parentCatalogId: catalogId, catalogType: 'EQUIPMENT' }, 0);
},
addOrg() {
this.$refs.TreeModal.open();
},
afterSubmit() {
this.onLoadData(this.treeNode);
}, },
addOrg() {},
edit() { edit() {
const data = this.selectedObj; const data = {
...this.selectedObj,
installTime:
this.selectedObj.installTime && moment(this.selectedObj.installTime, 'YYYY-MM-DD'),
runTime: this.selectedObj.runTime && moment(this.selectedObj.runTime, 'YYYY-MM-DD'),
};
delete data.children; delete data.children;
this.view(data, 1); this.view(data, 1);
}, },
del() { async del() {
const categoryId = this.selectedObj?.categoryId; if (isObjEmpty(this.selectedObj)) return;
if (categoryId) return;
try { try {
this.Api.delOceanusTree({ categoryId }); await Api.delEquipmentsTree(this.selectedObj);
this.$message.success('删除成功!'); this.$message.success('删除成功!');
this.init(); this.onLoadData(this.treeNode.$parent);
this.treeNode = undefined;
this.selectedKeys = [];
this.selectedObj = {};
} catch (e) { } catch (e) {
this.$message.warning('删除失败!'); this.$message.warning('删除失败!');
} }
}, },
treeDrawerRefresh(type, data) {
if (type === 0) {
this.onLoadData(this.treeNode);
}
if (type === 1) {
const { equipmentForm, catalogForm } = data;
const { equipmentName } = equipmentForm;
const { catalogId, catalogType } = catalogForm;
console.log(this.treeNode);
this.treeNode.dataRef.catalogName = equipmentName;
this.selectedObj = {
...equipmentForm,
catalogId,
catalogType,
};
this.treeData = [...this.treeData];
this.$emit('change', this.selectedObj);
}
},
}, },
}; };
</script> </script>
<template>
<a-tree-select
:value="value"
show-search
style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="Please select"
:tree-data="treeData"
allow-clear
tree-default-expand-all
:replaceFields="replaceFields"
@change="onChange"
/>
</template>
<!-- v-on="$listeners" -->
<script>
import api from '@/api/organization';
import { arrayToTree } from '@/utils';
export default {
model: {
prop: 'value',
event: 'change',
},
props: {
value: Number,
showMenu: Boolean,
getName: Function,
},
data() {
return {
treeData: [],
replaceFields: {
title: 'orgName',
key: 'orgId',
value: 'orgId',
},
};
},
async mounted() {
const rawData = await api.getOrganizationList();
const newData = rawData.map((i) => ({
...i,
}));
const newArr = new arrayToTree({
data: newData,
rootValue: 0,
parentKey: 'parentOrgId',
key: 'orgId',
}).treeData;
this.treeData = [...newArr];
},
methods: {
onChange(value, label, extra) {
this.getName && this.getName(label);
this.$emit('change', value);
},
},
};
</script>
<template>
<Drawer ref="drawerRef" v-model="visible" :title="title" :onOk="submit" :colesAfter="colesAfter">
<a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm">
<a-form-model-item label="设备编码" prop="equipmentCode">
<a-input v-model="form.equipmentCode" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="设备名称" prop="equipmentName">
<a-input v-model="form.equipmentName" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="类别" prop="categoryId">
<a-tree-select :treeData="oceanusTreeList" v-model="form.categoryId" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="等级" prop="equipmentGrade">
<Select v-model="form.equipmentGrade" :options="equipmentGradeList" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="安装日期" prop="installTime">
<a-date-picker class="tw-w-full" v-model="form.installTime" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="运行日期" prop="runTime">
<a-date-picker class="tw-w-full" v-model="form.runTime" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="供应商" prop="supplier">
<a-input v-model="form.supplier" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="制造商" prop="manufacturer">
<a-input v-model="form.manufacturer" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="专业" prop="specialtyCode">
<Select v-model="form.specialtyCode" :options="specialtyCodeList" :disabled="isView" />
</a-form-model-item>
</a-form-model>
</Drawer>
</template>
<script>
import { getStaticDataApi } from '@/api';
import Drawer from '@/components/table/drawer.vue';
import FormMixin from '@/components/FormMixin';
import Api from '@/api/oceanus';
import Select from '@/components/MySelect/index.vue';
import { arrayToTree, formatObj } from '@/utils';
export default {
components: { Drawer, Select },
props: {
refresh: Function,
},
mixins: [FormMixin],
data() {
return {
visible: false,
form: {},
rules: {
equipmentCode: [
{ required: true, message: 'Please select Activity zone', trigger: 'change' },
],
equipmentName: [
{ required: true, message: 'Please select Activity zone', trigger: 'change' },
],
categoryId: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
},
equipmentGradeList: [],
specialtyCodeList: [],
oceanusTreeList: [],
Api,
};
},
async mounted() {
const oceanusTreeList = await formatObj(await Api.getOceanusTree(), {
label: 'categoryName',
value: 'categoryId',
});
const newOceanusTreeList = new arrayToTree({
data: oceanusTreeList,
rootValue: -1,
parentKey: 'parentCategoryId',
key: 'categoryId',
}).treeData;
const equipmentGradeList = await getStaticDataApi({
paramModule: 'oceanus_equipment',
paramCode: 'equipment_grade',
});
const specialtyCodeList = await getStaticDataApi({
paramModule: 'oceanus_equipment',
paramCode: 'specialty_code',
});
this.oceanusTreeList = newOceanusTreeList;
this.equipmentGradeList = equipmentGradeList;
this.specialtyCodeList = specialtyCodeList;
},
methods: {
open() {
this.form = {};
this.visible = true;
},
add() {
const { parentCatalogId, catalogType, installTime, runTime, ...rest } = this.form;
const data = {
catalogForm: {
parentCatalogId,
catalogType,
},
equipmentForm: {
installTime: installTime && installTime.format('YYYY-MM-DD hh:mm:ss'),
runTime: runTime && runTime.format('YYYY-MM-DD hh:mm:ss'),
...rest,
},
};
return Api.addEquipmentsTree(data);
},
edit() {
const { catalogId, catalogType, installTime, runTime, ...rest } = this.form;
const data = {
catalogForm: {
catalogId,
catalogType,
},
equipmentForm: {
installTime: installTime && installTime.format('YYYY-MM-DD hh:mm:ss'),
runTime: runTime && runTime.format('YYYY-MM-DD hh:mm:ss'),
...rest,
},
};
return Api.updateEquipmentsTree(data);
},
colesAfter() {
const { catalogId, catalogType, installTime, runTime, ...rest } = this.form;
const data = {
catalogForm: {
catalogId,
catalogType,
},
equipmentForm: {
installTime: installTime && installTime.format('YYYY-MM-DD hh:mm:ss'),
runTime: runTime && runTime.format('YYYY-MM-DD hh:mm:ss'),
...rest,
},
};
this.refresh(this.type, data);
},
},
};
</script>
<template> <template>
<Drawer ref="drawerRef" v-model="visible" :title="title" :onOk="submit" :colesAfter="refresh"> <a-modal ref="drawerRef" :visible="visible" title="新增组织" @ok="submit" @cancel="close">
<a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm"> <a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm">
<a-form-model-item label="编码" prop="categoryCode"> <a-form-model-item label="组织" prop="catalogValue">
<a-input v-model="form.categoryCode" :disabled="isView" /> <OrganizationTree v-model="form.catalogValue" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="名称" prop="categoryName">
<a-input v-model="form.categoryName" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="说明" prop="remark">
<a-textarea v-model="form.remark" :disabled="isView" :rows="4" />
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
</Drawer> </a-modal>
</template> </template>
<script> <script>
import Drawer from '@/components/table/drawer.vue';
import FormMixin from '@/components/FormMixin'; import FormMixin from '@/components/FormMixin';
import Api from '@/api/oceanus'; import Api from '@/api/oceanus';
import OrganizationTree from './OrganizationTree.vue';
export default { export default {
components: { Drawer }, components: { OrganizationTree },
props: { props: {
refresh: Function, afterSubmit: Function,
parentNodeId: [String, Number],
},
watch: {
parentNodeId(val) {
this.parentId = val;
},
}, },
mixins: [FormMixin], mixins: [FormMixin],
data() { data() {
return { return {
visible: false, visible: false,
parentId: undefined,
form: {}, form: {},
rules: { rules: {
categoryCode: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }], catalogValue: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
categoryName: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
remark: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
}, },
Api, Api,
}; };
...@@ -43,11 +42,19 @@ export default { ...@@ -43,11 +42,19 @@ export default {
this.form = {}; this.form = {};
this.visible = true; this.visible = true;
}, },
add() { async add() {
return Api.addOceanusTree(this.form); const data = {
...this.form,
catalogType: 'ORGANIZATION',
parentCatalogId: this.parentId + '',
};
await Api.addEquipmentsTree({ catalogForm: data });
this.close();
this.afterSubmit && this.afterSubmit();
}, },
edit() { close() {
return Api.updateOceanusTree(this.form); this.form = {};
this.visible = false;
}, },
}, },
}; };
......
<template>
<my-card>
<a-tabs default-active-key="1" @change="callback">
<a-tab-pane key="1" tab="Tab 1"> Content of Tab Pane 1 </a-tab-pane>
<a-tab-pane key="2" tab="Tab 2" force-render> Content of Tab Pane 2 </a-tab-pane>
<a-tab-pane key="3" tab="Tab 3"> Content of Tab Pane 3 </a-tab-pane>
</a-tabs>
</my-card>
</template>
<script>
export default {
data() {
return {};
},
methods: {
callback(key) {
console.log(key);
},
},
};
</script>
...@@ -4,22 +4,28 @@ ...@@ -4,22 +4,28 @@
<LeftTree v-model="treeVale" /> <LeftTree v-model="treeVale" />
</a-col> </a-col>
<a-col :span="16"> <a-col :span="16">
<RightTable /> <RightBox v-if="!isObjEmpty(treeVale)" :info="treeVale" />
</a-col> </a-col>
</a-row> </a-row>
</template> </template>
<script> <script>
import RightTable from './components/RightTable.vue'; import RightBox from './Right/RightBox.vue';
import LeftTree from './components/LeftTree.vue'; import LeftTree from './Left/LeftTree.vue';
import { isObjEmpty } from '@/utils';
export default { export default {
components: { RightTable, LeftTree }, components: { RightBox, LeftTree },
data() { data() {
return { return {
treeVale: {}, treeVale: {},
isObjEmpty,
}; };
}, },
methods: {}, watch: {
treeVale(val) {
console.log(val);
},
},
}; };
</script> </script>
...@@ -125,6 +125,10 @@ export const formatObj = (ArrObj, obj) => { ...@@ -125,6 +125,10 @@ export const formatObj = (ArrObj, obj) => {
return newDataOne; return newDataOne;
}; };
export const isObjEmpty = (data = {}) => {
const arr = Object.keys(data);
return arr.length === 0;
};
/** /**
* 下载文件 * 下载文件
* @param {String} url 下载路径 * @param {String} url 下载路径
......
...@@ -135,8 +135,8 @@ function checkAuthorization() { ...@@ -135,8 +135,8 @@ function checkAuthorization() {
return !!getToken(); return !!getToken();
} }
function delReq(url, config) { function delReq(url, params, config) {
return request(url, METHOD.DELETE, config); return request(url, METHOD.DELETE, params, config);
} }
function getReq(url, params, config) { function getReq(url, params, config) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment