fix: 列表展示模板字段失效

This commit is contained in:
chenjianxing 2021-06-16 19:53:50 +08:00 committed by jianxing
parent 062a237775
commit a9f2301033
6 changed files with 43 additions and 9 deletions

View File

@ -18,8 +18,7 @@
<script>
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import treeTransfer from 'el-tree-transfer'
import {saveCustomTableHeader} from "@/common/js/tableUtils";
import {CUSTOM_TABLE_HEADER} from "@/common/js/default-table-header";
import {getAllFieldWithCustomFields, saveCustomTableHeader} from "@/common/js/tableUtils";
export default {
name: "MsCustomTableHeader",
@ -37,6 +36,7 @@ export default {
},
props: {
type: String,
customFields: Array
},
methods: {
allowDrop(draggingNode, dropNode, type) {
@ -44,7 +44,7 @@ export default {
},
open(items) {
items = JSON.parse(JSON.stringify(items));
let fields = JSON.parse(JSON.stringify(CUSTOM_TABLE_HEADER[this.type]));
let fields = getAllFieldWithCustomFields(this.type, this.customFields);
this.selectedKeys = [];
this.fromFields = [];
this.selectedKeys = items.map(item => item.key);

View File

@ -56,8 +56,9 @@
<ms-custom-table-header
v-if="fieldKey"
@reload="reloadTable"
@reload="resetHeader"
:type="fieldKey"
:custom-fields="customFields"
ref="customTableHeader"/>
</div>
@ -187,6 +188,7 @@ export default {
},
fields: Array,
fieldKey: String,
customFields: Array
},
mounted() {
getLabel(this, TEST_CASE_LIST);
@ -291,8 +293,11 @@ export default {
openCustomHeader() {
this.$refs.customTableHeader.open(this.fields);
},
resetHeader() {
this.$emit('update:fields', getCustomTableHeader(this.fieldKey, this.customFields));
this.reloadTable();
},
reloadTable() {
this.$emit('update:fields', getCustomTableHeader(this.fieldKey));
this.tableActive = false;
this.$nextTick(() => {
this.tableActive = true;

View File

@ -19,6 +19,7 @@
:fields.sync="fields"
field-key="TRACK_TEST_CASE"
@refresh="initTableData"
:custom-fields="testCaseTemplate.customFields"
ref="table">
<span v-for="item in fields" :key="item.key">

View File

@ -22,6 +22,7 @@
:fields.sync="fields"
field-key="ISSUE_LIST"
@refresh="getIssues"
:custom-fields="issueTemplate.customFields"
ref="table"
>
<span v-for="(item) in fields" :key="item.key">

View File

@ -171,7 +171,6 @@ export const CUSTOM_TABLE_HEADER = {
{id: 'nodePath', key: '5', label: i18n.t('test_track.case.module')},
{id: 'updateTime', key: '6', label: i18n.t('commons.update_time')},
{id: 'createUser', key: '7', label: i18n.t('commons.create_user')},
{id: 'maintainer', key: '8', label: i18n.t('custom_field.case_maintainer')},
],
//缺陷列表
ISSUE_LIST: [

View File

@ -237,11 +237,17 @@ export function getPageDate(response, page) {
* @param key
* @returns {[]|*}
*/
export function getCustomTableHeader(key) {
let fieldSetting = CUSTOM_TABLE_HEADER[key];
export function getCustomTableHeader(key, customFields) {
let fieldSetting = getAllFieldWithCustomFields(key, customFields);
return getCustomTableHeaderByFiledSetting(key, fieldSetting);
}
/**
* 获取 localStorage 的值过滤
* @param key
* @param fieldSetting
* @returns {[]|*}
*/
function getCustomTableHeaderByFiledSetting(key, fieldSetting) {
let fieldStr = localStorage.getItem(key);
if (fieldStr !== null) {
@ -268,7 +274,7 @@ function getCustomTableHeaderByFiledSetting(key, fieldSetting) {
* @returns {[]|*}
*/
export function getTableHeaderWithCustomFields(key, customFields) {
let fieldSetting = [CUSTOM_TABLE_HEADER[key]];
let fieldSetting = [...CUSTOM_TABLE_HEADER[key]]; // 复制
let keys = getCustomFieldsKeys(customFields);
customFields.forEach(item => {
if (!item.key) {
@ -287,6 +293,28 @@ export function getTableHeaderWithCustomFields(key, customFields) {
return getCustomTableHeaderByFiledSetting(key, fieldSetting);
}
/**
* 获取所有字段
* @param key
* @param customFields
* @returns {*[]}
*/
export function getAllFieldWithCustomFields(key, customFields) {
let fieldSetting = [...CUSTOM_TABLE_HEADER[key]];
if (customFields) {
customFields.forEach(item => {
let field = {
id: item.name,
key: item.key,
label: item.name,
isCustom: true
}
fieldSetting.push(field);
});
}
return fieldSetting;
}
export function generateTableHeaderKey(keys) {
let customFieldKeys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let i = 0; i < customFieldKeys.length; i++) {