v3.8.1发布,代码生成支持关联记录组件

dependabot/maven/jeecg-boot/commons-fileupload-commons-fileupload-1.6.0
JEECG 2025-06-26 11:50:22 +08:00
parent b34bb84fc9
commit e2805050cf
2 changed files with 571 additions and 3 deletions

View File

@ -55,6 +55,7 @@
import { useListPage } from '/@/hooks/system/useListPage';
import { useMessage } from '/@/hooks/web/useMessage';
import { defHttp } from '/@/utils/http/axios';
import { useTableColumns } from '../hooks/useTableColumns';
import { createAsyncComponent } from '@/utils/factory/createAsyncComponent';
import { useFixedHeightModal } from '../hooks/useLinkTable';
@ -148,9 +149,9 @@
};
const extConfigJson = ref<any>({});
// // BasicTable
// const { columns, downloadRowFile, getImgView, getPcaText, getFormatDate, handleColumnResult, hrefComponent, viewOnlineCellImage } =
// useTableColumns(onlineTableContext, extConfigJson);
// BasicTable
const { columns, downloadRowFile, getImgView, getPcaText, getFormatDate, handleColumnResult, hrefComponent, viewOnlineCellImage } =
useTableColumns(onlineTableContext, extConfigJson);
/**
* 查询table列信息 及其他配置

View File

@ -0,0 +1,567 @@
import type { Ref } from 'vue';
import { HrefSlots, OnlineColumn } from '/@/components/jeecg/OnLine/types/onlineConfig';
import { filterMultiDictText } from '/@/utils/dict/JDictSelectUtil';
import { computed, defineAsyncComponent, h, reactive, ref, toRaw, unref, watch, markRaw } from 'vue';
import { useRouter } from 'vue-router';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
import { getAreaTextByCode } from '/@/components/Form/src/utils/Area';
import { createImgPreview } from '/@/components/Preview/index';
import { importViewsFile, _eval } from '/@/utils';
import { useModal } from '/@/components/Modal';
import { getToken } from '/@/utils/auth';
import { downloadFile } from '/@/api/common/api';
import { getWeekMonthQuarterYear, split } from '/@/utils';
/**
* 获取实际列表需要的column配置
* @param onlineTableContext 从数据库中查出来的数据
* @param extConfigJson 扩展配置JSON
*/
export function useTableColumns(onlineTableContext, extConfigJson: Ref<any | undefined>) {
// href
let router = useRouter();
//
const columns = ref<Array<OnlineColumn>>([]);
// bpm_status
//const hasBpmStatus = ref<boolean>(false)
//
const dictOptionInfo = ref<any>({});
//
const selectedKeys = ref<any[]>([]);
//
//const selectRows = ref<Array<any>>([]);
// --computed
const rowSelection = ref<any>(null);
//
let enableScrollBar = ref(true);
// tablescroll
let tableScroll = computed(() => {
if (enableScrollBar.value == true) {
return undefined;
} else {
// X
return { x: false };
}
});
// online -
const [registerOnlineHrefModal, { openModal: openOnlineHrefModal }] = useModal();
const hrefMainTableId = ref('')
// online
const [registerPopModal, { openModal: openPopModal }] = useModal();
const popTableId = ref('')
//
function handleColumnResult(result, type = 'checkbox') {
//
dictOptionInfo.value = result.dictOptions;
// rowSelection
if (result.checkboxFlag == 'Y') {
rowSelection.value = {
selectedRowKeys: selectedKeys,
onChange: onSelectChange,
type,
};
} else {
rowSelection.value = null;
}
//
enableScrollBar.value = result.scrollFlag == 1;
let dataColumns = result.columns;
dataColumns.forEach((column) => {
// update-begin--author:liaozhiyang---date:20230818---forQQYUN-4161
if (column.fieldExtendJson) {
const json = JSON.parse(column.fieldExtendJson);
if (!!json.isFixed) {
column.fixed = 'left';
}
}
// update-end--author:liaozhiyang---date:20230818---forQQYUN-4161
// update-begin--author:liaozhiyang---date:20240517---forTV360X-129href
if (column.hrefSlotName && column.scopedSlots) {
const obj = result.fieldHrefSlots?.find((item) => item.slotName === column.hrefSlotName);
if (obj) {
column.fieldHref = obj;
}
}
// update-end--author:liaozhiyang---date:20240517---forTV360X-129href
Object.keys(column).map((key) => {
// ('') 0
if (column[key] == null) {
delete column[key];
}
});
});
// href
let fieldHrefSlots: HrefSlots[] = result.fieldHrefSlots;
const fieldHrefSlotKeysMap = {};
fieldHrefSlots.forEach((item) => (fieldHrefSlotKeysMap[item.slotName] = item));
let tableColumns: OnlineColumn[] = [];
// href dict 使
tableColumns = handleColumnHrefAndDict(dataColumns, fieldHrefSlotKeysMap);
// bpm_status
bpmStatusFilter(tableColumns);
console.log('-----列表列配置----', tableColumns);
// align
if (onlineTableContext.isTree() === true) {
//
let firstField = result.textField;
let index = -1;
for (let i = 0; i < tableColumns.length; i++) {
if (tableColumns[i].dataIndex == firstField) {
index = i;
break;
}
}
if (index > 0) {
//0-1
let deleteColumns = tableColumns.splice(index, 1);
tableColumns.unshift(deleteColumns[0]);
}
//
if (tableColumns.length > 0) {
tableColumns[0].align = 'left';
}
}
columns.value = tableColumns;
//
onlineTableContext.reloadTable();
}
/**
* 表格选择事件 [expose]
* @param selectedRowKeys
* @param selectRow
*/
function onSelectChange(selectedRowKeys, selectedRows) {
selectedKeys.value = selectedRowKeys;
onlineTableContext['selectedRows'] = toRaw(selectedRows);
onlineTableContext['selectedRowKeys'] = toRaw(selectedRowKeys);
}
/**
* 处理列的href和字典翻译
*/
function handleColumnHrefAndDict(columns: OnlineColumn[], fieldHrefSlotKeysMap: {}): OnlineColumn[] {
for (let column of columns) {
let { customRender, hrefSlotName, fieldType } = column;
// online yyyy-MM-dd (yyyy-MM-dd HH:mm:ss) issues/3042
if (fieldType == 'date' || fieldType == 'Date') {
column.customRender = ({ text }) => {
if (!text) {
return '';
}
if (text.length > 10) {
return text.substring(0, 10);
}
return text;
};
} else if (fieldType == 'link_table') {
//
// update-begin--author:liaozhiyang---date:20250318---forissues/7930
const fieldExtendJson = column.fieldExtendJson ?? '{}';
const json = JSON.parse(fieldExtendJson);
// update-end--author:liaozhiyang---date:20250318---forissues/7930
column.customRender = ({ text, record }) => {
if (!text) {
return '';
}
if(onlineTableContext.isPopList===true){
//
return record[column.dataIndex+"_dictText"]
}else{
let tempIdArray = (text+'').split(',');
//update-begin-author:taoyan date:2023-2-15 for: QQYUN-4286online
let tempLabelArray = [];
if(record[column.dataIndex+"_dictText"]){
tempLabelArray = record[column.dataIndex+"_dictText"].split(',');
}
//update-end-author:taoyan date:2023-2-15 for: QQYUN-4286online
let renderResult:any = []
if(renderResult.length==0){
return ''
}
//display: flex;width: 100%;flex-wrap: wrap;flex-direction: row;
return h('div',{style:{'overflow':'hidden'}}, renderResult);
}
};
} else if (fieldType === 'popup_dict') {
// update-begin--author:liaozhiyang---date:20240402---forQQYUN-8833JPopupDict
column.customRender = ({ text, record }) => {
const dict = record[column.dataIndex + '_dictText'];
if (dict != undefined) {
return record[column.dataIndex + '_dictText'];
}
return text;
};
// update-end--author:liaozhiyang---date:20240402---forQQYUN-8833JPopupDict
} else {
if (!hrefSlotName && column.scopedSlots && column.scopedSlots.customRender) {
//Onlinehref fieldHrefSlotKeysMap href
if (fieldHrefSlotKeysMap.hasOwnProperty(column.scopedSlots.customRender)) {
hrefSlotName = column.scopedSlots.customRender;
}
}
// customRender 使
// hrefSlotName 使href
// href
if (customRender || hrefSlotName) {
let dictCode = customRender as string;
let replaceFlag = '_replace_text_';
// ellipsis
column.ellipsis = true;
column.customRender = ({ text, record }) => {
let value = text;
// dictCode
if (dictCode) {
if (dictCode.startsWith(replaceFlag)) {
let textFieldName = dictCode.replace(replaceFlag, '');
value = record[textFieldName];
} else {
value = filterMultiDictText(unref(dictOptionInfo)[dictCode], text + '');
}
}
//
if (column.showLength) {
if (value && value.length > column.showLength) {
value = value.substr(0, column.showLength) + '...';
}
}
// hrefSlotName a
if (hrefSlotName) {
let field = fieldHrefSlotKeysMap[hrefSlotName];
if (field) {
return h(
'a',
{
onClick: () => handleClickFieldHref(field, record),
},
value
);
}
}
return value;
};
}
// scopedSlots slots
if (column.scopedSlots) {
// slot ellipsis
column.ellipsis = true;
let slots = column.scopedSlots;
column['slots'] = slots;
delete column.scopedSlots;
}
}
}
return columns;
}
/**
* href 点击事件
* @param field
* @param record
*/
function handleClickFieldHref(field, record) {
let href = field.href;
let urlPattern = /(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?/;
let compPattern = /\.vue(\?.*)?$/;
let jsPattern = /{{([^}]+)}}/g; // {{ xxx }}
if (typeof href === 'string') {
if(href.startsWith('ONLINE:')){
// ONLINE:tableId:fieldName
let arr = href.split(':')
hrefMainTableId.value = arr[1];
let fieldName = arr[2];
openOnlineHrefModal(true, {
isUpdate: true,
disableSubmit: true,
hideSub: true,
record:{id: record[fieldName]},
})
}else{
href = href.trim().replace(/\${([^}]+)?}/g, (_s1, s2) => record[s2]);
// {{...}} JS
if (jsPattern.test(href)) {
href = href.replace(jsPattern, function (text, s0) {
try {
// {{ ACCESS_TOKEN }}
if (s0.trim() === 'ACCESS_TOKEN') {
return getToken()
}
// update-begin--author:liaozhiyang---date:20230904---forQQYUN-6390evalnew Functionbuild
return _eval(s0);
// update-end--author:liaozhiyang---date:20230904---forQQYUN-6390evalnew Functionbuild
} catch (e) {
console.error(e);
return text;
}
});
}
if (urlPattern.test(href)) {
window.open(href, '_blank');
} else if (compPattern.test(href)) {
//
openHrefCompModal(href);
} else {
router.push(href);
}
}
}
}
//
const dialogStyle = {
top: 0,
left: 0,
height: '100%',
margin: 0,
padding: 0,
};
// update-begin--author:liaozhiyang---date:20231218---forQQYUN-6366antd4.x
//
const hrefComponent = reactive({
model: {
title: '',
okText: '关闭',
width: '100%',
open: false,
destroyOnClose: true,
style: dialogStyle,
// dialogStyle: dialogStyle,
bodyStyle: { padding: '8px', height: 'calc(100vh - 108px)', overflow: 'auto', overflowX: 'hidden' },
//
cancelButtonProps: { style: { display: 'none' } },
},
on: {
ok: () => (hrefComponent.model.open = false),
cancel: () => (hrefComponent.model.open = false),
},
is: <any>null,
params: {},
});
// update-end--author:liaozhiyang---date:20231218---forQQYUN-6366antd4.x
// --> modal
function openHrefCompModal(href) {
// href
let index = href.indexOf('?');
let path = href;
if (index !== -1) {
path = href.substring(0, index);
let paramString = href.substring(index + 1, href.length);
let paramArray = paramString.split('&');
let params = {};
paramArray.forEach((paramObject) => {
let paramItem = paramObject.split('=');
params[paramItem[0]] = paramItem[1];
});
hrefComponent.params = params;
} else {
hrefComponent.params = {};
}
// update-begin--author:liaozhiyang---date:20231218---forQQYUN-6366antd4.x
hrefComponent.model.open = true;
// update-end--author:liaozhiyang---date:20231218---forQQYUN-6366antd4.x
hrefComponent.model.title = '操作';
hrefComponent.is = markRaw(defineAsyncComponent(() => importViewsFile(path)));
}
//
let fixedAction:any = 'left';
if(onlineTableContext.isTree()){
fixedAction = 'right'
}
const actionColumn = reactive<OnlineColumn>({
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: fixedAction,
align: 'center',
width: 150,
});
//
watch(() => extConfigJson?.value, () => {
if (extConfigJson?.value?.tableFixedAction === 1) {
actionColumn.fixed = extConfigJson?.value?.tableFixedActionType || 'right';
//
if(onlineTableContext.isTree()){
actionColumn.fixed = 'right'
}
}
});
//
function bpmStatusFilter(tableColumns: OnlineColumn[]): boolean {
let flag = false;
for (let i = 0; i < tableColumns.length; i++) {
let item = tableColumns[i];
let fieldName = item.dataIndex;
if (fieldName!.toLowerCase() == 'bpm_status') {
flag = true;
break;
}
}
onlineTableContext['hasBpmStatus'] = flag;
return flag;
}
/**
* 文件
* @param text
*/
function downloadRowFile(text, record, column, id) {
if (!text) {
return;
}
// update-begin--author:liaozhiyang---date:20240124---forQQYUN-8020online
if (text.indexOf(',') > 0) {
downloadFile(`/online/cgform/field/download/${id}/${record.id}/${column.dataIndex}`, `文件_${record.id}.zip`);
} else {
const url = getFileAccessHttpUrl(text);
window.open(url);
}
// update-end--author:liaozhiyang---date:20240124---forQQYUN-8020online
}
/**
* 图片
* @param text
*/
function getImgView(text) {
if (text && text.indexOf(',') > 0) {
// update-begin--author:liaozhiyang---date:20250325---forissues/7990
text = split(text)[0];
// update-end--author:liaozhiyang---date:20250325---forissues/7990
}
return getFileAccessHttpUrl(text);
}
/**
* 根据编码获取省市区文本
* @param code
*/
function getPcaText(code) {
if (!code) {
return '';
}
return getAreaTextByCode(code);
}
/**
* 日期格式化
* @param text
*/
function getFormatDate(text, column) {
if (!text) {
return '';
}
let a = text;
if (a.length > 10) {
a = a.substring(0, 10);
}
// update-begin--author:liaozhiyang---date:20240430---forissues/6094online ()
let fieldExtendJson = column?.fieldExtendJson;
if (fieldExtendJson) {
fieldExtendJson = JSON.parse(fieldExtendJson);
if (fieldExtendJson.picker && fieldExtendJson.picker != 'default') {
const result = getWeekMonthQuarterYear(a);
return result[fieldExtendJson.picker];
}
}
// update-end--author:liaozhiyang---date:20240430---forissues/6094online ()
return a;
}
watch(selectedKeys, () => {
onlineTableContext['selectedRowKeys'] = toRaw(selectedKeys.value);
});
onlineTableContext['clearSelectedRow'] = () => {
selectedKeys.value = [];
onlineTableContext['selectedRows'] = [];
onlineTableContext['selectedRowKeys'] = [];
};
/**
* 预览列表 cell 图片
* @param text
*/
function viewOnlineCellImage(text) {
if (text) {
let imgList: any = [];
// update-begin--author:liaozhiyang---date:20250325---forissues/7990
const arr = split(text);
// update-end--author:liaozhiyang---date:20250325---forissues/7990
for (let str of arr) {
if (str) {
imgList.push(getFileAccessHttpUrl(str));
}
}
createImgPreview({ imageList: imgList });
}
}
/**
* link table控件在列表上显示 支持点击跳转表单
* @param id
* @param hrefTableName
*/
const onlinePopModalRef = ref();
async function handleClickLinkTable(id, hrefTableName, isListReadOnly){
popTableId.value = hrefTableName;
let formStatus = await onlinePopModalRef.value.getFormStatus();
//
if(formStatus==true){
hrefMainTableId.value = hrefTableName;
openOnlineHrefModal(true, {
isUpdate: true,
disableSubmit: true,
hideSub: true,
record:{id: id},
})
}else{
openPopModal(true, {
isUpdate: true,
// update-begin--author:liaozhiyang---date:20250318---forissues/7930
disableSubmit: isListReadOnly ? true : false,
// update-end--author:liaozhiyang---date:20250318---forissues/7930
record: {
id: id
}
});
}
}
return {
columns,
actionColumn,
selectedKeys,
rowSelection,
enableScrollBar,
tableScroll,
downloadRowFile,
getImgView,
getPcaText,
getFormatDate,
handleColumnResult,
onSelectChange,
hrefComponent,
viewOnlineCellImage,
hrefMainTableId,
registerOnlineHrefModal,
registerPopModal,
openPopModal,
openOnlineHrefModal,
onlinePopModalRef,
popTableId,
handleClickFieldHref,
};
}