Commit 5c4e3fdd authored by 罗林杰's avatar 罗林杰

修改文件名

parent b231c8e4
<template>
<div class="dict-manage">
<div class="search">
<el-form ref="queryForm" style="padding: 0 0 0 10px" :model="queryParams" :inline="true" label-width="auto">
<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"
/>
</el-form-item>
<el-form-item label="字典类型" prop="dictType">
<el-input
v-model.trim="queryParams.dictType"
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-option
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="dateRange"
size="small"
style="width: 300px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item>
<el-form-item>
<!-- //查询按钮-->
<el-button
:class="commonField.queryClass"
:type="commonField.typePrimary"
:icon="commonField.queryIcon"
:size="commonField.smallSize"
@click="handleQuery"
>{{ commonField.queryName }}</el-button>
<!-- //重置按钮-->
<el-button
:class="commonField.resetClass"
:icon="commonField.resetIcon"
:size="commonField.smallSize"
@click="resetQuery"
>{{ commonField.resetName }}</el-button>
</el-form-item>
<div style="padding-bottom: 15px" class="dictBtnRow">
<!-- //新增按钮-->
<el-button
v-hasPermi="hasDictAddPerm"
:class="commonField.addClass"
:type="commonField.typePrimary"
:icon="commonField.addIcon"
:size="commonField.smallSize"
@click="handleAdd"
>{{ commonField.addName }}</el-button>
<!-- //导出-->
<el-button
v-hasPermi="exportHaspermi"
:class="commonField.exportClass"
:type="commonField.typeSuccess"
:icon="commonField.exportIcon"
:size="commonField.smallSize"
@click="handleExport"
>{{ commonField.exportName }}</el-button>
</div>
</el-form>
</div>
<div style="min-height: 445px;padding:5px 10px">
<div class="tableTitle">字典管理列表</div>
<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">
<template slot-scope="scope">
{{ scope.row.dictName || '-' }}
</template>
</el-table-column>
<el-table-column label="字典类型" :show-overflow-tooltip="true">
<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: #03A487">{{ scope.row.dictType }}</span>
</router-link>
<div v-else>-</div>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="flag" :formatter="statusFormat">
<template slot-scope="scope">
<el-switch
v-model="scope.row.flag"
class="switchDisabledStyle"
inactive-value="0"
active-value="1"
@click.native="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
<el-table-column label="备注" prop="remarks" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.remarks || '-' }}
</template>
</el-table-column>
<el-table-column label="创建时间" :show-overflow-tooltip="true" prop="createTime">
<template slot-scope="scope">
<span>{{ scope.row.createDate | transformDateByFormat('YYYY-MM-DD HH:mm') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" class-name="small-padding fixed-width">
<template slot-scope="scope">
<!-- //修改-->
<el-button
v-hasPermi="hasDictUpdatePerm"
:class="commonField.updateClass"
:type="commonField.typeParent"
:size="commonField.size"
@click="handleUpdate(scope.row)"
>{{ commonField.updateName }}</el-button>
<!-- //删除-->
<el-button
v-hasPermi="hasDictDelPerm"
:class="commonField.delClass"
:type="commonField.typeParent"
:size="commonField.size"
@click="handleDelete(scope.row)"
>{{ commonField.deleteName }}</el-button>
</template>
</el-table-column>
</el-table>
</div>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.page"
:limit.sync="queryParams.rows"
@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="auto">
<el-form-item label="字典名称" prop="dictName">
<el-input v-model.trim="form.dictName" :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>
<el-form-item label="父字典名称">
<el-select v-model="form.parentId" style="width: 100%" clearable placeholder="请选择父字典类型" @clear="setRules" @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" prop="dataId">
<el-select v-model="form.dataId" style="width: 100%" clearable placeholder="请选择父字典数据" @visible-change="clearSelected">
<el-option
v-for="item in optionsDict"
:key="item.businessId"
:label="item.dictLabel"
:disabled="item.status == 1"
:value="item.businessId"
>
<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-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button class="cancelBtn" @click="cancel">取 消</el-button>
<el-button class="submitBtn" type="primary" :loading="manageLoading" :disabled="manageLoading" @click="submitForm">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listType,
getType,
delType,
addType,
updateType,
exportType,
clearCache,
selectDictType
} from '@/api/system/dict/type'
import Coolbutton from '@/components/coolbutton'
import { getDataCache, setDataCache } from '@/assets/js/filterData'
import commonField from '@/utils/commonField'
export default {
name: 'Dict',
components: { Coolbutton },
data() {
return {
options: [],
hasDictDelPerm: ['sys:dict:delete'],
hasDictRemovePerm: ['sys:dict:remove'],
hasDictResetPerm: ['sys:user:resetPwd'],
hasDictUpdatePerm: ['sys:dict:update'],
hasDictEditPerm: ['sys:dict:edit'],
hasDictAddPerm: ['sys:dict:add'],
exportHaspermi: ['sys:dict:export'],
// hasDictExportPerm: ['sys:dict:export'],
hasDictQueryPerm: ['sys:menu:query'],
optionsDict: [],
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// 字典表格数据
typeList: [],
// 弹出层标题
title: '',
// 是否显示弹出层
open: false,
// 状态数据字典
statusOptions: [
{
dictLabel: '正常',
dictValue: '1'
},
{
dictLabel: '停用',
dictValue: '0'
}
],
// 日期范围
dateRange: [],
// 查询参数
queryParams: {
page: 1,
rows: 10,
dictName: '',
dictType: '',
flag: ''
},
// 表单参数
form: {
parentId: '',
dataId: '',
dictTypeOne: '',
dictNameOne: ''
},
// 表单校验
rules: {
dictName: [
{ required: true, message: '请输入字典名称', trigger: 'blur' }
],
dictType: [
{ required: true, message: '请输入字典类型', trigger: 'blur' }
],
dataId: [
{ required: true, message: '请输入父字典数据', trigger: 'blur' }
]
},
manageLoading: false
}
},
computed: {
commonField() {
return commonField
}
},
/** 路由离开前存储筛选条件*/
beforeRouteLeave(to, from, next) {
setDataCache(this.$route.path, this.queryParams)
next()
},
created() {
if (JSON.parse(getDataCache(this.$route.path)) !== {}) {
this.queryParams = JSON.parse(getDataCache(this.$route.path)) // 获取存储的筛选项
}
this.getList()
},
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
}
)
},
// 动态表单验证
setRules() {
if (this.form.parentId !== null && this.form.parentId !== '') {
this.$set(this.rules, 'dataId', [{ required: true, message: '请输入父字典数据', trigger: 'blur' }])
} else {
this.$delete(this.rules, 'dataId')
}
},
// 获取当前父字典数据
getOptions(val) {
selectDictType(this.options.find(item => { return item.businessId === val }).dictType).then(response => {
this.optionsDict = response.data
this.setRules()
})
},
// 清除已选择的
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) {
const text = row.flag === '1' ? '启用' : '停用'
this.$confirm('确认确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return updateType(row)
}).then(() => {
this.$message({
message: text + '成功',
type: 'success'
})
}).catch(function() {
row.flag = row.flag === '0' ? '1' : '0'
})
},
// 字典状态字典翻译
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.flag)
},
// 取消按钮
cancel() {
this.open = false
this.reset()
},
// 表单重置
reset() {
this.form = {
dataId: '',
parentId: '',
businessId: undefined,
dictName: undefined,
dictType: undefined,
status: '0',
remarks: undefined,
flag: '1'
}
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.page = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = []
this.queryParams = {
page: 1,
rows: 10,
dictName: '',
dictType: '',
flag: ''
}
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.setRules()
this.open = true
this.title = 'add'
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.businessId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const dictId = row.businessId || this.ids
getType(dictId).then(response => {
this.form = response.data
this.setRules()
this.$nextTick(() => {
if (response.data.dataId !== null) {
this.form.dataId = response.data.dataId.toString()
}
this.$forceUpdate()
})
this.open = true
this.title = '修改字典类型'
})
},
/** 提交按钮 */
submitForm() {
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'
})
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'
})
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('是否确认操作?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
delType(dictIds).then(res => {
if (res.code === 200) {
that.getList()
that.msgSuccess('删除成功')
} else {
that.$message.error(res.message)
}
})
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams
this.$confirm('是否确认操作?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return exportType(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' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象
})
})
},
/** 清理缓存按钮操作 */
handleClearCache() {
clearCache().then(response => {
if (response.code === 200) {
this.$message({
message: '清理成功',
type: 'success'
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
</style>
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