导出方法修改成文件流形式

This commit is contained in:
不做码农 2023-01-30 17:40:46 +08:00
parent 25142f5cc5
commit ec270b7df4
8 changed files with 563 additions and 499 deletions

View File

@ -1,11 +1,12 @@
import request from '@/utils/request'
import { downFile } from '@/utils/request'
// 查询操作日志列表
export function list(query) {
return request({
url: '/monitor/operlog/list',
method: 'get',
params: query
params: query,
})
}
@ -13,7 +14,7 @@ export function list(query) {
export function delOperlog(operId) {
return request({
url: '/monitor/operlog/' + operId,
method: 'delete'
method: 'delete',
})
}
@ -21,15 +22,16 @@ export function delOperlog(operId) {
export function cleanOperlog() {
return request({
url: '/monitor/operlog/clean',
method: 'delete'
method: 'delete',
})
}
// 导出操作日志
export function exportOperlog(query) {
return request({
url: '/monitor/operlog/export',
method: 'get',
params: query
})
export async function exportOperlog(query) {
// return request({
// url: '/monitor/operlog/export',
// method: 'get',
// params: query
// })
await downFile('/monitor/operlog/export', query)
}

View File

@ -1,11 +1,12 @@
import request from '@/utils/request'
import { downFile } from '@/utils/request'
// 查询岗位列表
export function listPost(query) {
return request({
url: '/system/post/list',
method: 'get',
params: query
params: query,
})
}
@ -13,7 +14,7 @@ export function listPost(query) {
export function getPost(postId) {
return request({
url: '/system/post/' + postId,
method: 'get'
method: 'get',
})
}
@ -22,7 +23,7 @@ export function addPost(data) {
return request({
url: '/system/post',
method: 'post',
data: data
data: data,
})
}
@ -31,7 +32,7 @@ export function updatePost(data) {
return request({
url: '/system/post',
method: 'put',
data: data
data: data,
})
}
@ -39,15 +40,16 @@ export function updatePost(data) {
export function delPost(postId) {
return request({
url: '/system/post/' + postId,
method: 'delete'
method: 'delete',
})
}
// 导出岗位
export function exportPost(query) {
return request({
url: '/system/post/export',
method: 'get',
params: query
})
export async function exportPost(query) {
// return request({
// url: '/system/post/export',
// method: 'get',
// params: query
// })
await downFile('/system/post/export', { ...query })
}

View File

@ -1,12 +1,13 @@
import request from '@/utils/request'
import { praseStrZero } from "@/utils/ruoyi";
import { praseStrZero } from '@/utils/ruoyi'
import { downFile } from '@/utils/request'
// 查询用户列表
export function listUser(query) {
return request({
url: '/system/user/list',
method: 'get',
params: query
params: query,
})
}
@ -14,7 +15,7 @@ export function listUser(query) {
export function getUser(userId) {
return request({
url: '/system/user/' + praseStrZero(userId),
method: 'get'
method: 'get',
})
}
@ -23,7 +24,7 @@ export function addUser(data) {
return request({
url: '/system/user/edit',
method: 'post',
data: data
data: data,
})
}
@ -32,7 +33,7 @@ export function updateUser(data) {
return request({
url: '/system/user/edit',
method: 'put',
data: data
data: data,
})
}
@ -40,29 +41,30 @@ export function updateUser(data) {
export function delUser(userId) {
return request({
url: '/system/user/' + userId,
method: 'delete'
method: 'delete',
})
}
// 导出用户
export function exportUser(query) {
return request({
url: '/system/User/export',
method: 'get',
params: query
})
export async function exportUser(query) {
// return request({
// url: '/system/User/export',
// method: 'get',
// params: query
// })
await downFile('/system/user/export', { ...query })
}
// 用户密码重置
export function resetUserPwd(userId, password) {
const data = {
userId,
password
password,
}
return request({
url: '/system/user/resetPwd',
method: 'put',
data: data
data: data,
})
}
@ -70,12 +72,12 @@ export function resetUserPwd(userId, password) {
export function changeUserStatus(userId, status) {
const data = {
userId,
status
status,
}
return request({
url: '/system/user/changeStatus',
method: 'put',
data: data
data: data,
})
}
@ -83,7 +85,7 @@ export function changeUserStatus(userId, status) {
export function getUserProfile() {
return request({
url: '/system/user/Profile',
method: 'get'
method: 'get',
})
}
@ -92,7 +94,7 @@ export function updateUserProfile(data) {
return request({
url: '/system/user/profile',
method: 'put',
data: data
data: data,
})
}
@ -100,12 +102,12 @@ export function updateUserProfile(data) {
export function updateUserPwd(oldPassword, newPassword) {
const data = {
oldPassword,
newPassword
newPassword,
}
return request({
url: '/system/user/profile/updatePwd',
method: 'put',
params: data
params: data,
})
}
@ -114,7 +116,7 @@ export function uploadAvatar(data) {
return request({
url: '/system/user/profile/avatar',
method: 'post',
data: data
data: data,
})
}
@ -123,6 +125,6 @@ export function importTemplate() {
return request({
url: '/system/user/importTemplate',
method: 'get',
responseType: 'blob'//1.首先设置responseType对象格式为 blob:
responseType: 'blob', //1.首先设置responseType对象格式为 blob:
})
}

View File

@ -13,6 +13,7 @@ import router from './router'
import permission from './directive/permission'
import plugins from './plugins' // plugins
import signalR from '@/utils/signalR'
import { downFile } from '@/utils/request'
import './assets/icons' // icon
import './permission' // permission control
@ -43,6 +44,7 @@ Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.handleDict = handleDict
Vue.prototype.downFile = downFile
Vue.prototype.msgSuccess = function (msg) {
this.$message({ showClose: true, message: msg, type: "success" });

View File

@ -1,11 +1,12 @@
import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import { MessageBox, Message, Loading } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
// import { blobValidate } from "@/utils/ruoyi";
// import errorCode from '@/utils/errorCode'
// import { saveAs } from 'file-saver'
import { blobValidate } from '@/utils/ruoyi'
import errorCode from '@/utils/errorCode'
import { saveAs } from 'file-saver'
let downloadLoadingInstance
// 解决后端跨域获取不到cookie问题
axios.defaults.withCredentials = true
axios.defaults.headers['Content-Type'] = 'application/json'
@ -14,45 +15,49 @@ const service = axios.create({
// axios中请求配置有baseURL选项表示请求URL公共部分
baseURL: process.env.VUE_APP_BASE_API,
// 超时
timeout: 30000
timeout: 30000,
})
// request拦截器
service.interceptors.request.use(config => {
// 是否需要设置 token
if (getToken()) {
//将token放到请求头发送给服务器,将tokenkey放在请求头中
config.headers['Authorization'] = 'Bearer ' + getToken();
config.headers['userid'] = store.getters.userId;
} else {
// console.log(config)
}
return config;
}, error => {
console.log(error)
Promise.reject(error)
})
service.interceptors.request.use(
(config) => {
// 是否需要设置 token
if (getToken()) {
//将token放到请求头发送给服务器,将tokenkey放在请求头中
config.headers['Authorization'] = 'Bearer ' + getToken()
config.headers['userid'] = store.getters.userId
} else {
// console.log(config)
}
return config
},
(error) => {
console.log(error)
Promise.reject(error)
},
)
// 响应拦截器
service.interceptors.response.use(res => {
service.interceptors.response.use(
(res) => {
if (res.status !== 200) {
Promise.reject('network error');
return;
Promise.reject('network error')
return
}
// 未设置状态码则默认成功状态
const { code, msg } = res.data;
const { code, msg } = res.data
// 二进制数据则直接返回
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res.data
return res
}
if (code == 401) {
MessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
type: 'warning',
}).then(() => {
store.dispatch('LogOut').then(() => {
location.href = process.env.VUE_APP_ROUTER_PREFIX + 'index';
location.href = process.env.VUE_APP_ROUTER_PREFIX + 'index'
})
})
@ -60,33 +65,33 @@ service.interceptors.response.use(res => {
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
Message({
message: msg,
type: 'error'
type: 'error',
})
return Promise.reject(res.data)
} else {
//返回标准 code/msg/data字段
return res.data;
return res.data
}
},
error => {
(error) => {
console.log('err' + error)
let { message } = error;
if (message == "Network Error") {
message = "后端接口连接异常";
} else if (message.includes("timeout")) {
message = "系统接口请求超时";
} else if (message.includes("Request failed with status code 429")) {
message = "请求过于频繁,请稍后再试";
} else if (message.includes("Request failed with status code")) {
message = "系统接口" + message.substr(message.length - 3) + "异常";
let { message } = error
if (message == 'Network Error') {
message = '后端接口连接异常'
} else if (message.includes('timeout')) {
message = '系统接口请求超时'
} else if (message.includes('Request failed with status code 429')) {
message = '请求过于频繁,请稍后再试'
} else if (message.includes('Request failed with status code')) {
message = '系统接口' + message.substr(message.length - 3) + '异常'
}
Message({
message: message,
type: 'error',
duration: 5 * 1000
duration: 5 * 1000,
})
return Promise.reject(error)
}
},
)
/**
@ -98,12 +103,12 @@ export function get(url, params) {
return new Promise((resolve, reject) => {
axios
.get(url, {
params: params
params: params,
})
.then(res => {
.then((res) => {
resolve(res.data)
})
.catch(err => {
.catch((err) => {
reject(err)
})
})
@ -113,12 +118,12 @@ export function post(url, params) {
return new Promise((resolve, reject) => {
axios
.post(url, {
params: params
params: params,
})
.then(res => {
.then((res) => {
resolve(res.data)
})
.catch(err => {
.catch((err) => {
reject(err)
})
})
@ -131,39 +136,53 @@ export function post(url, params) {
*/
export function postForm(url, data, config) {
return new Promise((resolve, reject) => {
axios.post(url, data, config).then(res => {
resolve(res.data)
}).catch(err => {
reject(err)
})
axios
.post(url, data, config)
.then((res) => {
resolve(res.data)
})
.catch((err) => {
reject(err)
})
})
}
// 通用下载方法
// export function download(url, params, filename) {
// //downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
// return service.post(url, params, {
// //transformRequest: [(params) => { return tansParams(params) }],
// headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
// responseType: 'blob'
// }).then(async (data) => {
// const isLogin = await blobValidate(data);
// if (isLogin) {
// const blob = new Blob([data])
// saveAs(blob, filename)
// } else {
// const resText = await data.text();
// const rspObj = JSON.parse(resText);
// const errMsg = "出錯了";// errorCode[rspObj.code] || rspObj.msg || errorCode['default']
// Message.error(errMsg);
// }
// // downloadLoadingInstance.close();
// }).catch((r) => {
// console.error(r)
// Message.error('下载文件出现错误,请联系管理员!')
// // downloadLoadingInstance.close();
// })
// }
export async function downFile(url, params, config) {
downloadLoadingInstance = Loading.service({ text: '正在下载数据,请稍候', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' })
return service
.get(url, {
params,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob',
...config,
})
.then(async (resp) => {
const { data } = resp
const isLogin = await blobValidate(data)
if (isLogin) {
var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
var contentDisposition = decodeURI(resp.headers['content-disposition'])
var result = patt.exec(contentDisposition)
var fileName = result[1]
fileName = fileName.replace(/\"/g, '')
const blob = new Blob([data])
saveAs(blob, fileName)
} else {
const resText = await data.text()
const rspObj = JSON.parse(resText)
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
Message.error(errMsg)
}
downloadLoadingInstance.close()
})
.catch((r) => {
console.error(r)
Message.error('下载文件出现错误,请联系管理员!')
downloadLoadingInstance.close()
})
}
export default service

View File

@ -2,10 +2,24 @@
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="系统模块" prop="title">
<el-input v-model="queryParams.title" placeholder="请输入系统模块" clearable style="width: 200px;" size="small" @keyup.enter.native="handleQuery" />
<el-input
v-model="queryParams.title"
placeholder="请输入系统模块"
clearable
style="width: 200px"
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="操作人员" prop="operName">
<el-input v-model="queryParams.operName" placeholder="请输入操作人员" clearable style="width: 160px;" size="small" @keyup.enter.native="handleQuery" />
<el-input
v-model="queryParams.operName"
placeholder="请输入操作人员"
clearable
style="width: 160px"
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="类型" prop="businessType">
<el-select v-model="queryParams.businessType" placeholder="操作类型" clearable size="small" style="width: 240px">
@ -18,7 +32,16 @@
</el-select>
</el-form-item>
<el-form-item label="操作时间">
<el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
<el-date-picker
v-model="dateRange"
size="small"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
@ -28,13 +51,25 @@
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['monitor:operlog:remove']">删除</el-button>
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['monitor:operlog:remove']"
>删除</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleClean" v-hasPermi="['monitor:operlog:remove']">清空</el-button>
<el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleClean" v-hasPermi="['monitor:operlog:remove']"
>清空</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:operlog:export']">导出
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:operlog:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -54,14 +89,15 @@
<el-table-column label="主机" align="center" prop="operIp" width="130" :show-overflow-tooltip="true" />
<el-table-column label="操作地点" align="center" prop="operLocation" :show-overflow-tooltip="true" />
<el-table-column label="操作状态" align="center" prop="status">
<template slot-scope="{row}">
<template slot-scope="{ row }">
<dict-tag :options="statusOptions" :value="row.status"></dict-tag>
</template>
</el-table-column>
<el-table-column label="用时" align="center" prop="elapsed">
<template slot-scope="scope">
<span :style="scope.row.elapsed < 1000 ? 'color:green':scope.row.elapsed <3000 ?'color:orange':'color:red'">{{ scope.row.elapsed }}
ms</span>
<span :style="scope.row.elapsed < 1000 ? 'color:green' : scope.row.elapsed < 3000 ? 'color:orange' : 'color:red'"
>{{ scope.row.elapsed }} ms</span
>
</template>
</el-table-column>
<el-table-column label="日志内容" align="center" prop="errorMsg" :show-overflow-tooltip="true" />
@ -72,13 +108,14 @@
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row,scope.index)" v-hasPermi="['monitor:operlog:query']">详细
<el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row, scope.index)" v-hasPermi="['monitor:operlog:query']"
>详细
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 操作日志详细 -->
<el-dialog title="操作日志详细" :visible.sync="open" width="700px" append-to-body>
@ -129,15 +166,10 @@
</template>
<script>
import {
list,
delOperlog,
cleanOperlog,
exportOperlog,
} from "@/api/monitor/operlog";
import { list, delOperlog, cleanOperlog, exportOperlog } from '@/api/monitor/operlog'
export default {
name: "operlog",
name: 'operlog',
data() {
return {
//
@ -171,117 +203,102 @@ export default {
businessType: undefined,
status: undefined,
},
};
}
},
created() {
this.getList();
this.getList()
var dictParams = [
{ dictType: "sys_oper_type", columnName: "businessTypeOptions" },
{ dictType: "sys_common_status", columnName: "statusOptions" },
];
{ dictType: 'sys_oper_type', columnName: 'businessTypeOptions' },
{ dictType: 'sys_common_status', columnName: 'statusOptions' },
]
this.getDicts(dictParams).then((response) => {
response.data.forEach((element) => {
this[element.columnName] = element.list;
});
});
this[element.columnName] = element.list
})
})
},
methods: {
/** 查询登录日志 */
getList() {
this.loading = true;
list(this.addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.loading = false;
if (response.code == 200) {
this.list = response.data.result;
this.total = response.data.totalNum;
} else {
this.total = 0;
this.list = [];
}
this.loading = true
list(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
this.loading = false
if (response.code == 200) {
this.list = response.data.result
this.total = response.data.totalNum
} else {
this.total = 0
this.list = []
}
);
})
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
return this.selectDictLabel(this.statusOptions, row.status)
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
this.dateRange = []
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.operId);
this.multiple = !selection.length;
this.ids = selection.map((item) => item.operId)
this.multiple = !selection.length
},
/** 详细按钮操作 */
handleView(row) {
this.open = true;
this.form = row;
this.open = true
this.form = row
},
/** 删除按钮操作 */
handleDelete(row) {
const operIds = row.operId || this.ids;
this.$confirm(
'是否确认删除日志编号为"' + operIds + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
const operIds = row.operId || this.ids
this.$confirm('是否确认删除日志编号为"' + operIds + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return delOperlog(operIds);
return delOperlog(operIds)
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
});
this.getList()
this.msgSuccess('删除成功')
})
},
/** 清空按钮操作 */
handleClean() {
this.$confirm("是否确认清空所有操作日志数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
this.$confirm('是否确认清空所有操作日志数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return cleanOperlog();
return cleanOperlog()
})
.then(() => {
this.getList();
this.msgSuccess("清空成功");
});
this.getList()
this.msgSuccess('清空成功')
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有操作日志?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
exportOperlog(queryParams).then((response) => {
const { code, data } = response;
if (code == 200) {
this.msgSuccess("导出成功");
this.download(data.path);
} else {
this.msgError("导出失败");
}
});
});
const queryParams = this.queryParams
this.$confirm('是否确认导出所有操作日志?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
await exportOperlog(queryParams)
})
},
},
};
}
</script>

View File

@ -23,13 +23,26 @@
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:post:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:post:edit']">修改</el-button>
<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:post:edit']"
>修改</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:post:remove']">删除</el-button>
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:post:remove']"
>删除</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:post:export']">导出</el-button>
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:post:export']"
>导出</el-button
>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@ -53,12 +66,14 @@
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:post:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:post:remove']">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:post:remove']"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 添加或修改岗位对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
@ -74,7 +89,7 @@
</el-form-item>
<el-form-item label="岗位状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
<el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{ dict.dictLabel }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
@ -90,17 +105,10 @@
</template>
<script>
import {
listPost,
getPost,
delPost,
addPost,
updatePost,
exportPost,
} from "@/api/system/post";
import { listPost, getPost, delPost, addPost, updatePost, exportPost } from '@/api/system/post'
export default {
name: "post",
name: 'post',
data() {
return {
//
@ -118,7 +126,7 @@ export default {
//
postList: [],
//
title: "",
title: '',
//
open: false,
//
@ -135,33 +143,27 @@ export default {
form: {},
//
rules: {
postName: [
{ required: true, message: "岗位名称不能为空", trigger: "blur" },
],
postCode: [
{ required: true, message: "岗位编码不能为空", trigger: "blur" },
],
postSort: [
{ required: true, message: "岗位顺序不能为空", trigger: "blur" },
],
postName: [{ required: true, message: '岗位名称不能为空', trigger: 'blur' }],
postCode: [{ required: true, message: '岗位编码不能为空', trigger: 'blur' }],
postSort: [{ required: true, message: '岗位顺序不能为空', trigger: 'blur' }],
},
};
}
},
created() {
this.getList();
this.getDicts("sys_normal_disable").then((response) => {
this.statusOptions = response.data;
});
this.getList()
this.getDicts('sys_normal_disable').then((response) => {
this.statusOptions = response.data
})
},
methods: {
/** 查询岗位列表 */
getList() {
this.loading = true;
this.loading = true
listPost(this.queryParams).then((response) => {
this.postList = response.data.result;
this.total = response.data.totalNum;
this.loading = false;
});
this.postList = response.data.result
this.total = response.data.totalNum
this.loading = false
})
},
//
// statusFormat(row, column) {
@ -169,8 +171,8 @@ export default {
// },
//
cancel() {
this.open = false;
this.reset();
this.open = false
this.reset()
},
//
reset() {
@ -179,98 +181,93 @@ export default {
postCode: undefined,
postName: undefined,
postSort: 0,
status: "0",
status: '0',
remark: undefined,
};
this.resetForm("form");
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.postId);
this.single = selection.length != 1;
this.multiple = !selection.length;
this.ids = selection.map((item) => item.postId)
this.single = selection.length != 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加岗位";
this.reset()
this.open = true
this.title = '添加岗位'
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const postId = row.postId || this.ids;
this.reset()
const postId = row.postId || this.ids
getPost(postId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改岗位";
});
this.form = response.data
this.open = true
this.title = '修改岗位'
})
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate((valid) => {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.form.postId != undefined) {
updatePost(this.form).then((response) => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
this.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addPost(this.form).then((response) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
this.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
});
})
},
/** 删除按钮操作 */
handleDelete(row) {
const postIds = row.postId || this.ids;
this.$confirm(
'是否确认删除岗位编号为"' + postIds + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
const postIds = row.postId || this.ids
this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return delPost(postIds);
return delPost(postIds)
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
});
this.getList()
this.msgSuccess('删除成功')
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有岗位数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
const queryParams = this.queryParams
this.$confirm('是否确认导出所有岗位数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
await exportPost(queryParams)
})
.then(function () {
return exportPost(queryParams);
})
.then((response) => {
this.download(response.data.path);
});
// .then((response) => {
// this.download(response.data.path);
// });
},
},
};
}
</script>

View File

@ -4,23 +4,49 @@
<!--部门数据-->
<el-col :lg="4" :sm="24">
<div class="head-container">
<el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
<el-input
v-model="deptName"
placeholder="请输入部门名称"
clearable
size="small"
prefix-icon="el-icon-search"
style="margin-bottom: 20px"
/>
</div>
<div class="head-container">
<el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode" ref="tree"
default-expand-all @node-click="handleNodeClick" />
<el-tree
:data="deptOptions"
:props="defaultProps"
:expand-on-click-node="false"
:filter-node-method="filterNode"
ref="tree"
default-expand-all
@node-click="handleNodeClick"
/>
</div>
</el-col>
<!--用户数据-->
<el-col :lg="20" :sm="24">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="用户名称" prop="userName">
<el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable size="small" style="width: 240px"
@keyup.enter.native="handleQuery" />
<el-input
v-model="queryParams.userName"
placeholder="请输入用户名称"
clearable
size="small"
style="width: 240px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="手机号码" prop="phonenumber">
<el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable size="small" style="width: 240px"
@keyup.enter.native="handleQuery" />
<el-input
v-model="queryParams.phonenumber"
placeholder="请输入手机号码"
clearable
size="small"
style="width: 240px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="用户状态" clearable size="small" style="width: 240px">
@ -28,8 +54,16 @@
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
<el-date-picker
v-model="dateRange"
size="small"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
@ -46,10 +80,13 @@
v-hasPermi="['system:user:edit']">修改</el-button>
</el-col> -->
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['system:user:import']">导入</el-button>
<el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['system:user:import']"
>导入</el-button
>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:user:export']">导出
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:user:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
@ -80,11 +117,15 @@
<el-table-column label="创建人" align="center" prop="createBy" v-if="columns[2].checked"></el-table-column>
<el-table-column label="备注" align="center" prop="remark" v-if="columns[3].checked"></el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="160">
<template slot-scope="scope" v-if="scope.row.userId !== 1 | scope.row.userName != 'admin'">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']">删除
<template slot-scope="scope" v-if="(scope.row.userId !== 1) | (scope.row.userName != 'admin')">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']"
>修改</el-button
>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']"
>删除
</el-button>
<el-button size="mini" type="text" icon="el-icon-key" @click="handleResetPwd(scope.row)" v-hasPermi="['system:user:resetPwd']">重置
<el-button size="mini" type="text" icon="el-icon-key" @click="handleResetPwd(scope.row)" v-hasPermi="['system:user:resetPwd']"
>重置
</el-button>
</template>
</el-table-column>
@ -184,17 +225,25 @@
<!-- 用户导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload name="file" ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess" :auto-upload="false" drag>
<el-upload
name="file"
ref="upload"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip text-center" slot="tip">
<div class="el-upload__tip" slot="tip">
<el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
</div>
<div class="el-upload__tip" slot="tip"><el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据</div>
<span>仅允许导入xlsxlsx格式文件</span>
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
<el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
@ -206,23 +255,14 @@
</template>
<script>
import {
listUser,
getUser,
delUser,
addUser,
updateUser,
exportUser,
resetUserPwd,
changeUserStatus,
} from "@/api/system/user";
import { getToken } from "@/utils/auth";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus } from '@/api/system/user'
import { getToken } from '@/utils/auth'
import { treeselect } from '@/api/system/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
name: "user",
name: 'user',
components: { Treeselect },
data() {
return {
@ -241,7 +281,7 @@ export default {
//
userList: [],
//
title: "",
title: '',
//
deptOptions: undefined,
//
@ -263,23 +303,23 @@ export default {
//
form: {},
defaultProps: {
children: "children",
label: "label",
children: 'children',
label: 'label',
},
//
upload: {
//
open: false,
//
title: "",
title: '',
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: "Bearer " + getToken() },
headers: { Authorization: 'Bearer ' + getToken() },
//
url: process.env.VUE_APP_BASE_API + "/system/user/importData",
url: process.env.VUE_APP_BASE_API + '/system/user/importData',
},
//
queryParams: {
@ -306,111 +346,97 @@ export default {
],
//
rules: {
userName: [
{ required: true, message: "用户名称不能为空", trigger: "blur" },
],
nickName: [
{ required: true, message: "用户昵称不能为空", trigger: "blur" },
],
deptId: [
{ required: true, message: "归属部门不能为空", trigger: "change" },
],
password: [
{ required: true, message: "用户密码不能为空", trigger: "blur" },
],
userName: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }],
nickName: [{ required: true, message: '用户昵称不能为空', trigger: 'blur' }],
deptId: [{ required: true, message: '归属部门不能为空', trigger: 'change' }],
password: [{ required: true, message: '用户密码不能为空', trigger: 'blur' }],
email: [
{ required: false, message: "邮箱地址不能为空", trigger: "blur" },
{ required: false, message: '邮箱地址不能为空', trigger: 'blur' },
{
type: "email",
type: 'email',
message: "'请输入正确的邮箱地址",
trigger: ["blur", "change"],
trigger: ['blur', 'change'],
},
],
phonenumber: [
{ required: false, message: "手机号码不能为空", trigger: "blur" },
{ required: false, message: '手机号码不能为空', trigger: 'blur' },
{
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
message: "请输入正确的手机号码",
trigger: "blur",
message: '请输入正确的手机号码',
trigger: 'blur',
},
],
},
};
}
},
watch: {
//
deptName(val) {
this.$refs.tree.filter(val);
this.$refs.tree.filter(val)
},
},
created() {
this.getList();
this.getTreeselect();
this.getList()
this.getTreeselect()
this.getDicts("sys_normal_disable").then((response) => {
this.statusOptions = response.data;
});
this.getDicts("sys_user_sex").then((response) => {
this.sexOptions = response.data;
});
this.getConfigKey("sys.user.initPassword").then((response) => {
this.initPassword = response.data;
});
this.getDicts('sys_normal_disable').then((response) => {
this.statusOptions = response.data
})
this.getDicts('sys_user_sex').then((response) => {
this.sexOptions = response.data
})
this.getConfigKey('sys.user.initPassword').then((response) => {
this.initPassword = response.data
})
},
methods: {
/** 查询用户列表 */
getList() {
this.loading = true;
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.userList = response.data.result;
this.total = response.data.totalNum;
this.loading = false;
}
);
this.loading = true
listUser(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
this.userList = response.data.result
this.total = response.data.totalNum
this.loading = false
})
},
/** 查询部门下拉树结构 */
getTreeselect() {
treeselect().then((response) => {
this.deptOptions = response.data;
});
this.deptOptions = response.data
})
},
//
filterNode(value, data) {
if (!value) return true;
return data.label.indexOf(value) !== -1;
if (!value) return true
return data.label.indexOf(value) !== -1
},
//
handleNodeClick(data) {
this.queryParams.deptId = data.id;
this.getList();
this.queryParams.deptId = data.id
this.getList()
},
//
handleStatusChange(row) {
let text = row.status === "0" ? "启用" : "停用";
this.$confirm(
'确认要"' + text + '""' + row.userName + '"用户吗?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
let text = row.status === '0' ? '启用' : '停用'
this.$confirm('确认要"' + text + '""' + row.userName + '"用户吗?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return changeUserStatus(row.userId, row.status);
return changeUserStatus(row.userId, row.status)
})
.then(() => {
this.msgSuccess(text + "成功");
this.msgSuccess(text + '成功')
})
.catch(function () {
row.status = row.status === "0" ? "1" : "0";
});
row.status = row.status === '0' ? '1' : '0'
})
},
//
cancel() {
this.open = false;
this.reset();
this.open = false
this.reset()
},
//
reset() {
@ -423,58 +449,58 @@ export default {
phonenumber: undefined,
email: undefined,
sex: undefined,
status: "0",
status: '0',
remark: undefined,
postIds: [],
roleIds: [],
};
this.resetForm("form");
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.page = 1;
this.getList();
this.queryParams.page = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.queryParams.deptId = undefined;
this.resetForm("queryForm");
this.handleQuery();
this.dateRange = []
this.queryParams.deptId = undefined
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.userId);
this.single = selection.length != 1;
this.multiple = !selection.length;
this.ids = selection.map((item) => item.userId)
this.single = selection.length != 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.getTreeselect();
this.reset()
this.getTreeselect()
getUser().then((response) => {
this.postOptions = response.data.posts;
this.roleOptions = response.data.roles;
this.open = true;
this.title = "添加用户";
this.form.password = this.initPassword;
});
this.postOptions = response.data.posts
this.roleOptions = response.data.roles
this.open = true
this.title = '添加用户'
this.form.password = this.initPassword
})
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
const userId = row.userId || this.ids;
this.reset()
this.getTreeselect()
const userId = row.userId || this.ids
getUser(userId).then((response) => {
// this.form = response.data.user;
var data = response.data;
var data = response.data
this.form = {
userId: data.user.userId,
deptId: data.user.deptId,
userName: data.user.userName,
nickName: data.user.nickName,
password: "",
password: '',
phonenumber: data.user.phonenumber,
email: data.user.email,
sex: data.user.sex,
@ -482,124 +508,121 @@ export default {
remark: data.user.remark,
postIds: data.postIds,
roleIds: data.roleIds,
};
this.roleOptions = response.data.roles;
this.postOptions = response.data.posts;
}
this.roleOptions = response.data.roles
this.postOptions = response.data.posts
this.open = true;
this.title = "修改用户";
});
this.open = true
this.title = '修改用户'
})
},
/** 重置密码按钮操作 */
handleResetPwd(row) {
this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
this.$prompt('请输入"' + row.userName + '"的新密码', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
})
.then(({ value }) => {
resetUserPwd(row.userId, value).then((response) => {
this.msgSuccess("修改成功,新密码是:" + value);
});
this.msgSuccess('修改成功,新密码是:' + value)
})
})
.catch(() => {});
.catch(() => {})
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate((valid) => {
this.$refs['form'].validate((valid) => {
if (valid) {
console.log(JSON.stringify(this.form));
console.log(JSON.stringify(this.form))
// return;
if (this.form.userId != undefined) {
updateUser(this.form).then((response) => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
this.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addUser(this.form).then((response) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
this.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
});
})
},
/** 删除按钮操作 */
handleDelete(row) {
const userIds = row.userId || this.ids;
if (userIds == 1 || row.userName == "admin") {
this.msgError("不能对管理进行删除");
return;
const userIds = row.userId || this.ids
if (userIds == 1 || row.userName == 'admin') {
this.msgError('不能对管理进行删除')
return
}
this.$confirm(
'是否确认删除用户编号为"' + userIds + '"的数据项?',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(function () {
return delUser(userIds);
return delUser(userIds)
})
.then(() => {
this.getList();
this.msgSuccess("删除成功");
});
this.getList()
this.msgSuccess('删除成功')
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有用户数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
exportUser(queryParams).then((response) => {
const { code, data } = response;
if (code == 200) {
this.msgSuccess("导出成功");
this.download(data.path);
} else {
this.msgError("导出失败");
}
});
});
const queryParams = this.queryParams
this.$confirm('是否确认导出所有用户数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
// exportUser(queryParams).then((response) => {
// const { code, data } = response;
// if (code == 200) {
// this.msgSuccess("");
// this.download(data.path);
// } else {
// this.msgError("");
// }
// });
await exportUser(queryParams)
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = "用户导入";
this.upload.open = true;
this.upload.title = '用户导入'
this.upload.open = true
},
/** 下载模板操作 */
importTemplate() {
this.download("/system/user/importTemplate", "用户数据导入模板");
this.download('/system/user/importTemplate', '用户数据导入模板')
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
this.upload.isUploading = true
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
this.upload.open = false
this.upload.isUploading = false
this.$refs.upload.clearFiles()
this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
this.getList()
},
//
submitFileForm() {
this.$refs.upload.submit();
this.$refs.upload.submit()
},
/**
* 解决编辑时角色选中不了问题
*/
selectRole(e) {
console.log(e, JSON.stringify(this.form));
this.$forceUpdate();
console.log(e, JSON.stringify(this.form))
this.$forceUpdate()
},
},
};
}
</script>