提交 408ba038 编写于 作者: Mosher's avatar Mosher

update:表格列代码表值格式化支持

上级 87e8d584
{{#*inline "COLUMNTEXT"}}
{{#if (and item.psAppCodeList (eq item.cLConvertMode 'FRONT'))}}
<AppCodelist
codeListTag="{{item.psAppCodeList.codeListTag}}"
:context="state.context"
:data="record"
:value="text"
:viewParams="state.viewParams"
></AppCodelist>
{{else if (and item.enableLinkView item.linkPSAppView)}}
{{!-- 链接视图暂未支持 --}}
<span class="text">\{{text}}</span>
{{else}}
{{#if item.valueFormat}}
<AppSpan
name="{{lowerCase item.codeName}}"
:value="text"
{{#if item.psAppDEField}}
:dataType="{{item.psAppDEField.stdDataType}}"
{{/if}}
valueFormat="{{item.valueFormat}}"
:precision="{{#if item.precision}}{{item.precision}}{{else}}0{{/if}}"
></AppSpan>
{{else}}
{{!-- 自定义代码暂未支持, userTag暂未支持 --}}
<span class="text">\{{text}}</span>
{{/if}}
{{/if}}
{{/inline}}
{{#if (eq item.columnType 'GROUPGRIDCOLUMN')}}
{{#each item.psDEGridColumns as | column |}}
{{> @macro/front-end/widgets/grid-detail/include-grid.hbs type="COLUMN" item=column}}
......@@ -22,11 +51,23 @@
</AppFormItem>
</div>
<div v-else class="text-cell">
<span class="text">\{{text}}</span>
{{#if (and item.psDEUIAction item.psDEUIAction.uIActionTag)}}
<a style="{ display: 'block' }" @click="columnUIAction">
{{> COLUMNTEXT}}
</a>
{{else}}
{{> COLUMNTEXT}}
{{/if}}
</div>
{{else}}
<div class="text-cell">
<span class="text">\{{text}}</span>
{{#if (and item.psDEUIAction item.psDEUIAction.uIActionTag)}}
<a style="{ display: 'block' }" @click="columnUIAction">
{{> COLUMNTEXT}}
</a>
{{else}}
{{> COLUMNTEXT}}
{{/if}}
</div>
{{/if}}
{{else if (eq item.columnType 'UAGRIDCOLUMN')}}
......
......@@ -24,7 +24,9 @@ export const AppCodeListConfig:IParam = {
{{#if appCodeList.psCodeItems}}
'items':[
{{#each appCodeList.psCodeItems as |codeItem|}}
{'value': {{#if appCodeList.codeItemValueNumber}}{{codeItem.value}}{{else}}'{{codeItem.value}}'{{/if}}, 'text': '{{codeItem.text}}','codeName': '{{codeItem.codeName}}' }{{#unless @last}},{{/unless}}
{{#codeItem}}
{'value': {{#if appCodeList.codeItemValueNumber}}{{value}}{{else}}'{{value}}'{{/if}}, 'text': '{{text}}','codeName': '{{codeName}}','textClass': '{{#if textCls}}{{textCls}}{{else if psSysCss}}{{psSysCss.cssName}}{{/if}}',{{#if psSysImage}}{{#if psSysImage.cssClass}}'cssClass': '{{psSysImage.cssClass}}',{{/if}}{{#if psSysImage.imagePath}}'imagePath': '{{psSysImage.imagePath}}'{{/if}}{{/if}} }{{#unless @last}},{{/unless}}
{{/codeItem}}
{{/each}}
]
{{/if}}
......
<script setup lang="ts">
import { AppCodeListConfig } from '@/app/config';
import { deepCopy, IParam, isExistAndNotEmpty } from '@core';
import { ref, Ref } from 'vue';
interface Props {
codeListTag: string,
context: any,
data?: any,
localContext?: any,
localParam?: any,
name: string,
textOnly?: boolean,
textSeparator?: string
value: any,
viewParams?: any,
}
const props = withDefaults(defineProps<Props>(), {
textOnly: true,
textSeparator: '、'
});
// 代码表服务
const codeListService = App.getCodeListService();
// 显示文本值
const text: Ref<string> = ref('');
// 代码表项
const items: Ref<any[]> = ref([]);
// 默认值分隔符
const valueSeparator: string = ',';
// 数据处理
const handleData = async () => {
const tag = props.codeListTag;
if (!tag) {
return;
}
const context = deepCopy(props.context);
const viewParams = deepCopy(props.viewParams);
handleParams(context, viewParams);
codeListService.getCodeListItems({ tag, context, viewParams }).then((codeListItems: IParam[]) => {
items.value = getSelectedItems(codeListItems);
if (props.textOnly) {
text.value = getText();
}
}).catch((error) => {
console.warn(`代码表 ${tag} 获取数据项失败`);
})
}
const handleParams = (context: IParam, viewParams: IParam) => {
}
// 获取文本
const getText = (): string => {
let text: string = '';
items.value.forEach((item: any, index: number) => {
if (index !== 0) {
text += props.textSeparator;
}
text += item.text;
});
return isExistAndNotEmpty(text) ? text : '---';
}
// 获取选中数据
const getSelectedItems = (codeListItems: IParam[]): any[] => {
const codeList = AppCodeListConfig[props.codeListTag];
const _valueSeparator = codeList.valueSeparator || valueSeparator;
// 值的集合
let values: any[] = [];
// 选中代码表项的集合
const selectedItems: any[] = [];
if(codeList.orMode == 'NUM'){
codeListItems.forEach((_item: any, index: number)=>{
const nValue = parseInt((props.value as any), 10);
if((parseInt(_item.value, 10) & nValue) > 0){
selectedItems.push(deepCopy(_item));
}
});
} else {
// 数值直接赋值
if (typeof props.value === 'number'){
values = [props.value];
} else {
values = [...props.value.toString().split(_valueSeparator)];
}
values.forEach((v: any)=>{
let selected = codeListItems.find((_item:any)=> _item.value == v);
if (selected) {
selectedItems.push(selected);
} else {
selectedItems.push({text: v});
}
})
}
return selectedItems;
}
// 部件挂载
onMounted(() => {
handleData();
})
</script>
<template>
<div class="app-codelist">
<span v-if="textOnly">{{text}}</span>
<template v-else>
<template v-if="items.length == 0">
<span>---</span>
</template>
<template v-else>
<template v-for="(item, index) in items" :key="index">
<span class="app-codelist-item">
<i v-if="item.cssClass" :class="item.cssClass"></i>
<img v-if="item.imagePath" :src="item.imagePath" />
<span :class="item.textClass" :style="item.color ? { color: item.color } : ''">
{{item.text}}
</span>
<span v-if="index !== items.length - 1">{{textSeparator}}</span>
</span>
</template>
</template>
</template>
</div>
</template>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册