From 09abac7e834d4938e9cb243df0995f7b71531c07 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期一, 11 九月 2023 20:12:01 +0800
Subject: [PATCH] 1.优化
---
src/views/systemSetting/dataImport.vue | 342 +++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 226 insertions(+), 116 deletions(-)
diff --git a/src/views/systemSetting/dataImport.vue b/src/views/systemSetting/dataImport.vue
index 3f6df8b..1d27b90 100644
--- a/src/views/systemSetting/dataImport.vue
+++ b/src/views/systemSetting/dataImport.vue
@@ -93,13 +93,7 @@
style="overflow-y: scroll;"
highlight-current-row
>
- <!-- @selection-change="handleSelectionChange"-->
- <!-- <el-table-column-->
- <!-- type="selection"-->
- <!-- width="55"-->
- <!-- fixed-->
- <!-- />-->
<el-table-column
label="搴忓彿"
width="55"
@@ -108,7 +102,7 @@
:render-header="indexRender"
>
<template slot-scope="scope">
- {{ scope.$index }}
+ {{ scope.$index + 1 }}
</template>
</el-table-column>
@@ -119,21 +113,38 @@
:label="item"
align="center"
:render-header="addRedStar"
- width="220"
+ min-width="220"
>
<template slot-scope="{row}">
<div
- v-if="item.indexOf('鐢ㄦ埛缂栧彿(鍞竴)')!==-1||
+ v-if="item.indexOf('缂栧彿(鍞竴)')!==-1||
item.indexOf('鐢ㄦ埛濮撳悕')!==-1||
item.indexOf('瀵嗙爜')!==-1||
item.indexOf('鎵嬫満鍙�')!==-1||
- item.indexOf('閭')!==-1
+ item.indexOf('閭')!==-1||
+ item.indexOf('鍚嶇О')!==-1||
+ item.indexOf('鎻忚堪')!==-1
"
>
<el-input v-model="row[item]" placeholder="璇疯緭鍏�" />
</div>
- <div v-else-if="item.indexOf('鍦ㄨ亴鐘舵��')!==-1">
+ <div v-else-if="item.indexOf('鏁版嵁鑼冨洿')!==-1">
+ <el-select
+ v-model="row[item]"
+ placeholder="璇烽�夋嫨"
+ filterable
+ clearable
+ >
+ <el-option
+ v-for="item in powerArr"
+ :key="item.code"
+ :label="item.name"
+ :value="item.code"
+ />
+ </el-select>
+ </div>
+ <div v-else-if="item.indexOf('鐘舵��')!==-1">
<el-select
v-model="row[item]"
placeholder="璇烽�夋嫨"
@@ -148,7 +159,6 @@
/>
</el-select>
</div>
-
<div v-else-if="item.indexOf('鎵�灞炲矖浣嶇紪鐮�')!==-1">
<el-select
v-model="row[item]"
@@ -205,20 +215,41 @@
</el-select>
</div>
<div v-else-if="item.indexOf('鎵�灞炵粍缁囩紪鐮�')!==-1">
- <el-select
+ <el-cascader
+ ref="cascader"
v-model="row[item]"
- style="width: 100%;"
- placeholder="璇烽�夋嫨"
+ :options="orgOptions"
filterable
- clearable
- >
- <el-option
- v-for="item in orgArr"
- :key="item.torg_code"
- :label="item.torg_name"
- :value="item.torg_code"
- />
- </el-select>
+ :props="defaultProps"
+ :show-all-levels="false"
+ />
+
+ <!-- <el-select-->
+ <!-- v-model="row[item]"-->
+ <!-- style="width: 100%;"-->
+ <!-- placeholder="璇烽�夋嫨"-->
+ <!-- filterable-->
+ <!-- clearable-->
+ <!-- >-->
+ <!-- <el-option-->
+ <!-- v-for="item in orgArr"-->
+ <!-- :key="item.torg_code"-->
+ <!-- :label="item.torg_name"-->
+ <!-- :value="item.torg_code"-->
+ <!-- />-->
+ <!-- </el-select>-->
+ </div>
+ <div v-else-if="item.indexOf('鏁版嵁鏉冮檺')!==-1">
+ <el-cascader
+ ref="cascader"
+ v-model="row[item]"
+ :options="orgOptions"
+ filterable
+ collapse-tags
+ :disabled="row['鏁版嵁鑼冨洿']!=='CUSTOM'"
+ :props="orgDefaultProps"
+ :show-all-levels="false"
+ />
</div>
<div v-else> {{ row[item] }}</div>
</template>
@@ -262,6 +293,7 @@
import { DownLoadExcel, ExcelModelCheck, ExcelModelData } from '@/api/Excel'
import { GroupsPermissions, PostPermissions, PrentOrganization, RolePermissions } from '@/api/GeneralBasicData'
import { nanoid } from 'nanoid'
+import arrayToTree from 'array-to-tree'
export default {
name: 'UploadExcel',
@@ -277,14 +309,31 @@
excelCode: '',
excelArr: [],
- statusArr: [
- { code: 'Y', name: '鍦ㄨ亴' },
- { code: 'N', name: '绂昏亴' }
- ],
+ statusArr: [],
orgArr: [], // 缁勭粐
+ orgOptions: [],
+ defaultProps: {
+ checkStrictly: true,
+ expandTrigger: 'hover',
+ value: 'torg_code',
+ label: 'torg_name'
+ },
+ orgDefaultProps: {
+ multiple: true,
+ expandTrigger: 'hover',
+ value: 'torg_code',
+ label: 'torg_name'
+ },
postArr: [], // 宀椾綅
roleArr: [], // 瑙掕壊
- groupArr: []// 鐝粍
+ groupArr: [], // 鐝粍
+
+ powerArr: [
+ { code: 'ALL', name: '鍏ㄩ儴' },
+ { code: 'LEVEL', name: '鏈骇' },
+ { code: 'PERSON', name: '鏈汉' },
+ { code: 'CUSTOM', name: '鑷畾涔�' }
+ ]// 鏁版嵁鑼冨洿
}
},
@@ -321,13 +370,21 @@
this.tableHeader = header
this.sheetName = sheetName
- // 鐢ㄦ埛娓呭崟瀵煎叆鍒ゆ柇
- if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
+ // 浜哄憳绠$悊瀵煎叆鍒ゆ柇
+ if (this.sheetName.indexOf('浜哄憳绠$悊') !== -1) {
+ this.statusArr = [
+ { code: 'Y', name: '鍦ㄨ亴' },
+ { code: 'N', name: '绂昏亴' }
+ ]
const postArr = this.postArr.map(i => i.postcode)
const roleArr = this.roleArr.map(i => i.rolecode)
const groupArr = this.groupArr.map(i => i.usergroupcode)
const orgArr = this.orgArr.map(i => i.torg_code)
- this.tableData[this.sheetName.indexOf('鐢ㄦ埛娓呭崟')].forEach(j => {
+ this.tableData[this.sheetName.indexOf('浜哄憳绠$悊')].forEach(j => {
+ // j.鎵�灞炲矖浣嶇紪鐮� = typeof j.鎵�灞炲矖浣嶇紪鐮� === 'undefined' ? new Set() : j.鎵�灞炲矖浣嶇紪鐮�.split(',').filter(e => postArr.includes(e))
+ // j.鎵�灞炶鑹茬紪鐮� = typeof j.鎵�灞炶鑹茬紪鐮� === 'undefined' ? ''.split(',') : j.鎵�灞炶鑹茬紪鐮�.split(',').filter(e => roleArr.includes(e))
+ // j.鎵�灞炵彮缁勭紪鐮� = typeof j.鎵�灞炵彮缁勭紪鐮� === 'undefined' ? ''.split(',') : j.鎵�灞炵彮缁勭紪鐮�.split(',').filter(e => groupArr.includes(e))
+
j.鎵�灞炲矖浣嶇紪鐮� = j.鎵�灞炲矖浣嶇紪鐮�.split(',').filter(e => postArr.includes(e))
j.鎵�灞炶鑹茬紪鐮� = j.鎵�灞炶鑹茬紪鐮�.split(',').filter(e => roleArr.includes(e))
j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.split(',').filter(e => groupArr.includes(e))
@@ -335,8 +392,26 @@
j['*鍦ㄨ亴鐘舵��'] = this.statusArr.find(e => e.name === j['*鍦ㄨ亴鐘舵��']).code
j.uuid = nanoid()
})
+ console.log(this.tableData[0])
+ // console.log(JSON.stringify(this.tableData[0]))
+ }
+
+ if (this.sheetName.indexOf('瑙掕壊绠$悊') !== -1) {
+ this.statusArr = [
+ { code: 'Y', name: '鍋滅敤' },
+ { code: 'N', name: '鍚敤' }
+ ]
+
+ this.tableData[0].forEach(j => {
+ // j.鎵�灞炲矖浣嶇紪鐮� = j.鎵�灞炲矖浣嶇紪鐮�.split(',').filter(e => postArr.includes(e))
+ console.log(j['鏁版嵁鏉冮檺'], 1) // 绾ц仈澶氶�夊洖鏄� 寰呯爺绌� 涓嬫鍐�
+ j['鏁版嵁鑼冨洿'] = this.powerArr.find(e => e.name === j['鏁版嵁鑼冨洿']).code
+ j['*鐘舵��'] = this.statusArr.find(e => e.name === j['*鐘舵��']).code
+ j.uuid = nanoid()
+ })
}
},
+ // 鑾峰彇妯℃澘
async getExcelModelData() {
const { data: res } = await ExcelModelData()
this.excelArr = res
@@ -345,6 +420,7 @@
this.excelCode = window.location.hash.split('?')[1].split('=')[1]
}
},
+ // 妯℃澘涓嬭浇
async getExcel() {
const res = await DownLoadExcel({ FileCode: this.excelCode })
window.location.href = res.data
@@ -359,76 +435,120 @@
confirmButtonText: '纭畾',
cancelButtonText: '鍙栨秷',
type: 'warning'
- }).then(() => {
- let flag = true
- let msg = ''
- if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
- // if ([...new Set(this.tableData[0].filter(i => i['*鐢ㄦ埛缂栧彿(鍞竴)'] !== '').map(i => i['*鐢ㄦ埛缂栧彿(鍞竴)']))].length !== this.tableData[0].length) {
- if ([...new Set(this.tableData[0].map(i => i['*鐢ㄦ埛缂栧彿(鍞竴)']))].length !== this.tableData[0].length) {
- return this.$message.info('缂栫爜涓嶈兘閲嶅锛�')
- }
- this.tableData[0].forEach(j => {
- if (j['*鐢ㄦ埛缂栧彿(鍞竴)'].trim() === '') {
- flag = false
- msg = '*鐢ㄦ埛缂栧彿(鍞竴)'
- }
- if (j['*鐢ㄦ埛濮撳悕'].trim() === '') {
- flag = false
- msg = '*鐢ㄦ埛濮撳悕'
- }
- if (j['*瀵嗙爜'].trim() === '') {
- flag = false
- msg = '*瀵嗙爜'
- }
- if (j['*鍦ㄨ亴鐘舵��'].trim() === '') {
- flag = false
- msg = '*鍦ㄨ亴鐘舵��'
- }
- if (j['*鎵�灞炵粍缁囩紪鐮�'].trim() === '') {
- flag = false
- msg = '*鎵�灞炵粍缁囩紪鐮�'
- }
- })
-
- if (!flag) {
- return this.$message.info(msg + '涓嶈兘涓虹┖锛�')
- }
-
- this.tableData[0].forEach(j => {
- j.鎵�灞炲矖浣嶇紪鐮� = j.鎵�灞炲矖浣嶇紪鐮�.join(',')
- j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.join(',')
- j.鎵�灞炶鑹茬紪鐮� = j.鎵�灞炶鑹茬紪鐮�.join(',')
- })
-
- this.tableData[0].map(item => {
- delete (item.uuid)
- })
- }
-
- const data = {
- fileCode: this.excelCode,
- tableData: this.tableData
- }
- // console.log(JSON.stringify(this.tableData))
- ExcelModelCheck(data).then(res => {
- if (res.json1.code === '200' && res.json2.code === '200') {
- this.$notify.success('鏁版嵁鎻愪氦鎴愬姛!')
- this.tableData = []
- this.tableHeader = []
- this.sheetName = []
- this.excelCode = ''
- } else {
-
- }
- })
- }).catch(() => {
- this.$notify.info('宸插彇娑堟彁浜わ紒')
})
- },
+ .then(() => {
+ let flag = true
+ let msg = ''
+ if (this.sheetName.indexOf('浜哄憳绠$悊') !== -1) {
+ if ([...new Set(this.tableData[0].map(i => i['*鐢ㄦ埛缂栧彿(鍞竴)']))].length !== this.tableData[0].length) {
+ return this.$message.info('缂栫爜涓嶈兘閲嶅锛�')
+ }
+ this.tableData[0].forEach(j => {
+ if (!j['*鐢ㄦ埛缂栧彿(鍞竴)']) {
+ flag = false
+ msg = '*鐢ㄦ埛缂栧彿(鍞竴)'
+ }
+ if (!j['*鐢ㄦ埛濮撳悕']) {
+ flag = false
+ msg = '*鐢ㄦ埛濮撳悕'
+ }
+ if (!j['*瀵嗙爜']) {
+ flag = false
+ msg = '*瀵嗙爜'
+ }
+ if (!j['*鍦ㄨ亴鐘舵��']) {
+ flag = false
+ msg = '*鍦ㄨ亴鐘舵��'
+ }
+ if (!j['*鎵�灞炵粍缁囩紪鐮�']) {
+ flag = false
+ msg = '*鎵�灞炵粍缁囩紪鐮�'
+ }
+ })
+
+ if (!flag) {
+ return this.$message.info(msg + '涓嶈兘涓虹┖锛�')
+ }
+
+ this.tableData[0].forEach(j => {
+ j.鎵�灞炲矖浣嶇紪鐮� = j.鎵�灞炲矖浣嶇紪鐮�.join(',')
+ j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.join(',')
+ j.鎵�灞炶鑹茬紪鐮� = j.鎵�灞炶鑹茬紪鐮�.join(',')
+ j['*鎵�灞炵粍缁囩紪鐮�'] = j['*鎵�灞炵粍缁囩紪鐮�'][j['*鎵�灞炵粍缁囩紪鐮�'].length - 1]
+ })
+
+ this.tableData[0].map(item => {
+ delete (item.uuid)
+ })
+ }
+
+ const data = {
+ fileCode: this.excelCode,
+ tableData: this.tableData
+ }
+ // console.log(JSON.stringify(this.tableData))
+ ExcelModelCheck(data).then(res => {
+ if (res.json1.code === '301' || res.json1.code === '300') {
+ if (this.sheetName.indexOf('浜哄憳绠$悊') !== -1) {
+ const postArr = this.postArr.map(i => i.postcode)
+ const roleArr = this.roleArr.map(i => i.rolecode)
+ const groupArr = this.groupArr.map(i => i.usergroupcode)
+ const orgArr = this.orgArr.map(i => i.torg_code)
+ this.tableData[0].forEach(j => {
+ j.鎵�灞炲矖浣嶇紪鐮� = j.鎵�灞炲矖浣嶇紪鐮�.split(',').filter(e => postArr.includes(e))
+ j.鎵�灞炶鑹茬紪鐮� = j.鎵�灞炶鑹茬紪鐮�.split(',').filter(e => roleArr.includes(e))
+ j.鎵�灞炵彮缁勭紪鐮� = j.鎵�灞炵彮缁勭紪鐮�.split(',').filter(e => groupArr.includes(e))
+ // j['*鍦ㄨ亴鐘舵��'] = this.statusArr.find(e => e.name === j['*鍦ㄨ亴鐘舵��']).code
+ // j['*鎵�灞炵粍缁囩紪鐮�'] = j['*鎵�灞炵粍缁囩紪鐮�'][j['*鎵�灞炵粍缁囩紪鐮�'].length - 1]
+ j['*鎵�灞炵粍缁囩紪鐮�'] = this.findParent([], j['*鎵�灞炵粍缁囩紪鐮�'], this.orgOptions).reverse()
+
+ j.uuid = nanoid()
+ })
+ }
+ return this.$message.error(res.json1.message)
+ }
+
+ if (res.json1.code === '200' && res.json2.code === '200') {
+ this.$notify.success('鏁版嵁鎻愪氦鎴愬姛!')
+ this.tableData = []
+ this.tableHeader = []
+ this.sheetName = []
+ this.excelCode = ''
+ } else {
+ this.$notify.success('鏁版嵁鎻愪氦澶辫触!')
+ }
+ })
+ })
+ .catch(e => {
+ console.log(e)
+ this.$notify.info('宸插彇娑堟彁浜わ紒')
+ })
+ },
+ // parents:鐢ㄤ簬杩斿洖鐨勬暟缁勶紝childNode:瑕佹煡璇㈢殑鑺傜偣锛宼reeData锛歫son鏍戝舰鏁版嵁
+ findParent(parents, childNode, treeData) {
+ // console.log(parents, childNode, treeData, 2)
+
+ for (let i = 0; i < treeData.length; i++) {
+ // 鐖惰妭鐐规煡璇㈡潯浠�
+ if (treeData[i].torg_code === childNode) {
+ // 濡傛灉鎵惧埌缁撴灉,淇濆瓨褰撳墠鑺傜偣
+ parents.push(treeData[i].torg_code)
+ // 鐢ㄥ綋鍓嶈妭鐐瑰啀鍘诲師鏁版嵁鏌ユ壘褰撳墠鑺傜偣鐨勭埗鑺傜偣
+ this.findParent(parents, treeData[i].parent_id, this.orgOptions)
+ break
+ } else {
+ if (treeData[i].children instanceof Array) {
+ // 娌℃壘鍒帮紝閬嶅巻璇ヨ妭鐐圭殑瀛愯妭鐐�
+ this.findParent(parents, childNode, treeData[i].children)
+ }
+ }
+ }
+ return parents
+ },
addRow() {
- // 鐢ㄦ埛娓呭崟鏂板琛�
- if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
+ // 浜哄憳绠$悊鏂板琛�
+ if (this.sheetName.indexOf('浜哄憳绠$悊') !== -1) {
this.tableData[0].unshift({
uuid: nanoid(),
'*鐢ㄦ埛缂栧彿(鍞竴)': '',
@@ -445,8 +565,8 @@
}
},
delRow(row) {
- // 鐢ㄦ埛娓呭崟鍒犻櫎琛�
- if (this.sheetName.indexOf('鐢ㄦ埛娓呭崟') !== -1) {
+ // 浜哄憳绠$悊鍒犻櫎琛�
+ if (this.sheetName.indexOf('浜哄憳绠$悊') !== -1) {
if (this.tableData[0].length > 1) {
return this.tableData[0].splice(this.tableData[0].findIndex(i => i.uuid === row.uuid), 1)
} else {
@@ -471,11 +591,11 @@
async getPrentOrganization() {
const { data: res } = await PrentOrganization()
this.orgArr = res
- // this.cascaderOptions = arrayToTree(res, {
- // parentProperty: 'parent_id',
- // customID: 'torg_code',
- // childrenProperty: 'children'
- // })
+ this.orgOptions = arrayToTree(res, {
+ parentProperty: 'parent_id',
+ customID: 'torg_code',
+ childrenProperty: 'children'
+ })
},
// 鑾峰彇宀椾綅涓嬫媺鏁扮粍
async getPostPermissions() {
@@ -537,14 +657,4 @@
}
}
</script>
-
-<style scoped lang="scss">
-//::v-deep .el-table__body-wrapper {
-//overflow-y: auto;
-//overflow-x: scroll !important;
-//height: calc(100% - 34px);
-//width: 100% !important;
-//}
-
-</style>
--
Gitblit v1.9.3