【fix bug】66425【前端】升级vxe-table组件到3.6.10版本,并同步适配当前框架中所有使用到vxe-table组件的示例

This commit is contained in:
zhaoxiao
2023-03-15 09:48:17 +08:00
parent 131cbd9765
commit 61c230cb87
21 changed files with 449 additions and 295 deletions
@@ -12,7 +12,7 @@ import JVxeSubPopover from './JVxeSubPopover'
import JVxeDetailsModal from './JVxeDetailsModal'
import JVxePagination from './JVxePagination'
import { cloneObject, getVmParentByName, pushIfNotExist, randomString, simpleDebounce } from '@/utils/util'
import { UtilTools } from 'vxe-table/packages/tools/src/utils'
import { UtilTools } from 'vxe-table/packages/tools/utils'
import { getNoAuthCols } from '@/utils/authFilter'
export default {
@@ -351,7 +351,7 @@ export default {
this.statistics.average = []
// 处理成vxe可识别的columns
columns.forEach(column => {
columns.forEach((column, columnIndex) => {
if (this.excludeCode.indexOf(column.key) >= 0) {
return false
}
@@ -389,7 +389,7 @@ export default {
col[renderName] = renderOptions
// 处理字典
if (col.dictCode) {
this._loadDictConcatToOptions(col)
this._loadDictConcatToOptions(col, columnIndex)
}
// 处理校验
if (col.validateRules) {
@@ -631,7 +631,7 @@ export default {
}
// 显示详细信息
if (column.own.showDetails) {
if (column.params && column.params.showDetails) {
// 两个如果同时存在的话会出现死循环
if ($refs.subPopover) {
$refs.subPopover.close()
@@ -669,13 +669,15 @@ export default {
// 单元格编辑状态下被关闭时会触发该事件
handleEditClosed ({ column }) {
// 执行增强
getEnhancedMixins(column.own.$type, 'aopEvents').editClosed.apply(this, arguments)
getEnhancedMixins(column.params.type, 'aopEvents').editClosed.apply(this, arguments)
},
// 单元格被激活编辑时会触发该事件
handleEditActived ({ column }) {
// 执行增强
getEnhancedMixins(column.own.$type, 'aopEvents').editActived.apply(this, arguments)
if (column.params && column.params.type) {
getEnhancedMixins(column.params.type, 'aopEvents').editActived.apply(this, arguments)
}
},
/** 表尾数据处理方法,用于显示统计信息 */
@@ -794,10 +796,10 @@ export default {
this.$set(row, colKey, newValue)
// 触发 valueChange 事件
this.trigger('valueChange', {
type: column.own.$type,
type: column.params.type,
value: newValue,
oldValue: oldValue,
col: column.own,
col: column.params,
column: column,
isSetValues: true
})
@@ -1067,7 +1069,7 @@ export default {
},
/** 加载数据字典并合并到 options */
_loadDictConcatToOptions (column) {
_loadDictConcatToOptions (column, columnIndex) {
initDictOptions(column.dictCode).then((res) => {
if (res.success) {
const newOptions = (column.options || [])// .concat(res.result)
@@ -1077,6 +1079,9 @@ export default {
newOptions.push(item)
})
this.$set(column, 'options', newOptions)
const newParams = Object.assign(column.params, { options: newOptions })
this.$set(column, 'params', newParams)
this.$set(this._innerColumns, columnIndex, column)
} else {
console.group(`JVxeTable 查询字典(${column.dictCode})发生异常`)
console.warn(res.message)
@@ -1182,7 +1187,7 @@ export default {
XEUtils.remove(insertList, row => rows.indexOf(row) > -1)
xTable.handleTableData()
xTable.updateFooter()
xTable.updateCache()
xTable.updateCache && xTable.updateCache()
xTable.checkSelectionStatus()
if (scrollYLoad) {
xTable.updateScrollYSpace()
@@ -1219,7 +1224,9 @@ export default {
data[this.dragSortKey] = (idx + 1)
})
}
await xTable.updateCache(true)
if (xTable.updateCache) {
await xTable.updateCache(true)
}
return await xTable.updateData()
},
@@ -1255,7 +1262,7 @@ export default {
const { xTable } = this.$refs.vxe.$refs
// 添加默认值
xTable.tableFullColumn.forEach(column => {
const col = column.own
const col = column.params || {}
if (col.key && (record[col.key] == null || record[col.key] === '')) {
// 设置默认值
const createValue = getEnhancedMixins(col.$type || col.type, 'createValue')
@@ -1436,7 +1443,7 @@ function handlerConvertToValidator (event) {
rule.handler(event, (flag, msg) => {
let message = rule.message
if (typeof msg === 'string') {
message = replaceProps(column.own, msg)
message = replaceProps(column.params, msg)
}
if (flag == null) {
resolve(message)
@@ -1455,7 +1462,7 @@ function uniqueValidator (event) {
const tableData = this.getTableData()
let findCount = 0
for (const rowData of tableData) {
if (rowData[column.own.key] === cellValue) {
if (rowData[column.params.key] === cellValue) {
if (++findCount >= 2) {
return Promise.reject(new Error(rule.message))
}
@@ -50,7 +50,7 @@ export default {
visible: true
},
getValue (value) {
const { own: col } = this.column
const { params: col } = this.column
// 处理 customValue
if (Array.isArray(col.customValue)) {
const customValue = getCustomValue(col)
@@ -64,7 +64,7 @@ export default {
}
},
setValue (value) {
const { own: col } = this.column
const { params: col } = this.column
// 判断是否设定了customValue(自定义值)
if (Array.isArray(col.customValue)) {
const customValue = getCustomValue(col)
@@ -74,7 +74,7 @@ export default {
}
},
createValue ({ column }) {
const { own: col } = column
const { params: col } = column
if (Array.isArray(col.customValue)) {
const customValue = getCustomValue(col)
return col.defaultChecked ? customValue[0] : customValue[1]
@@ -93,11 +93,11 @@ function getCustomValue (col) {
</script>
<style lang="less">
// 关闭动画,防止滚动时动态赋值出现问题
.j-vxe-checkbox.no-animation {
.ant-checkbox-inner,
.ant-checkbox-inner::after {
transition: none !important;
}
// 关闭动画,防止滚动时动态赋值出现问题
.j-vxe-checkbox.no-animation {
.ant-checkbox-inner,
.ant-checkbox-inner::after {
transition: none !important;
}
}
</style>
@@ -8,8 +8,7 @@
style="width: 100%;"
@blur="handleBlur"
@change="handleChange"
@search="handleSearchSelect"
>
@search="handleSearchSelect">
<div v-if="loading" slot="notFoundContent">
<a-icon type="loading" />
@@ -47,7 +46,7 @@ export default {
}
const { linkage } = this.renderOptions
if (linkage) {
this.handleComputedSelectOptions(linkage)
return this.handleComputedSelectOptions(linkage)
}
return this.originColumn.options
},
@@ -184,7 +183,7 @@ export default {
})
}
} else {
options = this.column.own.options
options = (this.column.params || {}).options
}
return filterDictText(options, value)
}
@@ -197,7 +196,7 @@ export default {
}
},
setValue (value) {
const { column: { own: col }, params: { $table } } = this
const { column: { params: col }, params: { $table } } = this
// 判断是否是多选
if ((col.props || {}).mode === 'multiple') {
$table.$set(col.props, 'maxTagCount', 1)
@@ -45,12 +45,11 @@
name="file"
:data="{'isup': 1}"
:multiple="false"
:action="originColumn.action"
:action="uploadAction"
:headers="uploadHeaders"
:showUploadList="false"
v-bind="cellProps"
@change="handleChangeUpload"
>
@change="handleChangeUpload">
<a-button icon="upload">{{ originColumn.btnText || '点击上传' }}</a-button>
</a-upload>
</div>
@@ -80,11 +79,15 @@ export default {
}
return headers
},
hasFile () {
return this.innerFile != null
return !!this.innerFile
},
uploadAction () {
if (this.originColumn.action) {
return this.originColumn.action
}
return window._CONFIG.domianURL + '/sys/common/upload'
}
},
watch: {
innerValue: {
@@ -116,7 +119,7 @@ export default {
if (file.status === 'done') {
if (typeof file.response.success === 'boolean') {
if (file.response.success) {
value.path = file.response[col.responseName]
value.path = col.responseName ? file.response[col.responseName] : file.response.result.url
} else {
value.status = 'error'
value.message = file.response.message || '未知错误'
@@ -129,6 +132,10 @@ export default {
value.message = file.response.message || '未知错误'
}
this.innerFile = value
// 上传完成后触发通用change事件,将值抛出去
if (file.status === 'done') {
this.handleChangeCommon(this.innerFile)
}
},
// handleClickPreviewFile(id) {
@@ -43,15 +43,15 @@ installAllCell(VXETable)
// 比如点击了某个组件的弹出层面板之后,此时被激活单元格不应该被自动关闭,通过返回 false 可以阻止默认的行为。
VXETable.interceptor.add('event.clearActived', function (params, event, target) {
// 获取组件增强
const col = params.column.own
const col = params.column.params || {}
const interceptor = getEnhancedMixins(col.$type, 'interceptor')
// 执行增强
const flag = interceptor['event.clearActived'].apply(this, arguments)
if (flag === false) {
return false
}
const path = getEventPath(event)
// 此处判断一下event是否存在,防止后续内容报错
const path = event ? getEventPath(event) : []
for (const p of path) {
let className = p.className || ''
className = typeof className === 'string' ? className : className.toString()
@@ -28,10 +28,10 @@ export default {
return this.renderOptions.caseId
},
originColumn () {
return this.column.own
return this.column.params || {}
},
$type () {
return this.originColumn.$type
return this.originColumn.type
},
rows () {
return this.params.data
@@ -272,7 +272,7 @@ export default {
* @returns 返回新值
*/
createValue ({ row, column, $table, renderOptions, params }) {
return column.own.defaultValue
return (column.params || {}).defaultValue
}
}
}
@@ -307,7 +307,7 @@ export function dispatchEvent ({ cell, $event }, className, handler) {
return
}
window.setTimeout(() => {
const element = cell.getElementsByClassName(className)
const element = cell ? cell.getElementsByClassName(className) : null
if (element && element.length > 0) {
if (typeof handler === 'function') {
handler(element[0])
@@ -49,7 +49,7 @@ const vs = {
initialWebSocket () {
if (this.ws === null) {
const userId = store.getters.userInfo.id
const domain = window._CONFIG.domianURL.replace('https://', 'wss://').replace('http://', 'ws://')
const domain = window._CONFIG.domianWebSocketURL.replace('https://', 'wss://').replace('http://', 'ws://')
const url = `${domain}/vxeSocket/${userId}/${this.pageId}`
this.ws = new WebSocket(url)
@@ -33,12 +33,14 @@ export function installEditRender (VXETable, type, comp, spanComp) {
} else {
spanComp = AllCells[JVXETypes.normal]
}
// 如果是常显的cell,显示模板和编辑模板都用编辑模板
const cellRender = enhanced.switches.visible ? createRender(comp, enhanced, JVXERenderType.editer) : createRender(spanComp, enhanced, JVXERenderType.spaner)
// 添加渲染
VXETable.renderer.add(JVXETypes._prefix + type, {
// 可编辑模板
renderEdit: createRender(comp, enhanced, JVXERenderType.editer),
// 显示模板
renderCell: createRender(spanComp, enhanced, JVXERenderType.spaner),
renderCell: cellRender,
// 增强注册
...enhanced.installOptions
})
@@ -56,7 +58,7 @@ export function installCellRender (VXETable, type, comp = AllCells[JVXETypes.nor
})
}
function createRender (comp, enhanced, renderType) {
export function createRender (comp, enhanced, renderType) {
return function (h, renderOptions, params) {
return [h(comp, {
props: {