Browse Source

资产信息修改处理

develop^2
fuguobin 8 months ago
parent
commit
77ada34378
  1. 130
      src/store/modules/user.js
  2. 277
      src/views/model/asset/addParams.vue
  3. 3
      src/views/model/asset/index.vue

130
src/store/modules/user.js

@ -1,70 +1,78 @@
import { login, logout, getInfo } from '@/api/login' import { login, logout, getInfo } from "@/api/login";
import { getToken, setToken, removeToken } from '@/utils/auth' import { getToken, setToken, removeToken } from "@/utils/auth";
import defAva from '@/assets/images/profile.jpg' import defAva from "@/assets/images/profile.jpg";
const useUserStore = defineStore( const useUserStore = defineStore("user", {
'user', state: () => ({
{ token: getToken(),
state: () => ({ name: "",
token: getToken(), avatar: "",
name: '', roles: [],
avatar: '', permissions: [],
roles: [], }),
permissions: [] actions: {
}), // 登录
actions: { login(userInfo) {
// 登录 const username = userInfo.username.trim();
login(userInfo) { const password = userInfo.password;
const username = userInfo.username.trim() const code = userInfo.code;
const password = userInfo.password const uuid = userInfo.uuid;
const code = userInfo.code return new Promise((resolve, reject) => {
const uuid = userInfo.uuid login(username, password, code, uuid)
return new Promise((resolve, reject) => { .then((res) => {
login(username, password, code, uuid).then(res => { setToken(res.token);
setToken(res.token) this.token = res.token;
this.token = res.token resolve();
resolve()
}).catch(error => {
reject(error)
}) })
}) .catch((error) => {
}, reject(error);
// 获取用户信息 });
getInfo() { });
return new Promise((resolve, reject) => { },
getInfo().then(res => { // 获取用户信息
const user = res.user getInfo() {
const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar; return new Promise((resolve, reject) => {
getInfo()
.then((res) => {
const user = res.user;
const avatar =
user.avatar == "" || user.avatar == null
? defAva
: import.meta.env.VITE_APP_BASE_API + user.avatar;
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 if (res.roles && res.roles.length > 0) {
this.roles = res.roles // 验证返回的roles是否是一个非空数组
this.permissions = res.permissions this.roles = res.roles;
this.permissions = res.permissions;
} else { } else {
this.roles = ['ROLE_DEFAULT'] this.roles = ["ROLE_DEFAULT"];
} }
this.name = user.userName this.name = user.userName;
this.avatar = avatar; this.avatar = avatar;
resolve(res) resolve(res);
}).catch(error => {
reject(error)
}) })
}) .catch((error) => {
}, reject(error);
// 退出系统 });
logOut() { });
return new Promise((resolve, reject) => { },
logout(this.token).then(() => { // 退出系统
this.token = '' logOut() {
this.roles = [] return new Promise((resolve, reject) => {
this.permissions = [] logout(this.token)
removeToken() .then(() => {
resolve() this.token = "";
}).catch(error => { this.roles = [];
reject(error) this.permissions = [];
removeToken();
resolve();
}) })
}) .catch((error) => {
} reject(error);
} });
}) });
},
},
});
export default useUserStore export default useUserStore;

277
src/views/model/asset/addParams.vue

@ -3,10 +3,10 @@
<div class="submitBtn"> <div class="submitBtn">
<el-button <el-button
type="primary" type="primary"
:icon="Check" :icon="submitIcon"
@click="paramSubmit(paramsFormRef)" @click="paramSubmit(paramsFormRef)"
> >
提交 {{ paramsText }}
</el-button> </el-button>
</div> </div>
<el-collapse class="paramsCollapse" v-model="activeNames"> <el-collapse class="paramsCollapse" v-model="activeNames">
@ -16,11 +16,11 @@
class="paramsForm" class="paramsForm"
:rules="paramsRules" :rules="paramsRules"
:inline="true" :inline="true"
:model="paramsForm" :model="formData.paramsForm"
> >
<el-form-item label="组织" prop="orgName"> <el-form-item label="组织" prop="orgName">
<el-tree-select <el-tree-select
v-model="paramsForm.orgName" v-model="formData.paramsForm.orgName"
:data="deptOptions" :data="deptOptions"
:props="{ :props="{
value: 'label', value: 'label',
@ -34,16 +34,16 @@
@node-click="selectDept" @node-click="selectDept"
/> />
</el-form-item> </el-form-item>
<el-form-item label="编码"> <el-form-item label="编码" prop="assetCode">
<el-input <el-input
v-model="paramsForm.assetCode" v-model="formData.paramsForm.assetCode"
placeholder="编码" placeholder="编码"
clearable clearable
/> />
</el-form-item> </el-form-item>
<el-form-item label="是否可用" prop="flagEnabled"> <el-form-item label="是否可用" prop="flagEnabled">
<el-select <el-select
v-model="paramsForm.flagEnabled" v-model="formData.paramsForm.flagEnabled"
placeholder="请选择是否可用" placeholder="请选择是否可用"
> >
<el-option <el-option
@ -56,14 +56,14 @@
</el-form-item> </el-form-item>
<el-form-item label="名称" prop="assetName"> <el-form-item label="名称" prop="assetName">
<el-input <el-input
v-model="paramsForm.assetName" v-model="formData.paramsForm.assetName"
placeholder="名称" placeholder="名称"
clearable clearable
/> />
</el-form-item> </el-form-item>
<el-form-item label="类别" prop="assetType"> <el-form-item label="类别" prop="assetType">
<el-select <el-select
v-model="paramsForm.assetType" v-model="formData.paramsForm.assetType"
placeholder="请选择类别" placeholder="请选择类别"
clearable clearable
> >
@ -75,31 +75,48 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="组成设备"> <div>
<el-select <el-form-item label="组成设备">
v-model="paramsDevice" <el-select
multiple v-model="paramsDevice"
filterable multiple
allow-create filterable
default-first-option allow-create
:reserve-keyword="false" default-first-option
placeholder="组成设备" collapse-tags
style="width: 240px" collapse-tags-tooltip
> :max-collapse-tags="3"
<el-option :reserve-keyword="false"
v-for="item in deviceOption" placeholder="组成设备"
:key="item.id" style="width: 240px"
:label="item.deviceName" >
:value="item.centerDeviceCode" <el-option
/> v-for="item in deviceOption"
</el-select> :key="item.id"
</el-form-item> :label="item.deviceName"
<el-form-item> :value="item.centerDeviceCode"
<el-button type="success" @click="selectParams">选择参数</el-button> />
</el-form-item> </el-select>
</el-form-item>
<el-form-item>
<el-button type="success" @click="selectParams"
>选择参数</el-button
>
</el-form-item>
</div>
</el-form> </el-form>
</el-collapse-item> </el-collapse-item>
<el-collapse-item title="参数列表" name="2"> <el-collapse-item title="参数列表" name="2">
<vxe-toolbar>
<template #buttons>
<vxe-button
status="danger"
content="删除"
icon="vxe-icon-delete"
@click="removeEvent()"
></vxe-button>
</template>
</vxe-toolbar>
<vxe-table <vxe-table
class="tableCollapse" class="tableCollapse"
border border
@ -115,8 +132,8 @@
field="paramName" field="paramName"
title="参数名称" title="参数名称"
:filters="addressOptions" :filters="addressOptions"
:filter-method="filterAddressMethod" :filter-method="filterParamName"
:filter-recover-method="filterAddressRecoverMethod" :filter-recover-method="filterParamNameRecover"
> >
<template #filter="{ $panel, column }"> <template #filter="{ $panel, column }">
<vxe-input <vxe-input
@ -141,6 +158,15 @@
<vxe-checkbox v-model="row.contrlFlag"></vxe-checkbox> <vxe-checkbox v-model="row.contrlFlag"></vxe-checkbox>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column title="操作" width="100" show-overflow>
<template #default="{ row }">
<vxe-button
type="text"
icon="vxe-icon-delete"
@click="removeEvent(row)"
></vxe-button>
</template>
</vxe-column>
</vxe-table> </vxe-table>
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
@ -167,8 +193,8 @@
field="paramModelName" field="paramModelName"
title="参数模版名称" title="参数模版名称"
:filters="ageOptions" :filters="ageOptions"
:filter-method="filterAgeMethod" :filter-method="filterParamModel"
:filter-recover-method="filterAgeRecoverMethod" :filter-recover-method="filterParamModelRecover"
> >
<template #filter="{ $panel, column }"> <template #filter="{ $panel, column }">
<vxe-input <vxe-input
@ -187,8 +213,8 @@
field="paramName" field="paramName"
title="参数名称" title="参数名称"
:filters="addressOptions" :filters="addressOptions"
:filter-method="filterAddressMethod" :filter-method="filterParamNameSel"
:filter-recover-method="filterAddressRecoverMethod" :filter-recover-method="filterParamNameRecoverSel"
> >
<template #filter="{ $panel, column }"> <template #filter="{ $panel, column }">
<vxe-input <vxe-input
@ -221,9 +247,13 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from "vue"; import { ref, reactive, onMounted } from "vue";
import { useRoute } from "vue-router"; import { ElMessage } from "element-plus";
import { deptTreeSelect } from "@/api/system/user"; import { deptTreeSelect } from "@/api/system/user";
import { listByDeviceUuids } from "@/api/model/asset/params"; import {
listByDeviceUuids,
listParams,
delParams,
} from "@/api/model/asset/params";
import { listDeviceNoPage } from "@/api/model/device"; import { listDeviceNoPage } from "@/api/model/device";
import { import {
listInfo, listInfo,
@ -239,7 +269,11 @@ const { dc_asset_attr } = proxy.useDict("dc_asset_attr");
const activeNames = ref(["1", "2"]); const activeNames = ref(["1", "2"]);
const route = useRoute(); const route = useRoute();
const router = useRouter();
const id = route.query.id; const id = route.query.id;
const ids = ref();
const submitIcon = ref("Plus");
const paramsText = ref("新增");
const paramsFormRef = ref(); const paramsFormRef = ref();
const dialogTableVisible = ref(false); const dialogTableVisible = ref(false);
const deptOptions = ref([]); const deptOptions = ref([]);
@ -252,55 +286,95 @@ const enabledFlag = ref([
{ label: "可用", value: 1, elTagType: "default", elTagClass: null }, { label: "可用", value: 1, elTagType: "default", elTagClass: null },
{ label: "不可用", value: 0, elTagType: "default", elTagClass: null }, { label: "不可用", value: 0, elTagType: "default", elTagClass: null },
]); ]);
const paramsForm = reactive({ const formData = reactive({
assetCode: "", paramsForm: {
flagEnabled: null, assetCode: "",
assetName: "", flagEnabled: null,
assetType: "", assetName: "",
orgCode: null, assetType: "",
orgName: "", orgCode: null,
assetParamsDtos: [ orgName: "",
{ assetParamsDtos: [
paramCode: "", {
flagEnabled: false, paramCode: "",
contrlFlag: false, flagEnabled: false,
}, contrlFlag: false,
], },
],
},
}); });
const paramsTableRef = ref(); const paramsTableRef = ref();
const addTableRef = ref(); const addTableRef = ref();
const loading = ref(false); const loading = ref(false);
const sexOptions = ref([ const sexOptions = ref([
{ label: "高区", value: "高区" }, { label: "A", value: "A" },
{ label: "中区", value: "中区" }, { label: "B", value: "B" },
{ label: "低区", value: "低区" }, { label: "C", value: "C" },
{ label: "D", value: "D" },
]); ]);
const ageOptions = ref([{ data: "" }]); const ageOptions = ref([{ data: "" }]);
const addressOptions = ref([{ data: "" }]); const addressOptions = ref([{ data: "" }]);
const paramsRules = reactive({ const paramsRules = reactive({
orgName: [{ required: true, message: "请选择组织", trigger: "change" }],
assetCode: [{ required: true, message: "请输入编码", trigger: "blur" }],
flagEnabled: [
{ required: true, message: "请选择是否可用", trigger: "change" },
],
assetName: [{ required: true, message: "请输入资产名称", trigger: "blur" }], assetName: [{ required: true, message: "请输入资产名称", trigger: "blur" }],
assetType: [{ required: true, message: "请选择类别", trigger: "change" }],
}); });
const filterAgeMethod = ({ option, row }) => { const filterParamModel = ({ option, row }) => {
return row.age === Number(option.data); //
return row.paramModelName === option.data;
}; };
const filterAgeRecoverMethod = ({ option }) => { const filterParamModelRecover = ({ option }) => {
// //
option.data = ""; option.data = "";
}; };
const filterAddressMethod = ({ option, row }) => { const filterParamName = ({ option, row }) => {
return row.address === option.data; //
return row.paramName === option.data;
}; };
const filterAddressRecoverMethod = ({ option }) => { const filterParamNameRecover = ({ option }) => {
// //
option.data = "";
};
const filterParamNameSel = ({ option, row }) => {
//
return row.paramName === option.data;
};
const filterParamNameRecoverSel = ({ option }) => {
//
option.data = ""; option.data = "";
}; };
onMounted(() => { onMounted(() => {
const dsfsdf = route.query.id; if (route.query.id != undefined) {
debugger; getBasicInfo();
getParamsList();
}
getDeptTree(); getDeptTree();
getDevice(); getDevice();
}); });
function getBasicInfo() {
getInfo(route.query.id).then((response) => {
formData.paramsForm = response.data;
submitIcon.value = "Check";
paramsText.value = "修改";
});
}
function getParamsList() {
//
const params = {
assetCode: route.query.assetCode,
};
listParams(params).then((res) => {
if (res.code === 200) {
paramsList.value = res.rows;
paramsCode.value = paramsList.value.map((item) => item.paramCode);
}
});
}
function getDeptTree() { function getDeptTree() {
// //
deptTreeSelect().then((response) => { deptTreeSelect().then((response) => {
@ -319,7 +393,7 @@ function selectParams() {
if (paramsDevice.value.length != 0) { if (paramsDevice.value.length != 0) {
const params = { const params = {
deviceUuids: paramsDevice.value, deviceUuids: paramsDevice.value,
excludeParamCodes: [], excludeParamCodes: paramsCode.value,
}; };
listByDeviceUuids(params).then((res) => { listByDeviceUuids(params).then((res) => {
if (res.code === 200) { if (res.code === 200) {
@ -327,29 +401,73 @@ function selectParams() {
dialogTableVisible.value = true; dialogTableVisible.value = true;
} }
}); });
} else {
ElMessage({
message: "请先选择组成设备!",
type: "warning",
});
} }
} }
function selectDept(val) { function selectDept(val) {
// //
paramsForm.orgCode = val.id; formData.paramsForm.orgCode = val.id;
} }
function addConfirm() { function addConfirm() {
// //
const $addTable = addTableRef.value; const $addTable = addTableRef.value;
if ($addTable) { if ($addTable) {
const selectRecords = $addTable.getCheckboxRecords(); const selectRecords = $addTable.getCheckboxRecords();
paramsList.value = selectRecords.map((item) => { selectRecords.map((item) => {
return { paramsList.value.push({
...item, ...item,
flagEnabled: false, flagEnabled: false,
contrlFlag: false, contrlFlag: false,
}; });
}); });
paramsCode.value = selectRecords.map((item) => item.paramCode); paramsCode.value = paramsList.value.map((item) => item.paramCode);
console.log(paramsList.value, paramsCode.value);
dialogTableVisible.value = false; dialogTableVisible.value = false;
} }
} }
const removeEvent = async (row) => {
//
if (row) {
ids.value = row.id;
} else {
const $submitTable = paramsTableRef.value;
ids.value = $submitTable.getCheckboxRecords().map((item) => item.id);
if (ids.value.length === 0) {
ElMessage({
message: "请选择删除数据!",
type: "warning",
});
return;
}
}
if (route.query.id != undefined) {
proxy.$modal
.confirm("是否确认删除数据项?")
.then(function () {
return delParams(ids.value);
})
.then(() => {
getParamsList();
proxy.$modal.msgSuccess("删除成功");
})
.catch(() => {});
} else {
const $submitTable = paramsTableRef.value;
const selectParamsList = $submitTable.getCheckboxRecords();
if ($submitTable) {
$submitTable.remove(row || selectParamsList);
paramsList.value = $submitTable.getTableData().tableData;
paramsCode.value = paramsList.value.map((item) => item.paramCode);
console.log(paramsList.value);
}
}
};
const paramSubmit = async (formEl) => { const paramSubmit = async (formEl) => {
// //
if (!formEl) return; if (!formEl) return;
@ -363,21 +481,22 @@ const paramSubmit = async (formEl) => {
flagEnabled: item.flagEnabled, flagEnabled: item.flagEnabled,
contrlFlag: item.contrlFlag, contrlFlag: item.contrlFlag,
})); }));
paramsForm.assetParamsDtos = selectParamsListArr; formData.paramsForm.assetParamsDtos = selectParamsListArr;
if (id.value != undefined) { if (route.query.id != undefined) {
updateInfo(paramsForm).then((response) => { updateInfo(formData.paramsForm).then((response) => {
proxy.$modal.msgSuccess("修改成功"); proxy.$modal.msgSuccess("修改成功");
open.value = false; open.value = false;
getList();
}); });
} else { } else {
addInfo(paramsForm).then((response) => { addInfo(formData.paramsForm).then((response) => {
proxy.$modal.msgSuccess("新增成功"); proxy.$modal.msgSuccess("新增成功");
open.value = false; open.value = false;
getList();
}); });
} }
console.log(paramsForm); router.push({
path: "AssetInfo",
});
console.log(formData.paramsForm);
} }
} else { } else {
console.log("error submit!", fields); console.log("error submit!", fields);

3
src/views/model/asset/index.vue

@ -377,11 +377,12 @@ function handleAdd() {
function handleUpdate(row) { function handleUpdate(row) {
// reset(); // reset();
const id = row.id || ids.value; const id = row.id || ids.value;
debugger; const assetCode = row.assetCode;
router.push({ router.push({
path: "AddParams", path: "AddParams",
query: { query: {
id, id,
assetCode,
}, },
}); });
// getInfo(_id).then((response) => { // getInfo(_id).then((response) => {

Loading…
Cancel
Save