Commit 1ed98213 authored by renjintao's avatar renjintao

user

parent 488c9b1d
......@@ -2627,7 +2627,7 @@
},
"adler-32": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/adler-32/download/adler-32-1.2.0.tgz",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.2.0.tgz",
"integrity": "sha1-aj5r8KY5ALoVZSgIyxXGgT0aXyU=",
"requires": {
"exit-on-epipe": "~1.0.1",
......@@ -4774,7 +4774,7 @@
},
"codepage": {
"version": "1.14.0",
"resolved": "https://registry.npm.taobao.org/codepage/download/codepage-1.14.0.tgz",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.14.0.tgz",
"integrity": "sha1-jL4lSBMjVZ19MHVxsP/5HnodL5k=",
"requires": {
"commander": "~2.14.1",
......@@ -6226,7 +6226,7 @@
},
"echarts": {
"version": "4.8.0",
"resolved": "https://registry.npm.taobao.org/echarts/download/echarts-4.8.0.tgz?cache=0&sync_timestamp=1596215792462&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fecharts%2Fdownload%2Fecharts-4.8.0.tgz",
"resolved": "https://registry.npm.taobao.org/echarts/download/echarts-4.8.0.tgz",
"integrity": "sha1-ssHPuSKbE9No7hBPyO6mALV01MQ=",
"requires": {
"zrender": "4.3.1"
......@@ -20598,7 +20598,7 @@
},
"zrender": {
"version": "4.3.1",
"resolved": "https://registry.npm.taobao.org/zrender/download/zrender-4.3.1.tgz?cache=0&sync_timestamp=1596718989769&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fzrender%2Fdownload%2Fzrender-4.3.1.tgz",
"resolved": "https://registry.npm.taobao.org/zrender/download/zrender-4.3.1.tgz?cache=0&sync_timestamp=1597683748542&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fzrender%2Fdownload%2Fzrender-4.3.1.tgz",
"integrity": "sha1-uviqbcgYei+BlpLX1fm+36K5D6M="
}
}
......
<template>
<Layout class="full">
<Sider
hide-trigger
:style="{background: '#fff'}"
width="260"
class="menu"
style=" flex:0;border:none"
>
<div class="zh-tree" :style="{height:treeHeight+'px'}">
<h3 class="zh-title">部门结构</h3>
<div class="zh-box">
<Input search placeholder="请输入查询条件" v-model="treeInputSearch" />
<Tree :data="searchList" class="tree-content" @on-select-change="selectTreeNode"></Tree>
<Layout class="full">
<Sider hide-trigger :style="{background: '#fff'}" width="260" class="menu" style=" flex:0;border:none">
<div class="zh-tree" :style="{height:treeHeight+'px'}">
<h3 class="zh-title">部门结构</h3>
<div class="zh-box">
<Input search placeholder="请输入查询条件" v-model="treeInputSearch" />
<Tree :data="searchList" class="tree-content" @on-select-change="selectTreeNode"></Tree>
</div>
</div>
</div>
</Sider>
<Content class="content">
<DataGrid
:columns="columns"
ref="grid"
:action="action"
:conditions="easySearch"
placeholder="请输入姓名/员工编号"
: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>
</template>
</DataGrid>
<Modal v-model="addModal" title="新增" footer-hide width="800">
<Add @on-close="cancel" @on-ok="addOk" />
</Modal>
<Modal v-model="editModal" title="编辑" footer-hide width="800">
<Edit :eid="curId" @on-close="cancel" @on-ok="addOk" />
</Modal>
<Modal v-model="detailModal" title="详情" width="900">
<Detail :eid="curId" />
</Modal>
<Modal v-model="deletelModal" title="删除" @on-ok="removeOk" @on-cancel="cancel">
<p>确定删除?</p>
</Modal>
<!-- 重置密码 -->
<Modal
v-model="show7"
title="提示"
:mask-closable="false"
ok-text="确定"
cancel-text="取消"
@on-ok="reset"
>此操作将密码重置为初始密码, 是否继续?</Modal>
<!-- 授权 -->
<Modal
v-model="show3"
title="授权-当前用户"
:width="800"
:mask-closable="false"
ok-text="保存"
cancel-text="取消"
@on-ok="authOk"
@on-cancel="authCancle"
>
<div style="max-height:400px;overflow:auto">
<Form :model="authModel" :label-width="70">
<Row>
<Col span="24">
默认角色
<!-- <Input type="textarea" size="large" :rows="2" v-model="defaultRole" placeholder="暂无数据"/>
<DataGrid :columns="columns" ref="grid" :action="action" :conditions="easySearch" placeholder="请输入姓名/员工编号" :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>
</template>
</DataGrid>
<Modal v-model="addModal" title="新增" footer-hide width="800">
<Add @on-close="cancel" @on-ok="addOk" />
</Modal>
<Modal v-model="editModal" title="编辑" footer-hide width="800">
<Edit :eid="curId" @on-close="cancel" @on-ok="addOk" />
</Modal>
<Modal v-model="detailModal" title="详情" width="900">
<Detail :eid="curId" />
</Modal>
<Modal v-model="deletelModal" title="删除" @on-ok="removeOk" @on-cancel="cancel">
<p>确定删除?</p>
</Modal>
<!-- 重置密码 -->
<Modal v-model="show7" title="提示" :mask-closable="false" ok-text="确定" cancel-text="取消" @on-ok="reset">此操作将密码重置为初始密码, 是否继续?</Modal>
<!-- 授权 -->
<Modal v-model="show3" title="授权-当前用户" :width="800" :mask-closable="false" ok-text="保存" cancel-text="取消" @on-ok="authOk" @on-cancel="authCancle">
<div style="max-height:400px;overflow:auto">
<Form :model="authModel" :label-width="70">
<Row>
<Col span="24">
默认角色
<!-- <Input type="textarea" size="large" :rows="2" v-model="defaultRole" placeholder="暂无数据"/>
-->
<div style="width:750px;border:2px solid #E8EAEC;margin-top:10px">
<Row>
<CheckboxGroup v-model="authModel.default">
<Col
span="5"
offset="1"
v-for="(item,index) in authList1"
:key="index"
style="line-height:33px;font-size:14px;"
>
<Checkbox :label="item.id">{{item.name}}</Checkbox>
</Col>
</CheckboxGroup>
</Row>
</div>
</Col>
</Row>
<Row>
<Col span="24">
<div style="margin-top:10px;">
自定义角色
<div style="width:750px;border:2px solid #E8EAEC;margin-top:10px">
<div style="width:750px;border:2px solid #E8EAEC;margin-top:10px">
<Row>
<CheckboxGroup v-model="authModel.default">
<Col span="5" offset="1" v-for="(item,index) in authList1" :key="index" style="line-height:33px;font-size:14px;">
<Checkbox :label="item.id">{{item.name}}</Checkbox>
</Col>
</CheckboxGroup>
</Row>
</div>
</Col>
</Row>
<Row>
<CheckboxGroup v-model="authModel.extra">
<Col
span="5"
offset="1"
v-for="(item,index) in authList"
:key="index"
style="line-height:33px;font-size:14px;"
>
<Checkbox :label="item.id">{{item.name}}</Checkbox>
<Col span="24">
<div style="margin-top:10px;">
自定义角色
<div style="width:750px;border:2px solid #E8EAEC;margin-top:10px">
<Row>
<CheckboxGroup v-model="authModel.extra">
<Col span="5" offset="1" v-for="(item,index) in authList" :key="index" style="line-height:33px;font-size:14px;">
<Checkbox :label="item.id">{{item.name}}</Checkbox>
</Col>
</CheckboxGroup>
</Row>
</div>
</div>
</Col>
</CheckboxGroup>
</Row>
</div>
</div>
</Col>
</Row>
</Form>
</div>
</Modal>
<Modal v-model="syncAccountModal" title="同步账户" @on-ok="syncAccountOk" @on-cancel="cancel">
<p>确定同步账户?</p>
</Modal>
<Modal v-model="modalImport" title="导入excel" fullscreen hidefooter>
<Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList">
<Button icon="ios-cloud-upload-outline">上传Excel文件</Button>
</Upload>
<DataGrid
border
:height="tdHeightExcel"
:columns="columnsImport"
:data="excelData"
:tool="false"
:page="false"
:set="false"
></DataGrid>
<div slot="footer">
<span v-if="excelData.length>0">共 {{excelData.length}} 条数据</span>
<Button @click="cancelExcel">取消</Button>
<Button type="primary" @click="importOk">确定导入</Button>
</div>
</Modal>
</Form>
</div>
</Modal>
<Modal v-model="syncAccountModal" title="同步账户" @on-ok="syncAccountOk" @on-cancel="cancel">
<p>确定同步账户?</p>
</Modal>
<Modal v-model="modalImport" title="导入excel" fullscreen hidefooter>
<Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList">
<Button icon="ios-cloud-upload-outline">上传Excel文件</Button>
</Upload>
<DataGrid border :height="tdHeightExcel" :columns="columnsImport" :data="excelData" :tool="false" :page="false" :set="false"></DataGrid>
<div slot="footer">
<span v-if="excelData.length>0">共 {{excelData.length}} 条数据</span>
<Button @click="cancelExcel">取消</Button>
<Button type="primary" @click="importOk">确定导入</Button>
</div>
</Modal>
</Content>
</Layout>
</Layout>
</template>
<script>
import Api from "./api";
import ApiDepart from "../department/api";
......@@ -149,849 +100,898 @@ import Detail from "./detail";
import Search from "./search";
import service from "@/plugins/request";
import util from "@/libs/util";
import { Time } from "view-design";
import {
Time
} from "view-design";
import XLSX from "xlsx";
export default {
name: "list",
components: {
Add,
Edit,
Detail,
Search,
},
data() {
return {
action: Api.index,
easySearch: {
keys: {
op:
"userName,cardNo,national,phone,email,enableEquip,jobNo,remark,departmentTitle,roleTitles",
value: null,
default: true,
},
departmentId: { op: "In", value: "" },
},
treeData: [],
tdHeight: "",
tdHeightExcel: "",
treeInputSearch: "",
treeHeight: "",
tableHeight: "",
show7: false, //重置密码
show3: false, //授权角色
authList: [],
authList1: [],
authModel: { default: [], extra: [] },
ids: [],
addModal: false,
editModal: false,
detailModal: false,
deletelModal: false,
syncAccountModal: false,
curId: 0,
columns: [
// {
// title: '序号',
// type: 'index',
// width: 80,
// align: 'center'
// },
{ key: "id", title: this.l("id"), hide: true, align: "left" },
{
key: "userName",
title: this.l("userName"),
align: "left",
easy: true,
high: true,
render: (h, params) => {
return h("div", { class: "action" }, [
h(
"op",
name: "list",
components: {
Add,
Edit,
Detail,
Search,
},
data() {
return {
action: Api.index,
easySearch: {
keys: {
op: "userName,cardNo,national,phone,email,enableEquip,jobNo,remark,departmentTitle,roleTitles",
value: null,
default: true,
},
departmentId: {
op: "In",
value: ""
},
},
treeData: [],
tdHeight: "",
tdHeightExcel: "",
treeInputSearch: "",
treeHeight: "",
tableHeight: "",
show7: false, //重置密码
show3: false, //授权角色
authList: [],
authList1: [],
authModel: {
default: [],
extra: []
},
ids: [],
addModal: false,
editModal: false,
detailModal: false,
deletelModal: false,
syncAccountModal: false,
curId: 0,
columns: [
// {
// title: '序号',
// type: 'index',
// width: 80,
// align: 'center'
// },
{
attrs: { oprate: "detail" },
on: { click: () => this.detail(params.row.id) },
key: "id",
title: this.l("id"),
hide: true,
align: "left"
},
params.row.userName
),
]);
},
},
// {
// key: 'cardTypeId',
// title: this.l('cardTypeId'),
// align: 'left',
// high: true,
// hide: true
// },
{
key: "cardNo",
title: this.l("cardNo"),
align: "left",
easy: true,
high: true,
{
key: "userName",
title: this.l("userName"),
align: "left",
easy: true,
high: true,
render: (h, params) => {
return h("div", {
class: "action"
}, [
h(
"op", {
attrs: {
oprate: "detail"
},
on: {
click: () => this.detail(params.row.id)
},
},
params.row.userName
),
]);
},
},
// {
// key: 'cardTypeId',
// title: this.l('cardTypeId'),
// align: 'left',
// high: true,
// hide: true
// },
{
key: "cardNo",
title: this.l("cardNo"),
align: "left",
easy: true,
high: true,
},
{
key: "gender",
title: this.l("gender"),
align: "center",
high: true,
code: "User.base.gender",
},
{
key: "birthday",
title: this.l("birthday"),
align: "center",
high: true,
type: "date",
},
{
key: "degreeId",
title: this.l("degreeId"),
align: "left",
high: true,
code: "User.base.degree",
},
{
key: "status",
title: this.l("status"),
align: "center",
high: true,
code: "User.base.status",
},
{
key: "departmentId",
title: this.l("departmentId"),
align: "right",
easy: true,
high: true,
},
{
key: "departmentTitle",
title: this.l("departmentTitle"),
align: "left",
easy: true,
high: true,
},
{
key: "roleTitles",
title: this.l("roleTitles"),
align: "left",
easy: true,
high: true,
hide: true,
render: (h, params) => {
return h("div", {
class: "action"
}, [
h(
"op", {
attrs: {
oprate: "detail",
class: params.row.roleTitles == null ||
params.row.roleTitles == "" ?
"empower" : "detail",
},
on: {
click: () => this.authorize(params.row.id)
},
},
params.row.roleTitles == null || params.row.roleTitles == "" ?
"授权" :
params.row.roleTitles
),
]);
},
},
{
key: "accountId",
title: this.l("accountId"),
hide: true,
align: "left",
},
// {
// key: 'userType',
// title: this.l('userType'),
// hide: true,
// align: 'left'
// },
{
key: "phone",
title: this.l("phone"),
align: "left",
easy: true,
high: true,
},
{
key: "email",
title: this.l("email"),
align: "left",
easy: true,
high: true,
},
{
key: "licensedToWork",
title: this.l("licensedToWork"),
align: "left",
},
{
key: "positionId",
title: this.l("positionId"),
align: "left",
high: true,
code: "User.base.position",
},
{
key: "titleId",
title: this.l("titleId"),
align: "left",
high: true,
code: "User.base.jobtitle",
},
{
key: "creatorUserId",
title: this.l("creatorUserId"),
align: "left",
import: false,
hide: true,
},
{
key: "creationTime",
title: this.l("creationTime"),
align: "left",
import: false,
hide: true,
},
{
key: "lastModifierUserId",
title: this.l("lastModifierUserId"),
align: "left",
import: false,
hide: true,
},
{
key: "lastModificationTime",
title: this.l("lastModificationTime"),
align: "left",
import: false,
hide: true,
},
{
title: "操作",
key: "action",
width: 180,
align: "right",
import: false,
render: (h, params) => {
return h("div", {
class: "action"
}, [
h(
"op", {
attrs: {
oprate: "detail",
class: "empower",
},
on: {
click: () => this.syncAccount(params.row)
},
},
params.row.accountId == 0 ? "同步" : ""
),
h(
"op", {
attrs: {
oprate: "edit"
},
on: {
click: () => this.edit(params.row.id)
},
},
"编辑"
),
h(
"op", {
attrs: {
oprate: "remove"
},
on: {
click: () => this.remove(params.row)
},
},
"删除"
),
h(
"op", {
attrs: {
oprate: "detail",
},
on: {
click: () => this.openReset(params.row)
},
},
"重置密码"
),
]);
},
},
],
selectRow: {}, //删除时选中的行数据
//导入导出时使用start
formatList: ["xlsx"],
searchs: {
pageIndex: 1,
pageSize: 1000,
conditions: [],
},
list: [],
modalImport: false,
excelData: [],
departArr: [], //部门list
columnsImport: [],
//导入导出时使用end
};
},
created() {
this.treeHeight = window.innerHeight - 150;
this.tdHeight = window.innerHeight - 240;
this.tdHeightExcel = window.innerHeight - 240;
//导出对列表头进行预加载start
let tempCol = this.$u.clone(this.columns);
tempCol.forEach((ele, index) => {
if (ele.key == "action") {
ele.hide = true;
}
});
this.columnsImport = tempCol;
//导出对列表头进行预加载end
},
mounted() {
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
window.screenHeight = window.innerHeight;
this.treeHeight = window.screenHeight - 150;
this.tdHeight = window.screenHeight - 240;
this.tdHeightExcel = window.innerHeight - 240;
})();
};
this.initTree();
this.loadrole(0);
this.loadrole(1);
},
async fetch({
store,
params
}) {
await store.dispatch("loadDictionary"); // 加载数据字典
},
methods: {
addOk() {
this.$refs.grid.load();
// this.$refs.grid.reload(this.easySearch)
this.addModal = false;
this.detailModal = false;
this.editModal = false;
this.curId = 0;
//this.$refs.grid.easySearch()
},
{
key: "gender",
title: this.l("gender"),
align: "center",
high: true,
code: "User.base.gender",
search() {
this.$refs.grid.reload(this.easySearch);
},
{
key: "birthday",
title: this.l("birthday"),
align: "center",
high: true,
type: "date",
detail(id) {
this.detailModal = true;
this.curId = id;
},
{
key: "degreeId",
title: this.l("degreeId"),
align: "left",
high: true,
code: "User.base.degree",
edit(id) {
this.editModal = true;
this.curId = id;
},
{
key: "status",
title: this.l("status"),
align: "center",
high: true,
code: "User.base.status",
remove(row) {
this.deletelModal = true;
this.curId = row.id;
this.selectRow = row;
},
{
key: "departmentId",
title: this.l("departmentId"),
align: "right",
easy: true,
high: true,
removeOk() {
Api.delete({
id: this.curId
}).then((r) => {
if (r.success) {
this.$refs.grid.load();
this.deletelModal = false;
if (this.selectRow.accountId > 0) {
//删除成功后更新auth start
let parms = {
userId: this.curId,
accountId: this.selectRow.accountId,
tenantCode: util.cookies.get("tanantCode"),
isDeleted: true,
name: this.selectRow.userName,
};
Api.authAccount(parms).then((res) => {
if (res.success) {
this.$Message.success("账户同步成功");
}
});
}
//删除成功后更新auth end
this.$Message.success("删除成功");
}
});
},
{
key: "departmentTitle",
title: this.l("departmentTitle"),
align: "left",
easy: true,
high: true,
removeCancel() {
this.deletelModal = false;
},
{
key: "roleTitles",
title: this.l("roleTitles"),
align: "left",
easy: true,
high: true,
hide: true,
render: (h, params) => {
return h("div", { class: "action" }, [
h(
"op",
{
attrs: {
oprate: "detail",
class:
params.row.roleTitles == null ||
params.row.roleTitles == ""
? "empower"
: "detail",
},
on: { click: () => this.authorize(params.row.id) },
},
params.row.roleTitles == null || params.row.roleTitles == ""
? "授权"
: params.row.roleTitles
),
]);
},
cancel() {
this.curId = 0;
this.addModal = false;
this.detailModal = false;
this.editModal = false;
this.deletedlModal = false;
this.syncAccountModal = false;
},
{
key: "accountId",
title: this.l("accountId"),
hide: true,
align: "left",
l(key) {
let vkey = "user" + "." + key;
return this.$t(vkey) || key;
},
// {
// key: 'userType',
// title: this.l('userType'),
// hide: true,
// align: 'left'
// },
{
key: "phone",
title: this.l("phone"),
align: "left",
easy: true,
high: true,
initTree() {
this.$http.department.getDepartmentTree(this.treeData);
},
{
key: "email",
title: this.l("email"),
align: "left",
easy: true,
high: true,
selectTreeNode1(value) {
if (value != "") {
this.searchObj.departmentId = null;
this.searchObj.level_Desc = value[0].value;
this.mDatas.splice(0);
this.$http.sysUser.getSearchTable2(this.mDatas, this.searchObj);
}
},
{
key: "licensedToWork",
title: this.l("licensedToWork"),
align: "left",
selectTreeNode(value) {
if (value.length > 0) {
this.ids = [];
this.getAllIds(value);
if (this.ids.length > 0) {
this.easySearch.departmentId.value = this.ids;
} else {
this.easySearch.departmentId.value = [-1];
}
this.$refs.grid.easySearch();
}
},
{
key: "positionId",
title: this.l("positionId"),
align: "left",
high: true,
code: "User.base.position",
getAllIds(trees) {
trees.forEach((data, index) => {
var that = this;
this.ids.push(data.value);
if (data.children.length > 0) {
this.getAllIds(data.children);
}
});
},
{
key: "titleId",
title: this.l("titleId"),
align: "left",
high: true,
code: "User.base.jobtitle",
//重置密碼
openReset(row) {
this.show7 = true;
this.curId = row.id;
this.selectRow = row;
},
{
key: "creatorUserId",
title: this.l("creatorUserId"),
align: "left",
import: false,
hide: true,
reset() {
let parms = {
userId: this.curId,
accountId: this.selectRow.accountId,
};
Api.authResetpassword(parms).then((res) => {
if (res.success) {
this.$Message.success("重置成功!");
} else {
this.$Message.error("重置失败!");
}
});
},
{
key: "creationTime",
title: this.l("creationTime"),
align: "left",
import: false,
hide: true,
//授权角色
loadrole(type) {
var url = `${systemUrl}/MyRole/GetRolesAsync`;
var data = [];
service.get(`${url}`, {
role_type: type
}).then((response) => {
data = response.result.items;
if (type == 1) {
this.authList = data;
}
if (type == 0) {
this.authList1 = data;
}
});
},
{
key: "lastModifierUserId",
title: this.l("lastModifierUserId"),
align: "left",
import: false,
hide: true,
authorize(id) {
//授权
this.authModel.default = [];
this.authModel.extra = [];
this.curId = id;
this.show3 = true;
var url = `${systemUrl}/MyUserRole/GetPaged`;
service.get(`${url}`, {
userId: id
}).then((response) => {
var data = response.result.items;
var dt1 = data.filter(function (ite) {
return ite.role_type == 0;
});
var dt2 = data.filter(function (ite) {
return ite.role_type == 1;
});
dt1.forEach((item, i) => {
this.authModel.default.push(item.roleId);
});
dt2.forEach((item, i) => {
this.authModel.extra.push(item.roleId);
});
});
},
{
key: "lastModificationTime",
title: this.l("lastModificationTime"),
align: "left",
import: false,
hide: true,
authOk() {
var url = `${systemUrl}/MyUserRole/CreateOrUpdate`;
service
.post(`${url}`, {
myUserRole: {
userId: this.curId,
RoleIds: this.allChecked.join(","),
},
})
.then((response) => {
if (response.success) {
this.$Message.success("保存成功");
this.authModel.extra = [];
this.authModel.default = [];
this.$refs.grid.easySearch();
}
})
.catch((error) => {
this.$Message.error("保存失败");
});
},
{
title: "操作",
key: "action",
width: 180,
align: "right",
import: false,
render: (h, params) => {
return h("div", { class: "action" }, [
h(
"op",
{
attrs: {
oprate: "detail",
class: "empower",
},
on: { click: () => this.syncAccount(params.row) },
},
params.row.accountId == 0 ? "同步" : ""
),
h(
"op",
{
attrs: { oprate: "edit" },
on: { click: () => this.edit(params.row.id) },
},
"编辑"
),
h(
"op",
{
attrs: { oprate: "remove" },
on: { click: () => this.remove(params.row) },
},
"删除"
),
h(
"op",
{
attrs: {
oprate: "detail",
},
on: { click: () => this.openReset(params.row) },
},
"重置密码"
),
]);
},
authCancle() {},
//同步账户start
syncAccount(row) {
this.syncAccountModal = true;
this.selectRow = row;
},
],
selectRow: {}, //删除时选中的行数据
//导入导出时使用start
formatList: ["xlsx"],
searchs: {
pageIndex: 1,
pageSize: 1000,
conditions: [],
},
list: [],
modalImport: false,
excelData: [],
departArr: [], //部门list
columnsImport: [],
//导入导出时使用end
};
},
created() {
this.treeHeight = window.innerHeight - 150;
this.tdHeight = window.innerHeight - 240;
this.tdHeightExcel = window.innerHeight - 240;
//导出对列表头进行预加载start
let tempCol = this.$u.clone(this.columns);
tempCol.forEach((ele, index) => {
if (ele.key == "action") {
ele.hide = true;
}
});
this.columnsImport = tempCol;
//导出对列表头进行预加载end
},
mounted() {
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
window.screenHeight = window.innerHeight;
this.treeHeight = window.screenHeight - 150;
this.tdHeight = window.screenHeight - 240;
this.tdHeightExcel = window.innerHeight - 240;
})();
};
this.initTree();
this.loadrole(0);
this.loadrole(1);
},
async fetch({ store, params }) {
await store.dispatch("loadDictionary"); // 加载数据字典
},
methods: {
addOk() {
this.$refs.grid.load();
// this.$refs.grid.reload(this.easySearch)
this.addModal = false;
this.detailModal = false;
this.editModal = false;
this.curId = 0;
//this.$refs.grid.easySearch()
},
search() {
this.$refs.grid.reload(this.easySearch);
},
detail(id) {
this.detailModal = true;
this.curId = id;
},
edit(id) {
this.editModal = true;
this.curId = id;
},
remove(row) {
this.deletelModal = true;
this.curId = row.id;
this.selectRow = row;
},
removeOk() {
Api.delete({ id: this.curId }).then((r) => {
if (r.success) {
this.$refs.grid.load();
this.deletelModal = false;
if (this.selectRow.accountId > 0) {
//删除成功后更新auth start
syncAccountOk() {
let parms = {
userId: this.curId,
accountId: this.selectRow.accountId,
tanantCode: util.cookies.get("tanantCode"),
isDeleted: true,
name: this.selectRow.userName,
userId: this.selectRow.id,
loginName: this.selectRow.phone,
status: this.selectRow.status,
tenantCode: util.cookies.get("tanantCode"),
name: this.selectRow.userName,
};
Api.authAccount(parms).then((res) => {
if (res.success) {
this.$Message.success("账户同步成功");
}
});
}
//删除成功后更新auth end
if (this.selectRow.phone && this.selectRow.phone != "") {
Api.authAccount(parms).then((res) => {
if (res.success) {
this.$Message.success("账户同步成功");
let parms1 = {
userId: parms.userId,
accountId: res.result,
};
Api.updateAccount(parms1).then((res1) => {
if (res1.success) {
this.$Message.success("操作成功");
this.$refs.grid.easySearch();
} else {
this.$Message.error("同步失败");
}
});
}
});
} else {
this.$Message.error("请完善个人电话信息");
}
},
//同步账户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.$Message.success("删除成功");
}
});
},
removeCancel() {
this.deletelModal = false;
},
cancel() {
this.curId = 0;
this.addModal = false;
this.detailModal = false;
this.editModal = false;
this.deletedlModal = false;
this.syncAccountModal = false;
},
l(key) {
let vkey = "user" + "." + key;
return this.$t(vkey) || key;
},
initTree() {
this.$http.department.getDepartmentTree(this.treeData);
},
selectTreeNode1(value) {
if (value != "") {
this.searchObj.departmentId = null;
this.searchObj.level_Desc = value[0].value;
this.mDatas.splice(0);
this.$http.sysUser.getSearchTable2(this.mDatas, this.searchObj);
}
},
selectTreeNode(value) {
if (value.length > 0) {
this.ids = [];
this.getAllIds(value);
if (this.ids.length > 0) {
this.easySearch.departmentId.value = this.ids;
} else {
this.easySearch.departmentId.value = [-1];
}
this.$refs.grid.easySearch();
}
},
getAllIds(trees) {
trees.forEach((data, index) => {
var that = this;
this.ids.push(data.value);
if (data.children.length > 0) {
this.getAllIds(data.children);
}
});
},
//重置密碼
openReset(row) {
this.show7 = true;
this.curId = row.id;
this.selectRow = row;
},
reset() {
let parms = {
userId: this.curId,
accountId: this.selectRow.accountId,
};
Api.authResetpassword(parms).then((res) => {
if (res.success) {
this.$Message.success("重置成功!");
} else {
this.$Message.error("重置失败!");
}
});
},
//授权角色
loadrole(type) {
var url = `${systemUrl}/MyRole/GetRolesAsync`;
var data = [];
service.get(`${url}`, { role_type: type }).then((response) => {
data = response.result.items;
if (type == 1) {
this.authList = data;
}
if (type == 0) {
this.authList1 = data;
}
});
},
authorize(id) {
//授权
this.authModel.default = [];
this.authModel.extra = [];
this.curId = id;
this.show3 = true;
var url = `${systemUrl}/MyUserRole/GetPaged`;
service.get(`${url}`, { userId: id }).then((response) => {
var data = response.result.items;
var dt1 = data.filter(function (ite) {
return ite.role_type == 0;
});
var dt2 = data.filter(function (ite) {
return ite.role_type == 1;
});
dt1.forEach((item, i) => {
this.authModel.default.push(item.roleId);
});
dt2.forEach((item, i) => {
this.authModel.extra.push(item.roleId);
});
});
},
authOk() {
var url = `${systemUrl}/MyUserRole/CreateOrUpdate`;
service
.post(`${url}`, {
myUserRole: {
userId: this.curId,
RoleIds: this.allChecked.join(","),
},
})
.then((response) => {
if (response.success) {
this.$Message.success("保存成功");
this.authModel.extra = [];
this.authModel.default = [];
this.$refs.grid.easySearch();
}
})
.catch((error) => {
this.$Message.error("保存失败");
});
},
authCancle() {},
//同步账户start
syncAccount(row) {
this.syncAccountModal = true;
this.selectRow = row;
},
syncAccountOk() {
let parms = {
userId: this.selectRow.id,
loginName: this.selectRow.phone,
status: this.selectRow.status,
tanantCode: util.cookies.get("tanantCode"),
name: this.selectRow.userName,
};
if (this.selectRow.phone && this.selectRow.phone != "") {
Api.authAccount(parms).then((res) => {
if (res.success) {
this.$Message.success("账户同步成功");
let parms1 = {
userId: parms.userId,
accountId: res.result,
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赋值为空的字符串
};
Api.updateAccount(parms1).then((res1) => {
if (res1.success) {
this.$Message.success("操作成功");
this.$refs.grid.easySearch();
} else {
this.$Message.error("同步失败");
}
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);
}
});
});
}
});
} else {
this.$Message.error("请完善个人电话信息");
}
},
//同步账户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));
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];
}
});
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,
});
result.push(obj);
}
}
});
}
this.searchs.pageIndex = 1;
this.searchs.conditions = where;
this.searchs.pageSize = 1000;
//对读取的excel文件数据进行处理
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
});
}
});
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;
}
});
}
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.accountreset(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 = [];
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
//对列表里的数据字典项进行处理
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]
const workbook = await this.$u.readXLSX(file);
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var tempList = XLSX.utils.sheet_to_json(
workbook.Sheets[workbook.SheetNames[0]],
sheet2JSONOpts
);
}
});
});
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.accountreset(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 = [];
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
const workbook = await this.$u.readXLSX(file);
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var tempList = XLSX.utils.sheet_to_json(
workbook.Sheets[workbook.SheetNames[0]],
sheet2JSONOpts
);
//对读取的excel文件数据进行处理
var tempColums = this.$u.clone(this.columnsImport);
var arrTitles = Object.keys(tempList[0]); //获取列表title
var arrTitleUse = []; //使用数据字典的字段
tempColums.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({ key: elCode.key, code: elCode.code });
}
});
//对读取的excel文件数据进行处理
var tempColums = this.$u.clone(this.columnsImport);
var arrTitles = Object.keys(tempList[0]); //获取列表title
var arrTitleUse = []; //使用数据字典的字段
tempColums.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({
key: elCode.key,
code: elCode.code
});
}
});
tempList.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;
}
});
}
tempList.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.dirName(
this.$store.getters.dictionaryByKey(elem.code),
ele[elem.key]
);
}
});
});
//对列表里的数据字典项进行处理
arrTitleUse.forEach((elem) => {
if (ele[elem.key] && ele[elem.key] != "" && ele[elem.key] != null) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
ele[elem.key] = this.$u.dirName(
this.$store.getters.dictionaryByKey(elem.code),
ele[elem.key]
);
}
});
});
this.excelData = tempList;
console.log(workbook);
return false;
},
},
computed: {
searchList() {
let nodeList = this.treeData;
var text = this.treeInputSearch;
var newNodeList = [];
function searchTree(nodeLists, value) {
for (let i = 0; i < nodeLists.length; i++) {
if (nodeLists[i].title.indexOf(value) != -1) {
newNodeList.push(nodeLists[i]);
} else if (nodeLists[i].children.length > 0) {
searchTree(nodeLists[i].children, value);
}
}
}
if (text != "") {
searchTree(nodeList, text);
} else {
return nodeList;
}
return newNodeList;
this.excelData = tempList;
console.log(workbook);
return false;
},
},
allChecked: function () {
return [...this.authModel.extra, ...this.authModel.default];
computed: {
searchList() {
let nodeList = this.treeData;
var text = this.treeInputSearch;
var newNodeList = [];
function searchTree(nodeLists, value) {
for (let i = 0; i < nodeLists.length; i++) {
if (nodeLists[i].title.indexOf(value) != -1) {
newNodeList.push(nodeLists[i]);
} else if (nodeLists[i].children.length > 0) {
searchTree(nodeLists[i].children, value);
}
}
}
if (text != "") {
searchTree(nodeList, text);
} else {
return nodeList;
}
return newNodeList;
},
allChecked: function () {
return [...this.authModel.extra, ...this.authModel.default];
},
},
},
};
</script>
<style lang="less" scoped>
.full {
margin-top: 0;
.content {
margin-top: 10px;
}
margin-top: 0;
.content {
margin-top: 10px;
}
}
</style>
\ No newline at end of file
</style>
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