deesCloud-web/scripts/user.js

445 lines
12 KiB
JavaScript
Raw Normal View History

2025-08-01 16:50:32 +08:00
//组件
var Usercomponent = {
template:`
<div>
<div id="" style="display: inline-block;width: 100%;margin-top: 10px;">
<div style="float: left; width: 30%;background-color: #ECF5FF;">
<el-input v-model="input" placeholder="请输入用户" clearable></el-input>
</div>
<div style="float: left;margin-left: 5px;">
<el-button id ="bt_search" plain type="primary" icon="el-icon-search" @click="getUser(input)">搜索</el-button>
</div>
<div style="float: left; margin-left: 5px;">
<el-button id ="bt_add" plain type="primary" icon="el-icon-circle-plus-outline" @click="addUser()">新增</el-button>
</div>
</div>
<div class="span">
<el-table
:data="tableData"
style="width: 100%"
:height="tHeight"
:cell-style="{background:'#304156'}"
border
>
<el-table-column
prop="username"
label="用户名"
width="100">
</el-table-column>
<el-table-column
prop="userrole"
label="职位"
width="120">
</el-table-column>
<el-table-column
prop="user_department"
label="部门"
width="120">
</el-table-column>
<el-table-column
prop="cnt"
label="登录次数"
width="80">
</el-table-column>
<el-table-column
prop="loginTime"
label="最近登录时间"
width="170">
</el-table-column>
<el-table-column
label="操作"
width="100">
<template slot-scope="scope">
<!--style="height:23px;padding:0px" -->
<el-button @click="updateUser(scope.row)" type="text" size="medium" >修改</el-button>
<el-button @click="delUser(scope.row)" type="text" size="medium" >删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="block">
<span class="demonstration" style="background-color: #ECF5FF;"></span>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[50,100, 200, 300]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="recordTotal" style="background-color: #ECF5FF;">
</el-pagination>
</div>
<el-dialog
title="用户信息"
:visible.sync="dialogVisible"
:lock-scroll ="false"
width="30%">
<el-form ref="userform" :model="form" label-width="80px" :rules="rules">
<el-form-item label="用户名" prop="username">
<el-input v-model="form.username"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="form.password" show-password></el-input>
</el-form-item>
<el-form-item label="职位" prop="role">
<el-select v-model="form.role" placeholder="请选择职位">
<el-option-group
key="1"
label="">
<el-option label="访客" value="访客"></el-option>
</el-option-group>
<el-option-group
key="2"
label="">
<el-option label="项目成员" value="项目成员"></el-option>
<el-option label="部门成员" value="部门成员"></el-option>
<el-option label="区域工程师" value="区域工程师"></el-option>
<el-option label="审核专员" value="审核专员"></el-option>
</el-option-group>
<el-option-group
key="3"
label="">
<el-option label="授权管理员" value="授权管理员"></el-option>
<el-option label="项目组长" value="项目组长"></el-option>
<el-option label="区域经理" value="区域经理"></el-option>
<el-option label="部门经理" value="部门经理"></el-option>
<el-option label="系统管理员" value="系统管理员"></el-option>
</el-option-group>
</el-select>
</el-form-item>
<el-form-item label="部门" prop="department">
<el-select v-model="form.department" placeholder="请选择部门">
<el-option label="石油仪器事业部" value="石油仪器事业部"></el-option>
<el-option label="工程服务事业部" value="工程服务事业部"></el-option>
<el-option label="煤矿事业部" value="煤矿事业部"></el-option>
<el-option label="地勘事业部" value="地勘事业部"></el-option>
<el-option label="维保事业部" value="维保事业部"></el-option>
<el-option label="研发部" value="研发部"></el-option>
<el-option label="技术部" value="技术部"></el-option>
<el-option label="维保部" value="维保部"></el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button id ="bt_ok" plain type="primary" @click="postUser()"> </el-button>
</span>
</el-dialog>
</div>
`,
data(){
// 获取当前屏幕的分辨率
let screenW = window.screen.width;
let screenH = window.innerHeight;
console.log("screen width:",screenW);
console.log("screen height:",screenH);
return {
tHeight:screenH-192,
tableData: [],
input:'',
currentPage: 1,
pagesize:50,
recordTotal:0,
form: {
id:'',
username: '',
password:'',
role: '',
department:''
},
dialogVisible:false,
oper_type:0,
rules: {
username: [
{ required: true, message: '用户不可为空', trigger: 'blur' }
],
password: [
{ required: true, message: '密码不可为空', trigger: 'blur' }
],
role: [
{ required: true, message: '用户角色不可为空', trigger: 'blur' }
]
},
}
},
mounted() {
var _this = this;
var objs;
axios.post('/deescloud/getUsers', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: '',
index: this.$data.currentPage,
count: this.$data.pagesize
})
.then(function (response) {
console.log(response.data);
objs = response.data.data;
rcnt = response.data.total;
_this.$data.tableData = objs;
_this.$data.recordTotal = rcnt;
})
.catch(function (error) {
console.log(error);
});
},
methods: {
postUser(){
this.$refs['userform'].validate((valid) => {
if(valid){
/*
if (this.$data.form.username =='' || this.$data.form.password == '' || this.$data.form.role == '') {
this.$alert('用户名、密码、用户角色不能为空,请检查所填项!', '提示', {
confirmButtonText: '确定',
callback: action => {
},
lockScroll:false
});
return;
}*/
this.$data.dialogVisible = false;
var _this = this;
console.log(_this.$data.form);
var objs;
axios.post('/deescloud/postUser', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: _this.$data.form.id,
username:_this.$data.form.username,
password: _this.$data.form.password,
role: _this.$data.form.role,
department:_this.$data.form.department,
oper_type: _this.$data.oper_type
})
.then(function (response) {
let r = response.data.r;
let s = ""
let errType = ""
if (r == 0) {
errType = "success"
} else{
errType = "error"
}
if (_this.$data.oper_type == 1) {
if (r ==0) {
s = "新增用户成功!";
} else if(r == 1) {
s = "已存在相同用户名!";
}else{
s = "新增用户失败!";
}
} else if (_this.$data.oper_type ==2){
if (r ==0) {
s = "修改用户成功!";
} else{
s = "修改用户失败!";
}
}
_this.$message({
message: s,
type: errType,
duration: 1500
});
//更新页面
_this.getUser(_this.$data.input);
/*if (_this.$data.oper_type == 1) {
_this.getUser("");
}else{
_this.getUser(_this.$data.input);
}*/
})
.catch(function (error) {
console.log(error);
});
}
});
},
delUser(userinfo){
this.$data.oper_type = 3;
var _this = this;
var objs;
axios.post('/deescloud/postUser', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: userinfo.userid,
username:userinfo.username,
password: userinfo.password,
role: userinfo.userrole,
department:userinfo.user_department,
oper_type: _this.$data.oper_type
})
.then(function (response) {
let r = response.data.r;
let s = ""
let errType = ""
if (r == 0) {
s = "删除用户成功!";
errType = "success"
} else{
s = "删除用户失败!";
errType = "error"
}
_this.$message({
message: s,
type: errType,
duration: 1500
});
if (r ==0) {
_this.getUser("");//更新页面
}
})
.catch(function (error) {
console.log(error);
});
},
addUser(){
document.getElementById("bt_add").blur();
this.$data.oper_type = 1;
this.$data.form = {
id:'',
username: '',
password:'',
role: '',
department:'',
};
this.$nextTick(() => {
this.$refs['userform'].clearValidate()
});
this.$data.dialogVisible = true;
},
updateUser(userinfo){
this.$data.oper_type = 2;
this.$data.form = {
id:userinfo.userid,
username: userinfo.username,
password:userinfo.password,
role: userinfo.userrole,
department:userinfo.user_department
};
this.$nextTick(() => {
this.$refs['userform'].clearValidate()
});
this.$data.dialogVisible = true;
},
getUser(_search_name){
document.getElementById("bt_search").blur();
this.$data.currentPage=1;
var _this = this;
var objs;
axios.post('/deescloud/getUsers', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: _search_name,
index: this.$data.currentPage,
count: this.$data.pagesize
})
.then(function (response) {
console.log(response.data);
objs = response.data.data;
rcnt = response.data.total;
_this.$data.tableData = objs;
_this.$data.recordTotal = rcnt;
})
.catch(function (error) {
console.log(error);
});
},
handleSizeChange(val) {
this.$data.pagesize = val;
var _this = this;
var objs;
axios.post('/deescloud/getUsers', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: this.$data.input,
index: this.$data.currentPage,
count: this.$data.pagesize
})
.then(function (response) {
console.log(response.data);
objs = response.data.data;
rcnt = response.data.total;
_this.$data.tableData = objs;
_this.$data.recordTotal = rcnt;
})
.catch(function (error) {
console.log(error);
});
},
handleCurrentChange(val) {
this.$data.currentPage = val;
var _this = this;
var objs;
axios.post('/deescloud/getUsers', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
id: this.$data.input,
index: this.$data.currentPage,
count: this.$data.pagesize
})
.then(function (response) {
console.log(response.data);
objs = response.data.data;
rcnt = response.data.total;
_this.$data.tableData = objs;
_this.$data.recordTotal = rcnt;
})
.catch(function (error) {
console.log(error);
});
}
}
}