Commit 3afade40 authored by 杨硕's avatar 杨硕

字典数据添加导入

parent 0222ca62
......@@ -81,3 +81,27 @@ export function exportData(query) {
responseType: 'blob'
})
}
// 下载字典数据导入模板
export function importTemplate(params) {
return request({
url: '/system/dict/data/importTemplate',
method: 'get',
responseType: 'blob',
params
})
}
// 导入字典数据信息
export function importExcel(data) {
return request({
url: '/system/dict/data/importDictData',
method: 'post',
headers: {
'Content-Type': 'multipart/form-data'
},
transformRequest: [(data) => {
return data
}],
data
})
}
<template>
<div class="app-container-dict">
<el-form ref="queryForm" style="padding: 0 0 0 10px" :model="queryParams" :inline="true" label-width="68px">
<el-form-item label="字典名称" prop="dictName">
<el-input
v-model="queryParams.dictName"
placeholder="请输入字典名称"
clearable
:maxlength="30"
size="small"
style="width: 200px"
@keyup.enter.native="handleQuery"
<div class="app-container">
<el-form v-show="showSearch" ref="queryForm" style="width: 100%" :model="queryParams" :inline="true">
<el-form-item label="字典名称" prop="dictType">
<el-select v-model="queryParams.dictType" placeholder="请选择字典名称" clearable size="small">
<el-option
v-for="item in typeOptions"
:key="item.businessId"
:label="item.dictName"
:value="item.dictType"
/>
</el-select>
</el-form-item>
<el-form-item label="字典类型" prop="dictType">
<el-form-item label="字典标签" prop="dictLabel">
<el-input
v-model.trim="queryParams.dictType"
placeholder="请输入字典类型"
v-model="queryParams.dictLabel"
placeholder="请输入字典标签"
clearable
:maxlength="30"
size="small"
style="width: 200px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="flag">
<el-select
v-model="queryParams.flag"
placeholder="字典状态"
clearable
size="small"
style="width: 200px"
>
<el-select v-model="queryParams.flag" placeholder="数据状态" clearable size="small">
<el-option
v-for="dict in statusOptions"
:key="dict.dictValue"
......@@ -39,32 +31,22 @@
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="dateRange"
size="small"
style="width: 200px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
<el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">查询</el-button>
<el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<!-- <el-button-->
<!-- v-hasPermi="['sys:dict:add']"-->
<!-- type="primary"-->
<!-- icon="el-icon-plus"-->
<!-- size="small"-->
<!-- size="mini"-->
<!-- @click="handleAdd"-->
<!-- >新增</el-button>-->
<coolbutton :type="typePrimary" :name="addName" :size="smallSize" :icon="addIcon" :haspermi="addHaspermi" @btn-click="handleAdd" />
<!-- >新增-->
<!-- </el-button>-->
<coolbutton :type="typePrimary" :name="addName" :icon="addIcon" :size="size" :haspermi="addHaspermi" @btn-click="handleAdd" />
</el-col>
<el-col :span="1.5">
<!-- <el-button-->
......@@ -79,52 +61,49 @@
<!-- <coolbutton :type="typeSuccess" :name="updataName" :icon="updateIcon" :size="size" :haspermi="updateHaspermi" @btn-click="handleUpdate" />-->
</el-col>
<el-col :span="1.5">
<!-- <el-button-->
<!-- v-hasPermi="['sys:dict:delete']"-->
<!-- type="danger"-->
<!-- icon="el-icon-delete"-->
<!-- size="mini"-->
<!-- :disabled="multiple"-->
<!-- @click="handleDelete"-->
<!-- >删除-->
<!-- </el-button>-->
<!-- <coolbutton :type="typeDanger" :name="nameParent" :icon="delicon" :size="size" :haspermi="delHaspermi" @btn-click="handleDelete" />-->
<el-button
type="warning"
icon="el-icon-upload"
size="small"
@click="handleImport"
>导入</el-button>
</el-col>
<el-col :span="1.5">
<!-- <el-button-->
<!-- v-hasPermi="['sys:dict:export']"-->
<!-- type="success"-->
<!-- icon="el-icon-download"-->
<!-- size="small"-->
<!-- @click="handleExport"-->
<!-- >导出</el-button>-->
<coolbutton :type="typeSuccess" :name="exportName" :icon="exportIcon" :size="size" :haspermi="exportHaspermi" @btn-click="handleExport" />
<el-button
v-has-permi="['sys:dict:export']"
type="success"
icon="el-icon-download"
size="small"
@click="handleExport"
>导出
</el-button>
</el-col>
<!-- <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />-->
<right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
</el-row>
</el-form>
<div class="placeholder" />
<div style="min-height: 445px;padding:10px">
<h5 style="margin: 0 0 12px 0;font-size: 14px">字典管理列表</h5>
<el-table v-loading="loading" border :data="typeList" @selection-change="handleSelectionChange">
<el-table-column type="index" label="序号" width="55" align="center" />
<!-- <el-table-column label="字典编号" align="center" prop="businessId" />-->
<el-table-column label="字典名称" prop="dictName" :show-overflow-tooltip="true">
<div style="padding:10px">
<div class="mb12 font-small-bold">字典参数列表</div>
<el-table v-loading="loading" :data="dataList" border @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<!-- <el-table-column :show-overflow-tooltip="true" label="参数编码" prop="dictCode">-->
<!-- <template slot-scope="scope">-->
<!-- {{ scope.row.dictCode || '-' }}-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="字典编码" align="center" prop="businessId" />
<el-table-column :show-overflow-tooltip="true" label="字典标签" prop="dictLabel">
<template slot-scope="scope">
{{ scope.row.dictName || '-' }}
{{ scope.row.dictLabel || '-' }}
</template>
</el-table-column>
<el-table-column label="字典类型" :show-overflow-tooltip="true">
<el-table-column :show-overflow-tooltip="true" label="字典键值" prop="dictValue">
<template slot-scope="scope">
<!-- v-hasPermi="['system:dictConfig:list']"-->
<router-link
v-if="scope.row.businessId"
:to="'/dict/type/data/' + scope.row.businessId"
class="link-type"
>
<span style="color: #20a0ff">{{ scope.row.dictType }}</span>
</router-link>
<div v-else>-</div>
{{ scope.row.dictValue || '-' }}
</template>
</el-table-column>
<el-table-column :show-overflow-tooltip="true" label="字典排序" prop="dictSort">
<template slot-scope="scope">
{{ isNaN(scope.row.dictSort) ? '-' : scope.row.dictSort }}
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="flag">
......@@ -134,16 +113,16 @@
class="switchDisabledStyle"
inactive-value="0"
active-value="1"
@click.native="handleStatusChange(scope.row)"
@click.native="changeStatus(scope.row)"
/>
</template>
</el-table-column>
<el-table-column label="备注" prop="remarks" :show-overflow-tooltip="true">
<el-table-column :show-overflow-tooltip="true" label="备注" prop="remarks">
<template slot-scope="scope">
{{ scope.row.remarks || '-' }}
</template>
</el-table-column>
<el-table-column label="创建时间" :show-overflow-tooltip="true" prop="createTime">
<el-table-column :show-overflow-tooltip="true" label="创建时间" prop="createDate">
<template slot-scope="scope">
<span>{{ scope.row.createDate | transformDateByFormat('YYYY-MM-DD HH:mm') }}</span>
</template>
......@@ -151,20 +130,29 @@
<el-table-column label="操作" class-name="small-padding fixed-width">
<template slot-scope="scope">
<!-- <el-button-->
<!-- v-hasPermi="['sys:dict:edit']"-->
<!-- v-hasPermi="['sys:dictConfig:edit']"-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- style="color: #49cec9"-->
<!-- @click="handleUpdate(scope.row)"-->
<!-- >修改</el-button>-->
<coolbutton :type="typeParent" style="color: #49cec9" :name="updataName" :size="size" :haspermi="updateHaspermi" @btn-click="handleUpdate(scope.row)" />
<coolbutton style="color: #49cec9" :type="typeParent" :name="updataName" :size="size" :haspermi="editHaspermi" @btn-click="handleUpdate(scope.row)" />
<!-- <el-button-->
<!-- v-hasPermi="['sys:dict:remove']"-->
<!-- v-hasPermi="['sys:dictConfig:remove']"-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- @click="handleDelete(scope.row)"-->
<!-- >删除</el-button>-->
<coolbutton :type="typeParent" :name="nameParent" :size="size" :haspermi="delHaspermi" @btn-click="handleDelete(scope.row)" />
<coolbutton :type="typeParent" :icon="delicon" :name="nameParent" :size="size" :haspermi="removeHaspermi" @btn-click="handleDelete(scope.row)" />
<!-- <el-switch-->
<!-- v-model="scope.row.status"-->
<!-- v-hasPermi="['sys:dictConfig:toggle']"-->
<!-- disabled-->
<!-- class="switchDisabledStyle"-->
<!-- active-value="0"-->
<!-- inactive-value="1"-->
<!-- @click.native="changeStatus(scope.row)"-->
<!-- />-->
</template>
</el-table-column>
</el-table>
......@@ -172,123 +160,104 @@
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.page"
:limit.sync="queryParams.rows"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改参数配置对话框 -->
<el-dialog title="字典信息" :visible.sync="open" width="500px" append-to-body @close="reset">
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="字典名称" prop="dictName">
<el-input v-model.trim="form.dictName" :maxlength="30" placeholder="请输入字典名称" />
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="字典类型">
<el-input v-model.trim="form.dictType" :disabled="true" show-word-limit maxlength="30" placeholder="请输入字典类型" />
</el-form-item>
<el-form-item label="参数标签" prop="dictLabel">
<el-input v-model.trim="form.dictLabel" show-word-limit maxlength="30" placeholder="请输入参数标签" />
</el-form-item>
<el-form-item label="字典类型" prop="dictType">
<el-input v-model.trim="form.dictType" :maxlength="30" placeholder="请输入字典类型" />
<el-form-item label="参数键值" prop="dictValue">
<el-input v-model.trim="form.dictValue" show-word-limit maxlength="300" placeholder="请输入参数键值" />
</el-form-item>
<!-- <el-form-item label="状态" prop="flag">-->
<!-- <el-radio-group v-model="form.flag">-->
<el-form-item label="参数排序" prop="dictSort">
<el-input-number v-model="form.dictSort" style="width: 100%" controls-position="right" :min="0" />
</el-form-item>
<!-- <el-form-item label="参数状态" prop="status">-->
<!-- <el-radio-group v-model="form.status">-->
<!-- <el-radio-->
<!-- v-for="dict in statusOptions"-->
<!-- v-for="dict in statusOptions.filter(item => { return item.dictValue })"-->
<!-- :key="dict.dictValue"-->
<!-- :label="dict.dictValue"-->
<!-- >{{ dict.dictLabel }}-->
<!-- </el-radio>-->
<!-- >{{ dict.dictLabel }}</el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<el-form-item label="父字典名称">
<el-select v-model="form.parentId" style="width: 100%" clearable placeholder="请选择父字典类型" @change="getOptions">
<el-option
v-for="item in options"
:key="item.businessId"
:label="item.dictName"
:value="item.businessId"
/>
</el-select>
</el-form-item>
<el-form-item v-show="form.parentId">
<el-select v-model="form.dataId" style="width: 100%" clearable placeholder="请选择父字典数据" @visible-change="clearSelected">
<el-option
v-for="item in optionsDict"
:key="item.dictValue"
:label="item.dictLabel"
:disabled="item.status == 1"
:value="item.dictValue"
>
<span style="float: left">{{ item.dictLabel }}</span>
<span v-if="item.status === '1'" style="float: right; color: #8492a6; font-size: 12px;padding-left: 10px">{{ '已停用' }}</span>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remarks">
<el-input v-model.trim="form.remarks" maxlength="200" type="textarea" placeholder="请输入内容" />
<el-input v-model.trim="form.remarks" type="textarea" show-word-limit maxlength="200" placeholder="请输入内容" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" :loading="manageLoading" :disabled="manageLoading" @click="submitForm">确 定</el-button>
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
<!-- 字典数据导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
:on-change="employeeUpload"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:on-preview="handlePreview"
:file-list="files"
drag
>
<i class="el-icon-upload" />
<div class="el-upload__text">
将文件拖到此处,或
<em>点击上传</em>
</div>
<div slot="tip" class="el-upload__tip">
<!-- <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
<el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
</div>
<div slot="tip" class="el-upload__tip" style="color:red">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button @click="upload.open = false">取 消</el-button>
<el-button :loading="importLoading" type="primary" @click="submitFileForm">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listType,
getType,
delType,
addType,
updateType,
exportType,
clearCache,
optionselect,
selectRegionCode,
checkDictNameUnique,
selectDictType
} from '@/api/system/dict/type'
import { listData, getData, delData, addData, updateData, exportData, checkDictLabelUnique, importExcel, importTemplate } from '@/api/system/dict/data'
import { listType, getType, updateType } from '@/api/system/dict/type'
import dictCons from '@/utils/dictCons'
// import Template from '@/views/instance/Template'
import Coolbutton from '@/components/coolbutton'
import { getToken } from '@/utils/auth'
import { uploadFalseFile } from '@/api/system/user'
export default {
name: 'Dict',
name: 'Data',
components: { Coolbutton },
data() {
const verifyTypeProp = (rule, value, callback) => {
if (value === '' || value === undefined || value === null) {
callback()
} else if (!this.form.dictTypeOne || this.form.dictTypeOne !== this.form.dictType) {
// 验证编码是否重复
selectRegionCode(this.form.dictType).then(
(res) => {
if (res.code === 200) {
if (res.msg === '0') {
callback()
} else if (res.msg === '1') {
callback(new Error('字典类型已存在'))
} else {
callback()
}
} else {
callback()
}
}
).catch(err => {
callback()
})
} else {
callback()
}
}
const verifyNameProp = (rule, value, callback) => {
const verifyIDProp = (rule, value, callback) => {
if (value === '' || value === undefined || value === null) {
callback()
} else if (!this.form.dictNameOne || this.form.dictNameOne !== this.form.dictName) {
} else if (!this.form.dictLabelOne || this.form.dictLabelOne !== this.form.dictLabel) {
// 验证编码是否重复
checkDictNameUnique(this.form.dictName).then(
checkDictLabelUnique(this.form.dictLabel).then(
(res) => {
if (res.code === 200) {
if (res.msg === '0') {
callback()
} else if (res.msg === '1') {
callback(new Error('字典名称已存在'))
callback(new Error('字典标签已存在'))
} else {
callback()
}
......@@ -304,8 +273,6 @@ export default {
}
}
return {
test: '',
options: [],
typeParent: 'text',
typePrimary: 'primary',
typeSuccess: 'success',
......@@ -316,7 +283,7 @@ export default {
queryName: '查询',
exportName: '导出',
updataName: '修改',
size: 'mini',
size: 'small',
smallSize: 'small',
delicon: 'el-icon-delete',
addIcon: 'el-icon-plus',
......@@ -325,135 +292,100 @@ export default {
updateIcon: 'el-icon-edit',
resetIcon: '',
delHaspermi: ['sys:dict:delete'],
removeHaspermi: ['sys:dict:remove'],
removeHaspermi: ['sys:dictConfig:remove'],
resetHaspermi: ['sys:user:resetPwd'],
updateHaspermi: ['sys:dict:update'],
editHaspermi: ['sys:dict:edit'],
editHaspermi: ['sys:dictConfig:edit'],
addHaspermi: ['sys:dict:add'],
exportHaspermi: ['sys:dict:export'],
queryHaspermi: ['sys:menu:query'],
optionsDict: [],
// 导入列表
files: [],
// 字典数据导入参数
upload: {
// 是否显示弹出层(字典数据导入)
open: false,
// 弹出层标题(字典数据导入)
title: '',
// 是否禁用上传
isUploading: false,
// 是否更新已经存在的用户数据
updateSupport: 0,
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + '/system/user/importExcel'
},
// 遮罩层
loading: true,
loading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 字典表格数据
typeList: [],
dataList: [],
// 默认字典类型
defaultDictType: '',
// 弹出层标题
title: '',
// 是否显示弹出层
open: false,
// 状态数据字典
statusOptions: [
{
dictLabel: '启用',
dictValue: '1'
},
{
dictLabel: '停用',
dictValue: '0'
}
],
// 日期范围
dateRange: [],
statusOptions: [],
// 类型数据字典
typeOptions: [],
importLoading: false,
// 查询参数
queryParams: {
page: 1,
rows: 10,
pageNum: 1,
pageSize: 10,
dictName: undefined,
dictType: undefined,
status: '',
flag: undefined
// status: undefined
},
// 表单参数
form: {
parentId: '',
dataId: '',
dictTypeOne: '',
dictNameOne: ''
},
form: {},
// 表单校验
rules: {
dictName: [
{ required: true, message: '请输入字典名称', trigger: 'blur' }
// { validator: verifyNameProp, trigger: 'blur' }
dictLabel: [
{ required: true, message: '请输入参数标签', trigger: 'blur' }
// { validator: verifyIDProp, trigger: 'blur' }
],
dictType: [
{ required: true, message: '请输入字典类型', trigger: 'blur' }
// { validator: verifyTypeProp, trigger: 'blur' }
dictValue: [
{ required: true, message: '请输入参数键值', trigger: 'blur' }
],
dictSort: [
{ required: true, message: '请输入参数顺序', trigger: 'blur' }
]
},
manageLoading: false
}
},
/** 路由离开前存储筛选条件*/
beforeRouteLeave(to, from, next) {
this.$store.dispatch('searchSave/searchParamsSet', {
path: this.$route.path,
param: {
...this.queryParams
}
})
next()
},
created() {
if (this.$store.getters.searchParams[this.$route.path]) {
const { searchParams } = this.$store.getters; const { path } = this.$route
const param = JSON.parse(searchParams[path]) // 保留着的查询条件
this.queryParams = { ...param }
}
this.getList()
const dictId = this.$route.params && this.$route.params.dictId
this.getType(dictId)
this.getTypeList()
// this.getDicts(dictCons['NORMAL_DISABLE']).then(response => {
// this.statusOptions = response.data
// })
// optionselect().then(response => {
// this.options = response.data
// })
},
methods: {
/** 查询字典类型列表 */
getList() {
listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.options = response.rows
this.typeList = response.rows
this.total = response.total
this.loading = false
}
)
},
// 获取当前父字典数据
getOptions(val) {
selectDictType(this.options.find(item => { return item.businessId === val }).dictType).then(response => {
this.optionsDict = response.data
})
// this.form.dataId = ''
},
clearSelected(flag) {
// flag = true 为下拉框选项展开时的标识
if (flag) {
if (this.form.dataId) {
// 如果找不到 下拉框选项中对应选中的选项 或者 下拉框选项中对应选中的选项 状态为1(停用)则将双向绑定的数据清空
if (!this.optionsDict.find(item => { return item.dictCode === this.form.dataId }) ||
this.optionsDict.find(item => { return item.dictCode === this.form.dataId }).status === 1) {
this.form.dataId = ''
}
}
}
},
handleStatusChange(row) {
// 状态
changeStatus(row) {
const text = row.flag === '1' ? '启用' : '停用'
this.$confirm('确认确认操作?', '提示', {
this.$confirm('确认要"' + text + '""' + row.dictLabel + '"吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return updateType(row)
return updateData(row)
}).then(() => {
this.$message({
message: text + '成功',
......@@ -463,7 +395,37 @@ export default {
row.flag = row.flag === '0' ? '1' : '0'
})
},
// 字典状态字典翻译
/** 查询字典类型详细 */
getType(dictId) {
getType(dictId).then(response => {
this.queryParams.dictType = response.data.dictType
this.defaultDictType = response.data.dictType
this.getList()
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = '字典数据导入'
this.upload.open = true
},
/** 查询字典类型列表 */
getTypeList() {
listType().then(response => {
this.typeOptions = response.rows
})
},
/** 查询字典数据列表 */
getList() {
this.loading = true
listData(this.queryParams).then(response => {
if (response.rows) {
this.dataList = response.rows
this.total = response.total
}
this.loading = false
})
},
// 数据状态字典翻译
// statusFormat(row, column) {
// return this.selectDictLabel(this.statusOptions, row.flag)
// },
......@@ -475,32 +437,34 @@ export default {
// 表单重置
reset() {
this.form = {
dataId: '',
parentId: '',
businessId: undefined,
dictName: undefined,
dictType: undefined,
bussinessId: undefined,
dictCode: undefined,
dictLabel: undefined,
dictValue: undefined,
dictSort: 0,
flag: '1',
status: '0',
remarks: undefined,
flag: '1'
remarks: undefined
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.page = 1
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = []
this.resetForm('queryForm')
this.queryParams.dictType = this.defaultDictType
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = 'add'
this.title = '添加字典数据'
this.form.dictType = this.queryParams.dictType
},
// 多选框选中数据
handleSelectionChange(selection) {
......@@ -511,86 +475,65 @@ export default {
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const dictId = row.businessId || this.ids
getType(dictId).then(response => {
const dictCode = row.businessId || this.ids
getData(dictCode).then(response => {
this.form = response.data
this.$nextTick(() => {
this.form.dataId = response.data.dataId.toString()
this.$forceUpdate()
})
this.getOptions(this.form.parentId)
this.form.dictLabelOne = response.data.dictLabel
this.open = true
this.title = '修改字典类型'
this.title = '修改字典数据'
})
},
/** 提交按钮 */
submitForm() {
submitForm: function() {
this.$refs['form'].validate(valid => {
if (valid) {
this.manageLoading = true
const temp = Object.assign({}, this.form)
if (!temp.parentId) { temp.dataId = '' }
if (this.title === '修改字典类型') {
updateType(temp).then(response => {
if (response.code === 200) {
this.$message({
message: '修改成功',
type: 'success'
})
if (this.form.businessId !== undefined) {
updateData(this.form).then(response => {
this.msgSuccess('修改成功')
this.open = false
this.getList()
}
this.manageLoading = false
}).catch(() => { this.manageLoading = false })
} else {
addType(temp).then(response => {
if (response.code === 200) {
this.$message({
message: '新增成功',
type: 'success'
})
} else {
addData(this.form).then(response => {
this.msgSuccess('新增成功')
this.open = false
this.getList()
}
this.manageLoading = false
}).catch(() => { this.manageLoading = false })
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const dictIds = row.businessId || this.ids
const that = this
this.$confirm('是否确认操作?', '警告', {
const dictCodes = row.businessId || this.ids
this.$confirm('所选择数据被删除后不可再恢复,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
delType(dictIds).then(res => {
if (res.code === 200) {
that.getList()
that.msgSuccess('删除成功')
} else {
that.$message.error(res.message)
}
})
return delData(dictCodes)
}).then(() => {
this.getList()
this.$message({
message: '删除成功',
type: 'success'
})
}).catch(function() {})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams
this.$confirm('是否确认操作?', '警告', {
this.$confirm('是否确认导出所有数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return exportType(queryParams).then(response => {
return exportData(queryParams).then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href
downloadElement.download = '字典类型信息' + '.xls' // 下载后文件名
downloadElement.download = '字典数据信息' + '.xls' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
......@@ -599,22 +542,107 @@ export default {
})
})
},
/** 清理缓存按钮操作 */
handleClearCache() {
clearCache().then(response => {
if (response.code === 200) {
this.$message({
message: '清理成功',
type: 'success'
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true
},
// 文件上传成功处理
handleFileSuccess(response) {
this.upload.open = false
this.upload.isUploading = false
this.$refs.upload.clearFiles()
this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
this.getList()
},
employeeUpload(file, fileList) {
if (fileList.length > 1) {
fileList.splice(0, 1)
}
this.files = fileList[0].raw
},
handleRemove(file, fileList) {
this.files = []
},
beforeRemove(file, fileList) {
this.files = []
},
/* 上传文件所需求 */
handlePreview(file) {
},
/** 下载模板操作 */
importTemplate() {
var params = {
dictType: this.queryParams.dictType
}
importTemplate(params).then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href
downloadElement.download = '字典数据导入模板' + '.xls' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象
// this.download(response.msg);
})
},
// 提交上传文件
submitFileForm() {
// this.$refs.upload.submit()
this.importLoading = true
if (this.files.length === 0) {
this.$message.warning('请上传文件')
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = true
} else { // 根据后台需求数据格式
var formData = new FormData() // 当前为空
formData.append('file', this.files)
importExcel(formData).then(res => {
if (res.code === 200) {
if (res.data.filename === null) {
this.$message.success('导入成功')
this.files = []
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = false
// 导入成功后刷新页面
this.getList()
} else {
uploadFalseFile({ fileName: res.data.filename }).then(res => {
const blob = new Blob([res])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = '模板错误提示' + '.txt' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click() // 点击下载
document.body.removeChild(downloadElement) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放掉blob对象
this.importLoading = false
})
}
this.importLoading = false
} else if (res.code === 41020) {
this.$message.info('上传超时,请重新上传')
this.importLoading = false
} else {
this.$message.error(res.message)
this.importLoading = false
}
}).catch(err => {
this.$message.success(err.message)
this.importLoading = false
})
this.importLoading = false
}
}
}
}
</script>
<style lang="scss" scoped>
.app-container-dict {
.app-container {
font-size: 18px;
padding: 0;
.placeholder{
......@@ -622,18 +650,12 @@ export default {
background-color: #F4F4F4;
margin-bottom:10px
}
}
</style>
<style lang="scss">
.app-container-dict {
.el-form {
.optionsContent{
box-sizing: border-box;
width: 100%;
padding: 0 0 0 10px;
.el-form-item {
margin-top: 0;
margin-left: 0;
margin-bottom: 15px;
margin-right: 10px;
}
display: flex;
flex-direction: row;
}
}
</style>
......@@ -59,9 +59,8 @@
<!-- icon="el-icon-plus"-->
<!-- @click="handleAdd"-->
<!-- >新增</el-button>-->
<coolbutton style="padding: 8px 7px;" :type="typePrimary" :name="addName" :size="smallSize" :icon="addIcon" :haspermi="addHaspermi" @btn-click="handleAdd" />
<coolbutton :type="typePrimary" :name="addName" :size="smallSize" :icon="addIcon" :haspermi="addHaspermi" @btn-click="handleAdd" />
<el-button
style="padding: 8px 7px;"
type="warning"
icon="el-icon-upload"
size="small"
......@@ -75,7 +74,7 @@
<!-- icon="el-icon-download"-->
<!-- @click="handleExport"-->
<!-- >导出</el-button>-->
<coolbutton style="padding: 8px 7px;" :type="typeSuccess" :name="exportName" :size="smallSize" :icon="exportIcon" :haspermi="addHaspermi" @btn-click="handleExport" />
<coolbutton :type="typeSuccess" :name="exportName" :size="smallSize" :icon="exportIcon" :haspermi="addHaspermi" @btn-click="handleExport" />
</el-form-item>
</el-form>
</div>
......
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