|
@@ -14,7 +14,14 @@ import I18n from '@/utils/i18n'
|
|
|
import common from '@/constants/common.js'
|
|
import common from '@/constants/common.js'
|
|
|
|
|
|
|
|
const action = {
|
|
const action = {
|
|
|
- descDialog: function({ title, message, className = 'ibps-dialog-desc', confirmButtonColor = '#3396FB', confirmButtonText = '知道了', overlay = true }) {
|
|
|
|
|
|
|
+ descDialog: function({
|
|
|
|
|
+ title,
|
|
|
|
|
+ message,
|
|
|
|
|
+ className = 'ibps-dialog-desc',
|
|
|
|
|
+ confirmButtonColor = '#3396FB',
|
|
|
|
|
+ confirmButtonText = '知道了',
|
|
|
|
|
+ overlay = true
|
|
|
|
|
+ }) {
|
|
|
Dialog.alert({
|
|
Dialog.alert({
|
|
|
title,
|
|
title,
|
|
|
message,
|
|
message,
|
|
@@ -25,6 +32,16 @@ const action = {
|
|
|
messageAlign: 'left'
|
|
messageAlign: 'left'
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ confirm: function(message, title, options = {
|
|
|
|
|
+ className: 'ibps-dialog-desc',
|
|
|
|
|
+ confirmButtonColor: '#3396FB'
|
|
|
|
|
+ }) {
|
|
|
|
|
+ return Dialog.confirm({
|
|
|
|
|
+ title,
|
|
|
|
|
+ message,
|
|
|
|
|
+ ...options
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
msg: function(message, options) {
|
|
msg: function(message, options) {
|
|
|
if (!options) {
|
|
if (!options) {
|
|
|
options = options || {}
|
|
options = options || {}
|
|
@@ -64,28 +81,30 @@ const action = {
|
|
|
* 删除成功提示
|
|
* 删除成功提示
|
|
|
* @param {*} message
|
|
* @param {*} message
|
|
|
*/
|
|
*/
|
|
|
- removeSuccessMessage: function(message = I18n.t('common.dialog.removeSuccess')) {
|
|
|
|
|
|
|
+ removeSuccessMessage: function(
|
|
|
|
|
+ message = I18n.t('common.dialog.removeSuccess')
|
|
|
|
|
+ ) {
|
|
|
this.success(message)
|
|
this.success(message)
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 获取选择行的id
|
|
|
|
|
- * @param {*} rows
|
|
|
|
|
- * @param {*} pkKey
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 获取选择行的id
|
|
|
|
|
+ * @param {*} rows
|
|
|
|
|
+ * @param {*} pkKey
|
|
|
|
|
+ */
|
|
|
getSelectedIds: function(rows, pkKey = 'id') {
|
|
getSelectedIds: function(rows, pkKey = 'id') {
|
|
|
const ids = []
|
|
const ids = []
|
|
|
- rows.forEach(row => {
|
|
|
|
|
|
|
+ rows.forEach((row) => {
|
|
|
ids.push(row[pkKey])
|
|
ids.push(row[pkKey])
|
|
|
})
|
|
})
|
|
|
return ids
|
|
return ids
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 选择记录
|
|
|
|
|
- * 只能选择一个记录
|
|
|
|
|
- * [一般用于编辑、明细等只选择一个记录]
|
|
|
|
|
- *
|
|
|
|
|
- * @param {*} selection
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 选择记录
|
|
|
|
|
+ * 只能选择一个记录
|
|
|
|
|
+ * [一般用于编辑、明细等只选择一个记录]
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {*} selection
|
|
|
|
|
+ */
|
|
|
selectedRecord: function(selection) {
|
|
selectedRecord: function(selection) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
if (Utils.isEmpty(selection)) {
|
|
if (Utils.isEmpty(selection)) {
|
|
@@ -104,13 +123,13 @@ const action = {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 选择多个记录
|
|
|
|
|
- * [一般用于删除等选择多个记录]
|
|
|
|
|
- *
|
|
|
|
|
- * @param {*} selection 选中的值
|
|
|
|
|
- * @param {*} isArray 是否数组格式返回 默认 false
|
|
|
|
|
- * @param {*} separator 分割符 默认 `,`
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 选择多个记录
|
|
|
|
|
+ * [一般用于删除等选择多个记录]
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {*} selection 选中的值
|
|
|
|
|
+ * @param {*} isArray 是否数组格式返回 默认 false
|
|
|
|
|
+ * @param {*} separator 分割符 默认 `,`
|
|
|
|
|
+ */
|
|
|
selectedMultiRecord: function(selection, isArray = false, separator = ',') {
|
|
selectedMultiRecord: function(selection, isArray = false, separator = ',') {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
if (Utils.isEmpty(selection)) {
|
|
if (Utils.isEmpty(selection)) {
|
|
@@ -121,18 +140,24 @@ const action = {
|
|
|
if (!Array.isArray(selection)) {
|
|
if (!Array.isArray(selection)) {
|
|
|
selection = selection.split(separator)
|
|
selection = selection.split(separator)
|
|
|
}
|
|
}
|
|
|
- if (!isArray) { // 不是数组返回
|
|
|
|
|
|
|
+ if (!isArray) {
|
|
|
|
|
+ // 不是数组返回
|
|
|
selection = selection.join(separator)
|
|
selection = selection.join(separator)
|
|
|
}
|
|
}
|
|
|
resolve(selection)
|
|
resolve(selection)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 删除记录
|
|
|
|
|
- * @param {*} rows
|
|
|
|
|
- * @param {*} pkKey
|
|
|
|
|
- */
|
|
|
|
|
- removeRecord: function(selection, confirmMsg = I18n.t('common.dialog.removeRecord'), isArray = false, separator = ',') {
|
|
|
|
|
|
|
+ * 删除记录
|
|
|
|
|
+ * @param {*} rows
|
|
|
|
|
+ * @param {*} pkKey
|
|
|
|
|
+ */
|
|
|
|
|
+ removeRecord: function(
|
|
|
|
|
+ selection,
|
|
|
|
|
+ confirmMsg = I18n.t('common.dialog.removeRecord'),
|
|
|
|
|
+ isArray = false,
|
|
|
|
|
+ separator = ','
|
|
|
|
|
+ ) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
if (Utils.isEmpty(selection)) {
|
|
if (Utils.isEmpty(selection)) {
|
|
|
this.warning(I18n.t('common.dialog.selectedRecords'))
|
|
this.warning(I18n.t('common.dialog.selectedRecords'))
|
|
@@ -142,25 +167,33 @@ const action = {
|
|
|
if (!Array.isArray(selection)) {
|
|
if (!Array.isArray(selection)) {
|
|
|
selection = selection.split(separator)
|
|
selection = selection.split(separator)
|
|
|
}
|
|
}
|
|
|
- if (!isArray) { // 不是数组返回
|
|
|
|
|
|
|
+ if (!isArray) {
|
|
|
|
|
+ // 不是数组返回
|
|
|
selection = selection.join(separator)
|
|
selection = selection.join(separator)
|
|
|
}
|
|
}
|
|
|
Dialog.confirm({
|
|
Dialog.confirm({
|
|
|
title: I18n.t('common.dialog.title'),
|
|
title: I18n.t('common.dialog.title'),
|
|
|
message: confirmMsg
|
|
message: confirmMsg
|
|
|
- }).then(() => {
|
|
|
|
|
- resolve(selection)
|
|
|
|
|
- }).catch((err) => {
|
|
|
|
|
- reject(err)
|
|
|
|
|
})
|
|
})
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ resolve(selection)
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((err) => {
|
|
|
|
|
+ reject(err)
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 保存成功提示
|
|
|
|
|
- */
|
|
|
|
|
- saveSuccessMessage: function(message = I18n.t('common.dialog.operateSuccess'), callback) {
|
|
|
|
|
- message = Utils.isNotEmpty(message) ? message : I18n.t('common.dialog.operateSuccess')
|
|
|
|
|
|
|
+ * 保存成功提示
|
|
|
|
|
+ */
|
|
|
|
|
+ saveSuccessMessage: function(
|
|
|
|
|
+ message = I18n.t('common.dialog.operateSuccess'),
|
|
|
|
|
+ callback
|
|
|
|
|
+ ) {
|
|
|
|
|
+ message = Utils.isNotEmpty(message)
|
|
|
|
|
+ ? message
|
|
|
|
|
+ : I18n.t('common.dialog.operateSuccess')
|
|
|
|
|
|
|
|
// MessageBox.confirm(message,
|
|
// MessageBox.confirm(message,
|
|
|
// I18n.t('common.dialog.title'),
|
|
// I18n.t('common.dialog.title'),
|
|
@@ -177,9 +210,12 @@ const action = {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 保存成功提示
|
|
|
|
|
- */
|
|
|
|
|
- saveSuccessAlert: function(message = I18n.t('common.dialog.operateSuccess'), callback) {
|
|
|
|
|
|
|
+ * 保存成功提示
|
|
|
|
|
+ */
|
|
|
|
|
+ saveSuccessAlert: function(
|
|
|
|
|
+ message = I18n.t('common.dialog.operateSuccess'),
|
|
|
|
|
+ callback
|
|
|
|
|
+ ) {
|
|
|
// MessageBox.alert(message,
|
|
// MessageBox.alert(message,
|
|
|
// I18n.t('common.dialog.title'),
|
|
// I18n.t('common.dialog.title'),
|
|
|
// {
|
|
// {
|
|
@@ -191,11 +227,13 @@ const action = {
|
|
|
// })
|
|
// })
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 保存失败
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 保存失败
|
|
|
|
|
+ */
|
|
|
saveErrorMessage: function(message, callback) {
|
|
saveErrorMessage: function(message, callback) {
|
|
|
this.warning(message || I18n.t('common.dialog.saveError'))
|
|
this.warning(message || I18n.t('common.dialog.saveError'))
|
|
|
- if (callback) { callback() }
|
|
|
|
|
|
|
+ if (callback) {
|
|
|
|
|
+ callback()
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
initListData(vm, options = {}) {
|
|
initListData(vm, options = {}) {
|
|
|
const resultTypeKey = options.resultTypeKey || 'resultType'
|
|
const resultTypeKey = options.resultTypeKey || 'resultType'
|
|
@@ -212,15 +250,15 @@ const action = {
|
|
|
vm[resultKey] = []
|
|
vm[resultKey] = []
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 处理列表数据(不过滤)
|
|
|
|
|
- * @param vm 当前对象
|
|
|
|
|
- * @param data 后台返回的列表数据
|
|
|
|
|
- * @param options 参数
|
|
|
|
|
- * dataResultKey 默认 dataResult
|
|
|
|
|
- * pageResultKey 默认 pageResult
|
|
|
|
|
- * resultKey 结果key 默认 listData
|
|
|
|
|
- * pageKey 分页key 默认 pagination
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 处理列表数据(不过滤)
|
|
|
|
|
+ * @param vm 当前对象
|
|
|
|
|
+ * @param data 后台返回的列表数据
|
|
|
|
|
+ * @param options 参数
|
|
|
|
|
+ * dataResultKey 默认 dataResult
|
|
|
|
|
+ * pageResultKey 默认 pageResult
|
|
|
|
|
+ * resultKey 结果key 默认 listData
|
|
|
|
|
+ * pageKey 分页key 默认 pagination
|
|
|
|
|
+ */
|
|
|
handleListData: function(vm, data, options = {}) {
|
|
handleListData: function(vm, data, options = {}) {
|
|
|
const loadingKey = options.loadingKey || 'loading'
|
|
const loadingKey = options.loadingKey || 'loading'
|
|
|
const refreshingKey = options.refreshingKey || 'refreshing'
|
|
const refreshingKey = options.refreshingKey || 'refreshing'
|
|
@@ -251,20 +289,26 @@ const action = {
|
|
|
vm[paginationKey] = pagination
|
|
vm[paginationKey] = pagination
|
|
|
// 处理结果类型
|
|
// 处理结果类型
|
|
|
vm[resultTypeKey] = this.handleResultType(vm, options)
|
|
vm[resultTypeKey] = this.handleResultType(vm, options)
|
|
|
- console.log('vm[resultTypeKey]===>', vm[dataResultKey], vm[pageResultKey], vm[resultKey])
|
|
|
|
|
vm[resultMessageKey] = null
|
|
vm[resultMessageKey] = null
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 处理列表数据(带过滤)
|
|
|
|
|
- * @param vm 当前对象
|
|
|
|
|
- * @param data 后台返回的列表数据
|
|
|
|
|
- * @param options 参数
|
|
|
|
|
- * dataResultKey 默认 dataResult
|
|
|
|
|
- * pageResultKey 默认 pageResult
|
|
|
|
|
- * resultKey 结果key 默认 listData
|
|
|
|
|
- * pageKey 分页key 默认 pagination
|
|
|
|
|
- */
|
|
|
|
|
- existHandleListData: function(vm, data, filtration, itemid, tid, options = {}) {
|
|
|
|
|
|
|
+ * 处理列表数据(带过滤)
|
|
|
|
|
+ * @param vm 当前对象
|
|
|
|
|
+ * @param data 后台返回的列表数据
|
|
|
|
|
+ * @param options 参数
|
|
|
|
|
+ * dataResultKey 默认 dataResult
|
|
|
|
|
+ * pageResultKey 默认 pageResult
|
|
|
|
|
+ * resultKey 结果key 默认 listData
|
|
|
|
|
+ * pageKey 分页key 默认 pagination
|
|
|
|
|
+ */
|
|
|
|
|
+ existHandleListData: function(
|
|
|
|
|
+ vm,
|
|
|
|
|
+ data,
|
|
|
|
|
+ filtration,
|
|
|
|
|
+ itemid,
|
|
|
|
|
+ tid,
|
|
|
|
|
+ options = {}
|
|
|
|
|
+ ) {
|
|
|
const loadingKey = options.loadingKey || 'loading'
|
|
const loadingKey = options.loadingKey || 'loading'
|
|
|
const refreshingKey = options.refreshingKey || 'refreshing'
|
|
const refreshingKey = options.refreshingKey || 'refreshing'
|
|
|
const finishedKey = options.finishedKey || 'finished'
|
|
const finishedKey = options.finishedKey || 'finished'
|
|
@@ -286,7 +330,7 @@ const action = {
|
|
|
if (Utils.isNotEmpty(listData)) {
|
|
if (Utils.isNotEmpty(listData)) {
|
|
|
const mid = []
|
|
const mid = []
|
|
|
listData.forEach((item, i) => {
|
|
listData.forEach((item, i) => {
|
|
|
- const obj = filtration.findIndex(t => t[tid] === item[itemid])
|
|
|
|
|
|
|
+ const obj = filtration.findIndex((t) => t[tid] === item[itemid])
|
|
|
if (obj != -1) {
|
|
if (obj != -1) {
|
|
|
mid.push(item)
|
|
mid.push(item)
|
|
|
}
|
|
}
|
|
@@ -377,16 +421,20 @@ const action = {
|
|
|
vm[resultMessageKey] = e.message
|
|
vm[resultMessageKey] = e.message
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 设置分页设置
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 设置分页设置
|
|
|
|
|
+ */
|
|
|
setPagination: function(pagination, defaultPagination) {
|
|
setPagination: function(pagination, defaultPagination) {
|
|
|
- pagination.page = defaultPagination ? defaultPagination.page || common.PAGE : common.PAGE
|
|
|
|
|
- pagination.limit = defaultPagination ? defaultPagination.limit || common.LIMIT : common.LIMIT
|
|
|
|
|
|
|
+ pagination.page = defaultPagination
|
|
|
|
|
+ ? defaultPagination.page || common.PAGE
|
|
|
|
|
+ : common.PAGE
|
|
|
|
|
+ pagination.limit = defaultPagination
|
|
|
|
|
+ ? defaultPagination.limit || common.LIMIT
|
|
|
|
|
+ : common.LIMIT
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 设置排序
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 设置排序
|
|
|
|
|
+ */
|
|
|
setSorts: function(sorts, sort, defaultSorts = {}) {
|
|
setSorts: function(sorts, sort, defaultSorts = {}) {
|
|
|
const defaultSortsData = function() {
|
|
const defaultSortsData = function() {
|
|
|
for (const key in defaultSorts) {
|
|
for (const key in defaultSorts) {
|
|
@@ -410,35 +458,39 @@ const action = {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 格式分页数据
|
|
|
|
|
- * @param {} params 查询的参数
|
|
|
|
|
- * @param {} page 分页
|
|
|
|
|
- * @param {} sorts 排序
|
|
|
|
|
- */
|
|
|
|
|
- formatParams: function(params, page, sorts) {
|
|
|
|
|
|
|
+ * 格式分页数据
|
|
|
|
|
+ * @param {} params 查询的参数
|
|
|
|
|
+ * @param {} page 分页
|
|
|
|
|
+ * @param {} sorts 排序
|
|
|
|
|
+ */
|
|
|
|
|
+ formatParams: function(params, pagination, sorts) {
|
|
|
const results = {}
|
|
const results = {}
|
|
|
if (params) {
|
|
if (params) {
|
|
|
results.parameters = Object.keys(params).map((k) => {
|
|
results.parameters = Object.keys(params).map((k) => {
|
|
|
- return k === 'arg' ? params[k] : {
|
|
|
|
|
- 'key': k,
|
|
|
|
|
- 'value': params[k]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return k === 'arg'
|
|
|
|
|
+ ? params[k]
|
|
|
|
|
+ : {
|
|
|
|
|
+ key: k,
|
|
|
|
|
+ value: params[k] || ''
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- if (page) {
|
|
|
|
|
- results.requestPage = {
|
|
|
|
|
- 'pageNo': page.page || common.PAGE,
|
|
|
|
|
- 'limit': page.limit || common.LIMIT
|
|
|
|
|
|
|
+ if (pagination) {
|
|
|
|
|
+ const requestPage = {
|
|
|
|
|
+ pageNo: pagination.page || common.PAGE,
|
|
|
|
|
+ limit: pagination.limit || common.LIMIT
|
|
|
}
|
|
}
|
|
|
- if (Utils.isNotEmpty(page.totalCount)) { // mock 数据时候要传
|
|
|
|
|
- results.requestPage['totalCount'] = page.totalCount
|
|
|
|
|
|
|
+ if (Utils.isNotEmpty(pagination.totalCount)) {
|
|
|
|
|
+ // mock 数据时候要传
|
|
|
|
|
+ requestPage['totalCount'] = pagination.totalCount
|
|
|
}
|
|
}
|
|
|
|
|
+ results.requestPage = requestPage
|
|
|
}
|
|
}
|
|
|
if (sorts) {
|
|
if (sorts) {
|
|
|
results.sorts = Object.keys(sorts).map((k) => {
|
|
results.sorts = Object.keys(sorts).map((k) => {
|
|
|
return {
|
|
return {
|
|
|
- 'field': k,
|
|
|
|
|
- 'order': sorts[k]
|
|
|
|
|
|
|
+ field: k,
|
|
|
|
|
+ order: sorts[k]
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -446,11 +498,17 @@ const action = {
|
|
|
return results
|
|
return results
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
- * 下载
|
|
|
|
|
- */
|
|
|
|
|
- download: function(data, fileName, responseType = 'application/octet-stream') {
|
|
|
|
|
- const blob = data instanceof Blob ? data : new Blob([data], { type: responseType })
|
|
|
|
|
- if ('download' in document.createElement('a')) { // 非IE下载
|
|
|
|
|
|
|
+ * 下载
|
|
|
|
|
+ */
|
|
|
|
|
+ download: function(
|
|
|
|
|
+ data,
|
|
|
|
|
+ fileName,
|
|
|
|
|
+ responseType = 'application/octet-stream'
|
|
|
|
|
+ ) {
|
|
|
|
|
+ const blob =
|
|
|
|
|
+ data instanceof Blob ? data : new Blob([data], { type: responseType })
|
|
|
|
|
+ if ('download' in document.createElement('a')) {
|
|
|
|
|
+ // 非IE下载
|
|
|
const url = window.URL.createObjectURL(blob)
|
|
const url = window.URL.createObjectURL(blob)
|
|
|
const link = document.createElement('a')
|
|
const link = document.createElement('a')
|
|
|
link.style.display = 'none'
|
|
link.style.display = 'none'
|
|
@@ -460,18 +518,22 @@ const action = {
|
|
|
link.click()
|
|
link.click()
|
|
|
window.URL.revokeObjectURL(link.href)
|
|
window.URL.revokeObjectURL(link.href)
|
|
|
document.body.removeChild(link)
|
|
document.body.removeChild(link)
|
|
|
- } else { // IE10+下载
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // IE10+下载
|
|
|
navigator.msSaveBlob(blob, fileName)
|
|
navigator.msSaveBlob(blob, fileName)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 导出文件
|
|
|
|
|
- */
|
|
|
|
|
- exportFile: function(data, fileName, responseType = 'application/octet-stream') {
|
|
|
|
|
|
|
+ * 导出文件
|
|
|
|
|
+ */
|
|
|
|
|
+ exportFile: function(
|
|
|
|
|
+ data,
|
|
|
|
|
+ fileName,
|
|
|
|
|
+ responseType = 'application/octet-stream'
|
|
|
|
|
+ ) {
|
|
|
this.download(data, fileName, responseType)
|
|
this.download(data, fileName, responseType)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default action
|
|
export default action
|