Commit 9732195b authored by renjintao's avatar renjintao

转换title

parent 7ca70bdf
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
/> />
</slot> </slot>
</div>&nbsp; </div>&nbsp;
<Button v-if="high" @click="modalSearch=true" type="text"><Icon type="md-search" />高级</Button> <Button v-if="high" @click="modalSearch=true" type="text">
<Icon type="md-search" />高级
</Button>
<div class="searchBack"> <div class="searchBack">
<slot name="searchBack"></slot> <slot name="searchBack"></slot>
</div> </div>
...@@ -113,17 +115,17 @@ ...@@ -113,17 +115,17 @@
<script> <script>
export default { export default {
name: 'DataGrid', name: "DataGrid",
data() { data() {
return { return {
keys: '', keys: "",
selectItems: [], selectItems: [],
footerToolbar: false, footerToolbar: false,
modalSearch: false, modalSearch: false,
search: { search: {
pageIndex: 1, pageIndex: 1,
pageSize: 20, pageSize: 20,
conditions: [] conditions: [],
}, },
pageSizeOpts: [20, 50, 100], pageSizeOpts: [20, 50, 100],
tableHeight: 0, tableHeight: 0,
...@@ -134,168 +136,174 @@ export default { ...@@ -134,168 +136,174 @@ export default {
configLoad: false, configLoad: false,
userConfig: null, //用户页面配置信息。, userConfig: null, //用户页面配置信息。,
// userId: 1 // userId: 1
userId: this.$store.state.userInfo.userId userId: this.$store.state.userInfo.userId,
} };
}, },
props: { props: {
border: { border: {
//是否显示边框 //是否显示边框
type: Boolean, type: Boolean,
default: true default: true,
}, },
batch: { batch: {
//是否批量操作 //是否批量操作
type: Boolean, type: Boolean,
default: true default: true,
}, },
lazy: { lazy: {
//懒加载设置,设置为真时候,默认不加载数据。 //懒加载设置,设置为真时候,默认不加载数据。
type: Boolean, type: Boolean,
default: false default: false,
}, },
placeholder: { placeholder: {
type: String, type: String,
default: '请输入关键字' default: "请输入关键字",
}, },
height: { height: {
type: Number, type: Number,
default: 0 default: 0,
}, },
tool: { tool: {
//是否显示工具栏 //是否显示工具栏
type: Boolean, type: Boolean,
default: true default: true,
}, },
easy: { easy: {
//是否显示简单搜索 //是否显示简单搜索
type: Boolean, type: Boolean,
default: true default: true,
}, },
high: { high: {
//是否显示高级搜索 //是否显示高级搜索
type: Boolean, type: Boolean,
default: true default: true,
}, },
draggable: { draggable: {
//是否可以拖拽 //是否可以拖拽
type: Boolean, type: Boolean,
default: false default: false,
}, },
set: { set: {
//是否显示列设置 //是否显示列设置
type: Boolean, type: Boolean,
default: true default: true,
}, },
page: { page: {
//是否分页 //是否分页
type: Boolean, type: Boolean,
default: true default: true,
}, },
data: { data: {
// 当作table使用,直接显示数据 // 当作table使用,直接显示数据
type: Array, type: Array,
default: function() { default: function () {
return [] return [];
} },
}, },
columns: { columns: {
//要显示的字段 //要显示的字段
type: Array, type: Array,
default: [] default: [],
}, },
action: { action: {
//接口地址 //接口地址
type: String, type: String,
default: '' default: "",
}, },
conditions: { conditions: {
//查询条件 //查询条件
type: Object, type: Object,
default: function() { default: function () {
return { return {
keys: { op: 'name', value: '', default: true } keys: { op: "name", value: "", default: true },
} };
} },
}, },
type: { type: {
type: String, type: String,
default: 'table', default: "table",
validator: function(value) { validator: function (value) {
// 这个值必须匹配下列字符串中的一个 // 这个值必须匹配下列字符串中的一个
return ['table', 'card', 'list'].indexOf(value) !== -1 return ["table", "card", "list"].indexOf(value) !== -1;
} },
}, },
span: { span: {
type: Number, type: Number,
default: 24 default: 24,
} },
}, },
created() { created() {
this.columns.forEach((u) => { this.columns.forEach((u) => {
if (!u.hide) { if (!u.hide) {
u.hide = false u.hide = false;
} }
}) });
this.columnsCur = this.$u.clone(this.columns) this.columnsCur = this.$u.clone(this.columns);
}, },
mounted() { mounted() {
if (this.data&&this.data.length>0) { if (this.data && this.data.length > 0) {
this.list = this.data this.list = this.data;
return return;
} }
this.keys = '' this.keys = "";
this.intY() this.intY();
if (this.lazy==true) { if (this.lazy == true) {
return; return;
} }
this.loadUserConfig() if (this.set == true) {
this.loadUserConfig();
}
// else
// {
// this.columnsCur = this.$u.clone(this.columns);
// }
if (this.height === 0) { if (this.height === 0) {
window.onresize = () => { window.onresize = () => {
///浏览器窗口大小变化 ///浏览器窗口大小变化
return (() => { return (() => {
window.screenHeight = window.innerHeight window.screenHeight = window.innerHeight;
this.tableHeight = window.screenHeight - this.firstY - 60 this.tableHeight = window.screenHeight - this.firstY - 60;
})() })();
} };
} else { } else {
this.tableHeight = this.height this.tableHeight = this.height;
} }
//注册拖拽事件。 //注册拖拽事件。
this.$dragging.$on('dragend', (e) => { this.$dragging.$on("dragend", (e) => {
// console.log("dragend",e); // console.log("dragend",e);
this.saveUserconfig() this.saveUserconfig();
}) });
}, },
methods: { methods: {
//数据加载 //数据加载
load() { load() {
if (this.height == 0) { if (this.height == 0) {
this.tableHeight = window.innerHeight - this.firstY - 60 this.tableHeight = window.innerHeight - this.firstY - 60;
} }
if (this.action) { if (this.action) {
this.$api.post(this.action, this.search).then((r) => { this.$api.post(this.action, this.search).then((r) => {
this.list = r.result.items this.list = r.result.items;
this.search.total = r.result.totalCount this.search.total = r.result.totalCount;
}) });
} }
}, },
columnInit() { columnInit() {
if (this.userConfig) { if (this.userConfig) {
var curColumns = [] var curColumns = [];
var config = JSON.parse(this.userConfig.content) var config = JSON.parse(this.userConfig.content);
// console.warn("2:列比对",config) // console.warn("2:列比对",config)
if (config.length == this.columnsCur.length) { if (config.length == this.columnsCur.length) {
config.map((u) => { config.map((u) => {
var item = this.columnsCur.filter((c) => { var item = this.columnsCur.filter((c) => {
return c.key == u.key return c.key == u.key;
}) });
if (item[0]) { if (item[0]) {
item[0].hide = u.hide item[0].hide = u.hide;
curColumns.push(item[0]) curColumns.push(item[0]);
} }
}) });
// console.warn("3:初始化列") // console.warn("3:初始化列")
this.columnsCur = curColumns this.columnsCur = curColumns;
} }
} }
}, },
...@@ -303,210 +311,209 @@ export default { ...@@ -303,210 +311,209 @@ export default {
var query = { var query = {
conditions: [ conditions: [
{ {
fieldName: 'creatorUserId', fieldName: "creatorUserId",
fieldValue: this.userId, fieldValue: this.userId,
conditionalType: 'Equal' conditionalType: "Equal",
}, },
{ {
fieldName: 'component', fieldName: "component",
fieldValue: 'Grid', fieldValue: "Grid",
conditionalType: 'Equal' conditionalType: "Equal",
}, },
{ {
fieldName: 'page', fieldName: "page",
fieldValue: window.location.pathname, fieldValue: window.location.pathname,
conditionalType: 'Equal' conditionalType: "Equal",
} },
], ],
pageSize: 1 pageSize: 1,
} };
this.$api.post(`${window.systemUrl}/config/list`, query).then((r) => { this.$api.post(`${window.systemUrl}/config/list`, query).then((r) => {
if (r.success) { if (r.success) {
if (r.result.length == 1) { if (r.result.length == 1) {
this.userConfig = r.result[0] this.userConfig = r.result[0];
// console.warn("1:加载用户配置") // console.warn("1:加载用户配置")
this.columnInit() this.columnInit();
} }
if (!this.configLoad) { if (!this.configLoad) {
this.easySearch() this.easySearch();
} }
this.configLoad = true this.configLoad = true;
} }
}) });
}, },
saveUserconfig() { saveUserconfig() {
let url = `${window.systemUrl}/config/update` let url = `${window.systemUrl}/config/update`;
var content = [] var content = [];
this.columnsCur.map((u) => { this.columnsCur.map((u) => {
content.push({ content.push({
key: u.key, key: u.key,
hide: u.hide hide: u.hide,
}) });
}) });
if (!this.userConfig) { if (!this.userConfig) {
url = `${window.systemUrl}/config/create` url = `${window.systemUrl}/config/create`;
var data = { var data = {
page: window.location.pathname, page: window.location.pathname,
component: 'Grid', component: "Grid",
key: this.$u.guid(), key: this.$u.guid(),
content: JSON.stringify(content) content: JSON.stringify(content),
} };
this.$api.post(url, data).then((r) => { this.$api.post(url, data).then((r) => {
this.loadUserConfig() this.loadUserConfig();
}) });
} else { } else {
this.userConfig.content = JSON.stringify(content) this.userConfig.content = JSON.stringify(content);
this.$api.post(url, this.userConfig) this.$api.post(url, this.userConfig);
} }
}, },
//展开 //展开
expand(row, status) { expand(row, status) {
this.$emit('on-expand', row, status) this.$emit("on-expand", row, status);
}, },
//拖拽 //拖拽
onDragDrop(a, b) { onDragDrop(a, b) {
this.$emit('on-drag-drop', a, b) this.$emit("on-drag-drop", a, b);
}, },
easySearch() { easySearch() {
if (this.conditions && this.conditions.keys.default) { if (this.conditions && this.conditions.keys.default) {
//判断没有传入条件的用默认的查询 //判断没有传入条件的用默认的查询
this.conditions.keys.value = this.keys this.conditions.keys.value = this.keys;
} }
this.reload(this.conditions) this.reload(this.conditions);
}, },
undoConfig() { undoConfig() {
//列设置恢复初始化 //列设置恢复初始化
this.columnsCur = this.$u.clone(this.columns) this.columnsCur = this.$u.clone(this.columns);
this.saveUserconfig() this.saveUserconfig();
}, },
complexSearch() { complexSearch() {
var search = this.$refs.search.$children.filter((u) => { var search = this.$refs.search.$children.filter((u) => {
return u.condition return u.condition;
}) });
if (search) { if (search) {
var conditions = search[0].condition var conditions = search[0].condition;
this.reload(conditions) this.reload(conditions);
} }
}, },
reload(conditions) { reload(conditions) {
var where = [] var where = [];
if (conditions) { if (conditions) {
Object.keys(conditions).forEach((u) => { Object.keys(conditions).forEach((u) => {
let v = conditions[u].value let v = conditions[u].value;
let op = conditions[u].op let op = conditions[u].op;
if (!this.$u.isNull(v)) { if (!this.$u.isNull(v)) {
if (op == 'Range') { if (op == "Range") {
let times = [] let times = [];
v.map((u) => { v.map((u) => {
if (!this.$u.isNull(u)) { if (!this.$u.isNull(u)) {
times.push(this.$u.toTime(u)) times.push(this.$u.toTime(u));
} }
}) });
v = times.join(',') v = times.join(",");
} else if (op.indexOf('In') > -1) { } else if (op.indexOf("In") > -1) {
v = v.join(',') v = v.join(",");
} }
if (!this.$u.isNull(v)) { if (!this.$u.isNull(v)) {
where.push({ where.push({
fieldName: u, fieldName: u,
fieldValue: v, fieldValue: v,
conditionalType: op conditionalType: op,
}) });
} }
} }
}) });
} }
this.search.pageIndex = 1 this.search.pageIndex = 1;
this.search.conditions = where this.search.conditions = where;
this.load() this.load();
}, },
pageChange(page) { pageChange(page) {
this.search.page = page this.search.page = page;
this.search.pageIndex = page this.search.pageIndex = page;
this.load() this.load();
}, },
pageSizeChange(size) { pageSizeChange(size) {
this.search.pageSize = size this.search.pageSize = size;
this.search.pageIndex = 1 this.search.pageIndex = 1;
this.load() this.load();
}, },
columnChange(item, i) { columnChange(item, i) {
item.hide = !item.hide item.hide = !item.hide;
this.$set(this.columnsCur, item, i) this.$set(this.columnsCur, item, i);
this.saveUserconfig() this.saveUserconfig();
}, },
selectionChange(items) { selectionChange(items) {
this.$emit('on-selection-change', items) this.$emit("on-selection-change", items);
this.selectItems = items this.selectItems = items;
this.footerToolbar = items.length > 0 this.footerToolbar = items.length > 0;
}, },
onSelect(rows, row) { onSelect(rows, row) {
this.$emit('on-selection-change', rows, row) this.$emit("on-selection-change", rows, row);
}, },
intY() { intY() {
if (this.$refs.table != undefined) { if (this.$refs.table != undefined) {
this.firstY = this.$refs.table.$el.getBoundingClientRect().top this.firstY = this.$refs.table.$el.getBoundingClientRect().top;
} }
}, },
selectAll(status) { selectAll(status) {
this.$refs.table.selectAll(status) this.$refs.table.selectAll(status);
} },
}, },
computed: { computed: {
columnsNow() { columnsNow() {
var cols = this.columnsCur.filter((u) => { var cols = this.columnsCur.filter((u) => {
if (u.code) { if (u.code) {
u.render = (h, params) => { u.render = (h, params) => {
let values = u.key let values = u.key;
let type = 'text' let type = "text";
if (u.category) { if (u.category) {
type = u.category type = u.category;
} }
return h('state', { return h("state", {
props: { props: {
code: u.code, code: u.code,
type: type, type: type,
value: params.row[values] + '' value: params.row[values] + "",
} },
}) });
} };
} }
if (u.type == 'user') { if (u.type == "user") {
u.render = (h, params) => { u.render = (h, params) => {
let values = u.key let values = u.key;
return h('User', { return h("User", {
props: { props: {
value: params.row[values] value: params.row[values],
} },
}) });
} };
} }
if (u.type == 'date' || u.type == 'dateTime') { if (u.type == "date" || u.type == "dateTime") {
u.render = (h, params) => { u.render = (h, params) => {
let values = u.key let values = u.key;
return h('DTSpan', { return h("DTSpan", {
props: { props: {
type: u.type, type: u.type,
value: params.row[values] value: params.row[values],
} },
}) });
} };
}
return !u.hide
})
return cols
} }
return !u.hide;
});
return cols;
}, },
watch:{
"data.length"(){
this.list=this.data;
}, },
"height"() watch: {
{ "data.length"() {
this.tableHeight=this.height; this.list = this.data;
} },
} height() {
} this.tableHeight = this.height;
},
},
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
...@@ -515,7 +522,6 @@ export default { ...@@ -515,7 +522,6 @@ export default {
// height: 100%; // height: 100%;
.tableCommon { .tableCommon {
width: 100%; width: 100%;
} }
.tip { .tip {
display: inline; display: inline;
......
...@@ -207,7 +207,7 @@ henq.getNowTime = () => { ...@@ -207,7 +207,7 @@ henq.getNowTime = () => {
return year + month + date + hours + minutes + seconds; return year + month + date + hours + minutes + seconds;
} }
//读取本地excel //读取本地excel
henq.readXLSX=(file)=>{ henq.readXLSX = (file) => {
let nameSplit = file.name.split("."); let nameSplit = file.name.split(".");
let format = nameSplit[nameSplit.length - 1]; let format = nameSplit[nameSplit.length - 1];
if (!["xlsx", "csv"].includes(format)) { if (!["xlsx", "csv"].includes(format)) {
...@@ -218,31 +218,41 @@ henq.readXLSX=(file)=>{ ...@@ -218,31 +218,41 @@ henq.readXLSX=(file)=>{
reader.readAsBinaryString(file); reader.readAsBinaryString(file);
reader.onload = function (evt) { reader.onload = function (evt) {
let data = evt.target.result; // 读到的数据 let data = evt.target.result; // 读到的数据
var workbook = XLSX.read(data, { type: "binary" }); var workbook = XLSX.read(data, {
type: "binary"
});
resolve(workbook); resolve(workbook);
}; };
}); });
} }
//得到根据value得到对应数据字典的name //得到根据value得到对应数据字典的name
henq.dirName=(code,v)=>{ henq.dirName = (code, v) => {
var items="" var items = ""
let i = 0
code.forEach(ele => { code.forEach(ele => {
if(ele.code==v) if (ele.code == v) {
{ items = ele.name
items=ele.name i++
} }
}); });
if (i == 0) { //如果没查到对应的name,则返回默认name
items = code[0].name
}
return items return items
} }
//得到根据name得到对应数据字典的code //得到根据name得到对应数据字典的code
henq.dirCode=(code,v)=>{ henq.dirCode = (code, v) => {
var items="" var items = ""
let i = 0
code.forEach(ele => { code.forEach(ele => {
if(ele.name==v) if (ele.name == v) {
{ items = ele.code
items=ele.code i++
} }
}); });
if (i == 0) { //如果没查到对应的name,则返回默认name
items = code[0].code
}
return items return items
} }
export default henq; export default henq;
...@@ -125,10 +125,11 @@ ...@@ -125,10 +125,11 @@
<DataGrid <DataGrid
border border
:height="tdHeightExcel" :height="tdHeightExcel"
:columns="columnImport" :columns="columnsImport"
:data="excelData" :data="excelData"
:tool="false" :tool="false"
:page="false" :page="false"
:set="false"
></DataGrid> ></DataGrid>
<div slot="footer"> <div slot="footer">
<span v-if="excelData.length>0">共 {{excelData.length}} 条数据</span> <span v-if="excelData.length>0">共 {{excelData.length}} 条数据</span>
...@@ -279,7 +280,7 @@ export default { ...@@ -279,7 +280,7 @@ export default {
align: "left", align: "left",
easy: true, easy: true,
high: true, high: true,
hide:true, hide: true,
render: (h, params) => { render: (h, params) => {
return h("div", { class: "action" }, [ return h("div", { class: "action" }, [
h( h(
...@@ -302,26 +303,6 @@ export default { ...@@ -302,26 +303,6 @@ export default {
]); ]);
}, },
}, },
{
key: "creatorUserId",
title: this.l("creatorUserId"),
align: "left",
},
{
key: "creationTime",
title: this.l("creationTime"),
align: "left",
},
{
key: "lastModifierUserId",
title: this.l("lastModifierUserId"),
align: "left",
},
{
key: "lastModificationTime",
title: this.l("lastModificationTime"),
align: "left",
},
{ {
key: "accountId", key: "accountId",
title: this.l("accountId"), title: this.l("accountId"),
...@@ -367,11 +348,40 @@ export default { ...@@ -367,11 +348,40 @@ export default {
high: true, high: true,
code: "User.base.jobtitle", 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: "操作", title: "操作",
key: "action", key: "action",
width: 180, width: 180,
align: "right", align: "right",
import: false,
render: (h, params) => { render: (h, params) => {
return h("div", { class: "action" }, [ return h("div", { class: "action" }, [
h( h(
...@@ -417,7 +427,7 @@ export default { ...@@ -417,7 +427,7 @@ export default {
], ],
selectRow: {}, //删除时选中的行数据 selectRow: {}, //删除时选中的行数据
//导入导出时使用start //导入导出时使用start
formatList: ['xlsx'], formatList: ["xlsx"],
searchs: { searchs: {
pageIndex: 1, pageIndex: 1,
pageSize: 1000, pageSize: 1000,
...@@ -426,133 +436,9 @@ export default { ...@@ -426,133 +436,9 @@ export default {
list: [], list: [],
modalImport: false, modalImport: false,
excelData: [], excelData: [],
columnImport: [
{
key: "userName",
title: this.l("userName"),
align: "left",
easy: true,
high: 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,
// },
{
key: "accountId",
title: this.l("accountId"),
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",
// type: "user",
// },
// {
// key: "creationTime",
// title: this.l("creationTime"),
// align: "left",
// },
// {
// key: "lastModifierUserId",
// title: this.l("lastModifierUserId"),
// align: "left",
// type: "user",
// },
// {
// key: "lastModificationTime",
// title: this.l("lastModificationTime"),
// align: "left",
// },
],
departArr: [], //部门list departArr: [], //部门list
columnsImport: [],
//导入导出时使用end //导入导出时使用end
}; };
}, },
...@@ -560,6 +446,15 @@ export default { ...@@ -560,6 +446,15 @@ export default {
this.treeHeight = window.innerHeight - 150; this.treeHeight = window.innerHeight - 150;
this.tdHeight = window.innerHeight - 240; this.tdHeight = window.innerHeight - 240;
this.tdHeightExcel = 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() { mounted() {
window.onresize = () => { window.onresize = () => {
...@@ -832,9 +727,9 @@ export default { ...@@ -832,9 +727,9 @@ export default {
const tHeader = []; // 设置Excel的表格第一行的标题 const tHeader = []; // 设置Excel的表格第一行的标题
const filterVal = []; //list里对象的属性 const filterVal = []; //list里对象的属性
var tempCol = []; var tempCol = [];
var columnsCur = this.columns; //导出列标题信息griddata this.$refs.grid.columnsCur var columnsCur = this.$u.clone(this.columns); //导出列标题信息griddata this.$refs.grid.columnsCur
columnsCur.forEach((el) => { columnsCur.forEach((el) => {
if (!el.hide && el.key != "action") { if ((el.hide && !el.import) || (!el.hide && el.key != "action")) {
if (el.code) { if (el.code) {
//tHeader.push(el.key + "DirName"); //tHeader.push(el.key + "DirName");
//filterVal.push(el.key + "DirName"); //filterVal.push(el.key + "DirName");
...@@ -873,31 +768,55 @@ export default { ...@@ -873,31 +768,55 @@ export default {
ApiDepart.getpaged().then((r) => { ApiDepart.getpaged().then((r) => {
this.departArr = r.result.items; this.departArr = r.result.items;
}); });
console.log(this.columnImport)
}, },
//导入excel文件 //导入excel文件
async beforeUpload(file) { async beforeUpload(file) {
this.excelData = []; this.excelData = [];
this.$refs.uploadfile.clearFiles(); //清除上一次上传文件列表
var tempColums = this.$u.clone(this.columnsImport);
const workbook = await this.$u.readXLSX(file); const workbook = await this.$u.readXLSX(file);
const sheet2JSONOpts = { const sheet2JSONOpts = {
defval: "", //给defval赋值为空的字符串 defval: "", //给defval赋值为空的字符串
}; };
var tempList = XLSX.utils.sheet_to_json( var csv = XLSX.utils.sheet_to_csv(
workbook.Sheets[workbook.SheetNames[0]], workbook.Sheets[workbook.SheetNames[0]],
sheet2JSONOpts sheet2JSONOpts
); );
this.$refs.uploadfile.clearFiles();//清除上一次上传文件列表 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文件数据进行处理 //对读取的excel文件数据进行处理
var tempColums = tempList[0]; //必须保证excel第一行数据行DirName有数据值,否则取不到所有的标题
var arrTitle = Object.keys(tempColums);
var arrTitleUse = []; //使用数据字典的字段 var arrTitleUse = []; //使用数据字典的字段
arrTitle.forEach((el) => { tempColums.forEach((elCode) => {
if (el.indexOf("DirName") != -1) { if (elCode.code) {
arrTitleUse.push({ name: el, val: el.substring(0, el.length - 7) }); arrTitleUse.push({ key: elCode.key, code: elCode.code });
} }
}); });
tempList.forEach((ele) => {
result.forEach((ele) => {
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id //如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
if ( if (
ele.departmentTitle && ele.departmentTitle &&
...@@ -909,7 +828,8 @@ export default { ...@@ -909,7 +828,8 @@ export default {
ele.departmentId = e.id; ele.departmentId = e.id;
} }
}); });
} else if (//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle } else if (
//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
ele.departmentId && ele.departmentId &&
ele.departmentId + "" != "" && ele.departmentId + "" != "" &&
(!ele.departmentTitle || ele.departmentTitle == "") (!ele.departmentTitle || ele.departmentTitle == "")
...@@ -923,29 +843,17 @@ export default { ...@@ -923,29 +843,17 @@ export default {
//对列表里的数据字典项进行处理 //对列表里的数据字典项进行处理
arrTitleUse.forEach((elem) => { arrTitleUse.forEach((elem) => {
if (!ele[elem.val] || ele[elem.val] == "" || ele[elem.val] == null) { if (ele[elem.key] && ele[elem.key] != "" && ele[elem.key] != null) {
this.columnImport.forEach((co) => {
if (co.key == elem.val) {
if (ele[elem.name]) {
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值 //如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
ele[elem.val] = this.$u.dirCode( ele[elem.key] = this.$u.dirCode(
this.$store.getters.dictionaryByKey(co.code), this.$store.getters.dictionaryByKey(elem.code),
ele[elem.name] ele[elem.key]
); );
} else {
//如果对应的DirName不存在,则赋值此字段对应的数据字典项对应的第一个默认值
ele[elem.val] = this.$store.getters.dictionaryByKey(
co.code
)[0].code;
}
}
});
} }
}); });
}); });
this.excelData = result;
this.excelData = tempList; //console.log(workbook);
console.log(workbook);
return false; return false;
}, },
//确定批量导入 //确定批量导入
...@@ -989,6 +897,70 @@ export default { ...@@ -989,6 +897,70 @@ export default {
this.excelData = []; this.excelData = [];
this.$refs.uploadfile.clearFiles(); 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 });
}
});
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]
);
}
});
});
this.excelData = tempList;
console.log(workbook);
return false;
},
}, },
computed: { computed: {
searchList() { 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