add 带模板导入、人员信息(部分完成)

This commit is contained in:
赵霄
2023-09-04 16:09:35 +08:00
parent 83a55d9d29
commit 3ec511e114
9 changed files with 561 additions and 110 deletions
+5
View File
@@ -509,6 +509,11 @@ module.exports = {
pleaseUpload: 'Please Upload',
file: 'File'
},
importWithTemplate: {
chooseFile: 'Select file',
downTemplate: 'Click to download template',
noFileMsg: 'Please select a file'
},
// 系统管理
system,
// 个人中心
+5
View File
@@ -509,6 +509,11 @@ module.exports = {
pleaseUpload: '请上传',
file: '文件'
},
importWithTemplate: {
chooseFile: '选择文件',
downTemplate: '点击下载模板',
noFileMsg: '请选择一个文件'
},
// 系统管理
system,
// 个人中心
+121
View File
@@ -0,0 +1,121 @@
<template>
<a-modal
:title="$t('import')"
:maskClosable="false"
:width="600"
:closable="true"
:confirm-loading="confirmLoading"
@ok="handleOk"
@cancel="handleCancel"
:visible="visible">
<a-form layout="inline">
<a-form-item :label="$t('importWithTemplate.chooseFile')">
<div class="form-content">
<a-input v-model="fileName" />
<j-upload type="primary" :number="1" @change="handleFileChange" :show-upload-list="false" :return-url="false" v-bind="$attrs">
<template v-slot:customButton>
<a-button type="primary">{{ $t('importWithTemplate.chooseFile') }}</a-button>
</template>
</j-upload>
</div>
<a-button type="link" class="down-template-btn" @click="downTemplate">{{ $t('importWithTemplate.downTemplate') }}</a-button>
</a-form-item>
</a-form>
</a-modal>
</template>
<script>
import '@assets/less/common.less'
import { urlToParams } from '../utils/util'
import { downloadFile } from '../api/manage'
export default {
name: 'ImportWithTemplate',
props: {
// 下载模板的地址
downTemplateUrl: {
type: String,
required: false,
default: null
},
// 导入模板文件名
templateName: {
type: String,
required: false,
default: null
}
},
data () {
return {
visible: false,
confirmLoading: false,
fileId: null,
fileName: null
}
},
methods: {
open () {
this.visible = true
},
handleOk () {
if (this.fileId) {
this.$emit('ok', this.fileId)
this.close()
} else {
this.$message.warn(this.$t('importWithTemplate.noFileMsg'))
}
},
handleCancel () {
this.close()
},
close () {
this.visible = false
this.fileId = null
this.fileName = null
},
handleFileChange (fileList) {
this.fileName = fileList[0].fileName
const file = urlToParams(fileList[0].filePath)
this.fileId = file.id
},
// 下载导入模板
downTemplate () {
if (!this.downTemplateUrl) {
this.$message.warn('请设置downTemplateUrl属性')
return
}
const fileName = this.templateName || '导入模板'
downloadFile(this.downTemplateUrl, fileName + '.xlsx')
}
}
}
</script>
<style scoped lang="less">
.form-content {
display: flex;
margin-top: 5px;
.ant-input {
pointer-events: none;
}
.ant-btn {
margin-left: 16px;
}
}
.ant-form-inline .ant-form-item {
width: 100%;
display: flex;
/deep/ .ant-form-item-control-wrapper {
flex: 1;
width: 0;
}
}
/deep/ .ant-form-item-control {
line-height: 32px;
}
</style>
+210
View File
@@ -0,0 +1,210 @@
<template>
<div class="person-comp-box">
<a-steps direction="vertical">
<a-step v-for="(step, index) in stepsData" :key="step.id" :status="step.nodeName === currentNode ? 'process' : 'wait'"
:class="{'red-tail': index < currentNodeIndex}">
<template #icon>
<div class="step-cus-icon"
:class="{'step-cus-icon-done': index < currentNodeIndex, 'step-cus-icon-now': step.nodeName === currentNode}">
<i class="iconfont icon-user" />
</div>
</template>
<!-- 流程节点标题-->
<template #title>
<a-tooltip>
<template #title>{{ step.nodeName }}</template>
<div class="step-title">{{ step.nodeName }}</div>
</a-tooltip>
</template>
<!-- 流程节点选人内容-->
<template #description>
<div class="personnel-container">
<div class="personnel-container-title" :class="{'personnel-container-select-title': index === 0}">
<a-tooltip>
<template #title>{{ step.nodeRoleName }}</template>
<div class="personnel-container-title-text">{{ step.nodeRoleName }}</div>
</a-tooltip>
</div>
<div class="personnel-container-content">
<div class="personnel-container-content-text">
<template v-if="step.canChoose && index >= currentNodeIndex">
<!-- TODO 数据库设计确定后处理数据抛出格式-->
<user-selection type="checkbox" input-type="textarea" />
</template>
<div class="personnel-container-content-echo-text" v-else>{{ step.userList }}</div>
</div>
<a-icon type="clock-circle" theme="filled" v-if="index === currentNodeIndex" class="personnel-container-content-icon" />
<a-icon type="check"
v-if="index < currentNodeIndex"
class="personnel-container-content-icon personnel-container-content-icon-now" />
</div>
</div>
</template>
</a-step>
</a-steps>
</div>
</template>
<script>
import '@assets/less/common.less'
import UserSelection from './selection/UserSelection.vue'
export default {
name: 'PersonnelInfo',
components: { UserSelection },
props: {
// 数据
data: {
type: Array,
required: true,
default: () => {
return []
}
},
// 当前节点
currentNode: {
type: String,
required: false,
default: null
}
},
data () {
return {
stepsData: [],
currentNodeIndex: 0 // 当前节点的位置
}
},
watch: {
data: {
handler () {
this.stepsData = JSON.parse(JSON.stringify(this.data))
this.currentNodeIndex = this.stepsData.findIndex(tt => tt.nodeName === this.currentNode)
},
deep: true,
immediate: true
}
}
}
</script>
<style scoped lang="less">
.person-comp-box {
height: 100%;
overflow-y: auto;
}
/deep/ .ant-steps-vertical .ant-steps-item-icon {
margin-right: 0;
}
/deep/ .ant-steps-item-title {
max-width: 100%;
}
/deep/ .ant-steps-item-content {
padding: 0 12px;
}
.step-title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 16px;
font-family: PingFang SC-Regular, PingFang SC, sans-serif;
color: #1D2129;
font-weight: 550;
}
.personnel-container {
&-title {
height: 36px;
background: #6A7484;
border-radius: 8px 8px 0 0;
padding: 0 16px;
&-text {
font-size: 16px;
font-family: PingFang SC-Regular, PingFang SC, sans-serif;
color: #FFFFFF;
line-height: 36px;
}
}
&-select-title {
background: #9F5258;
}
&-content {
background: #FFFFFF;
border-radius: 0 0 8px 8px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
padding: 16px;
min-height: 52px;
display: flex;
align-items: center;
&-text {
flex: 1;
width: 0;
}
&-icon {
margin-left: 16px;
color: @primary-color;
font-size: 20px;
}
&-icon-now {
font-size: 10px;
width: 20px;
height: 20px;
background: #FAE6E5;
border-radius: 10px 10px 10px 10px;
opacity: 1;
line-height: 20px;
text-align: center;
}
&-echo-text {
font-size: 14px;
font-family: PingFang SC-Regular, PingFang SC, sans-serif;
font-weight: 400;
color: #4E5969;
line-height: 22px;
}
}
}
/deep/ .user-organ-wrap .button-box {
height: 32px;
}
/deep/ .ant-steps-vertical > .ant-steps-item > .ant-steps-item-container > .ant-steps-item-tail {
left: 14px;
padding: 31px 0 4px;
}
.step-cus-icon {
width: 28px;
height: 28px;
background: #F2F3F5;
border-radius: 32px 32px 32px 32px;
display: flex;
align-items: center;
justify-content: center;
&-done {
background: rgba(213, 44, 38, 0.08);
color: @primary-color;
}
&-now {
color: white;
background: @primary-color;
}
}
/deep/ .red-tail > .ant-steps-item-container > .ant-steps-item-tail::after {
background-color: @primary-color;
}
</style>
+166 -102
View File
@@ -2,44 +2,36 @@
<div :id="containerId" style="position: relative">
<a-upload
name="file"
:multiple="multiple"
:action="uploadAction"
:headers="headers"
:data="{'biz':bizPath}"
:fileList="fileList"
:beforeUpload="doBeforeUpload"
:beforeUpload="beforeUpload"
@change="handleChange"
:disabled="disabled"
:returnUrl="returnUrl"
:listType="complistType"
@preview="handlePreview"
@download="handleDownload"
:showUploadList="{
showDownloadIcon: isDownload
}"
v-bind="$attrs"
v-on="childListeners"
:showUploadList="showUploadList ? {
showDownloadIcon: isDownload
} : false"
:class="{'uploadty-disabled':disabled}">
<template>
<div v-if="isImageComp">
<a-icon type="plus" />
<div class="ant-upload-text">{{ text }}</div>
</div>
<a-button v-else-if="buttonVisible">
<a-icon type="upload" />
{{ text }}
</a-button>
<slot name="customButton">
<div v-if="isImageComp">
<a-icon type="plus" />
<div class="ant-upload-text">{{ text }}</div>
</div>
<a-button v-else-if="buttonVisible">
<a-icon type="upload" />
{{ text }}
</a-button>
</slot>
</template>
</a-upload>
<div id="images">
<div class="image" v-viewer="{movable: false}">
<img v-show="image" :src="imageUrl">
</div>
</div>
<j-image-preview-modal ref="imagePreviewModal" />
</div>
</template>
@@ -48,11 +40,15 @@
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { getFileAccessHttpUrl, downloadFile } from '@/api/manage'
import { previewPdf } from '@/utils/previewPdf'
import JImagePreviewModal from '@comp/jero/modal/JImagePreviewModal.vue'
import { getFileInfo } from '@/api/api'
import { previewPdf } from '../../utils/previewPdf'
// eslint-disable-next-line no-undef
// const Base64 = require('js-base64').Base64
const FILE_TYPE_ALL = 'all'
const FILE_TYPE_IMG = 'image'
// const FILE_TYPE_TXT = 'file'
const FILE_TYPE_IMGS = ['jpg', 'jpeg', 'png', 'raw']
const FILE_TYPE_PDF = 'pdf'
@@ -66,20 +62,19 @@ const Base64 = require('js-base64').Base64
const CAN_PREVIEW_FILE_TYPE = ['pdf', 'image']
// 不支持预览的文件后缀
const CAN_PREVIEW_FILE_SUFFIX = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'mp3', 'mp4', 'flv']
const uidGenerator = () => {
return '-' + parseInt(Math.random() * 10000 + 1, 10)
}
export default {
name: 'JUpload',
components: { JImagePreviewModal },
data () {
return {
uploadAction: window._CONFIG.domianURL + '/sys/common/upload',
headers: {},
fileList: [],
newFileList: [],
image: false,
uploadGoOn: true,
containerId: null,
imageUrl: null
fileTypes: this.fileType
}
},
props: {
@@ -126,6 +121,16 @@ export default {
required: false,
default: true
},
/**
* 仅返回文件id
* true 仅返回文件id
* false 返回reurl
* */
returnId: {
type: Boolean,
required: false,
default: false
},
number: {
type: Number,
required: false,
@@ -136,15 +141,9 @@ export default {
required: false,
default: true
},
multiple: {
type: Boolean,
default: true
},
beforeUpload: {
type: Function
},
isDownload: {
showUploadList: {
type: Boolean,
required: false,
default: true
}
},
@@ -153,16 +152,15 @@ export default {
immediate: true,
handler () {
const val = this.value
this.initFileList(val)
// if (val instanceof Array) {
// if (this.returnUrl) {
// this.initFileList(val.join(','))
// } else {
// this.initFileListArr(val)
// }
// } else {
// this.initFileList(val)
// }
if (val instanceof Array) {
if (this.returnUrl) {
this.initFileList(val.join(','))
} else {
this.initFileListArr(val)
}
} else {
this.initFileList(val)
}
}
}
},
@@ -190,67 +188,90 @@ export default {
// ---------------------------- end 图片左右换位置 -------------------------------------
},
methods: {
// 将url的参数拆分成对象
urlToParams (url) {
const commonUrl = window._CONFIG.staticDomainURL
// url截取参数的部分
const paramsStr = url.slice(url.indexOf('?') + 1)
const paramsObj = {
url,
id: url.slice(url.indexOf(commonUrl) + commonUrl.length + 1, url.indexOf('?'))
}
paramsStr.split('&').forEach(item => {
const arr = item.split('=')
paramsObj[arr[0]] = arr[1]
})
return paramsObj
},
initFileList (val) {
initFileListArr (val) {
if (!val || val.length === 0) {
this.fileList = []
return
}
// 所有文件url的数组
let arr = []
// 用于临时存储文件的数组,最终会被赋值到this.fileList
const fileList = []
if (val instanceof Array) {
// url数组直接返回,如果是对象数组,就将每个对象的url取出
arr = this.returnUrl ? val : val.map(item => item.filePath)
} else {
// 将字符串拆分数组(props声明value只能是Array或String)
arr = val.split(',')
for (let a = 0; a < val.length; a++) {
this.fileList.forEach((item) => {
if (item.url === val[a]) {
item.uid = uidGenerator()
item.response.status = 'done'
}
})
}
arr.forEach(url => {
if (url) {
const params = this.urlToParams(url)
},
async initFileList (paths) {
if (!paths || paths.length === 0) {
this.fileList = []
return
}
let arr = paths.split(',')
// 返回路径的时候,对路径进行操作,取出所属id
if (!this.returnId && arr.length > 0) {
const newArr = []
arr.map(item => {
const itemArr = item.split('/')
newArr.push(itemArr[itemArr.length - 1])
})
arr = newArr
}
const fileList = []
for (let a = 0; a < arr.length; a++) {
// 获取每一个文件的信息,组成fileList
// 突然想判断现在的fileList 中是否是历史的信息,如果是的话则先进行匹配
const isHistory = this.fileList.find(file => file.response.status === 'history' && (file.response.result || {}).id === arr[a])
console.log('isHistory===', isHistory)
if (isHistory) {
fileList.push(isHistory)
} else {
const fileObj = await this.getFileInfo(arr[a])
const url = getFileAccessHttpUrl(arr[a])
const fileName = (fileObj || {}).fileName
const fileNameNotType = fileName.substring(0, fileName.lastIndexOf('.'))
const previewUrl = (fileObj || {}).url || ''
const previewName = previewUrl.substring(previewUrl.lastIndexOf(fileNameNotType))
fileList.push({
uid: params.id,
name: params.fullfilename,
uid: uidGenerator(),
name: (fileObj || {}).fileName,
status: 'done',
url,
// response用于下载和预览
url: url,
previewName,
response: {
success: true,
result: {
id: params.id,
fileName: params.fullfilename
},
status: 'history'
status: 'history',
message: arr[a],
result: fileObj
}
})
}
})
// 将处理好的数据回显
this.fileList = fileList
}
this.fileList = [...fileList]
},
handlePathChange () {
const uploadFiles = this.fileList
let path = ''
// 文件id
let fileIds = ''
if (!uploadFiles || uploadFiles.length === 0) {
path = ''
}
const arr = []
// 如果returnid为true 只返回id
if (this.returnId) {
for (let a = 0; a < uploadFiles.length; a++) {
if (uploadFiles[a].status === 'done') {
arr.push(uploadFiles[a].response.result.id)
} else {
return
}
}
if (arr.length > 0) {
fileIds = arr.join(',')
}
this.$emit('change', fileIds)
return
}
for (let a = 0; a < uploadFiles.length; a++) {
if (uploadFiles[a].status === 'done') {
@@ -264,20 +285,39 @@ export default {
}
this.$emit('change', path)
},
doBeforeUpload (file) {
beforeUpload (file) {
this.uploadGoOn = true
const fileType = file.type
if (this.fileType === FILE_TYPE_IMG) {
if (fileType.indexOf('image') < 0) {
this.$message.warning('请上传图片')
file.uploadGoOn = true
const fileSize = file.size // 上传的文件大小
const fileType = file.type // 上传的文件类型
if (fileSize > 1024 * 1024 * 100) {
this.$message.warning('文件大小限制为100M')
this.uploadGoOn = false
file.uploadGoOn = false
return false
}
// 不等于全部类型可以上传的时候,对上传的文件进行判断
if (this.fileType !== FILE_TYPE_ALL) {
// filter(tt => fileType.indexOf(tt) > -1) 判断用户传的文件类型,和要求传的文件类型是否一致
// 当上传的图片格式为jpg时,在此组件中,会返回类型为 image/jpeg ElememntUI设计如此 所以需要把用户传下来的jpg强制改成jpeg
this.fileTypes = this.fileTypes.replace('jpg', 'jpeg')
const arr = this.fileTypes.split(',').filter(tt => fileType.indexOf(tt) > -1)
if (arr.length === 0) {
this.$message.warning(this.fileTypeErrorMessage || `请上传${this.fileTypes}文件`)
this.uploadGoOn = false
file.uploadGoOn = false
return false
}
}
// 扩展 beforeUpload 验证
if (typeof this.beforeUpload === 'function') {
return this.beforeUpload(file)
if (this.fileTypes === FILE_TYPE_IMG) {
if (fileType.indexOf('image') < 0) {
this.$message.warning('请上传图片')
this.uploadGoOn = false
file.uploadGoOn = false
return false
}
}
// TODO 扩展功能验证文件大小
return true
},
handleChange (info) {
@@ -292,14 +332,15 @@ export default {
if (info.file.response.success) {
fileList = fileList.map((file) => {
if (file.response) {
// const reUrl = `${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.response.result.fileName}`
// TODO getFileAccessHttpUrl方法会追加token,在之后拼参数
file.url = getFileAccessHttpUrl(file.response.result.id) + '&fullfilename=' + file.response.result.fileName
// let reUrl = `${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.response.result.fileName}`;
file.url = getFileAccessHttpUrl(file.response.result.id)
}
return file
})
} else {
this.$message.error(info.file.response.message)
info.fileList.pop()
this.uploadGoOn = false
this.$message.warn(info.file.response.message)
}
// this.$message.success(`${info.file.name} 上传成功!`);
} else if (info.file.status === 'error') {
@@ -373,6 +414,29 @@ export default {
const url = `${window._CONFIG.onlinePreviewDomainURL}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}`
window.open(url)
},
getFileUrl (fileId) {
return `${window._CONFIG.domianURL}/sys/common/download/${fileId}`
},
/**
* 通过文件的id获取文件的相关信息
* @param id
*/
getFileInfo (id) {
return new Promise(resolve => {
let result = {}
getFileInfo({ id: id }).then(res => {
if (res.success) {
result = res.result
}
}).finally(() => {
resolve(result)
})
})
},
/**
* 单个文件的下载功能
* @param file
*/
handleDownload (file) {
// 下载文件
downloadFile(`/sys/common/download/${file.response.result.id}`, file.name)
@@ -387,7 +451,7 @@ export default {
}
</script>
<style lang="less">
<style lang="less" scoped>
.uploadty-disabled {
.ant-upload-list-item {
.anticon-close {
+15 -1
View File
@@ -2,6 +2,10 @@
<div>
<div class="user-organ-wrap">
<a-input
:type="inputType"
:autosize="true"
:rows="1"
readonly="readonly"
class="user-input"
:placeholder="placeholder"
:value="checkedValue"
@@ -9,7 +13,7 @@
>
</a-input>
<a-button type="primary" class="button-box" @click="selectClick">
{{$t('userSelect.select')}}
{{ $t('userSelect.select') }}
</a-button>
</div>
<user-select-modal v-bind="$attrs" ref="selectModal" @change="selectChange" @nameChange="nameChange"></user-select-modal>
@@ -46,6 +50,12 @@ export default {
filedName: {
type: String,
default: ''
},
// 回显输入框的类型,默认是input
inputType: {
type: String,
required: false,
default: 'text'
}
},
watch: {
@@ -84,9 +94,13 @@ export default {
.user-organ-wrap {
width: 100%;
position: relative;
.user-input {
resize: none;
width: calc(100% - 70px);
pointer-events: none;
}
.button-box {
height: 38px;
margin-left: 5px;
+3
View File
@@ -440,6 +440,9 @@ export const ConfigurableTableMixin = {
},
onClearSelected () {
this.selectedRowKeys = []
},
handleImportByFileId (fileId) {
// TODO 完善通过文件id上传文件的方法
}
}
}
+16 -7
View File
@@ -4,7 +4,7 @@
* data中url定义 list为查询列表 delete为删除单条记录 deleteBatch为批量删除
*/
import { filterObj } from '@/utils/util'
import { downFile, getAction, getFileAccessHttpUrl, postAction } from '@/api/manage'
import { downFile, downloadFile, getAction, getFileAccessHttpUrl, postAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
import store from '@/store'
@@ -293,7 +293,7 @@ export const JeroListMixin = {
// 加一个大的提示
const modalLoading = this.$info({
title: '提示',
content: <span>正在导出请稍候 <a-spin size="small"/></span>,
content: <span>正在导出请稍候 <a-spin size="small" /></span>,
keyboard: false
})
// 把知道了这个按钮去掉
@@ -329,7 +329,7 @@ export const JeroListMixin = {
if (!this.loading) {
importModalLoading = this.$info({
title: '提示',
content: <span>正在导入请稍候 <a-spin size="small"/></span>,
content: <span>正在导入请稍候 <a-spin size="small" /></span>,
keyboard: false
})
}
@@ -353,9 +353,9 @@ export const JeroListMixin = {
this.$warning({
title: message,
content: (<div>
<span>{msg}</span><br/>
<span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
</div>
<span>{msg}</span><br />
<span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
</div>
)
})
} else {
@@ -410,7 +410,16 @@ export const JeroListMixin = {
}
const url = getFileAccessHttpUrl(text)
window.open(url)
},
// 下载导入模板
downTemplate (fileName) {
if (!fileName || typeof fileName !== 'string') {
fileName = '模板文件'
}
downloadFile(this.url.downTemplateUrl, fileName + '.xlsx')
},
handleImportByFileId (fileId) {
// TODO 完善通过文件id上传文件的方法
}
}
}
+20
View File
@@ -602,3 +602,23 @@ export function evil (fn) {
const Fn = Function // 一个变量指向Function,防止有些前端编译工具报错
return new Fn('return ' + fn)()
}
/**
* 将url的参数拆分成对象
* @param url
* @returns {{id: *, url}}
*/
export function urlToParams (url) {
const commonUrl = window._CONFIG.staticDomainURL
// url截取参数的部分
const paramsStr = url.slice(url.indexOf('?') + 1)
const paramsObj = {
url,
id: url.slice(url.indexOf(commonUrl) + commonUrl.length + 1, url.indexOf('?'))
}
paramsStr.split('&').forEach(item => {
const arr = item.split('=')
paramsObj[arr[0]] = arr[1]
})
return paramsObj
}