This commit is contained in:
fengchenchen
2023-08-14 17:10:11 +08:00
commit 37f6ec895d
1145 changed files with 437754 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
*
*/
import { disabledAuthFilter } from '@/utils/authFilter'
export const DisabledAuthFilterMixin = {
props: ['formData'],
data () {
return {
}
},
methods: {
isDisabledAuth (code) {
return disabledAuthFilter(code, this.formData)
}
}
}
+189
View File
@@ -0,0 +1,189 @@
import JEditableTable from '@/components/jero/JEditableTable'
import { VALIDATE_NO_PASSED, getRefPromise, validateFormAndTables } from '@/utils/JEditableTableUtil'
import { httpAction, getAction } from '@/api/manage'
export const JEditableTableMixin = {
components: {
JEditableTable
},
data () {
return {
title: '操作',
visible: false,
form: this.$form.createForm(this),
confirmLoading: false,
model: {},
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 18 }
},
addDefaultRowNum: null // 这个变量应该是一个数字,但是为了保留原本代码中的提示逻辑,定义为null
}
},
methods: {
/** 获取所有的editableTable实例 */
getAllTable () {
if (!(this.refKeys instanceof Array)) {
throw this.throwNotArray('refKeys')
}
const values = this.refKeys.map(key => getRefPromise(this, key))
return Promise.all(values)
},
/** 遍历所有的JEditableTable实例 */
eachAllTable (callback) {
// 开始遍历
this.getAllTable().then(tables => {
tables.forEach((item, index) => {
if (typeof callback === 'function') {
callback(item, index)
}
})
})
},
/** 当点击新增按钮时调用此方法 */
add () {
// update-begin-author:lvdandan date:20201113 for:LOWCOD-1049 JEditaTable,子表默认添加一条数据,addDefaultRowNum设置无效 #1930
return new Promise((resolve) => {
this.tableReset()
resolve()
}).then(() => {
if (typeof this.addBefore === 'function') {
this.addBefore()
}
// 默认新增空数据
let rowNum = this.addDefaultRowNum
if (typeof rowNum !== 'number') {
rowNum = 1
console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字,所以默认添加一条空数据,如果不想默认添加空数据,请将定义 addDefaultRowNum 为 0')
}
this.eachAllTable((item) => {
item.add(rowNum)
})
if (typeof this.addAfter === 'function') this.addAfter(this.model)
this.edit({})
})
// update-end-author:lvdandan date:20201113 for:LOWCOD-1049 JEditaTable,子表默认添加一条数据,addDefaultRowNum设置无效 #1930
},
/** 当点击了编辑(修改)按钮时调用此方法 */
edit (record) {
if (record && JSON.stringify(record) !== '{}') {
this.tableReset()
}
if (typeof this.editBefore === 'function') this.editBefore(record)
this.visible = true
this.activeKey = this.refKeys[0]
this.form.resetFields()
this.model = Object.assign({}, record)
if (typeof this.editAfter === 'function') this.editAfter(this.model)
},
/** 关闭弹窗,并将所有JEditableTable实例回归到初始状态 */
close () {
this.visible = false
this.$emit('close')
},
// 清空子表table的数据
tableReset () {
this.eachAllTable((item) => {
item.clearRow()
})
},
/** 查询某个tab的数据 */
requestSubTableData (url, params, tab, success) {
tab.loading = true
getAction(url, params).then(res => {
const { result } = res
let dataSource = []
if (result) {
if (Array.isArray(result)) {
dataSource = result
} else if (Array.isArray(result.records)) {
dataSource = result.records
}
}
tab.dataSource = dataSource
if (typeof success === 'function') {
success(res)
}
}).finally(() => {
tab.loading = false
})
},
/** 发起请求,自动判断是执行新增还是修改操作 */
request (formData) {
let url = this.url.add
const method = 'post'
if (this.model.id) {
url = this.url.edit
// method = 'put'
}
this.confirmLoading = true
httpAction(url, formData, method).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
/* --- handle 事件 --- */
/** ATab 选项卡切换事件 */
handleChangeTabs (key) {
// 自动重置scrollTop状态,防止出现白屏
getRefPromise(this, key).then(editableTable => {
editableTable.resetScrollTop()
})
},
/** 关闭按钮点击事件 */
handleCancel () {
this.close()
},
/** 确定按钮点击事件 */
handleOk () {
/** 触发表单验证 */
this.getAllTable().then(tables => {
/** 一次性验证主表和所有的次表 */
return validateFormAndTables(this.form, tables)
}).then(allValues => {
if (typeof this.classifyIntoFormData !== 'function') {
throw this.throwNotFunction('classifyIntoFormData')
}
const formData = this.classifyIntoFormData(allValues)
// 发起请求
return this.request(formData)
}).catch(e => {
if (e.error === VALIDATE_NO_PASSED) {
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
} else {
console.error(e)
}
})
},
/* --- throw --- */
/** not a function */
throwNotFunction (name) {
return `${name} 未定义或不是一个函数`
},
/** not a array */
throwNotArray (name) {
return `${name} 未定义或不是一个数组`
}
}
}
+198
View File
@@ -0,0 +1,198 @@
import JEditableTable from '@/components/jero/JEditableTable'
import { VALIDATE_NO_PASSED, getRefPromise, validateFormModelAndTables } from '@/utils/JEditableTableUtil'
import { httpAction, getAction } from '@/api/manage'
export const JEditableTableModelMixin = {
components: {
JEditableTable
},
data () {
return {
title: '操作',
visible: false,
confirmLoading: false,
model: {},
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 18 }
},
addDefaultRowNum: null, // 这个变量应该是一个数字,但是为了保留原本代码中的提示逻辑,定义为null
refKeys: null
}
},
methods: {
/** 获取所有的editableTable实例 */
getAllTable () {
if (!(this.refKeys instanceof Array)) {
throw this.throwNotArray('refKeys')
}
const values = this.refKeys.map(key => getRefPromise(this, key))
return Promise.all(values)
},
/** 遍历所有的JEditableTable实例 */
eachAllTable (callback) {
// 开始遍历
this.getAllTable().then(tables => {
tables.forEach((item, index) => {
if (typeof callback === 'function') {
callback(item, index)
}
})
})
},
/** 当点击新增按钮时调用此方法 */
add () {
// update-begin-author:lvdandan date:20201113 for:LOWCOD-1049 JEditaTable,子表默认添加一条数据,addDefaultRowNum设置无效 #1930
return new Promise((resolve) => {
this.tableReset()
resolve()
}).then(() => {
if (typeof this.addBefore === 'function') {
this.addBefore()
}
// 默认新增空数据
let rowNum = this.addDefaultRowNum
if (typeof rowNum !== 'number') {
rowNum = 1
console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字,所以默认添加一条空数据,如果不想默认添加空数据,请将定义 addDefaultRowNum 为 0')
}
this.eachAllTable((item) => {
item.add(rowNum)
})
if (typeof this.addAfter === 'function') this.addAfter(this.model)
this.edit(this.model)
})
// update-end-author:lvdandan date:20201113 for:LOWCOD-1049 JEditaTable,子表默认添加一条数据,addDefaultRowNum设置无效 #1930
},
/** 当点击了编辑(修改)按钮时调用此方法 */
edit (record) {
if (record && JSON.stringify(record) !== '{}' && record.id) {
this.tableReset()
}
if (typeof this.editBefore === 'function') this.editBefore(record)
this.visible = true
this.activeKey = this.refKeys[0]
this.$refs.form.resetFields()
this.model = Object.assign({}, record)
if (typeof this.editAfter === 'function') this.editAfter(this.model)
},
/** 关闭弹窗,并将所有JEditableTable实例回归到初始状态 */
close () {
this.visible = false
this.$emit('close')
},
// 清空子表table的数据
tableReset () {
this.eachAllTable((item) => {
item.clearRow()
})
},
/** 查询某个tab的数据 */
requestSubTableData (url, params, tab, success) {
tab.loading = true
getAction(url, params).then(res => {
const { result } = res
let dataSource = []
if (result) {
if (Array.isArray(result)) {
dataSource = result
} else if (Array.isArray(result.records)) {
dataSource = result.records
}
}
tab.dataSource = dataSource
if (typeof success === 'function') {
success(res)
}
}).finally(() => {
tab.loading = false
})
},
/** 发起请求,自动判断是执行新增还是修改操作 */
request (formData) {
let url = this.url.add
const method = 'post'
if (this.model.id) {
url = this.url.edit
// method = 'put'
}
this.confirmLoading = true
httpAction(url, formData, method).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
/* --- handle 事件 --- */
/** ATab 选项卡切换事件 */
handleChangeTabs (key) {
// 自动重置scrollTop状态,防止出现白屏
getRefPromise(this, key).then(editableTable => {
editableTable.resetScrollTop()
})
},
/** 关闭按钮点击事件 */
handleCancel () {
this.close()
},
/** 确定按钮点击事件 */
handleOk () {
/** 触发表单验证 */
this.getAllTable().then(tables => {
/** 一次性验证主表和所有的次表 */
return validateFormModelAndTables(this.$refs.form, this.model, tables)
}).then(allValues => {
/** 一次性验证一对一的所有子表 */
return this.validateSubForm(allValues)
}).then(allValues => {
if (typeof this.classifyIntoFormData !== 'function') {
throw this.throwNotFunction('classifyIntoFormData')
}
const formData = this.classifyIntoFormData(allValues)
// 发起请求
return this.request(formData)
}).catch(e => {
if (e.error === VALIDATE_NO_PASSED) {
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
// update--begin--autor:liusq-----date:20210316------for:未通过表单验证跳转tab问题------
this.activeKey = e.index == null ? this.activeKey : (e.paneKey ? e.paneKey : this.refKeys[e.index])
// update--end--autor:liusq-----date:20210316------for:未通过表单验证跳转tab问题------
} else {
console.error(e)
}
})
},
// 校验所有子表表单
validateSubForm (allValues) {
return new Promise((resolve) => {
resolve(allValues)
})
},
/* --- throw --- */
/** not a function */
throwNotFunction (name) {
return `${name} 未定义或不是一个函数`
},
/** not a array */
throwNotArray (name) {
return `${name} 未定义或不是一个数组`
}
}
}
+178
View File
@@ -0,0 +1,178 @@
import { getRefPromise, validateFormAndTables } from '@/components/jero/JVxeTable/utils/vxeUtils.js'
import { httpAction, getAction } from '@/api/manage'
const VALIDATE_NO_PASSED = ''
export const JVxeTableMixin = {
data () {
return {
title: '操作',
visible: false,
form: this.$form.createForm(this),
confirmLoading: false,
scrolling: true,
model: {},
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 18 }
},
refKeys: null,
addDefaultRowNum: null // 这个变量应该是一个数字,但是为了保留原本代码中的提示逻辑,定义为null
}
},
methods: {
/** 获取所有的JVxeTable实例 */
getAllTable () {
if (!(this.refKeys instanceof Array)) {
throw this.throwNotArray('refKeys')
}
const values = this.refKeys.map(key => getRefPromise(this, key))
return Promise.all(values)
},
/** 遍历所有的JVxeTable实例 */
eachAllTable (callback) {
// 开始遍历
this.getAllTable().then(tables => {
tables.forEach((item, index) => {
if (typeof callback === 'function') {
callback(item, index)
}
})
})
},
/** 当点击新增按钮时调用此方法 */
add () {
if (typeof this.addBefore === 'function') this.addBefore()
// 默认新增空数据
let rowNum = this.addDefaultRowNum
if (typeof rowNum !== 'number') {
rowNum = 1
console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字,所以默认添加一条空数据,如果不想默认添加空数据,请将定义 addDefaultRowNum 为 0')
}
this.eachAllTable((item) => {
setTimeout(() => {
item.addRows()
}, 30)
})
if (typeof this.addAfter === 'function') this.addAfter(this.model)
this.edit({})
},
/** 当点击了编辑(修改)按钮时调用此方法 */
edit (record) {
if (typeof this.editBefore === 'function') this.editBefore(record)
this.visible = true
this.activeKey = this.refKeys[0]
this.form.resetFields()
this.model = Object.assign({}, record)
if (typeof this.editAfter === 'function') this.editAfter(this.model)
},
/** 关闭弹窗,并将所有JVxeTable实例回归到初始状态 */
close () {
this.visible = false
this.eachAllTable((item) => {
item._remove()
})
this.$emit('close')
},
/** 查询某个tab的数据 */
requestSubTableData (url, params, tab, success) {
tab.loading = true
getAction(url, params).then(res => {
const { result } = res
let dataSource = []
if (result) {
if (Array.isArray(result)) {
dataSource = result
} else if (Array.isArray(result.records)) {
dataSource = result.records
}
}
tab.dataSource = dataSource
if (typeof success === 'function') {
success(res)
}
}).finally(() => {
tab.loading = false
})
},
/** 发起请求,自动判断是执行新增还是修改操作 */
request (formData) {
let url = this.url.add
const method = 'post'
if (this.model.id) {
url = this.url.edit
// method = 'put'
}
this.confirmLoading = true
console.log('formData===>', formData)
httpAction(url, formData, method).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
/* --- handle 事件 --- */
/** ATab 选项卡切换事件 */
handleChangeTabs (key) {
// 自动重置scrollTop状态,防止出现白屏
getRefPromise(this, key).then(vxeTable => {
vxeTable.resetScrollTop()
})
},
/** 关闭按钮点击事件 */
handleCancel () {
this.close()
},
/** 确定按钮点击事件 */
handleOk () {
/** 触发表单验证 */
this.getAllTable().then(tables => {
/** 一次性验证主表和所有的次表 */
return validateFormAndTables(this.form, tables)
}).then(allValues => {
if (typeof this.classifyIntoFormData !== 'function') {
throw this.throwNotFunction('classifyIntoFormData')
}
const formData = this.classifyIntoFormData(allValues)
// 发起请求
return this.request(formData)
}).catch(e => {
if (e.error === VALIDATE_NO_PASSED) {
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
} else {
console.error(e)
}
})
},
/* --- throw --- */
/** not a function */
throwNotFunction (name) {
return `${name} 未定义或不是一个函数`
},
/** not a array */
throwNotArray (name) {
return `${name} 未定义或不是一个数组`
}
}
}
+186
View File
@@ -0,0 +1,186 @@
import { VALIDATE_FAILED, getRefPromise, validateFormModelAndTables } from '@/components/jero/JVxeTable/utils/vxeUtils.js'
import { httpAction, getAction } from '@/api/manage'
export const JVxeTableModelMixin = {
data () {
return {
title: '操作',
visible: false,
confirmLoading: false,
scrolling: true,
model: {},
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 18 }
},
refKeys: null,
addDefaultRowNum: null // 这个变量应该是一个数字,但是为了保留原本代码中的提示逻辑,定义为null
}
},
methods: {
/** 获取所有的JVxeTable实例 */
getAllTable () {
if (!(this.refKeys instanceof Array)) {
throw this.throwNotArray('refKeys')
}
const values = this.refKeys.map(key => getRefPromise(this, key))
return Promise.all(values)
},
/** 遍历所有的JVxeTable实例 */
eachAllTable (callback) {
// 开始遍历
this.getAllTable().then(tables => {
console.log('tables', tables)
tables.forEach((item, index) => {
if (typeof callback === 'function') {
callback(item, index)
}
})
})
},
/** 当点击新增按钮时调用此方法 */
add () {
if (typeof this.addBefore === 'function') this.addBefore()
// 默认新增空数据
let rowNum = this.addDefaultRowNum
if (typeof rowNum !== 'number') {
rowNum = 1
console.warn('由于你没有在 data 中定义 addDefaultRowNum 或 addDefaultRowNum 不是数字,所以默认添加一条空数据,如果不想默认添加空数据,请将定义 addDefaultRowNum 为 0')
}
this.eachAllTable((item) => {
// update-begin-author:taoyan date:20210315 for: 一对多jvex 默认几行不好使了 LOWCOD-1349
setTimeout(() => {
item.addRows()
}, 30)
// update-end-author:taoyan date:20210315 for: 一对多jvex 默认几行不好使了 LOWCOD-1349
})
if (typeof this.addAfter === 'function') this.addAfter(this.model)
this.edit(this.model)
},
/** 当点击了编辑(修改)按钮时调用此方法 */
edit (record) {
if (typeof this.editBefore === 'function') this.editBefore(record)
this.visible = true
this.activeKey = this.refKeys[0]
this.$refs.form.resetFields()
this.model = Object.assign({}, record)
if (typeof this.editAfter === 'function') this.editAfter(this.model)
},
/** 关闭弹窗,并将所有JVxeTable实例回归到初始状态 */
close () {
this.visible = false
this.eachAllTable((item) => {
item._remove()
})
this.$emit('close')
},
/** 查询某个tab的数据 */
requestSubTableData (url, params, tab, success) {
tab.loading = true
getAction(url, params).then(res => {
const { result } = res
let dataSource = []
if (result) {
if (Array.isArray(result)) {
dataSource = result
} else if (Array.isArray(result.records)) {
dataSource = result.records
}
}
tab.dataSource = dataSource
if (typeof success === 'function') {
success(res)
}
}).finally(() => {
tab.loading = false
})
},
/** 发起请求,自动判断是执行新增还是修改操作 */
request (formData) {
let url = this.url.add
const method = 'post'
if (this.model.id) {
url = this.url.edit
// method = 'put'
}
this.confirmLoading = true
console.log('formData===>', formData)
httpAction(url, formData, method).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
/* --- handle 事件 --- */
/** ATab 选项卡切换事件 */
handleChangeTabs (key) {
// 自动重置scrollTop状态,防止出现白屏
getRefPromise(this, key).then(vxeTable => {
vxeTable.resetScrollTop()
})
},
/** 关闭按钮点击事件 */
handleCancel () {
this.close()
},
/** 确定按钮点击事件 */
handleOk () {
/** 触发表单验证 */
this.getAllTable().then(tables => {
/** 一次性验证主表和所有的次表 */
return validateFormModelAndTables(this.$refs.form, this.model, tables)
}).then(allValues => {
/** 一次性验证一对一的所有子表 */
return this.validateSubForm(allValues)
}).then(allValues => {
if (typeof this.classifyIntoFormData !== 'function') {
throw this.throwNotFunction('classifyIntoFormData')
}
const formData = this.classifyIntoFormData(allValues)
// 发起请求
return this.request(formData)
}).catch(e => {
if (e.error === VALIDATE_FAILED) {
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
} else {
console.error(e)
}
})
},
// 校验所有子表表单
validateSubForm (allValues) {
return new Promise((resolve) => {
resolve(allValues)
})
},
/* --- throw --- */
/** not a function */
throwNotFunction (name) {
return `${name} 未定义或不是一个函数`
},
/** not a array */
throwNotArray (name) {
return `${name} 未定义或不是一个数组`
}
}
}
+407
View File
@@ -0,0 +1,407 @@
/**
* 新增修改完成调用 modalFormOk方法 编辑弹框组件ref定义为modalForm
* 高级查询按钮调用 superQuery方法 高级查询组件ref定义为superQueryModal
* data中url定义 list为查询列表 delete为删除单条记录 deleteBatch为批量删除
*/
import { filterObj } from '@/utils/util'
import { downFile, getAction, getFileAccessHttpUrl, postAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
import store from '@/store'
// 导入的加载提示
let importModalLoading
export const JeroListMixin = {
data () {
return {
/* 查询条件-请不要在queryParam中声明非字符串值的属性 */
queryParam: {},
/* 数据源 */
dataSource: [],
/* 分页参数 */
ipagination: {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '20', '30'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' 共' + total + '条'
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
/* 排序参数 */
isorter: {
column: 'createTime',
order: 'desc'
},
/* 筛选参数 */
filters: {},
/* table加载状态 */
loading: false,
/* table选中keys */
selectedRowKeys: [],
/* table选中records */
selectionRows: [],
/* 查询折叠 */
toggleSearchStatus: false,
/* 高级查询条件生效状态 */
superQueryFlag: false,
/* 高级查询条件 */
superQueryParams: '',
/** 高级查询拼接方式 */
superQueryMatchType: 'and'
}
},
created () {
if (!this.disableMixinCreated) {
this.loadData()
// 初始化字典配置 在自己页面定义
this.initDictConfig()
}
},
computed: {
// token header
tokenHeader () {
const head = { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) }
const tenantid = Vue.ls.get(TENANT_ID)
if (tenantid) {
head['tenant-id'] = tenantid
}
return head
}
},
methods: {
loadData (arg) {
if (!this.url.list) {
this.$message.error('请设置url.list属性!')
return
}
// 加载数据 若传入参数1则加载第一页的内容
if (arg === 1) {
this.ipagination.current = 1
}
const params = this.getQueryParams()// 查询条件
this.loading = true
getAction(this.url.list, params).then((res) => {
if (res.success) {
// update-begin---author:zhangyafei Date:20201118 for:适配不分页的数据列表------------
this.dataSource = res.result.records || res.result
if (res.result.total) {
this.ipagination.total = res.result.total
} else {
this.ipagination.total = 0
}
// update-end---author:zhangyafei Date:20201118 for:适配不分页的数据列表------------
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.loading = false
})
},
initDictConfig () {
},
handleSuperQuery (params, matchType) {
// 高级查询方法
if (!params) {
this.superQueryParams = ''
this.superQueryFlag = false
} else {
this.superQueryFlag = true
this.superQueryParams = JSON.stringify(params)
this.superQueryMatchType = matchType
}
this.loadData(1)
},
getQueryParams () {
// 获取查询条件
const sqp = {}
if (this.superQueryParams) {
sqp.superQueryParams = encodeURI(this.superQueryParams)
sqp.superQueryMatchType = this.superQueryMatchType
}
const param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)
param.field = this.getQueryField()
param.pageNo = this.ipagination.current
param.pageSize = this.ipagination.pageSize
return filterObj(param)
},
getQueryField () {
// TODO 字段权限控制
let str = 'id,'
this.columns.forEach(function (value) {
str += ',' + value.dataIndex
})
return str
},
onSelectChange (selectedRowKeys, selectionRows) {
this.selectedRowKeys = selectedRowKeys
this.selectionRows = selectionRows
},
onClearSelected () {
this.selectedRowKeys = []
this.selectionRows = []
},
searchQuery () {
this.loadData(1)
// 点击查询清空列表选中行
this.selectedRowKeys = []
this.selectionRows = []
},
superQuery () {
this.$refs.superQueryModal.show()
},
searchReset () {
this.queryParam = {}
this.loadData(1)
},
batchDel: function () {
if (!this.url.deleteBatch) {
this.$message.error('请设置url.deleteBatch属性!')
return
}
if (this.selectedRowKeys.length <= 0) {
this.$message.warning('请选择一条记录!')
} else {
let ids = ''
for (let a = 0; a < this.selectedRowKeys.length; a++) {
ids += this.selectedRowKeys[a] + ','
}
const that = this
this.$confirm({
title: '确认删除',
content: '是否删除选中数据?',
onOk: function () {
that.loading = true
postAction(that.url.deleteBatch, { ids: ids }).then((res) => {
if (res.success) {
// 重新计算分页问题
that.reCalculatePage(that.selectedRowKeys.length)
that.$message.success(res.message)
that.loadData()
that.onClearSelected()
} else {
that.$message.warning(res.message)
}
}).finally(() => {
that.loading = false
})
}
})
}
},
handleDelete: function (id) {
if (!this.url.delete) {
this.$message.error('请设置url.delete属性!')
return
}
const that = this
this.$confirm({
title: '确认删除',
content: '确定要删除此条数据吗?',
onOk: function () {
postAction(that.url.delete, { id: id }).then((res) => {
if (res.success) {
that.$message.success(res.message)
// 判断当前删除的数据是否是最后一页的最后一条数据,如果是的话页码减一
if (that.ipagination.current > 1 && ((that.ipagination.current - 1) * that.ipagination.pageSize) + 1 === that.ipagination.total) {
that.ipagination.current -= 1
}
that.loadData()
} else {
that.$message.warning(res.message)
}
})
}
})
},
reCalculatePage (count) {
// 总数量-count
const total = this.ipagination.total - count
// 获取删除后的分页数
const currentIndex = Math.ceil(total / this.ipagination.pageSize)
// 删除后的分页数<所在当前页
if (currentIndex < this.ipagination.current) {
this.ipagination.current = currentIndex
}
console.log('currentIndex', currentIndex)
},
handleEdit: function (record) {
this.$refs.modalForm.edit(record)
this.$refs.modalForm.title = this.$t('edit')
this.$refs.modalForm.disableSubmit = false
},
handleAdd: function () {
this.$refs.modalForm.add()
this.$refs.modalForm.title = this.$t('newlyAdded')
this.$refs.modalForm.disableSubmit = false
},
handleTableChange (pagination, filters, sorter) {
// 分页、排序、筛选变化时触发
if (Object.keys(sorter).length > 0) {
this.isorter.column = sorter.field
this.isorter.order = sorter.order === 'ascend' ? 'asc' : 'desc'
}
this.ipagination = pagination
this.loadData()
},
handleToggleSearch () {
this.toggleSearchStatus = !this.toggleSearchStatus
},
// 给popup查询使用(查询区域不支持回填多个字段,限制只返回一个字段)
getPopupField (fields) {
return fields.split(',')[0]
},
modalFormOk () {
// 新增/修改 成功时,重载列表
this.loadData()
// 清空列表选中
this.onClearSelected()
},
handleDetail: function (record) {
this.$refs.modalForm.edit(record)
this.$refs.modalForm.title = '详情'
this.$refs.modalForm.disableSubmit = true
},
/* 导出 */
handleExportXls2 () {
const paramsStr = encodeURI(JSON.stringify(this.getQueryParams()))
window.location.href = `${window._CONFIG.domianURL}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`
},
handleExportXls (fileName) {
if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件'
}
const param = this.getQueryParams()
if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
param.selections = this.selectedRowKeys.join(',')
}
console.log('导出参数', param)
// 加一个大的提示
const modalLoading = this.$info({
title: '提示',
content: <span>正在导出,请稍候 <a-spin size="small"/></span>,
keyboard: false
})
// 把知道了这个按钮去掉
this.$nextTick(() => {
document.getElementsByClassName('ant-modal-confirm-btns')[0].style = 'display:none'
})
downFile(this.url.exportXlsUrl, param).then((data) => {
if (!data) {
this.$message.warning('文件下载失败')
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
} else {
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName + '.xls')
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url) // 释放掉blob对象
}
}).finally(() => {
// 销毁这个提示
modalLoading.destroy()
})
},
/* 导入 */
handleImportExcel (info) {
// 加一个大的提示
if (!this.loading) {
importModalLoading = this.$info({
title: '提示',
content: <span>正在导入,请稍候 <a-spin size="small"/></span>,
keyboard: false
})
}
this.loading = true
// 把知道了这个按钮去掉
this.$nextTick(() => {
document.getElementsByClassName('ant-modal-confirm-btns')[0].style = 'display:none'
})
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList)
}
if (info.file.status === 'done') {
// 销毁这个提示
importModalLoading && importModalLoading.destroy()
this.loading = false
if (info.file.response.success) {
// this.$message.success(`${info.file.name} 文件上传成功`);
if (info.file.response.code === 201) {
const { message, result: { msg, fileUrl, fileName } } = info.file.response
const href = window._CONFIG.domianURL + fileUrl
this.$warning({
title: message,
content: (<div>
<span>{msg}</span><br/>
<span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
</div>
)
})
} else {
this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
}
this.loadData()
} else {
this.$message.error(`${info.file.name} ${info.file.response.message}.`)
}
} else if (info.file.status === 'error') {
// 销毁这个提示
importModalLoading && importModalLoading.destroy()
this.loading = false
if (info.file.response.status === 500) {
const data = info.file.response
const token = Vue.ls.get(ACCESS_TOKEN)
if (token && data.message.includes('Token失效')) {
this.error({
title: '登录已过期',
content: '很抱歉,登录已过期,请重新登录',
okText: '重新登录',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
})
}
} else {
this.$message.error(`文件上传失败: ${info.file.msg} `)
}
}
},
/* 图片预览 */
getImgView (text) {
if (text && text.indexOf(',') > 0) {
text = text.substring(0, text.indexOf(','))
}
return getFileAccessHttpUrl(text)
},
/* 文件下载 */
// update--autor:lvdandan-----date:20200630------for:修改下载文件方法名uploadFile改为downloadFile------
downloadFile (text) {
if (!text) {
this.$message.warning('未知的文件')
return
}
if (text.indexOf(',') > 0) {
text = text.substring(0, text.indexOf(','))
}
const url = getFileAccessHttpUrl(text)
window.open(url)
}
}
}
+27
View File
@@ -0,0 +1,27 @@
import { formatDate } from '@/utils/util'
import Area from '@/components/_util/Area'
const onlUtil = {
data () {
return {
mixin_pca: '',
flowCodePre: 'onl_'
}
},
created () {
this.mixin_pca = new Area(this.$Jpcaa)
},
methods: {
simpleDateFormat (millisecond, format) {
return formatDate(millisecond, format)
},
getPcaText (code) {
return this.mixin_pca.getText(code)
},
getPcaCode (text) {
return this.mixin_pca.getCode(text)
}
}
}
export { onlUtil }
+63
View File
@@ -0,0 +1,63 @@
import store from '@/store/'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import Vue from 'vue'
export const WebsocketMixin = {
mounted () {
this.initWebSocket()
},
destroyed: function () {
// 离开页面生命周期函数
this.websocketOnclose()
},
methods: {
initWebSocket: function () {
const token = Vue.ls.get(ACCESS_TOKEN)
console.log('------------WebSocket连接成功')
// WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
const userId = store.getters.userInfo.id
if (!this.socketUrl.startsWith('/')) {
this.socketUrl = '/' + this.socketUrl
}
if (!this.socketUrl.endsWith('/')) {
this.socketUrl = this.socketUrl + '/'
}
const url = window._CONFIG.domianURL.replace('https://', 'wss://').replace('http://', 'ws://') + this.socketUrl + userId + '/' + token
this.websock = new WebSocket(url)
this.websock.onopen = this.websocketOnopen
this.websock.onerror = this.websocketOnerror
this.websock.onmessage = this.websocketOnmessage
this.websock.onclose = this.websocketOnclose
},
websocketOnopen: function () {
console.log('WebSocket连接成功')
},
websocketOnerror: function () {
console.log('WebSocket连接发生错误')
this.reconnect()
},
websocketOnclose: function () {
this.reconnect()
},
websocketSend (text) {
// 数据发送
try {
this.websock.send(text)
} catch (err) {
console.log('send failed (' + err.code + ')')
}
},
reconnect () {
const that = this
if (that.lockReconnect) return
that.lockReconnect = true
// 没连接上会一直重连,设置延迟避免请求过多
// setTimeout(function () {
// console.info('尝试重连...')
// that.initWebSocket()
// that.lockReconnect = false
// }, 5000)
}
}
}
+279
View File
@@ -0,0 +1,279 @@
import _ from 'lodash'
const events = {
start: 'mousedown',
move: 'mousemove',
stop: 'mouseup'
}
const tableAll = [] // 单个页面存放多个表格的columns
let columnsAll = []
let columnsKey = ''
let minColumn = [] // 存放设置最小宽的列及宽度
const DragHandler = {
name: 'nio-drag-handler',
// 获取混入的方法(重新设置表头宽度)
inject: ['onResizeColumn'],
props: {
column: { type: Object, required: true },
minWidth: { type: Number, required: true }
},
data () {
return {
dragging: false,
thWidth: 0, // 列头的宽度,用于计算
startX: 0,
moveEvent: {
remove: function () {
}
},
stopEvent: {
remove: function () {
}
}
}
},
// 销毁监听
beforeDestroy () {
this.removeEvents()
},
methods: {
// 鼠标开始拖拽
handleMouseDown (e) {
e.stopPropagation()
e.preventDefault()
this.handleStart(e)
},
handleStart (e) {
this.dragging = true
this.removeEvents()
this.thWidth = this.$el.parentNode.getBoundingClientRect().width
if (e instanceof MouseEvent && e.which !== 1) {
return
}
if (e.stopPropagation) e.stopPropagation()
this.startX = e.pageX
this.moveEvent = addEventListenerWrap(document.documentElement, events.move, this.handleMove)
this.stopEvent = addEventListenerWrap(document.documentElement, events.stop, this.handleStop)
},
handleMove (e) {
this.updateWidth(e)
},
handleStop (e) {
this.dragging = false
this.updateWidth(e)
this.removeEvents()
},
updateWidth (e) {
const pageX = e.pageX
const tmpDeltaX = this.startX - pageX
let w = Math.max(this.thWidth - tmpDeltaX, this.minWidth)
w = Math.min(w, Infinity)
this.onResizeColumn(w, this.column)
},
removeEvents () {
this.moveEvent.remove()
this.stopEvent.remove()
}
},
// 渲染div 绑定拖拽
render (h) {
const line = h('div', { class: 'nio-drag-handler-line' }, [])
return h('div', { class: 'nio-drag-handler', on: { mousedown: this.handleMouseDown } }, [line])
}
}
const ResizeHeaderOne = function (val, name, minWidths) {
columnsAll = val
columnsKey = name
minColumn = minWidths
if (tableAll.indexOf(val) === -1) {
tableAll.push(val)
}
return (h, props, children) => {
const { key, column, ...restProps } = props
let col = {}
// 处理多级表头
// col = getRenderCoL(key, val)
col = getRenderCoL(key, columnsAll)
let content = [].concat(children)
if (col) {
let handlerVNode
if (minColumn && minWidths !== undefined && minColumn.length > 0) {
// 存放所有需要手动设置最小宽度的列的dataIndex
const colsDataIndex = []
minColumn.forEach((item) => {
colsDataIndex.push(item[0].dataIndex)
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(item[1]),
column: col
}
}, [])
content = content.concat(
handlerVNode
)
})
// 不需要手动设置最小宽度的列
if (colsDataIndex.indexOf(col.dataIndex) === -1) {
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(col.width, 100),
column: col
}
}, [])
content = content.concat(
handlerVNode
)
}
} else {
handlerVNode = h(DragHandler, {
props: {
width: col.width,
minWidth: Math.min(col.width, 100),
column: col
}
}, [])
content = content.concat(
handlerVNode
)
}
}
let className = ''
if ((restProps.attrs && restProps.attrs.colSpan && restProps.attrs.colSpan === 1) || (restProps.attrs && restProps.attrs.colSpan && restProps.attrs.colSpan > 0)) {
className = ' second'
}
return h('th', {
key,
props: { col },
...Object.assign({}, restProps, { class: (restProps.class || '') + ' nio-header-th' + className })
}, content)
}
}
export const ResizeHeader = {
methods: {
drag (columns, name, minWidths) {
return {
header: {
// minWidths : 最小宽度 => [[需要设置的列,最小宽],[需要设置的列,最小宽],...]
cell: ResizeHeaderOne(columns, name, minWidths)
}
}
}
}
}
const getRenderCoL = (key, tbCols) => {
let result = ''
_.forEach(tbCols, (item) => {
if (item.children) {
result = getRenderCoL(key, item.children)
return !result
} else {
const k = item.dataIndex || item.key
if (k === key) {
result = item
return false
}
}
})
return result
}
// 拖拽的节流方法
const throttle2 = (fn, delay) => {
let valid = true
return (...args) => {
if (!valid) {
return
}
valid = false
setTimeout(() => {
fn(...args)
valid = true
}, delay)
}
}
// 对table组件进行重构的核心方法组件
// 监听鼠标移动的方法
function addEventListenerWrap (target, eventType, cb) {
if (target && target.addEventListener) {
target.addEventListener(eventType, cb)
}
return {
remove: () => {
if (target && target.removeEventListener) {
target.removeEventListener(eventType, cb)
}
}
}
}
// 在table组件中混入的一个方法 provide => onResizeColumn
// 目的是在table重写中(DragHandler方法)
// 可以用到构造的onResizeColumn方法(重新设置表头的宽度)
export const ResizeColumnProvide = {
name: 'ResizeColumnProvideMixin',
provide () {
return {
onResizeColumn: this.onResizeColumn
}
},
data () {
const onResizeColumn = throttle2(this._resizeColumn, 30)
return {
moving: false, // 这个属性是为了在拖拽时 阻止表头触发排序的功能
onResizeColumn
}
},
methods: {
_resizeColumn (w, column) {
tableAll.forEach(item => {
item.forEach((i) => {
if (i === column && i.dataIndex === column.dataIndex) {
columnsAll = item
}
})
})
this.moving = true
const time = setTimeout(() => {
this.moving = false
clearTimeout(time)
}, 2000)
// 在拖拽时找到对应表头 重新设置表头的宽度
let num = -1
let numOne = -1
for (let i = 0; i < columnsAll.length; i++) {
if (columnsAll[i].dataIndex === column.dataIndex) {
num = i
break
}
if (columnsAll[i].children && columnsAll[i].children.length > 0) {
for (let j = 0; j < columnsAll[i].children.length; j++) {
if (columnsAll[i].children[j].dataIndex === column.dataIndex) {
num = i
numOne = j
break
}
}
}
}
// const matchedIndex = columns.findIndex(item => item.dataIndex === column.dataIndex)
// console.log(matchedIndex)
// columns[matchedIndex].width = w
if (numOne > -1) {
columnsAll[num].children[numOne].width = w
} else {
columnsAll[num].width = w
}
this[columnsKey] = columnsAll
}
}
}