新增 crud.js,整合通用的增删改查
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
const { run } = require('runjs')
|
||||
const chalk = require('chalk')
|
||||
const config = require('../vue.config.js')
|
||||
const rawArgv = process.argv.slice(2)
|
||||
const args = rawArgv.join(' ')
|
||||
|
||||
if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
|
||||
const report = rawArgv.includes('--report')
|
||||
|
||||
run(`vue-cli-service build ${args}`)
|
||||
|
||||
const publicPath = config.publicPath
|
||||
|
||||
var connect = require('connect')
|
||||
var serveStatic = require('serve-static')
|
||||
const app = connect()
|
||||
|
||||
app.use(
|
||||
publicPath,
|
||||
serveStatic('./dist', {
|
||||
index: ['index.html', '/']
|
||||
})
|
||||
)
|
||||
|
||||
} else {
|
||||
run(`vue-cli-service build ${args}`)
|
||||
}
|
||||
31
package.json
31
package.json
@@ -27,36 +27,37 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/PanJiaChen/vue-element-admin.git"
|
||||
"url": "https://github.com/elunez/eladmin-web.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/elunez/eladmin/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"clipboard": "2.0.4",
|
||||
"@riophae/vue-treeselect": "0.1.0",
|
||||
"vue-cropper": "0.4.9",
|
||||
"axios": "0.18.1",
|
||||
"echarts": "4.2.1",
|
||||
"fuse.js": "3.4.4",
|
||||
"js-cookie": "2.2.0",
|
||||
"normalize.css": "7.0.0",
|
||||
"nprogress": "0.2.0",
|
||||
"path-to-regexp": "2.4.0",
|
||||
"screenfull": "4.2.0",
|
||||
"vue": "2.6.10",
|
||||
"vue-count-to": "1.0.13",
|
||||
"vue-router": "3.0.2",
|
||||
"vue-splitpane": "1.0.4",
|
||||
"vuex": "3.1.0",
|
||||
"clipboard": "2.0.4",
|
||||
"codemirror": "^5.38.0",
|
||||
"connect": "3.6.6",
|
||||
"echarts": "4.2.1",
|
||||
"echarts-gl": "^1.1.1",
|
||||
"element-ui": "^2.12.0",
|
||||
"file-saver": "1.3.8",
|
||||
"fuse.js": "3.4.4",
|
||||
"js-cookie": "2.2.0",
|
||||
"jsencrypt": "^3.0.0-rc.1",
|
||||
"jszip": "3.1.5",
|
||||
"mavon-editor": "^2.7.0",
|
||||
"normalize.css": "7.0.0",
|
||||
"nprogress": "0.2.0",
|
||||
"path-to-regexp": "2.4.0",
|
||||
"qs": "^6.9.1",
|
||||
"screenfull": "4.2.0",
|
||||
"vue": "2.6.10",
|
||||
"vue-count-to": "1.0.13",
|
||||
"vue-cropper": "0.4.9",
|
||||
"vue-router": "3.0.2",
|
||||
"vue-splitpane": "1.0.4",
|
||||
"vuex": "3.1.0",
|
||||
"wangeditor": ">=3.0.0",
|
||||
"xlsx": "^0.11.16"
|
||||
},
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import request from '@/utils/request'
|
||||
import qs from 'qs'
|
||||
|
||||
export function initData(url, params) {
|
||||
return request({
|
||||
url: url,
|
||||
method: 'get',
|
||||
params
|
||||
url: url + '?' + qs.stringify(params, { indices: false }),
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
export function download(url, params) {
|
||||
return request({
|
||||
url: url + '?' + qs.stringify(params, { indices: false }),
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -44,3 +44,11 @@ export function downloadJob(params) {
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
add,
|
||||
edit,
|
||||
del,
|
||||
getAllJob,
|
||||
downloadJob
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
.filter-item {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin-bottom: 10px;
|
||||
margin: 0 2px 10px 0;
|
||||
input {
|
||||
height: 30.5px;
|
||||
line-height: 30.5px;
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
.logo-con{
|
||||
height: 60px;
|
||||
padding: 13px 0px 0px;
|
||||
padding: 13px 0 0;
|
||||
img{
|
||||
height: 32px;
|
||||
width: 135px;
|
||||
@@ -58,7 +58,7 @@
|
||||
background: none repeat scroll 0 0 white;
|
||||
border-top: 1px solid #e7eaec;
|
||||
overflow: hidden;
|
||||
padding: 10px 6px 0px 6px;
|
||||
padding: 10px 6px 0 6px;
|
||||
height: 33px;
|
||||
font-size: 0.7rem !important;
|
||||
color: #7a8b9a;
|
||||
@@ -77,7 +77,7 @@
|
||||
width: 368px;
|
||||
}
|
||||
.my-blockquote{
|
||||
margin: 0px 0px 10px;
|
||||
margin: 0 0 10px;
|
||||
padding: 15px;
|
||||
line-height: 22px;
|
||||
border-left: 5px solid #00437B;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
.cell {
|
||||
.el-tag {
|
||||
margin-right: 0px;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
text-align: center;
|
||||
|
||||
.el-tag {
|
||||
margin-right: 0px;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ html {
|
||||
}
|
||||
|
||||
.no-padding {
|
||||
padding: 0px !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.padding-content {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
background-color: $menuBg;
|
||||
height: 100%;
|
||||
position: fixed;
|
||||
font-size: 0px;
|
||||
font-size: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
@@ -30,7 +30,7 @@
|
||||
}
|
||||
|
||||
.el-scrollbar__bar.is-vertical {
|
||||
right: 0px;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.el-scrollbar {
|
||||
@@ -146,7 +146,7 @@
|
||||
// mobile responsive
|
||||
.mobile {
|
||||
.main-container {
|
||||
margin-left: 0px;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.sidebar-container {
|
||||
|
||||
288
src/mixins/crud.js
Normal file
288
src/mixins/crud.js
Normal file
@@ -0,0 +1,288 @@
|
||||
import { initData, download } from '@/api/data'
|
||||
import { parseTime, downloadFile } from '@/utils/index'
|
||||
import checkPermission from '@/utils/permission'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 表格数据
|
||||
data: [],
|
||||
// 排序规则,默认 id 降序, 支持多字段排序 ['id,desc', 'createTime,asc']
|
||||
sort: ['id,desc', 'createTime,asc'],
|
||||
// 页码
|
||||
page: 0,
|
||||
// 每页数据条数
|
||||
size: 10,
|
||||
// 总数据条数
|
||||
total: 0,
|
||||
// 请求数据的url
|
||||
url: '',
|
||||
// 查询数据的参数
|
||||
params: {},
|
||||
// 待查询的对象
|
||||
query: {},
|
||||
// 等待时间
|
||||
time: 50,
|
||||
// 是否为新增类型的表单
|
||||
isAdd: false,
|
||||
// 导出的 Loading
|
||||
downloadLoading: false,
|
||||
// 表格 Loading 属性
|
||||
loading: true,
|
||||
// 删除 Loading 属性
|
||||
delLoading: false,
|
||||
// 弹窗属性
|
||||
dialog: false,
|
||||
// Form 表单
|
||||
form: {},
|
||||
// 弹窗的标题
|
||||
title: '',
|
||||
// 方法
|
||||
method: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
parseTime,
|
||||
downloadFile,
|
||||
checkPermission,
|
||||
async init() {
|
||||
if (!await this.beforeInit()) {
|
||||
return
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.loading = true
|
||||
// 请求数据
|
||||
initData(this.url, this.getQueryParame()).then(data => {
|
||||
this.total = data.totalElements
|
||||
this.data = data.content
|
||||
// time 毫秒后显示表格
|
||||
setTimeout(() => {
|
||||
this.loading = false
|
||||
}, this.time)
|
||||
resolve(data)
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
beforeInit() {
|
||||
return true
|
||||
},
|
||||
getQueryParame: function() {
|
||||
return {
|
||||
page: this.page,
|
||||
size: this.size,
|
||||
sort: this.sort,
|
||||
...this.query,
|
||||
...this.params
|
||||
}
|
||||
},
|
||||
// 改变页码
|
||||
pageChange(e) {
|
||||
this.page = e - 1
|
||||
this.init()
|
||||
},
|
||||
// 改变每页显示数
|
||||
sizeChange(e) {
|
||||
this.page = 0
|
||||
this.size = e
|
||||
this.init()
|
||||
},
|
||||
// 预防删除第二页最后一条数据时,或者多选删除第二页的数据时,页码错误导致请求无数据
|
||||
dleChangePage(size) {
|
||||
if (size === undefined) {
|
||||
size = 1
|
||||
}
|
||||
if (this.data.length === size && this.page !== 0) {
|
||||
this.page = this.page - 1
|
||||
}
|
||||
},
|
||||
// 查询方法
|
||||
toQuery() {
|
||||
this.page = 0
|
||||
this.init()
|
||||
},
|
||||
/**
|
||||
* 通用的提示封装
|
||||
*/
|
||||
submitSuccessNotify() {
|
||||
this.$notify({
|
||||
title: '提交成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
},
|
||||
addSuccessNotify() {
|
||||
this.$notify({
|
||||
title: '新增成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
},
|
||||
editSuccessNotify() {
|
||||
this.$notify({
|
||||
title: '编辑成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
},
|
||||
delSuccessNotify() {
|
||||
this.$notify({
|
||||
title: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
},
|
||||
notify(title, type) {
|
||||
this.$notify({
|
||||
title: title,
|
||||
type: type,
|
||||
duration: 2500
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 删除前可以调用 beforeDelMethod 做一些操作
|
||||
*/
|
||||
beforeDelMethod() {
|
||||
return true
|
||||
},
|
||||
/**
|
||||
* 通用的删除
|
||||
*/
|
||||
delMethod(id) {
|
||||
if (!this.beforeDelMethod()) {
|
||||
return
|
||||
}
|
||||
this.delLoading = true
|
||||
this.crudMethod.del(id).then(() => {
|
||||
this.delLoading = false
|
||||
this.$refs[id].doClose()
|
||||
this.dleChangePage()
|
||||
this.delSuccessNotify()
|
||||
this.afterDelMethod()
|
||||
this.init()
|
||||
}).catch(() => {
|
||||
this.delLoading = false
|
||||
this.$refs[id].doClose()
|
||||
})
|
||||
},
|
||||
afterDelMethod() {
|
||||
},
|
||||
/**
|
||||
* 显示新增弹窗前可以调用该方法
|
||||
*/
|
||||
beforeShowAddForm() {
|
||||
},
|
||||
/**
|
||||
* 显示新增弹窗
|
||||
*/
|
||||
showAddFormDialog() {
|
||||
this.isAdd = true
|
||||
this.beforeShowAddForm()
|
||||
this.dialog = true
|
||||
},
|
||||
/**
|
||||
* 显示编辑弹窗前可以调用该方法
|
||||
*/
|
||||
beforeShowEditForm(data) {
|
||||
},
|
||||
/**
|
||||
* 显示编辑弹窗
|
||||
*/
|
||||
showEditFormDialog(data = '') {
|
||||
this.isAdd = false
|
||||
if (data) {
|
||||
this.form = JSON.parse(JSON.stringify(data))
|
||||
}
|
||||
this.beforeShowEditForm(data)
|
||||
this.dialog = true
|
||||
},
|
||||
/**
|
||||
* 新增方法
|
||||
*/
|
||||
addMethod() {
|
||||
this.crudMethod.add(this.form).then(() => {
|
||||
this.hideFormDialog()
|
||||
this.addSuccessNotify()
|
||||
this.loading = false
|
||||
this.afterAddMethod()
|
||||
this.init()
|
||||
}).catch(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 新增后可以调用该方法
|
||||
*/
|
||||
afterAddMethod() {
|
||||
},
|
||||
/**
|
||||
* 通用的编辑方法
|
||||
*/
|
||||
editMethod() {
|
||||
this.crudMethod.edit(this.form).then(() => {
|
||||
this.hideFormDialog()
|
||||
this.editSuccessNotify()
|
||||
this.loading = false
|
||||
this.afterEditMethod()
|
||||
this.init()
|
||||
}).catch(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 编辑后可以调用该方法
|
||||
*/
|
||||
afterEditMethod() {
|
||||
},
|
||||
/**
|
||||
* 提交前可以调用该方法
|
||||
*/
|
||||
beforeSubmitMethod() {
|
||||
return true
|
||||
},
|
||||
/**
|
||||
* 提交
|
||||
*/
|
||||
submitMethod() {
|
||||
if (!this.beforeSubmitMethod()) {
|
||||
return
|
||||
}
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true
|
||||
if (this.isAdd) {
|
||||
this.addMethod()
|
||||
} else this.editMethod()
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 隐藏弹窗
|
||||
*/
|
||||
hideFormDialog() {
|
||||
this.dialog = false
|
||||
this.$refs['form'].resetFields()
|
||||
},
|
||||
/**
|
||||
* 获取弹窗的标题
|
||||
*/
|
||||
getFormTitle() {
|
||||
return this.isAdd ? `新增${this.title}` : `编辑${this.title}`
|
||||
},
|
||||
/**
|
||||
* 通用导出
|
||||
*/
|
||||
downloadMethod() {
|
||||
this.beforeInit()
|
||||
this.downloadLoading = true
|
||||
download(this.url + '/download', this.params).then(result => {
|
||||
this.downloadFile(result, this.title, 'xlsx')
|
||||
this.downloadLoading = false
|
||||
}).catch(() => {
|
||||
this.downloadLoading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,28 @@ import { initData } from '@/api/data'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: true, data: [], page: 0, size: 10, total: 0, url: '', params: {}, query: {}, time: 50, isAdd: false, downloadLoading: false
|
||||
// 表格 Loading 属性
|
||||
loading: true,
|
||||
// 表格数据
|
||||
data: [],
|
||||
// 页码
|
||||
page: 0,
|
||||
// 每页数据条数
|
||||
size: 10,
|
||||
// 总数据条数
|
||||
total: 0,
|
||||
// 请求数据的url
|
||||
url: '',
|
||||
// 查询数据的参数
|
||||
params: {},
|
||||
// 待查询的对象
|
||||
query: {},
|
||||
// 等待时间
|
||||
time: 50,
|
||||
// 是否为新增类型的表单
|
||||
isAdd: false,
|
||||
// 导出的 Loading
|
||||
downloadLoading: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -13,9 +34,11 @@ export default {
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.loading = true
|
||||
// 请求数据
|
||||
initData(this.url, this.params).then(res => {
|
||||
this.total = res.totalElements
|
||||
this.data = res.content
|
||||
// time 毫秒后显示表格
|
||||
setTimeout(() => {
|
||||
this.loading = false
|
||||
}, this.time)
|
||||
@@ -29,10 +52,12 @@ export default {
|
||||
beforeInit() {
|
||||
return true
|
||||
},
|
||||
// 改变页码
|
||||
pageChange(e) {
|
||||
this.page = e - 1
|
||||
this.init()
|
||||
},
|
||||
// 改变每页显示数
|
||||
sizeChange(e) {
|
||||
this.page = 0
|
||||
this.size = e
|
||||
@@ -47,6 +72,7 @@ export default {
|
||||
this.page = this.page - 1
|
||||
}
|
||||
},
|
||||
// 查询方法
|
||||
toQuery() {
|
||||
this.page = 0
|
||||
this.init()
|
||||
|
||||
@@ -81,7 +81,7 @@ service.interceptors.response.use(
|
||||
if (errorMsg !== undefined) {
|
||||
Notification.error({
|
||||
title: errorMsg,
|
||||
duration: 3000
|
||||
duration: 2500
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
<template>
|
||||
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '新增岗位' : '编辑岗位'" width="500px">
|
||||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model.number="form.sort" :min="0" :max="999" controls-position="right" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.pid !== 0" label="状态" prop="enabled">
|
||||
<el-radio v-for="item in dicts" :key="item.id" v-model="form.enabled" :label="item.value">{{ item.label }}</el-radio>
|
||||
</el-form-item>
|
||||
<el-form-item label="所属部门">
|
||||
<treeselect v-model="deptId" :options="depts" style="width: 370px" placeholder="选择部门" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="text" @click="cancel">取消</el-button>
|
||||
<el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getDepts } from '@/api/dept'
|
||||
import { add, edit } from '@/api/job'
|
||||
import Treeselect from '@riophae/vue-treeselect'
|
||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||
export default {
|
||||
components: { Treeselect },
|
||||
props: {
|
||||
isAdd: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
dicts: {
|
||||
type: Array,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false, dialog: false, depts: [], deptId: null,
|
||||
form: {
|
||||
id: '',
|
||||
name: '',
|
||||
sort: 999,
|
||||
enabled: 'true',
|
||||
createTime: '',
|
||||
dept: { id: '' }
|
||||
},
|
||||
rules: {
|
||||
name: [
|
||||
{ required: true, message: '请输入名称', trigger: 'blur' }
|
||||
],
|
||||
sort: [
|
||||
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancel() {
|
||||
this.resetForm()
|
||||
},
|
||||
doSubmit() {
|
||||
this.form.dept.id = this.deptId
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
if (this.deptId === null || this.deptId === undefined) {
|
||||
this.$message({
|
||||
message: '所属部门不能为空',
|
||||
type: 'warning'
|
||||
})
|
||||
} else {
|
||||
this.loading = true
|
||||
if (this.isAdd) {
|
||||
this.doAdd()
|
||||
} else this.doEdit()
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
doAdd() {
|
||||
add(this.form).then(res => {
|
||||
this.resetForm()
|
||||
this.$notify({
|
||||
title: '添加成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
this.loading = false
|
||||
this.$parent.init()
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
doEdit() {
|
||||
edit(this.form).then(res => {
|
||||
this.resetForm()
|
||||
this.$notify({
|
||||
title: '修改成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
this.loading = false
|
||||
this.$parent.init()
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
resetForm() {
|
||||
this.dialog = false
|
||||
this.$refs['form'].resetFields()
|
||||
this.deptId = null
|
||||
this.form = {
|
||||
id: '',
|
||||
name: '',
|
||||
sort: 999,
|
||||
enabled: 'true',
|
||||
createTime: '',
|
||||
dept: { id: '' }
|
||||
}
|
||||
},
|
||||
getDepts() {
|
||||
getDepts({ enabled: true }).then(res => {
|
||||
this.depts = res.content
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||
/deep/ .el-input-number .el-input__inner {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
@@ -3,9 +3,9 @@
|
||||
<!--工具栏-->
|
||||
<div class="head-container">
|
||||
<!-- 搜索 -->
|
||||
<el-input v-model="query.value" clearable size="small" placeholder="输入岗位名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
||||
<el-input v-model="query.name" clearable size="small" placeholder="输入岗位名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
||||
<el-date-picker
|
||||
v-model="query.date"
|
||||
v-model="query.createTime"
|
||||
:default-time="['00:00:00','23:59:59']"
|
||||
type="daterange"
|
||||
range-separator=":"
|
||||
@@ -19,30 +19,49 @@
|
||||
<el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
|
||||
</el-select>
|
||||
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
|
||||
<!-- 新增 -->
|
||||
<div v-permission="['admin','job:add']" style="display: inline-block;margin: 0px 2px;">
|
||||
<el-button
|
||||
class="filter-item"
|
||||
size="mini"
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
@click="add"
|
||||
>新增</el-button>
|
||||
</div>
|
||||
<!-- 导出 -->
|
||||
<div style="display: inline-block;">
|
||||
<el-button
|
||||
:loading="downloadLoading"
|
||||
size="mini"
|
||||
class="filter-item"
|
||||
type="warning"
|
||||
icon="el-icon-download"
|
||||
@click="download"
|
||||
>导出</el-button>
|
||||
</div>
|
||||
<!-- 新增按钮 -->
|
||||
<el-button
|
||||
v-permission="['admin','job:add']"
|
||||
class="filter-item"
|
||||
size="mini"
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
@click="showAddFormDialog"
|
||||
>新增</el-button>
|
||||
<!-- 导出按钮 -->
|
||||
<el-button
|
||||
:loading="downloadLoading"
|
||||
size="mini"
|
||||
class="filter-item"
|
||||
type="warning"
|
||||
icon="el-icon-download"
|
||||
@click="downloadMethod"
|
||||
>导出</el-button>
|
||||
</div>
|
||||
<!--表单组件-->
|
||||
<eForm ref="form" :is-add="isAdd" :dicts="dict.job_status" />
|
||||
<!--表单渲染-->
|
||||
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="hideFormDialog" :visible.sync="dialog" :title="getFormTitle()" width="500px">
|
||||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
|
||||
<el-form-item v-show="false" label="ID" prop="id">
|
||||
<el-input v-model="form.id" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model.number="form.sort" :min="0" :max="999" controls-position="right" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.pid !== 0" label="状态" prop="enabled">
|
||||
<el-radio v-for="item in dict.job_status" :key="item.id" v-model="form.enabled" :label="item.value">{{ item.label }}</el-radio>
|
||||
</el-form-item>
|
||||
<el-form-item label="部门" prop="dept.id">
|
||||
<treeselect v-model="form.dept.id" :options="depts" style="width: 370px" placeholder="选择部门" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="text" @click="hideFormDialog">取消</el-button>
|
||||
<el-button :loading="loading" type="primary" @click="submitMethod">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!--表格渲染-->
|
||||
<el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
|
||||
<el-table-column prop="name" label="名称" />
|
||||
@@ -71,9 +90,10 @@
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 编辑与删除 -->
|
||||
<el-table-column v-if="checkPermission(['admin','job:edit','job:del'])" label="操作" width="130px" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-permission="['admin','job:edit']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)" />
|
||||
<el-button v-permission="['admin','job:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
|
||||
<el-popover
|
||||
:ref="scope.row.id"
|
||||
v-permission="['admin','job:del']"
|
||||
@@ -83,7 +103,7 @@
|
||||
<p>确定删除本条数据吗?</p>
|
||||
<div style="text-align: right; margin: 0">
|
||||
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
|
||||
<el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
|
||||
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.id)">确定</el-button>
|
||||
</div>
|
||||
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
|
||||
</el-popover>
|
||||
@@ -103,24 +123,45 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import checkPermission from '@/utils/permission'
|
||||
import initData from '@/mixins/initData'
|
||||
import { del, edit, downloadJob } from '@/api/job'
|
||||
import { parseTime, downloadFile } from '@/utils/index'
|
||||
import eForm from './form'
|
||||
import crud from '@/mixins/crud'
|
||||
import crudJob from '@/api/job'
|
||||
import { getDepts } from '@/api/dept'
|
||||
import Treeselect from '@riophae/vue-treeselect'
|
||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
|
||||
export default {
|
||||
name: 'Job',
|
||||
components: { eForm },
|
||||
mixins: [initData],
|
||||
// 设置数据字典
|
||||
components: { Treeselect },
|
||||
mixins: [crud],
|
||||
// 数据字典
|
||||
dicts: ['job_status'],
|
||||
data() {
|
||||
return {
|
||||
delLoading: false,
|
||||
crudMethod: {
|
||||
...crudJob
|
||||
},
|
||||
sort: ['sort,asc', 'id,desc'],
|
||||
title: '岗位',
|
||||
enabledTypeOptions: [
|
||||
{ key: 'true', display_name: '正常' },
|
||||
{ key: 'false', display_name: '禁用' }
|
||||
]
|
||||
],
|
||||
form: {
|
||||
id: '',
|
||||
name: '',
|
||||
sort: 999,
|
||||
enabled: 'true',
|
||||
createTime: '',
|
||||
dept: { id: null }
|
||||
},
|
||||
depts: [],
|
||||
rules: {
|
||||
name: [
|
||||
{ required: true, message: '请输入名称', trigger: 'blur' }
|
||||
],
|
||||
sort: [
|
||||
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -129,60 +170,23 @@ export default {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
parseTime,
|
||||
checkPermission,
|
||||
beforeInit() {
|
||||
this.url = 'api/job'
|
||||
const sort = 'sort,asc'
|
||||
this.params = { page: this.page, size: this.size, sort: sort }
|
||||
const query = this.query
|
||||
const value = query.value
|
||||
const enabled = query.enabled
|
||||
if (value) { this.params['name'] = value }
|
||||
if (query.date) {
|
||||
this.params['startTime'] = query.date[0]
|
||||
this.params['endTime'] = query.date[1]
|
||||
}
|
||||
if (enabled !== '' && enabled !== null) { this.params['enabled'] = enabled }
|
||||
return true
|
||||
},
|
||||
subDelete(id) {
|
||||
this.delLoading = true
|
||||
del(id).then(res => {
|
||||
this.delLoading = false
|
||||
this.$refs[id].doClose()
|
||||
this.dleChangePage()
|
||||
this.init()
|
||||
this.$notify({
|
||||
title: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
}).catch(err => {
|
||||
this.delLoading = false
|
||||
this.$refs[id].doClose()
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
beforeShowAddForm() {
|
||||
this.getDepts()
|
||||
},
|
||||
add() {
|
||||
this.isAdd = true
|
||||
this.$refs.form.getDepts()
|
||||
this.$refs.form.dialog = true
|
||||
beforeShowEditForm(data) {
|
||||
this.getDepts()
|
||||
this.form.enabled = data.enabled.toString()
|
||||
},
|
||||
edit(data) {
|
||||
this.isAdd = false
|
||||
const _this = this.$refs.form
|
||||
_this.getDepts()
|
||||
_this.form = {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
sort: data.sort,
|
||||
enabled: data.enabled.toString(),
|
||||
createTime: data.createTime,
|
||||
dept: { id: data.dept.id }
|
||||
beforeSubmitMethod() {
|
||||
if (!this.form.dept.id) {
|
||||
this.notify('所属部门不能为空', 'warning')
|
||||
return false
|
||||
}
|
||||
_this.deptId = data.dept.id
|
||||
_this.dialog = true
|
||||
return true
|
||||
},
|
||||
// 改变状态
|
||||
changeEnabled(data, val) {
|
||||
@@ -191,12 +195,8 @@ export default {
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
edit(data).then(res => {
|
||||
this.$notify({
|
||||
title: this.dict.label.job_status[val] + '成功',
|
||||
type: 'success',
|
||||
duration: 2500
|
||||
})
|
||||
this.crudMethod.edit(data).then(() => {
|
||||
this.notify(this.dict.label.job_status[val] + '成功', 'success')
|
||||
}).catch(err => {
|
||||
data.enabled = !data.enabled
|
||||
console.log(err.response.data.message)
|
||||
@@ -205,20 +205,18 @@ export default {
|
||||
data.enabled = !data.enabled
|
||||
})
|
||||
},
|
||||
download() {
|
||||
this.beforeInit()
|
||||
this.downloadLoading = true
|
||||
downloadJob(this.params).then(result => {
|
||||
downloadFile(result, '岗位列表', 'xlsx')
|
||||
this.downloadLoading = false
|
||||
}).catch(() => {
|
||||
this.downloadLoading = false
|
||||
// 获取部门数据
|
||||
getDepts() {
|
||||
getDepts({ enabled: true }).then(res => {
|
||||
this.depts = res.content
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||
/deep/ .el-input-number .el-input__inner {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user