From ea085433e27ed412cccafa0a21defefb218a863b Mon Sep 17 00:00:00 2001
From: dqjdda <201507802@qq.com>
Date: Fri, 22 Nov 2019 12:22:52 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20crud.js=EF=BC=8C=E6=95=B4?=
=?UTF-8?q?=E5=90=88=E9=80=9A=E7=94=A8=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9?=
=?UTF-8?q?=E6=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build/index.js | 27 ---
package.json | 31 ++--
src/api/data.js | 14 +-
src/api/job.js | 8 +
src/assets/styles/eladmin.scss | 8 +-
src/assets/styles/element-ui.scss | 4 +-
src/assets/styles/index.scss | 2 +-
src/assets/styles/sidebar.scss | 6 +-
src/mixins/crud.js | 288 ++++++++++++++++++++++++++++++
src/mixins/initData.js | 28 ++-
src/utils/request.js | 2 +-
src/views/system/job/form.vue | 140 ---------------
src/views/system/job/index.vue | 198 ++++++++++----------
13 files changed, 459 insertions(+), 297 deletions(-)
delete mode 100644 build/index.js
create mode 100644 src/mixins/crud.js
delete mode 100644 src/views/system/job/form.vue
diff --git a/build/index.js b/build/index.js
deleted file mode 100644
index 244ff4a..0000000
--- a/build/index.js
+++ /dev/null
@@ -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}`)
-}
diff --git a/package.json b/package.json
index d0cdfef..d84f0c2 100644
--- a/package.json
+++ b/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"
},
diff --git a/src/api/data.js b/src/api/data.js
index 7a91ac6..d975d75 100644
--- a/src/api/data.js
+++ b/src/api/data.js
@@ -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'
})
}
diff --git a/src/api/job.js b/src/api/job.js
index 49ba283..4eb1187 100644
--- a/src/api/job.js
+++ b/src/api/job.js
@@ -44,3 +44,11 @@ export function downloadJob(params) {
responseType: 'blob'
})
}
+
+export default {
+ add,
+ edit,
+ del,
+ getAllJob,
+ downloadJob
+}
diff --git a/src/assets/styles/eladmin.scss b/src/assets/styles/eladmin.scss
index 624aaf9..c23186d 100644
--- a/src/assets/styles/eladmin.scss
+++ b/src/assets/styles/eladmin.scss
@@ -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;
diff --git a/src/assets/styles/element-ui.scss b/src/assets/styles/element-ui.scss
index 9581d56..8f7881c 100644
--- a/src/assets/styles/element-ui.scss
+++ b/src/assets/styles/element-ui.scss
@@ -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;
}
}
}
diff --git a/src/assets/styles/index.scss b/src/assets/styles/index.scss
index fdf9ba4..2e8715e 100644
--- a/src/assets/styles/index.scss
+++ b/src/assets/styles/index.scss
@@ -34,7 +34,7 @@ html {
}
.no-padding {
- padding: 0px !important;
+ padding: 0 !important;
}
.padding-content {
diff --git a/src/assets/styles/sidebar.scss b/src/assets/styles/sidebar.scss
index 3dad4c3..17381fc 100644
--- a/src/assets/styles/sidebar.scss
+++ b/src/assets/styles/sidebar.scss
@@ -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 {
diff --git a/src/mixins/crud.js b/src/mixins/crud.js
new file mode 100644
index 0000000..dacd6fb
--- /dev/null
+++ b/src/mixins/crud.js
@@ -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
+ })
+ }
+ }
+}
diff --git a/src/mixins/initData.js b/src/mixins/initData.js
index 2162dc1..aca65a6 100644
--- a/src/mixins/initData.js
+++ b/src/mixins/initData.js
@@ -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()
diff --git a/src/utils/request.js b/src/utils/request.js
index 3a66a88..0fb30a2 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -81,7 +81,7 @@ service.interceptors.response.use(
if (errorMsg !== undefined) {
Notification.error({
title: errorMsg,
- duration: 3000
+ duration: 2500
})
}
}
diff --git a/src/views/system/job/form.vue b/src/views/system/job/form.vue
deleted file mode 100644
index 4eefdb1..0000000
--- a/src/views/system/job/form.vue
+++ /dev/null
@@ -1,140 +0,0 @@
-
-