Commit c39ff743 authored by renjintao's avatar renjintao

user 优化

parent a2cb213b
......@@ -10,14 +10,13 @@
</div>
</Sider>
<Content class="content">
<DataGrid :columns="columns" ref="grid" :action="action" :conditions="easySearch" placeholder="请输入姓名/员工编号" :high="true" :height="tdHeight">
<DataGrid :columns="columns" ref="grid" :action="action" :conditions="easySearch" placeholder="请输入姓名/员工编号" exportTitle="用户管理" :high="true" :height="tdHeight">
<template slot="searchForm">
<Search />
</template>
<template slot="buttons">
<Button type="primary" @click="addModal=true">新增</Button>
<Button @click="import2Excel">导入</Button>
<Button @click="export2Excel">导出</Button>
<Button @click="openModalIm">导入</Button>
</template>
</DataGrid>
<Modal v-model="addModal" title="新增" footer-hide width="800">
......@@ -87,6 +86,7 @@
<Button type="primary" @click="importOk">确定导入</Button>
</div>
</Modal>
<ImportExcel ref="importExcel" @on-get-data="getData" :modalTitle="temTitle" :columns="columns" :open="ModalIm" @on-cancel="ModalImCancel" @on-ok="ok" />
</Content>
</Layout>
</template>
......@@ -205,6 +205,7 @@ export default {
align: "center",
high: true,
code: "User.base.gender",
import: true,
},
{
key: "birthday",
......@@ -212,6 +213,7 @@ export default {
align: "center",
high: true,
type: "date",
import: true,
},
{
key: "degreeId",
......@@ -219,6 +221,7 @@ export default {
align: "left",
high: true,
code: "User.base.degree",
import: true,
},
{
key: "status",
......@@ -226,6 +229,7 @@ export default {
align: "center",
high: true,
code: "User.base.status",
import: true,
},
{
key: "departmentId",
......@@ -233,6 +237,7 @@ export default {
align: "right",
easy: true,
high: true,
import: true,
},
{
key: "departmentTitle",
......@@ -240,6 +245,7 @@ export default {
align: "left",
easy: true,
high: true,
import: true,
},
{
......@@ -277,6 +283,7 @@ export default {
title: this.l("accountId"),
hide: true,
align: "left",
import: true,
},
// {
// key: 'userType',
......@@ -290,6 +297,7 @@ export default {
align: "left",
easy: true,
high: true,
import: true,
},
{
key: "email",
......@@ -297,12 +305,14 @@ export default {
align: "left",
easy: true,
high: true,
import: true,
},
{
key: "licensedToWork",
title: this.l("licensedToWork"),
align: "left",
code: "User.base.workLicense",
import: true,
},
{
key: "positionId",
......@@ -310,6 +320,7 @@ export default {
align: "left",
high: true,
code: "User.base.position",
import: true,
},
{
key: "titleId",
......@@ -317,6 +328,7 @@ export default {
align: "left",
high: true,
code: "User.base.jobtitle",
import: true,
},
{
key: "creatorUserId",
......@@ -324,6 +336,7 @@ export default {
align: "left",
import: false,
hide: true,
import: true,
},
{
key: "creationTime",
......@@ -331,6 +344,7 @@ export default {
align: "left",
import: false,
hide: true,
import: true,
},
{
key: "lastModifierUserId",
......@@ -338,6 +352,7 @@ export default {
align: "left",
import: false,
hide: true,
import: true,
},
{
key: "lastModificationTime",
......@@ -345,6 +360,7 @@ export default {
align: "left",
import: false,
hide: true,
import: true,
},
{
title: "操作",
......@@ -419,6 +435,8 @@ export default {
departArr: [], //部门list
columnsImport: [],
temTitle: '用户管理',
ModalIm: false,
//导入导出时使用end
};
},
......@@ -676,220 +694,8 @@ export default {
}
},
//同步账户end
//导出excel
export2Excel() {
//当前显示数据
var where = [];
var conditions = this.easySearch;
if (conditions) {
Object.keys(conditions).forEach((u) => {
let v = conditions[u].value;
let op = conditions[u].op;
if (!this.$u.isNull(v)) {
if (op == "Range") {
let times = [];
v.map((u) => {
if (!this.$u.isNull(u)) {
times.push(this.$u.toTime(u));
}
});
v = times.join(",");
} else if (op.indexOf("In") > -1) {
v = v.join(",");
}
if (!this.$u.isNull(v)) {
where.push({
fieldName: u,
fieldValue: v,
conditionalType: op,
});
}
}
});
}
this.searchs.pageIndex = 1;
this.searchs.conditions = where;
this.searchs.pageSize = 1000;
this.$api.post(this.action, this.searchs).then((r) => {
this.list = r.result.items;
const tHeader = []; // 设置Excel的表格第一行的标题
const filterVal = []; //list里对象的属性
var tempCol = [];
var columnsCur = this.$u.clone(this.columns); //导出列标题信息griddata this.$refs.grid.columnsCur
columnsCur.forEach((el) => {
if ((el.hide && !el.import) || (!el.hide && el.key != "action")) {
if (el.code) {
//tHeader.push(el.key + "DirName");
//filterVal.push(el.key + "DirName");
//tempCol.push({ key: el.key + "DirName", code: el.code }); //临时存放code数据字典的字段及对应的数据字典code
tempCol.push({
key: el.key,
code: el.code
}); //临时存放code数据字典的字段及对应的数据字典code
}
tHeader.push(this.l(el.key));
filterVal.push(el.key);
}
});
this.list.forEach((e) => {
//给导出数据增加数据字典对应的name
tempCol.forEach((ele) => {
e[ele.key] = this.$u.dirName(
this.$store.getters.dictionaryByKey(ele.code),
e[ele.key]
);
});
});
let nowDate = this.$u.getNowTime(); //年月日时分秒yyyyMMddhhmmss
//获取导出数据结束
this.$u.outExcel(
"用户管理(" + nowDate + ")",
tHeader,
filterVal,
this.list
);
});
},
//导入excel
//打开弹出层
import2Excel() {
this.modalImport = true;
this.excelData = [];
this.$refs.uploadfile.clearFiles();
ApiDepart.getpaged().then((r) => {
this.departArr = r.result.items;
});
},
//导入excel文件
async beforeUpload(file) {
this.excelData = [];
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
var tempColums = this.$u.clone(this.columnsImport);
const workbook = await this.$u.readXLSX(file);
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var csv = XLSX.utils.sheet_to_csv(
workbook.Sheets[workbook.SheetNames[0]],
sheet2JSONOpts
);
var lines = csv.split("\n"); //第一行标题
var headers = lines[0].split(",");
var arrTi = [];
//转换到colum后的list表头start
headers.forEach((elHead) => {
tempColums.forEach((elCol) => {
if (elHead == elCol.title) {
//elHead=elCol.key
arrTi.push(elCol.key);
}
});
});
headers = arrTi;
//转换到colum后的list表头end
var result = [];
for (var i = 1; i < lines.length - 1; i++) {
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
//对读取的excel文件数据进行处理
var arrTitleUse = []; //使用数据字典的字段
tempColums.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({
key: elCode.key,
code: elCode.code
});
}
});
result.forEach((ele) => {
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
if (
ele.departmentTitle &&
ele.departmentTitle != "" &&
(!ele.departmentId || ele.departmentId == "")
) {
this.departArr.forEach((e) => {
if (ele.departmentTitle && ele.departmentTitle == e.name) {
ele.departmentId = e.id;
}
});
} else if (
//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
ele.departmentId &&
ele.departmentId + "" != "" &&
(!ele.departmentTitle || ele.departmentTitle == "")
) {
this.departArr.forEach((e) => {
if (ele.departmentId && ele.departmentId == e.id) {
ele.departmentTitle = e.name;
}
});
}
//对列表里的数据字典项进行处理
arrTitleUse.forEach((elem) => {
if (ele[elem.key] && ele[elem.key] != "" && ele[elem.key] != null) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
ele[elem.key] = this.$u.dirCode(
this.$store.getters.dictionaryByKey(elem.code),
ele[elem.key]
);
}
});
});
this.excelData = result;
//console.log(workbook);
return false;
},
//确定批量导入
importOk() {
let tempData = this.$u.clone(this.excelData);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
userName: ele.userName,
cardNo: ele.cardNo,
gender: ele.gender,
birthday: ele.birthday,
degreeId: ele.degreeId,
departmentId: ele.departmentId,
status: ele.status,
phone: ele.phone,
email: ele.email,
licensedToWork: ele.licensedToWork,
positionId: ele.positionId,
titleId: ele.titleId,
departmentTitle: ele.departmentTitle,
};
tempList.push(obj);
});
let parms = {
list: tempList,
};
Api.userImport(parms).then((res) => {
if (res.success) {
this.$Message.success("批量导入成功!");
this.$refs.grid.load();
this.cancelExcel();
} else {
this.$Message.error("批量导入失败!");
}
});
},
//取消导入excel
cancelExcel() {
this.modalImport = false;
this.excelData = [];
this.$refs.uploadfile.clearFiles();
},
//旧方法,设置dirname,通过取excel第一行的数据定义colums
async beforeUploadOld(file) {
this.excelData = [];
......@@ -957,6 +763,52 @@ export default {
console.log(workbook);
return false;
},
//导入功能
openModalIm() {
this.ModalIm = true
},
ModalImCancel() {
this.ModalIm = false
},
ok() {
this.$refs.grid.load();
},
getData(val) {
let url = `${systemUrl}/userimportservice/import`;
this.$refs.importExcel.deelData(url, this.columns, this.formatMethod(val))
},
//根据页面二次处理数据
formatMethod(val) {
let tempData = this.$u.clone(val);
let tempList = [];
tempData.forEach((ele) => {
let obj = {
userName: ele.userName ? ele.userName : '',
cardNo: ele.cardNo ? ele.cardNo : '', //用户编号
gender: ele.gender ? ele.gender : '', //性别
birthday: ele.birthday ? ele.birthday : '',
degreeId: ele.degreeId ? ele.degreeId : '',
departmentId: ele.departmentId ? ele.departmentId : null,
status: ele.status ? ele.status : null,
phone: ele.phone ? ele.phone : '',
email: ele.email ? ele.email : '',
licensedToWork: ele.licensedToWork ? ele.licensedToWork : null,
positionId: ele.positionId ? ele.positionId : null,
titleId: ele.titleId ? ele.titleId : null,
departmentTitle: ele.departmentTitle ? ele.departmentTitle : '',
};
if (ele.userName && ele.userName != '' && ele.cardNo && ele.cardNo != '' && ele.departmentId && ele.departmentId != null && ele.phone && ele.phone != '') {
obj.ico = false
} else {
obj.ico = true
}
tempList.push(obj);
});
return tempList
},
//批量导入end
},
computed: {
searchList() {
......
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