Commit e4fed9fa authored by renjintao's avatar renjintao

importimport

parent c511ba38
<template>
<div class="table-content">
<div class="table-content">
<div class="table-tools" v-if="tool">
<div class="table-search">
<slot name="easySearch" v-if="easy">
<Form inline>
<FormItem>
<Input
search
enter-button
:placeholder="placeholder"
@on-search="easySearch"
v-width="300"
v-model="keys"
/>
<Input search enter-button :placeholder="placeholder" @on-search="easySearch" v-width="300" v-model="keys" />
</FormItem>
<FormItem>
<Button v-if="high" @click="modalSearch=true" type="text">
......@@ -40,38 +33,11 @@
</slot>
</Col>
</Row>
<Table
v-else
:border="border"
:columns="columnsNow"
:data="list"
:height="tableHeight"
:draggable="draggable"
ref="table"
class="tableCommon"
@on-expand="expand"
@on-drag-drop="onDragDrop"
@on-selection-change="selectionChange"
@on-select="onSelect"
:row-key="rowKey"
></Table>
<Table v-else :border="border" :columns="columnsNow" :data="list" :height="tableHeight" :draggable="draggable" ref="table" class="tableCommon" @on-expand="expand" @on-drag-drop="onDragDrop" @on-selection-change="selectionChange" @on-select="onSelect" :row-key="rowKey"></Table>
</div>
<div class="table-footer">
<slot name="footer"></slot>
<Page
v-if="page"
:total="search.total"
:current="search.page"
class="fr"
show-total
size="small"
show-elevator
show-sizer
:page-size="search.pageSize"
:page-size-opts="pageSizeOpts"
@on-change="pageChange"
@on-page-size-change="pageSizeChange"
/>
<Page v-if="page" :total="search.total" :current="search.page" class="fr" show-total size="small" show-elevator show-sizer :page-size="search.pageSize" :page-size-opts="pageSizeOpts" @on-change="pageChange" @on-page-size-change="pageSizeChange" />
</div>
<Modal v-if="high" v-model="modalSearch" title="高级搜索" draggable width="800" ref="search">
<slot name="searchForm"></slot>
......@@ -80,14 +46,7 @@
<Button @click="complexSearch" type="primary" style="margin-left:10px;">查询</Button>
</div>
</Modal>
<Drawer
title="列设置"
v-if="set"
v-model="config"
:scrollable="true"
placement="left"
:mask="false"
>
<Drawer title="列设置" v-if="set" v-model="config" :scrollable="true" placement="left" :mask="false">
<div slot="header">
列设置
<a @click="undoConfig" class="ml50">
......@@ -95,11 +54,7 @@
</a>
</div>
<ul class="table-columns">
<li
v-for="(li,index) in columnsCur"
:key="index"
v-dragging="{ item: li, list: columnsCur, group: 'li' }"
>
<li v-for="(li,index) in columnsCur" :key="index" v-dragging="{ item: li, list: columnsCur, group: 'li' }">
<label @click="columnChange(li,index)" :class="{dis:li.hide}">
<Icon :type="li.hide?'md-eye-off':'md-eye'" size="16" class="mr10" />
<span>{{li.title}}</span>
......@@ -113,7 +68,7 @@
<slot name="batch"></slot>
<Button @click="cancelBatch">取消</Button>
</FooterToolbar>
</div>
</div>
</template>
<script>
......@@ -226,7 +181,11 @@ export default {
type: Object,
default: function () {
return {
keys: { op: "name", value: "", default: true },
keys: {
op: "name",
value: "",
default: true
},
};
},
},
......@@ -342,8 +301,7 @@ export default {
},
loadUserConfig() {
var query = {
conditions: [
{
conditions: [{
fieldName: "creatorUserId",
fieldValue: this.userId,
conditionalType: "Equal",
......@@ -561,13 +519,13 @@ export default {
},
},
watch: {
"data.length"() {
"data"() {
this.list = this.data;
},
height() {
this.tableHeight = this.height;
},
"columns.length"() {
"columns"() {
this.columns.forEach((u) => {
if (!u.hide) {
u.hide = false;
......@@ -585,16 +543,20 @@ export default {
height: 100%;
display: flex;
flex-direction: column;
.tip {
display: inline;
}
form {
display: inline-block;
.ivu-form-item {
margin: 0;
vertical-align: middle;
}
}
.table-main {
width: 100%;
text-align: left;
......@@ -602,66 +564,83 @@ export default {
display: block;
overflow-y: auto;
flex-grow: 1;
tr td .ivu-table-cell {
padding: 0 5px;
}
overflow-x: hidden;
}
.table-tools {
display: flex;
line-height: 50px;
.table-search {
flex-grow: 1;
}
.btns {
min-width: 200px;
text-align: right;
}
}
.table-footer {
line-height: 45px;
}
.ivu-footer-toolbar {
text-align: left;
background: rgba(0, 0, 0, 0.7);
color: #fff;
}
}
.table-columns {
max-height: calc(100% - 50px);
overflow: auto;
li {
list-style: none;
line-height: 40px;
cursor: move;
border-bottom: 1px dotted #249e91;
color: #249e91;
span {
cursor: pointer;
}
.mr10 {
cursor: pointer;
}
.move {
float: right;
margin: 10px 10px 0 0;
cursor: move;
}
.dis {
color: #aaa;
}
}
}
.searchBack {
display: inline;
margin-left: 20px;
button {
margin-left: 10px;
}
a {
margin-left: 20px;
color: #2680eb;
}
a:hover {
color: #249e91;
}
......
<template>
<Form ref="form" :model="entity" :rules="rules" :label-width="90">
<template>
<Form ref="form" :model="entity" :rules="rules" :label-width="90">
<Row>
<Col :span="12">
......@@ -22,9 +22,10 @@
<Button type="primary" @click="handleSubmit" :disabled="disabled">保存</Button>
<Button @click="handleClose" class="ml20">取消</Button>
</FormItem>
</Form>
</Form>
</template>
<script>
<script>
import Api from "./api";
import InputExcel from "@/components/page/inputExcel.vue";
export default {
......@@ -35,17 +36,25 @@ export default {
data() {
return {
disabled: false,
parms: "app=import&eid="+this.$u.guid()+"&name=excel",
parms: "app=import&eid=" + this.$u.guid() + "&name=excel",
imgName: "",
entity: {
name: "",
file: "",
filePath:"",
path: "",
remark: "",
},
rules: {
name: [{ required: true, message: "必填", trigger: "blur" }],
file:[{ required: true, message: "请上传文件", trigger: "change" }]
name: [{
required: true,
message: "必填",
trigger: "blur"
}],
file: [{
required: true,
message: "请上传文件",
trigger: "change"
}]
},
};
},
......@@ -85,7 +94,9 @@ export default {
this.$emit("on-close");
},
load(v) {
Api.get({ id: v }).then((r) => {
Api.get({
id: v
}).then((r) => {
this.entity = r.result;
this.entity.id = 0;
});
......@@ -103,8 +114,8 @@ export default {
watch: {
imgName(newName, oldName) {
const imgPathsArr = JSON.parse(newName);
this.entity.file=imgPathsArr[0].fileName
this.entity.filePath=imgPathsArr[0].filePath
this.entity.file = imgPathsArr[0].fileName
this.entity.path = imgPathsArr[0].filePath
},
v() {
this.entity = this.$u.clone(this.v);
......
......@@ -24,5 +24,8 @@ export default {
deletes(params) {
return Api.post(`${systemUrl}/importcenter/batchdelete`, params);
},
openExcel(params) {//处理时打开以前上传的excel返回数据
return Api.post(`${systemUrl}/importcenter/open`, params);
},
}
<template>
<div class="detail">
<div class="detail">
<Row>
<Filed :span="12" :name="l('name')">{{entity.name}}</Filed>
<Filed :span="12" :name="l('file')"><a @click="downFile(entity.filePath)">{{entity.file}}</a></Filed>
<Filed :span="12" :name="l('status')">{{entity.status}}</Filed>
<Filed :span="12" :name="l('file')">
<a @click="downFile(entity.path)">{{entity.file}}</a>
</Filed>
<Filed :span="12" :name="l('status')">
<state code="improt.im.status" :value="entity.status" type="text"></state>
</Filed>
<Filed :span="24" :name="l('remark')">{{entity.remark}}</Filed>
<Filed :span="12" :name="l('creationTime')">{{entity.creationTime}}</Filed>
<Filed :span="12" :name="l('creatorUserId')">{{entity.creatorUserId}}</Filed>
<Filed :span="12" :name="l('creatorUserId')">
<User :value="entity.creatorUserId"></User>
</Filed>
<!--
<Filed :span="12" :name="l('lastModificationTime')">{{entity.lastModificationTime}}</Filed>
<Filed :span="12" :name="l('lastModifierUserId')">{{entity.lastModifierUserId}}</Filed>
<Filed :span="12" :name="l('lastModifierUserId')">
{{entity.lastModifierUserId}}
<User :value="entity.lastModifierUserId"></User>
</Filed>
<Filed :span="12" :name="l('isDeleted')">{{entity.isDeleted}}</Filed>
<Filed :span="12" :name="l('deletionTime')">{{entity.deletionTime}}</Filed>
<Filed :span="12" :name="l('deleterUserId')">{{entity.deleterUserId}}</Filed>
<Filed :span="12" :name="l('deleterUserId')">
{{entity.deleterUserId}}
<User :value="entity.deleterUserId"></User>
</Filed>
<Filed :span="12" :name="l('creator')">{{entity.creator}}</Filed>
<Filed :span="12" :name="l('lastModifier')">{{entity.lastModifier}}</Filed>
-->
</Row>
</div>
</div>
</template>
<script>
import Api from "./api";
export default {
......@@ -28,8 +42,16 @@ export default {
downUrl: fileUrlDown,
fileUrlPath: "",
rules: {
name: [{ required: true, message: "必填", trigger: "blur" }],
code: [{ required: true, message: "必填", trigger: "blur" }],
name: [{
required: true,
message: "必填",
trigger: "blur",
}, ],
code: [{
required: true,
message: "必填",
trigger: "blur",
}, ],
},
};
},
......@@ -43,7 +65,9 @@ export default {
},
methods: {
load(v) {
Api.get({ id: v }).then((r) => {
Api.get({
id: v,
}).then((r) => {
this.entity = r.result;
this.$emit("on-load");
});
......@@ -52,8 +76,8 @@ export default {
this.$emit("on-close");
},
downFile(path) {
alert(path)
let truePath = path.trim();
//alert(path)
let truePath = path;
if (truePath.length > 2) {
if (
truePath.substring(0, 7).toLowerCase() == "http://" ||
......
<template>
<div>
<div>
<DataGrid :columns="columns" ref="grid" :action="action">
<template slot="easySearch">
<Form ref="formInline" :model="easySearch" inline>
......@@ -21,8 +21,9 @@
<Modal v-model="modal" :title="title" width="1200" :fullscreen="full" footer-hide>
<component :is="detail" :eid="curId" @on-close="cancel" @on-ok="ok" />
</Modal>
</div>
</div>
</template>
<script>
import Api from "./api";
import Search from "./search";
......@@ -40,15 +41,17 @@ export default {
return {
action: Api.index,
easySearch: {
keys: { op: "name", value: null },
keys: {
op: "name",
value: null
},
},
modal: false,
full:false,
full: false,
title: "新增",
detail: null,
curId: 0,
columns: [
{
columns: [{
key: "id",
title: this.$t("id"),
hide: true,
......@@ -73,7 +76,7 @@ export default {
key: "creationTime",
title: this.l("creationTime"),
align: "center",
width:"180",
width: "180",
high: true,
},
{
......@@ -81,59 +84,65 @@ export default {
title: this.l("creatorUserId"),
align: "left",
high: true,
type:"user",
width:"180",
},
{
key: "lastModificationTime",
title: this.l("lastModificationTime"),
align: "left",
high: true,
hide: true,
},
{
key: "lastModifierUserId",
title: this.l("lastModifierUserId"),
align: "left",
high: true,
hide: true,
},
{
key: "isDeleted",
title: this.l("isDeleted"),
align: "left",
high: true,
hide: true,
},
{
key: "deletionTime",
title: this.l("deletionTime"),
align: "left",
high: true,
hide: true,
},
{
key: "deleterUserId",
title: this.l("deleterUserId"),
align: "left",
high: true,
hide: true,
},
{ key: "creator", title: this.l("creator"), align: "left", high: true,hide: true, },
{
key: "lastModifier",
title: this.l("lastModifier"),
align: "left",
high: true,
hide: true,
},
type: "user",
width: "180",
},
// {
// key: "lastModificationTime",
// title: this.l("lastModificationTime"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "lastModifierUserId",
// title: this.l("lastModifierUserId"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "isDeleted",
// title: this.l("isDeleted"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "deletionTime",
// title: this.l("deletionTime"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "deleterUserId",
// title: this.l("deleterUserId"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "creator",
// title: this.l("creator"),
// align: "left",
// high: true,
// hide: true,
// },
// {
// key: "lastModifier",
// title: this.l("lastModifier"),
// align: "left",
// high: true,
// hide: true,
// },
{
key: "status",
title: this.l("status"),
align: "center",
high: true,
code: "mimprot.im.status",
width:"150",
code: "improt.im.status",
width: "150",
},
{
title: "操作",
......@@ -141,28 +150,39 @@ export default {
width: 140,
align: "center",
render: (h, params) => {
return h("div", { class: "action" }, [
return h("div", {
class: "action"
}, [
h(
"op",
{
attrs: { oprate: "detail" },
on: { click: () => this.view(params.row.id) },
"op", {
attrs: {
oprate: "detail"
},
on: {
click: () => this.view(params.row.id)
},
},
"查看"
),
h(
"op",
{
attrs: { oprate: "delete" },
on: { click: () => this.remove(params.row.id) },
"op", {
attrs: {
oprate: "delete"
},
on: {
click: () => this.remove(params.row.id)
},
},
"删除"
),
h(
"op",
{
attrs: { oprate: "edit" },
on: { click: () => this.process(params.row) },
"op", {
attrs: {
oprate: "edit"
},
on: {
click: () => this.process(params.row)
},
},
"处理"
),
......@@ -175,7 +195,10 @@ export default {
mounted() {
console.log(this);
},
async fetch({ store, params }) {
async fetch({
store,
params
}) {
await store.dispatch("loadDictionary"); // 加载数据字典
},
methods: {
......@@ -189,7 +212,7 @@ export default {
},
add() {
this.curId = 0;
this.full=false;
this.full = false;
this.title = "新增";
this.detail = () => import("./add");
this.modal = true;
......@@ -203,21 +226,21 @@ export default {
view(id) {
this.curId = id;
this.title = "详情";
this.full=false;
this.full = false;
this.detail = () => import("./detail");
this.modal = true;
},
edit(id) {
this.curId = id;
this.title = "编辑";
this.full=false;
this.full = false;
this.detail = () => import("./edit");
this.modal = true;
},
process(row) {
this.curId = row.id;
this.title = "处理文件:"+row.name;
this.full=true;
this.title = "处理文件:" + row.name;
this.full = true;
this.detail = () => import("./process");
this.modal = true;
},
......@@ -240,5 +263,6 @@ export default {
},
};
</script>
<style lang="less">
</style>
<template>
<div class="content">
<DataGrid
border
:height="tdHeightExcel"
:columns="columnsImport"
:data="excelData"
:page="false"
:set="false"
>
<div class="content">
<TablePaste hide-table :input-props="inputProps" @on-success="handleSuccess" @on-error="handleError" v-show="showTablePaste" />
<DataGrid border :height="tdHeightExcel" :columns="columnsImport" :data="excelData" :page="false" :set="false">
<template slot="easySearch">
<Form inline>
<FormItem>
<span>导入到</span>
</FormItem>
<FormItem>
<dictionary code="import.im.page" style="width:160px" @on-change="pageChange"></dictionary>
<dictionary code="import.im.page" style="width:160px" @on-change="pageChange" v-model="pageType"></dictionary>
</FormItem>
<FormItem>
<div class="tip mr20">{{excelData.length}}条数据</div>
......@@ -27,17 +21,20 @@
<template slot="buttons">
<Form inline>
<FormItem>
<Button>下载文件</Button>
<Button @click="downFile">下载原始文件</Button>
</FormItem>
<FormItem>
<div style="height:34px;overflow: hidden;padding:0">
<Upload action :before-upload="beforeUpload" ref="uploadfile" :format="formatList">
<Button icon="ios-cloud-upload-outline">重新上传</Button>
<Button icon="ios-cloud-upload-outline" @click="resetParms">重新上传</Button>
</Upload>
</div>
</FormItem>
<FormItem>
<Button>粘贴excel</Button>
<Button @click="openPaste" :type="btnType" :ghost="ghostStatus">{{btnTxt}}</Button>
</FormItem>
<FormItem>
<Button @click="resetTable">还原到原始文件</Button>
</FormItem>
</Form>
</template>
......@@ -51,44 +48,51 @@
</FormItem>
</Form>
</FooterToolbar>
</div>
</div>
</template>
<script>
import Api from "./api";
import XLSX from "xlsx";
import { Switch } from "view-design";
import {
Switch
} from "view-design";
export default {
name: "Edit",
data() {
return {
pageType: undefined,
entity: {},
downUrl: fileUrlDown,
fileUrlPath: "",
disabled: false,
columns: [
{
columns0: [{
key: "userName",
title: this.l("userName"),
align: "left",
easy: true,
high: true,
render: (h, params) => {
return h("div", { class: "action" }, [
return h(
"div", {
class: "action",
},
[
h(
"op",
{
attrs: { oprate: "detail" },
on: { click: () => this.detail(params.row.id) },
"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"),
......@@ -147,25 +151,29 @@ export default {
high: true,
hide: true,
render: (h, params) => {
return h("div", { class: "action" }, [
return h(
"div", {
class: "action",
},
[
h(
"op",
{
"op", {
attrs: {
oprate: "detail",
class:
params.row.roleTitles == null ||
params.row.roleTitles == ""
? "empower"
: "detail",
class: params.row.roleTitles == null ||
params.row.roleTitles == "" ?
"empower" : "detail",
},
on: { click: () => this.authorize(params.row.id) },
on: {
click: () => this.authorize(params.row.id),
},
params.row.roleTitles == null || params.row.roleTitles == ""
? "授权"
: params.row.roleTitles
},
params.row.roleTitles == null || params.row.roleTitles == "" ?
"授权" :
params.row.roleTitles
),
]);
]
);
},
},
{
......@@ -248,66 +256,86 @@ export default {
align: "right",
import: false,
render: (h, params) => {
return h("div", { class: "action" }, [
return h(
"div", {
class: "action",
},
[
h(
"op",
{
"op", {
attrs: {
oprate: "detail",
class: "empower",
},
on: { click: () => this.syncAccount(params.row) },
on: {
click: () => this.syncAccount(params.row),
},
},
params.row.accountId == 0 ? "同步" : ""
),
h(
"op",
{
attrs: { oprate: "edit" },
on: { click: () => this.edit(params.row.id) },
"op", {
attrs: {
oprate: "edit",
},
on: {
click: () => this.edit(params.row.id),
},
},
"编辑"
),
h(
"op",
{
attrs: { oprate: "remove" },
on: { click: () => this.remove(params.row) },
"op", {
attrs: {
oprate: "remove",
},
on: {
click: () => this.remove(params.row),
},
},
"删除"
),
h(
"op",
{
"op", {
attrs: {
oprate: "detail",
},
on: { click: () => this.openReset(params.row) },
on: {
click: () => this.openReset(params.row),
},
},
"重置密码"
),
]);
]
);
},
},
],
columns1: [
{
columns1: [{
key: "userName",
title: this.l("userName"),
align: "left",
easy: true,
high: true,
render: (h, params) => {
return h("div", { class: "action" }, [
return h(
"div", {
class: "action",
},
[
h(
"op",
{
attrs: { oprate: "detail" },
on: { click: () => this.detail(params.row.id) },
"op", {
attrs: {
oprate: "detail",
},
on: {
click: () => this.detail(params.row.id),
},
},
params.row.userName
),
]);
]
);
},
},
......@@ -319,70 +347,25 @@ export default {
code: "User.base.status",
},
],
excelData: [
{
userName: "测试人员001",
cardNo: "",
gender: "0",
birthday: "1990-09-26 00:00:00",
degreeId: "3",
status: "1",
departmentId: "197",
departmentTitle: "整备",
creatorUserId: "",
creationTime: "2020-08-19 11:43:33",
lastModifierUserId: "",
lastModificationTime: "",
phone: "13745781247",
email: "LZ@outlook.com",
licensedToWork: "3",
positionId: "2",
titleId: "1",
},
{
userName: "测试人员002",
cardNo: "11011",
gender: "1",
birthday: "1981-07-17 00:00:00",
degreeId: "3",
status: "1",
departmentId: "196",
departmentTitle: "乘务",
creatorUserId: "",
creationTime: "2020-08-19 11:43:33",
lastModifierUserId: "",
lastModificationTime: "",
phone: "14761586449",
email: "1594289563@qq.com",
licensedToWork: "3",
positionId: "3",
titleId: "4",
},
{
userName: "测试人员003",
cardNo: "11012",
gender: "0",
birthday: "1996-07-01 00:00:00",
degreeId: "3",
status: "1",
departmentId: "198",
departmentTitle: "物料库房",
creatorUserId: "",
creationTime: "2020-08-19 11:43:33",
lastModifierUserId: "",
lastModificationTime: "",
phone: "19254832512",
email: "1228562934@qq.com",
licensedToWork: "3",
positionId: "1",
titleId: "1",
},
],
tdHeightExcel: "",
excelData: [],
formatList: ["xlsx"],
columnsImport: [],
departArr: [], //部门list
sheetNames: [], //excel的表明
workBook: {},
openDatas: [],
dataType: 0,
//粘贴excel内容start
btnType: 'default',
ghostStatus: false,
btnTxt: "打开粘贴Excel",
showTablePaste: false,
inputProps: {
rows: 10,
placeholder: "请从Excel复制一段表格数据,粘贴在这里",
},
value: "",
};
},
props: {
......@@ -391,7 +374,7 @@ export default {
created() {
this.tdHeightExcel = window.innerHeight - 180;
//导出对列表头进行预加载start
this.loadColum(this.columns);
this.loadColum(this.columns0);
this.$api.get(`${systemUrl}/Department/GetDepartments`).then((r) => {
this.departArr = r.result.items;
});
......@@ -399,6 +382,9 @@ export default {
//导出对列表头进行预加载end
},
mounted() {
if (this.eid > 0) {
this.load(this.eid);
}
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
......@@ -409,9 +395,42 @@ export default {
},
methods: {
load(v) {
Api.get({ id: v }).then((r) => {
Api.get({
id: v,
}).then((r) => {
this.entity = r.result;
});
this.dataType = 0;
this.sheetNames = [];
this.excelData = [];
Api.openExcel({
id: v,
}).then((res) => {
if (res.success) {
this.openDatas = res.result;
this.dealOpenTable(0);
//获取excel sheetname
if (res.result.length > 0) {
res.result.forEach((el) => {
this.sheetNames.push(el.title);
});
}
}
});
},
//加载原文件列表
dealOpenTable(val) {
this.excelData = this.openDatas[val].dataTable;
var tempCos = Object.keys(this.openDatas[val].dataTable[0]);
this.columnsImport = [];
var headersNow = [];
tempCos.forEach((el) => {
let headObj = {};
headObj.title = el;
headObj.key = el;
headersNow.push(headObj);
});
this.columnsImport = headersNow;
},
handleSubmit() {
this.$refs.form.validate((v) => {
......@@ -445,19 +464,79 @@ export default {
});
this.columnsImport = tempCol;
},
//下载原excel文件
downFile() {
//alert(path)
let truePath = this.entity.path;
if (truePath.length > 2) {
if (
truePath.substring(0, 7).toLowerCase() == "http://" ||
truePath.substring(0, 8).toLowerCase() == "https://"
) {
window.open(truePath, "_blank");
} else {
this.fileUrlPath = this.downUrl + this.entity.path;
window.open(this.fileUrlPath, "_blank");
}
}
},
//导入excel文件
//打开传时初始化
resetParms() {
this.pageType = undefined;
this.btnTxt = "打开粘贴Excel";
this.showTablePaste = false;
this.btnType = 'default';
this.ghostStatus = false;
},
async beforeUpload(file) {
//初始化
this.sheetNames = [];
this.workBook = {};
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
//上传成功后的读取到excel信息
this.workBook = await this.$u.readXLSX(file);
this.sheetNames = this.workBook.SheetNames; //execel里的表明
this.dealSheet(0); //默认显示excel第一张表
//console.log(workbook);
this.dealSheet(0); //默认显示第一个表
return false;
},
//对上传的excel表信息进行处理,不对表头进行处理
dealSheet(index) {
//对表信息进行处理
this.dataType = 1;
this.columnsImport = [];
this.excelData = [];
const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串
};
var csv = XLSX.utils.sheet_to_csv(
this.workBook.Sheets[this.workBook.SheetNames[index]],
sheet2JSONOpts
);
var lines = csv.split("\n"); //第一行标题
var headers = lines[0].split(",");
var headersNow = [];
headers.forEach((elHead) => {
let headObj = {};
headObj.title = elHead;
headObj.key = elHead;
headersNow.push(headObj);
});
this.columnsImport = headersNow;
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);
}
this.excelData = result;
},
//对已选择了功能模块的列表信息进行处理,对表头也处理
dealSheet1(index) {
this.excelData = [];
var tempColums = this.$u.clone(this.columnsImport);
const sheet2JSONOpts = {
......@@ -470,6 +549,7 @@ export default {
var lines = csv.split("\n"); //第一行标题
var headers = lines[0].split(",");
var arrTi = [];
//转换到colum后的list表头start
headers.forEach((elHead) => {
......@@ -496,10 +576,12 @@ export default {
var arrTitleUse = []; //使用数据字典的字段
tempColums.forEach((elCode) => {
if (elCode.code) {
arrTitleUse.push({ key: elCode.key, code: elCode.code });
arrTitleUse.push({
key: elCode.key,
code: elCode.code,
});
}
});
result.forEach((ele) => {
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
if (
......@@ -524,7 +606,6 @@ export default {
}
});
}
//对列表里的数据字典项进行处理
arrTitleUse.forEach((elem) => {
if (ele[elem.key] && ele[elem.key] != "" && ele[elem.key] != null) {
......@@ -540,18 +621,23 @@ export default {
},
//切换sheet表重新加载
sheetClick(val) {
if (this.dataType == 0) {
this.dealOpenTable(val);
} else {
this.dealSheet(val);
}
},
//选择导入的模块 0:用户管理
pageChange(val) {
switch (val) {
case 0:
this.loadColum(this.columns);
this.loadColum(this.columns0);
break;
case 1:
this.loadColum(this.columns1);
break;
default:
this.loadColum(this.columns);
this.loadColum(this.columns0);
}
},
handleClose() {
......@@ -562,6 +648,43 @@ export default {
this.$refs.uploadfile.clearFiles();
this.$emit("on-close");
},
//粘贴excel相关start
openPaste() {
if (this.btnTxt == "打开粘贴Excel") {
this.btnType = 'primary';
this.ghostStatus = true;
this.showTablePaste = true;
this.btnTxt = "关闭粘贴Excel";
} else {
this.btnType = 'default';
this.ghostStatus = false;
this.showTablePaste = false;
this.btnTxt = "打开粘贴Excel";
}
},
handleSuccess(tableData) {
this.excelData = [];
this.columnsImport = [];
this.sheetNames = [];
//console.log(tableData);
this.columnsImport = tableData.columns;
this.excelData = tableData.data;
},
handleError(tableData, errorIndex) {
//console.log(tableData, errorIndex);
this.$Message.error("表格数据有误");
},
//粘贴excel相关end
//重新加载excel
resetTable() {
this.pageType = undefined;
this.btnTxt = "打开粘贴Excel";
this.showTablePaste = false;
this.btnType = 'default';
this.ghostStatus = false;
this.load(this.eid);
},
l(key) {
key = "user" + "." + key;
return this.$t(key);
......@@ -576,17 +699,28 @@ export default {
},
};
</script>
<style lang="less">
.content {
.table-footer {
line-height: 45px;
background: #f5f5f5;
}
.ivu-footer-toolbar {
text-align: left;
.ivu-footer-toolbar-right {
float: left;
}
}
.demo-split {
border: 1px solid #dcdee2;
}
.demo-split-pane {
padding: 10px;
}
}
</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