提交 b67d8160 编写于 作者: Mosher's avatar Mosher

update:更新

上级 3cf49ebd
<?xml version="1.0" encoding="UTF-8"?>
<svg width="8px" height="8px" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>错误</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="列表-导入数据-文件上传完成" transform="translate(-701.000000, -283.000000)" fill-rule="nonzero">
<g id="编组-33" transform="translate(411.000000, 200.000000)">
<g id="编组-28" transform="translate(290.000000, 80.000000)">
<g id="错误" transform="translate(0.000000, 3.000000)">
<rect id="矩形" fill="#000000" opacity="0" x="0" y="0" width="8" height="8"></rect>
<path d="M5.32710539,3.99998149 L6.84507188,2.48212949 C6.94422436,2.38297944 6.99992781,2.24850193 6.99992781,2.10828119 C6.99992781,1.96806046 6.94422436,1.83358295 6.84507188,1.7344329 L6.26554524,1.15501641 C6.05908708,0.948614421 5.72441082,0.948614421 5.51795266,1.15501641 L4.00009363,2.67276095 L2.48201968,1.15480149 C2.38285492,1.05566372 2.24836879,1 2.1081474,1 C1.96792602,1 1.83345589,1.05574268 1.73431964,1.15490895 L1.15490046,1.73421799 C1.05572164,1.83335405 1,1.9678368 1,2.10806628 C1,2.24829576 1.05572164,2.3827785 1.15490046,2.48191457 L2.67286695,3.99987403 L1.15490046,5.51794095 C1.05572164,5.61707701 1,5.75155976 1,5.89178924 C1,6.03201871 1.05572164,6.16650146 1.15490046,6.26563753 L1.73431964,6.84526894 C1.94086374,7.05156469 2.27547557,7.05156469 2.48201968,6.84526894 L3.99998617,5.32720202 L5.5178452,6.84526894 C5.72442616,7.05157702 6.05907174,7.05157702 6.2656527,6.84526894 L6.84517934,6.26563753 C7.05160689,6.05910658 7.05160689,5.72436443 6.84517934,5.51783349 L5.32710539,3.99998149 Z" id="路径" fill="#E22D2D"></path>
</g>
</g>
</g>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="41px" height="46px" viewBox="0 0 41 46" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>导入</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="列表-导入数据" transform="translate(-662.000000, -314.000000)" fill="#57A3FD" fill-rule="nonzero">
<g id="编组-20" transform="translate(411.000000, 200.000000)">
<g id="导入" transform="translate(251.000000, 114.000000)">
<path d="M28.0376544,3.76410323 L29.7766688,6.44368556 L13.239007,15.644894 L11.4999926,12.9647074 L28.0376544,3.76410323 Z M9.11219211,14.7380049 L12.3001824,14.7380049 L12.3001824,22.3302555 L9.11158406,20.5436659 L9.11219211,14.7380049 Z" id="形状"></path>
<path d="M0.00060804817,8.56257961 L21.8671937,19.2041768 L21.8671937,46 L0.00060804817,35.2816707 L0.00060804817,8.56257961 Z M2.27835205,12.0982991 L2.27835205,33.9010967 L19.5894497,42.3869442 L19.5894497,20.5841466 L2.277744,12.0982991 L2.27835205,12.0982991 Z" id="形状"></path>
<path d="M20.163446,0 L41,9.44953043 L21.7066692,19.2041768 L0,8.56257961 L20.163446,0 Z M20.1330436,2.44576083 L5.38912041,8.70758522 L21.69086,16.6992054 L35.8151834,9.55768043 L20.1336517,2.44636502 L20.1330436,2.44576083 Z" id="形状"></path>
<polygon id="路径" points="20.8207448 18.8332042 41 9.37884022 41 36.1746635 21.8671937 46"></polygon>
</g>
</g>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="12px" height="12px" viewBox="0 0 12 12" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>链接</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="列表-导入数据-文件上传完成" transform="translate(-443.000000, -470.000000)" fill-rule="nonzero">
<g id="编组-33" transform="translate(411.000000, 200.000000)">
<g id="编组-21" transform="translate(32.000000, 246.000000)">
<g id="编组-18" transform="translate(0.000000, 21.000000)">
<g id="链接" transform="translate(0.000000, 3.000000)">
<rect id="矩形" fill="#000000" opacity="0" x="0" y="0" width="12" height="12"></rect>
<path d="M11.1405,1.071 L10.99425,0.924 C10.18275,0.1125 8.86725,0.1125 8.05575,0.924 L4.0155,4.965 C3.20325,5.7765 3.20325,7.09125 4.0155,7.9035 L4.1625,8.04975 C4.18725,8.0745 4.212,8.09775 4.23825,8.121 L5.346,7.0125 C5.316,6.99525 5.28825,6.9735 5.26425,6.948 L5.1165,6.801 C4.91475,6.5985 4.91475,6.26925 5.1165,6.06675 L5.26425,5.919 L6.219,4.965 L7.641,3.543 L9.1575,2.0265 C9.36075,1.824 9.6885,1.824 9.89175,2.0265 L10.03875,2.1735 C10.242,2.376 10.242,2.70525 10.03875,2.90775 L8.856,4.0905 C9.27,4.5855 9.43425,5.211 9.3525,5.7975 L11.1405,4.0095 C11.95275,3.198 11.95275,1.8825 11.1405,1.071 Z M8.2035,4.0095 L8.055,3.8625 C8.031,3.8385 8.0055,3.8145 7.98,3.792 L6.873,4.89825 C6.90075,4.91775 6.92775,4.9395 6.95325,4.965 L7.0995,5.112 C7.30275,5.31375 7.30275,5.64375 7.0995,5.84625 L6.65925,6.28725 L5.99925,6.948 L4.57725,8.37 L3.06,9.8865 C2.8575,10.08975 2.5275,10.08975 2.32575,9.8865 L2.17875,9.74025 C1.97625,9.53775 1.97625,9.20775 2.17875,9.00525 L3.4305,7.75425 C3.009,7.29075 2.8125,6.70275 2.84625,6.13275 L1.07625,7.9035 C0.264,8.71425 0.264,10.0305 1.07625,10.84125 L1.22325,10.9875 C2.03475,11.799 3.35025,11.799 4.16175,10.9875 L8.20275,6.94725 C9.0135,6.1365 9.0135,4.821 8.2035,4.0095 Z" id="形状" fill="#57A3FD"></path>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg width="8px" height="8px" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>对勾</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="列表-导入数据-文件上传完成" transform="translate(-449.000000, -283.000000)" fill-rule="nonzero">
<g id="编组-33" transform="translate(411.000000, 200.000000)">
<g id="编组-27" transform="translate(38.000000, 80.000000)">
<g id="对勾" transform="translate(0.000000, 3.000000)">
<rect id="矩形" fill="#000000" opacity="0" x="0" y="0" width="8" height="8"></rect>
<path d="M3.30402372e-13,5.33257243 C3.30402372e-13,5.33257243 2.03169794,6.1761155 3.04160137,8 C4.25460894,5.74294272 6.58297755,3.63765154 7.27272727,3.48194744 C7.27272727,2.54788794 7.27272727,2.1637215 7.27272727,0.727272727 C4.49362734,2.55115723 3.15913288,5.90953621 3.15913288,5.90953621 L1.69706055,4.36364049 L3.30402372e-13,5.33257243 Z" id="路径" fill="#49C81F"></path>
<path d="M3.30402372e-13,5.33257243 C3.30402372e-13,5.33257243 2.03169794,6.1761155 3.04160137,8 C4.25460894,5.74294272 6.58297755,3.63765154 7.27272727,3.48194744 C7.27272727,2.54788794 7.27272727,2.1637215 7.27272727,0.727272727 C4.49362734,2.55115723 3.15913288,5.90953621 3.15913288,5.90953621 L1.69706055,4.36364049 L3.30402372e-13,5.33257243 Z" id="路径" fill="#49C81F"></path>
</g>
</g>
</g>
</g>
</g>
</svg>
\ No newline at end of file
// 导入视图样式
.app-data-upload-view{ .app-data-upload-view{
font-family: "Microsoft YaHei";
.main-content{
height: 174px;
background: #FAFAFB;
border-radius: 4px;
border: 1px dashed #D7D7D7;
// 上传文件区域
.upload-container{
cursor: pointer;
height: 100%;
width: 100%; width: 100%;
text-align: center;
padding-top: 58px;
.icon-import{
display: block;
margin: 0 auto 17px;
}
.select-file-text{
height: 17px;
font-size: 12px;
color: #565656;
line-height: 17px;
}
}
// 信息展示容器
.data-info-container{
padding: 8px 10px 6px;
height: 100%; height: 100%;
padding: 16px; width: 100%;
.import-temp{ // 进度条
text-align: right; .progress{
vertical-align: middle; margin-bottom: 6px ;
color: #409EFF; .el-progress-bar__outer{
background-color: #FFFFFF;
}
.el-progress-bar__inner{
background-color: #D7E9FF;
}
} }
.data-info-content{ .message-container{
height: 150px;
display: flex;
justify-content: space-between;
ul li{
list-style-type: none;
padding-left: 20px;
}
.result-list{
height: 100%; height: 100%;
width: 100%; width: 100%;
overflow: auto; overflow: auto;
} }
.font-class{ //成功信息区
margin: 0px; .result-list{
padding: 0px; ul .success-item{
font-family: '微软雅黑','黑体','宋体'; background: url("~@/assets/img/icon-success.svg") no-repeat 5px 5px;
font-size: 16px; background-size: 10px 10px;
}
}
//错误信息区
.result-list{
ul .error-item{
background: url("~@/assets/img/icon-error.svg") no-repeat 5px 5px;
background-size: 10px 10px;
}
}
}
}
}
// 下载模板区
.second-content{
padding: 16px 12px 0;
margin-bottom: 30px;
.import-template-message{
font-size: 12px;
height: 17px;
color: #565656;
line-height: 17px;
}
.import-template{
.icon-link{
width: 12px;
margin-bottom: -1px;
margin-right: 3px;
}
height: 17px;
font-size: 12px;
color: #57A3FD;
line-height: 17px;
}
}
// 底部按钮
.button-container{
text-align: right;
margin: 15px;
.el-button{
margin: 0 0 0 8px;
padding: 3px 15px;
font-size: 12px;
line-height: 20px;
}
.primary-button{
color: #FFFFFF;
background-color: #57A3FD;
border-color: #57A3FD;
&:hover{
background: #66b1ff;
border-color: #66b1ff;
}
&:disabled{
color: var(--button-font-color-light);
border-color: var(--button-font-color-light);
background-color: var(--button-background-color-light);
}
}
}
}
//模态样式
.view-default.app-data-upload-modal{
.app-data-upload-view{
width: 100%;
height: 100%;
padding: 0 20px 24px 20px;
}
.ivu-modal-content .ivu-modal-body{
height: calc(100% - 58px);
}
// 模态标题
.ivu-modal-header{
padding: 16px;
border: 0;
.ivu-modal-header-inner{
color: #333333;
font-weight: 600;
height: 24px;
line-height: 24px;
}
}
// 关闭图标
.ivu-modal-close .ivu-icon-ios-close{
color: #999999;
font-weight: 600;
} }
.progress {
margin-top: -15px;
} }
\ No newline at end of file
}
\ No newline at end of file
<template> <template>
<div class="app-data-upload-view" v-loading.fullscreen="isUploading" element-loading-background="rgba(57, 57, 57, 0.2)"> <div class="app-data-upload-view" element-loading-background="rgba(57, 57, 57, 0.2)">
<el-row style="margin-top:24px" :gutter="20"> <input
<el-col :span="4"> ref="inputUpLoad"
<el-button type="primary" @click="handleUpLoad">{{$t('components.appDataUploadView.selectfile')}}</el-button> type="file"
<input ref="inputUpLoad" type="file" style="display: none" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @change="importFile"/> style="display: none"
</el-col> accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
<el-col :span="4"> @change="fileChange"
<el-button type="primary" @click="uploadServer">{{$t('components.appDataUploadView.uploadserver')}}</el-button> />
</el-col> <div class="main-content">
<el-col :span="16"> <div v-if="!selectedFile" class="upload-container" @click="handleUpLoad">
<div class="import-temp"><span style="cursor: pointer;" @click="downloadTemp">{{$t('components.appDataUploadView.datatemplate')}}</span></div> <img class="icon-import" src="@/assets/img/icon-import.svg" />
</el-col> <span class="select-file-text">{{ $t('components.appDataUploadView.selectfile') }}</span>
</el-row> </div>
<el-divider></el-divider> <div v-else class="data-info-container">
<el-progress class="progress" v-show="isUploading" :text-inside="true" :stroke-width="14" :percentage="uploadProgress"></el-progress> <div v-if="!isUploaded" class="message-container">
<el-row style="height:480px;padding: 0px 12px;"> <div class="success-list" v-if="!isUploading">
<div class="data-info-content" > {{ $t('components.appDataUploadView.selectfilesucess') }}
<template v-if="importDataArray.length >0 && isUploading === false"> </div>
<div class="success-list" v-if="isUploading">
导入过程中,请稍候
</div>
</div>
<div v-else class="message-container">
<div class="result-list" v-if="Object.keys(responseResult).length > 0">
<ul> <ul>
<li v-for="(item,index) in importDataArray" :key="index" class="font-class"> <li class="title"><span>{{ $t('components.appDataUploadView.importresult') }}</span></li>
{{item[importUniqueItem]?$t('components.appDataUploadView.dataid')+item[importUniqueItem]+$t('components.appDataUploadView.read')+'......':$t('components.appDataUploadView.read')+'......'}} <li>
<span>
{{ $t('components.appDataUploadView.totaldata') }} {{ responseResult.total }} {{ $t('components.appDataUploadView.total') }}{{ $t('app.commonwords.wrong') }}[{{ responseResult.error }}],{{ $t('app.commonwords.success') }}[{{ responseResult.success }}]
</span>
</li>
<template
v-if="responseResult.errorInfos && responseResult.errorInfos.length !== 0">
<li class="title"><span>{{ $t('components.appDataUploadView.errorinfo') }}</span></li>
<li class="error-item" v-for="(item, index) in responseResult.errorInfos" :key="index">
<span v-if="item.index">{{ $t('components.appDataUploadView.start') }} {{item.index}} {{ $t('components.appDataUploadView.row') }}</span><span v-html="item.errorinfo"></span>
</li> </li>
</ul>
</template>
<template v-if="hasImported === true && importDataArray.length === 0">
<span class="font-class">{{isUploading === true?$t('components.appDataUploadView.importing')+"......":promptInfo}}</span>
</template> </template>
</ul>
</div>
</div> </div>
</el-row>
<el-row>
<!-- <el-col :span="4">
<div class="import-temp">
<div style="cursor: pointer;display: inline-block;" @click="downloadSuccessData">{{importSuccessData.length >0?"下载导入成功数据":""}}</div>
</div> </div>
</el-col>
<el-col :span="4">
<div class="import-temp">
<span style="cursor: pointer;display: inline-block;" @click="downloadErrorData">{{importErrorData.length >0?"下载导入失败数据":""}}</span>
</div> </div>
</el-col> --> <el-row class="second-content">
<el-col :span="2" :offset="22"> <el-col>
<el-button type="primary" @click="handleOK">{{$t('components.appDataUploadView.confirm')}}</el-button> <div class="import-template-message">{{ $t('components.appDataUploadView.datatemplatemessage') }}</div>
<div class="import-template">
<img class="icon-link" src="@/assets/img/icon-link.svg" />
<span style="cursor: pointer" @click="downloadTemp">
{{ viewParams.appDeLogicName + $t('components.appDataUploadView.datatemplate') }}</span
>
</div>
</el-col> </el-col>
<div class="import-template-download-info" v-if="isUploaded && responseResult.errorfile" @click="downloadFeedbackMsg">
{{ $t('components.appDataUploadView.downloadinfo') }}
</div>
</el-row>
<el-row class="button-container">
<el-button type="primary" @click="handleCancel">{{ $t('components.appDataUploadView.cancel') }}</el-button>
<el-button
:disabled="!selectedFile"
:loading="isUploading"
type="primary"
class="primary-button"
@click="uploadServer"
>{{ $t('components.appDataUploadView.uploadserver') }}</el-button
>
</el-row> </el-row>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import XLSX from 'xlsx';
import CodeListService from "@/codelist/codelist-service";
import EntityService from '@/service/entity-service';
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Environment } from '@/environments/environment'; import { Environment } from '@/environments/environment';
import moment from "moment"; import { Util } from '@/utils';
import axios from 'axios';
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
@Component({ @Component({})
})
export default class AppDataUploadView extends Vue { export default class AppDataUploadView extends Vue {
/** @Prop() public viewparam: any;
* 传入视图上下文
*
* @type {string}
* @memberof AppDataUploadView
*/
@Prop() protected viewdata!: string;
/**
* 传入视图参数
*
* @type {string}
* @memberof AppDataUploadView
*/
@Prop() protected viewparam!: string;
/**
* 代码表服务对象
*
* @type {CodeListService}
* @memberof AppDataUploadView
*/
public codeListService:CodeListService = new CodeListService();
/** /**
* 实体服务对象 * 视图上下文
*
* @protected
* @type {EntityService}
* @memberof AppDataUploadView
*/
protected entityService: EntityService = new EntityService();
/**
* 视图参数
* *
* @type {*} * @type {*}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
protected viewparams:any = {}; @Prop() public viewdata: any;
/** public viewParams: any = {};
* 导入数据模型
*
* @type {Array<*>}
* @memberof AppDataUploadView
*/
protected importDataModel:Array<any> = [];
/** public context: any = {};
* 导入数据集合
*
* @type {Array<*>}
* @memberof AppDataUploadView
*/
protected importDataArray:Array<any> = [];
/** /**
* 导入标识 * 选择文件数据
* *
* @type {string} * @type {*}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
protected importId:string = ""; public selectedFile: any | null = null;
/** /**
* 是否已有导入数据 * 是否上传完成
* *
* @type {boolean} * @type {boolean}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
protected hasImported:boolean = false; public isUploaded: boolean = false;
/**
* 导入数据识别项属性
*
* @type {string}
* @memberof AppDataUploadView
*/
protected importUniqueItem:string ="";
/** /**
* 提示信息 * 上传进度
* *
* @type {string} * @type {number}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
protected promptInfo:string =""; public uploadedProgress: number = 0;
/** /**
* 导入状态 * 是否上传过程中
* *
* @type {boolean} * @type {boolean}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
protected isUploading:boolean = false; public isUploading: boolean = false;
/** /**
* 导入成功数据 * 导入结果集合
* *
* @type {string} * @type {Array<*>}
* @memberof AppDataUploadView
*/
protected importSuccessData:Array<any> = [];
/**
* 导入失败数据
*
* @type {string}
* @memberof AppDataUploadView
*/
protected importErrorData:Array<any> = [];
/**
* 读取完成的数据
*
* @type {*}
* @memberof AppDataUploadView
*/
public workBookData:any;
/**
* 所有的代码表
*
* @type {*}
* @memberof AppDataUploadView
*/
public allCodeList:any;
/**
* 属性Map(用作属性转化)
*
* @type {*}
* @memberof AppDataUploadView
*/
public allFieldMap:Map<string,any> = new Map();
/**
* 上传服务器数据切片数
*
* @type {number}
* @memberof AppDataUploadView
*/
public sliceUploadCnt: number = Environment.sliceUploadCnt;
/**
* 上传服务器进度条百分比
*
* @type {number}
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public uploadProgress: number = 0; public responseResult: any = {};
/** /**
* 视图参数变化 * 视图参数变化
...@@ -218,64 +140,20 @@ export default class AppDataUploadView extends Vue { ...@@ -218,64 +140,20 @@ export default class AppDataUploadView extends Vue {
* @param {*} oldVal * @param {*} oldVal
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
@Watch('viewparam',{immediate: true, deep: true}) @Watch('viewparam', { immediate: true, deep: true })
onParamData(newVal: any, oldVal: any) { onParamData(newVal: any, oldVal: any) {
if(newVal){ if (newVal) {
Object.assign(this.viewparams, JSON.parse(this.viewparam)); this.viewParams = JSON.parse(newVal);
this.initBasic(); console.log('视图残花', this.viewParams);
}
} }
/**
* 初始化基础数据
*
* @memberof AppDataUploadView
*/
public async initBasic(){
if(this.viewparams.importId){
this.importId = this.viewparams.importId;
}
if(this.viewparams.importData){
this.importDataModel = Object.values(this.viewparams.importData);
this.BubbleSort(this.importDataModel,this.importDataModel.length);
}
this.importDataModel.forEach((item:any) =>{
if(item.isuniqueitem){
this.importUniqueItem = item.headername;
}
this.allFieldMap.set(item.headername,item);
});
//获取代码表值
this.allCodeList = await this.getChartAllCodeList();
} }
/** @Watch('viewdata', { immediate: true, deep: true })
* 冒泡排序 onViewDataChange(newVal: any, oldVal: any) {
* if (newVal) {
* @param {*} newVal this.context = JSON.parse(newVal);
* @param {*} oldVal console.log('上下文', this.context);
* @memberof AppDataUploadView
*/
public BubbleSort(array:Array<any>,length:number){
for (let i = 0; i < length; i++){
for (let j = 0; j < length - i - 1; j++){
if (array[j].order > array[j + 1].order){
let temp:any;
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
} }
/**
* 下载导入数据模板
*
* @memberof AppDataUploadView
*/
public downloadTemp(){
this.importExcel(this.viewparams.appDeLogicName+this.$t('components.appDataUploadView.datatemp'),[]);
} }
/** /**
...@@ -283,275 +161,245 @@ export default class AppDataUploadView extends Vue { ...@@ -283,275 +161,245 @@ export default class AppDataUploadView extends Vue {
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public handleUpLoad(){ public handleUpLoad() {
this.importSuccessData = [];
(this.$refs.inputUpLoad as any).click(); (this.$refs.inputUpLoad as any).click();
} }
/** /**
* 上传服务器 * 取消
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public uploadServer(){ public handleCancel() {
if(this.importDataArray.length == 0){ this.$emit('close', []);
return;
}
let tempDataArray:Array<any> = [];
this.transformData(this.importDataArray,tempDataArray);
this.hasImported = true;
this.isUploading = true;
this.uploadProgress = 0;
this.importDataArray = [];
this.sliceUploadService(tempDataArray, 0);
} }
/** /**
* 数据切片上传 * 文件数据变化
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public sliceUploadService(dataArray: Array<any>, cnt: number) { public fileChange($event: any) {
if(cnt > dataArray.length) { let obj = $event.target || $event.srcElement;
this.isUploading = false; if (!obj.files) {
this.uploadProgress = 100;
return; return;
} }
let sliceArray: Array<any> = []; this.selectedFile = obj.files && obj.files.length > 0 ? obj.files[0] : {};
if(dataArray) {
sliceArray = dataArray.slice(cnt, cnt+this.sliceUploadCnt);
} }
try{
this.entityService.getService(this.viewparams.serviceName).then((service:any) =>{
service.ImportData(this.viewdata,{name:this.importId,importData:sliceArray}).then((res:any) =>{
const result:any = res.data;
if(result && result.rst !== 0){
this.promptInfo = (this.$t('components.appDataUploadView.importfailed') as string);
this.isUploading = false;
return;
}
this.importSuccessData = result.data;
this.promptInfo = (this.$t('components.appDataUploadView.completed') as string);
this.uploadProgress = Number((cnt / dataArray.length * 100).toFixed(2));
this.sliceUploadService(dataArray, cnt + this.sliceUploadCnt);
}).catch((error:any) =>{
this.isUploading = false;
this.promptInfo = (this.$t('components.appDataUploadView.importfailed') as string);
console.error(error);
})
}).catch((error:any) =>{
this.isUploading = false;
this.promptInfo = (this.$t('components.appDataUploadView.importfailed') as string);
console.error(error);
})
}catch(error){
this.isUploading = false;
this.promptInfo = (this.$t('components.appDataUploadView.importfailed') as string);
console.error(error);
};
}
/**
* 导出excel
*
* @memberof AppDataUploadView
*/
public async importExcel (filename:string,_data:any){
const tHeader: Array<any> = [];
this.importDataModel.forEach((item: any) => {
tHeader.push(item.headername);
});
//const data = await this.formatExcelData(filterVal, _data);
const data = _data?_data:[];
this.$export.exportExcel().then((excel:any)=>{
excel.export_json_to_excel({
header: tHeader, //表头 必填
data:data, //具体数据 必填
filename: filename, //非必填
autoWidth: true, //非必填
bookType: "xlsx" //非必填
});
});
};
/** /**
* 确认 * 设置UI状态
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public handleOK(){ public setUIState(uploadedProgress: number, isUploading: boolean, isUploaded: boolean, result: any = {}) {
this.$emit('close',this.importSuccessData); this.uploadedProgress = uploadedProgress;
this.isUploading = isUploading;
this.isUploaded = isUploaded;
this.responseResult = result;
} }
/** /**
* 导入Excel * 下载导入数据模板
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public importFile($event:any) { public downloadTemp() {
let obj = $event.target || $event.srcElement; let requestUrl: string = '';
if (!obj.files) { if (this.viewdata && this.context.srfparentkey && this.context.srfparentdename && this.context.srfparentdename !== this.viewdata.appEntityName) {
return; requestUrl += `/${Util.srfpluralize(this.viewdata.srfparentdename)}/${this.viewdata.srfparentkey}`;
}
requestUrl += `/${Util.srfpluralize(this.viewParams.serviceName)}/importtemplate`;
if (this.viewParams.importId) {
requestUrl += `?srfimporttag=${this.viewParams.importId}`;
}
axios({
url: requestUrl,
method: 'get',
responseType: 'blob',
}).then((response: any) => {
if (response.status == 200) {
let fileName = response.headers['content-disposition']
.split(';')
.find((str: string) => str.indexOf('filename=') != -1)
.slice(9);
fileName = decodeURIComponent(fileName);
let blob = new Blob([response.data], { type: 'application/vnd.ms-excel' });
let elink = document.createElement('a');
elink.download = fileName;
elink.style.display = 'none';
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
} }
let f = obj.files[0]; });
let reader = new FileReader();
reader.onload = (e:any) => {
let data = e.target.result;
this.workBookData = XLSX.read(data, {type: 'binary',cellDates: true});
let xlsxData = XLSX.utils.sheet_to_json(this.workBookData.Sheets[this.workBookData.SheetNames[0]]);
let list1 = this.getFirstRow(this.workBookData);
xlsxData = this.AddXlsxData(xlsxData, list1);
this.importDataArray = this.$util.deepCopy(xlsxData);
(this.$refs.inputUpLoad as any).value = '';
};
reader.readAsBinaryString(f);
} }
/** /**
* 获取excel第一行的内容 * 下载导入反馈信息
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public getFirstRow(wb:any) { public downloadFeedbackMsg() {
//// 读取的excel单元格内容 if(!this.responseResult || !this.responseResult.errorfile || !this.responseResult.errorfile.fileid){
let wbData = wb.Sheets[wb.SheetNames[0]]; this.$Notice.error({ desc: this.$t('components.appDataUploadView.downloaderror') as string });
// 匹配excel第一行的内容 return;
let re = /^[A-Z]1$/;
let temparr = [];
// excel第一行内容赋值给数组
for (let key in wbData) {
if (wbData.hasOwnProperty(key)) {
if (re.test(key)) {
temparr.push(wbData[key].h);
} }
let downloadUrl: string = `${Environment.ExportFile}/${this.responseResult.errorfile.folder}/${this.responseResult.errorfile.fileid}`;
const headers = {};
axios({
method: 'get',
url: downloadUrl,
headers: headers,
responseType: 'blob'
}).then((response: any) => {
if (!response || response.status != 200) {
this.$Notice.error({ desc: this.$t('components.appDataUploadView.downloaderror') as string });
return;
} }
// 请求成功,后台返回的是一个文件流
if (response.data) {
// 获取文件名
const filename = `导入错误${this.responseResult.errorfile.fileid}.xlsx`;
let filetype = this.calcFilemime('xlsx');
// 用blob对象获取文件流
let blob = new Blob([response.data], { type: filetype });
// 通过文件流创建下载链接
var href = URL.createObjectURL(blob);
// 创建一个a元素并设置相关属性
let a = document.createElement('a');
a.href = href;
a.download = filename;
// 添加a元素到当前网页
document.body.appendChild(a);
// 触发a元素的点击事件,实现下载
a.click();
// 从当前网页移除a元素
document.body.removeChild(a);
// 释放blob对象
URL.revokeObjectURL(href);
} else {
this.$Notice.error({ desc: this.$t('components.appDataUploadView.downloaderror') as string });
} }
return temparr; }).catch((error: any) => {
console.error(error);
});
} }
/** /**
* 增加对应字段空白内容 * 计算文件mime类型
* *
* @memberof AppDataUploadView * @param filetype 文件后缀
*/ * @memberof AppDataUploadView
public AddXlsxData(xlsxData:any, list1:any) { */
// 空白字段替换值 public calcFilemime(filetype: string): string {
let addData = null; let mime = "application/vnd.ms-excel";
for (let i = 0; i < xlsxData.length; i++) { switch (filetype) {
// 要被JSON的数组 case ".xlsx":
for (let j = 0; j < list1.length; j++) { mime = "application/vnd.ms-excel";
// excel第一行内容 break;
if (!xlsxData[i][list1[j]]) { case ".wps":
xlsxData[i][list1[j]] = addData; mime = "application/kswps";
} break;
} case ".doc":
} mime = "application/msword";
return xlsxData; break;
case ".docx":
mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case ".txt":
mime = "text/plain";
break;
case ".zip":
mime = "application/zip";
break;
case ".png":
mime = "image/png";
break;
case ".gif":
mime = "image/gif";
break;
case ".jpeg":
mime = "image/jpeg";
break;
case ".jpg":
mime = "image/jpeg";
break;
case ".rtf":
mime = "application/rtf";
break;
case ".avi":
mime = "video/x-msvideo";
break;
case ".gz":
mime = "application/x-gzip";
break;
case ".tar":
mime = "application/x-tar";
break;
}
return mime;
} }
/** /**
* 获取图表所需代码表 * 上传服务器
* *
* @memberof AppDataUploadView * @memberof AppDataUploadView
*/ */
public async getChartAllCodeList(){ public uploadServer() {
let codeListMap:Map<string,any> = new Map(); if (!this.selectedFile) {
if(Object.values(this.importDataModel).length >0){ return;
await Object.values(this.importDataModel).forEach(async (singleDataModel:any) =>{
if(singleDataModel.codelist){
let tempCodeListMap:Map<any,any> = new Map();
let res:any = await this.getCodeList(singleDataModel.codelist);
if(res && res.length >0){
res.forEach((codeListItem:any) =>{
tempCodeListMap.set(codeListItem.value,codeListItem.text);
})
}
codeListMap.set(singleDataModel.codelist.tag,tempCodeListMap);
} }
try {
let requestUrl: string = '';
this.setUIState(0, true, false);
if (this.viewdata && this.viewdata.srfparentkey && this.viewdata.srfparentdename) {
requestUrl += `/${Util.srfpluralize(this.viewdata.srfparentdename)}/${this.viewdata.srfparentkey}`;
}
requestUrl += `/${Util.srfpluralize(this.viewParams.serviceName)}/importdata2`;
if (this.viewParams.importId) {
requestUrl += `?srfimporttag=${this.viewParams.importId}`;
}
const data = new FormData();
data.append('file', this.selectedFile);
axios
.post(requestUrl, data, {
headers: { 'Content-Type': 'multipart/form-data' },
onUploadProgress: (progressEvent: any) => {
this.uploadedProgress = Math.floor((progressEvent.loaded / progressEvent.total) * 100);
},
}) })
} .then((res: any) => {
return codeListMap; const result: any = {};
} if (res && res.status && res.status == 200) {
const { data: data } = res;
/** const {errorinfo,success,total,errorfile} = data;
* 获取代码表 result.total = total ? Number(total) : 0;
* result.success = success ? Number(success) : 0;
* @returns {Promise<any>} result.errorfile = errorfile;
* @memberof AppDataUploadView if(errorinfo && Object.keys(errorinfo).length >0){
*/ result.error = Object.keys(errorinfo).length;
public getCodeList(codeListObject:any):Promise<any>{ result.errorInfos = [];
return new Promise((resolve:any,reject:any) =>{ Object.keys(errorinfo).forEach((item:any) =>{
if(codeListObject.tag && Object.is(codeListObject.type,"STATIC")){ result.errorInfos.push({index: Number(item) + 1, errorinfo: errorinfo[item].errorInfo});
const codelist = this.$store.getters.getCodeList(codeListObject.tag);
if (codelist) {
resolve([...JSON.parse(JSON.stringify(codelist.items))]);
} else {
console.log(`----${codeListObject.tag}----${(this.$t('app.commonWords.codeNotExist') as string)}`);
}
}else if(codeListObject.tag && Object.is(codeListObject.type,"DYNAMIC")){
this.codeListService.getItems(codeListObject.tag).then((res:any) => {
resolve(res);
}).catch((error:any) => {
console.log(`----${codeListObject.tag}----${(this.$t('app.commonWords.codeNotExist') as string)}`);
});
}
}) })
} }
/**
* 转化数据
*
* @memberof AppDataUploadView
*/
public transformData(data:Array<any>,result:Array<any>){
data.forEach((item:any) =>{
let curObject:any = {};
Object.keys(item).forEach((ele:any) => {
// todo XLSX读取时间为国际时间(东8区)+8H转为标准时间
if (item[ele] instanceof Date){
const tempDate:Date = item[ele];
item[ele] = moment(tempDate).add(8, 'h').format("YYYY-MM-DD HH:mm:ss");
} }
if(this.allFieldMap.get(ele).codelist){ this.setUIState(0, false, true, result);
let codelistTag:string = this.allFieldMap.get(ele).codelist.tag; }).catch((error: any) => {
let codelistIsNumber:boolean = this.allFieldMap.get(ele).codelist.isnumber; const errorResult: any = {};
let curCodeList:any = this.transCodeList(codelistTag,codelistIsNumber,true); if (error && error.status && error.status !== 200) {
Object.defineProperty(curObject, this.allFieldMap.get(ele).name, { errorResult.errorInfos = [];
value: curCodeList.get(item[ele]), errorResult.errorInfos.push({ errorInfo: error.data && error.data.message ? error.data.message : '' });
writable : true,
enumerable : true,
configurable : true
});
}else{
Object.defineProperty(curObject, this.allFieldMap.get(ele).name, {
value: item[ele],
writable : true,
enumerable : true,
configurable : true
});
} }
this.setUIState(0, false, true, errorResult);
}); });
result.push(curObject); } catch (error: any) {
}) this.setUIState(0, false, true, { errorInfos:[{errorInfo: error.data}] });
} }
/**
* 翻译代码表
*
* @memberof AppDataUploadView
*/
public transCodeList(codeListTag:string,codelistIsNumber:boolean,isTransform:boolean){
let curCodeList:any = this.allCodeList.get(codeListTag);
if(isTransform){
let tempCodelist:Map<string,string> = new Map();
curCodeList.forEach((item:string,key:string) =>{
let value:any = codelistIsNumber?Number(key):key;
tempCodelist.set(item,value);
})
curCodeList = tempCodelist;
} }
return curCodeList;
}
} }
</script> </script>
......
...@@ -40,17 +40,25 @@ function getLocaleResourceBase(){ ...@@ -40,17 +40,25 @@ function getLocaleResourceBase(){
global: 'ཁྱོན་ཡོངས།', global: 'ཁྱོན་ཡོངས།',
}, },
appDataUploadView: { appDataUploadView: {
"viewtitle":"ཉེར་སྤྱོད་གཞི་གྲངས་ནང་འདྲེན་མཐོང་རིས་", "selectfile":"ས་ཁོངས་དེ་མནན་ན་ཡར་བསྐུར་།",
"selectfile":"ཡིག་ཆ་འདེམས་པ་", "uploadserver":"ཡར་སྤྲོད་གཞི་གྲངས་",
"uploadserver":"ཡར་བསྐུར་ཞབས་ཞུ་ཆས་།", "datatemplate":"ནང་འདྲེན་གཞི་གྲངས་དཔེ་པང་",
"datatemplate":"ཕབ་ལེན་ནང་འདྲེན་གཞི་གྲངས་དཔེ་པང་།",
"dataid":"གཞི་གྲངས་ཀྱི་མཚོན་རྟགས་",
"read":"ཀློག་ལེན་གྲུབ་འབྲས་ཐོབ་པའི་ངང་", "read":"ཀློག་ལེན་གྲུབ་འབྲས་ཐོབ་པའི་ངང་",
"importing":"ནང་འདྲེན་བྱེད་བཞིན་ཡོད།",
"completed":"ནང་འདྲེན་ལེགས་སྒྲུབ་", "completed":"ནང་འདྲེན་ལེགས་སྒྲུབ་",
"confirm":"ངོས་འཛིན་", "confirm":"ངོས་འཛིན་",
"datatemp":"ནང་འདྲེན་གཞི་གྲངས་དཔེ་པང་", "datatemp":"ནང་འདྲེན་གཞི་གྲངས་དཔེ་པང་",
"importfailed":"ནང་འདྲེན་ཕམ་པ།" "importfailed":"ནང་འདྲེན་ཕམ་པ།",
"datatemplatemessage":"དཔེ་གཟུགས་ཕབ་ལེན་དང་ནང་འཇུག་བྱེད་པ་མ་ཟད།རེ་བ་ལྟར་འབྲི་དགོས།",
"cancel":"མེད་པར་བཟོ་བ་",
"selectfilesucess":"ཡིག་ཆ་བདམས་ནས་གྲུབ་འབྲས་ཐོབ་པའི་ངང་།",
"importresult":"ནང་འདྲེན་འབྲས་བུ་",
"totaldata": "སྡོམ་པས་ནང་འདྲེན་གཞི་གྲངས།",
"total": "ལྕུག་མ།",
"errorinfo": "ནོར་འཁྲུལ་ཆ་འཕྲིན།",
"start": "དོན་ཚན་དང་པོ།",
"row": "ཕྲེང་",
"downloadinfo": "ལྡོག་སྐྱེལ་ཆ་འཕྲིན་ཕབ་ལེན་",
"downloaderror": "ཡིག་ཆ་ཕབ་ལེན་ཕམ་།"
}, },
appDebugActions:{ appDebugActions:{
button: 'ཁ་འབྱེད་སྡེབ་སྒྲིག་རྣམ་པ་', button: 'ཁ་འབྱེད་སྡེབ་སྒྲིག་རྣམ་པ་',
......
...@@ -40,17 +40,24 @@ function getLocaleResourceBase(){ ...@@ -40,17 +40,24 @@ function getLocaleResourceBase(){
global: 'Global', global: 'Global',
}, },
appDataUploadView: { appDataUploadView: {
"viewtitle":"AppDataUploadView", "selectfile":"Click this area to upload",
"selectfile":"Select File",
"uploadserver":"Upload Server", "uploadserver":"Upload Server",
"datatemplate":"Download Import Data Template", "datatemplate":"Import Data Template",
"dataid":"Data ID is ", "datatemplatemessage":"Download the Import Data Template, According to the specification required to fill in",
"read":" read Successful", "read":" read Successful",
"importing":"Importing",
"completed":"Import Completed", "completed":"Import Completed",
"confirm":"OK", "confirm":"OK",
"datatemp":"Data Template", "cancel":"Cancel",
"importfailed":"Import Failed" "importfailed":"Import Failed",
"selectfilesucess":"File selected successfully",
"importresult":"Import Result",
"totaldata": "Total Imported Data",
"total": "Count",
"errorinfo": "Error Message",
"start": "Line",
"row": "",
"downloadinfo": "Download The Feedback",
"downloaderror": "Failed To Download File"
}, },
appDebugActions: { appDebugActions: {
button: 'Open Configuration Mode', button: 'Open Configuration Mode',
......
...@@ -40,17 +40,24 @@ function getLocaleResourceBase(){ ...@@ -40,17 +40,24 @@ function getLocaleResourceBase(){
global: '全局', global: '全局',
}, },
appDataUploadView: { appDataUploadView: {
"viewtitle":"应用数据导入视图", "selectfile":"单击此区域进行上传",
"selectfile":"选取文件", "uploadserver":"上传数据",
"uploadserver":"上传服务器", "datatemplate":"导入数据模板",
"datatemplate":"下载导入数据模板", "datatemplatemessage":"下载导入模版,并按要求填写:",
"dataid":"数据标识为",
"read":"读取成功", "read":"读取成功",
"importing":"导入中",
"completed":"导入完成", "completed":"导入完成",
"confirm":"确认", "confirm":"确认",
"datatemp":"导入数据模板", "cancel":"取消",
"importfailed":"导入失败" "importfailed":"导入失败",
"selectfilesucess":"选取文件成功",
"importresult":"导入结果",
"totaldata": "共计导入数据",
"total": "条",
"errorinfo": "错误信息",
"start": "第",
"row": "行",
"downloadinfo": "下载反馈信息",
"downloaderror": "下载文件失败"
}, },
appDebugActions:{ appDebugActions:{
button: '开启配置模式', button: '开启配置模式',
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册